+ if (!TEST_ptr(dh = DH_new())
+ || !TEST_ptr(p = BN_new())
+ || !TEST_ptr(q = BN_new())
+ || !TEST_ptr(g = BN_new())
+ || !TEST_ptr(priv_key = BN_new()))
+ goto err1;
+
+ /*
+ * I) basic tests
+ */
+
+ /* using a small predefined Sophie Germain DH group with generator 3 */
+ if (!TEST_true(BN_set_word(p, 4079L))
+ || !TEST_true(BN_set_word(q, 2039L))
+ || !TEST_true(BN_set_word(g, 3L))
+ || !TEST_true(DH_set0_pqg(dh, p, q, g)))
+ goto err1;
+
+ /* test the combined getter for p, q, and g */
+ DH_get0_pqg(dh, &p2, &q2, &g2);
+ if (!TEST_ptr_eq(p2, p)
+ || !TEST_ptr_eq(q2, q)
+ || !TEST_ptr_eq(g2, g))
+ goto err2;
+
+ /* test the simple getters for p, q, and g */
+ if (!TEST_ptr_eq(DH_get0_p(dh), p2)
+ || !TEST_ptr_eq(DH_get0_q(dh), q2)
+ || !TEST_ptr_eq(DH_get0_g(dh), g2))
+ goto err2;
+
+ /* set the private key only*/
+ if (!TEST_true(BN_set_word(priv_key, 1234L))
+ || !TEST_true(DH_set0_key(dh, NULL, priv_key)))
+ goto err2;
+
+ /* test the combined getter for pub_key and priv_key */
+ DH_get0_key(dh, &pub_key2, &priv_key2);
+ if (!TEST_ptr_eq(pub_key2, NULL)
+ || !TEST_ptr_eq(priv_key2, priv_key))
+ goto err3;
+
+ /* test the simple getters for pub_key and priv_key */
+ if (!TEST_ptr_eq(DH_get0_pub_key(dh), pub_key2)
+ || !TEST_ptr_eq(DH_get0_priv_key(dh), priv_key2))
+ goto err3;
+
+ /* now generate a key pair ... */
+ if (!DH_generate_key(dh))
+ goto err3;
+
+ /* ... and check whether the private key was reused: */
+
+ /* test it with the combined getter for pub_key and priv_key */
+ DH_get0_key(dh, &pub_key2, &priv_key2);
+ if (!TEST_ptr(pub_key2)
+ || !TEST_ptr_eq(priv_key2, priv_key))
+ goto err3;
+
+ /* test it the simple getters for pub_key and priv_key */
+ if (!TEST_ptr_eq(DH_get0_pub_key(dh), pub_key2)
+ || !TEST_ptr_eq(DH_get0_priv_key(dh), priv_key2))
+ goto err3;
+
+ /* check whether the public key was calculated correctly */
+ TEST_uint_eq(BN_get_word(pub_key2), 3331L);
+
+ /*
+ * II) key generation
+ */
+
+ /* generate a DH group ... */