summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorShane Lontis <shane.lontis@oracle.com>2020-01-31 08:18:46 +1000
committerShane Lontis <shane.lontis@oracle.com>2020-01-31 08:18:46 +1000
commitca2bf555cd64bc9624af1259ce3cd27f95a5763e (patch)
treee02beb157e56973ada62c679cb7b3b8756e86dfe /test
parentcd624ccd41ac3ac779c1c7a7a1e63427ce9588dd (diff)
Add support for DH 'modp' group parameters (RFC 3526)
Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/10897)
Diffstat (limited to 'test')
-rw-r--r--test/dhtest.c33
-rw-r--r--test/evp_extra_test.c24
2 files changed, 50 insertions, 7 deletions
diff --git a/test/dhtest.c b/test/dhtest.c
index e8a91f17f8..a357d0262f 100644
--- a/test/dhtest.c
+++ b/test/dhtest.c
@@ -676,6 +676,38 @@ static int rfc7919_test(void)
DH_free(b);
return ret;
}
+
+static int prime_groups[] = {
+ NID_ffdhe2048,
+ NID_ffdhe3072,
+ NID_ffdhe4096,
+ NID_ffdhe6144,
+ NID_ffdhe8192,
+ NID_modp_2048,
+ NID_modp_3072,
+ NID_modp_4096,
+ NID_modp_6144,
+};
+
+static int dh_test_prime_groups(int index)
+{
+ int ok = 0;
+ DH *dh = NULL;
+ const BIGNUM *p, *q, *g;
+
+ if (!TEST_ptr(dh = DH_new_by_nid(prime_groups[index])))
+ goto err;
+ DH_get0_pqg(dh, &p, &q, &g);
+ if (!TEST_ptr(p) || !TEST_ptr(q) || !TEST_ptr(g))
+ goto err;
+
+ if (!TEST_int_eq(DH_get_nid(dh), prime_groups[index]))
+ goto err;
+ ok = 1;
+err:
+ DH_free(dh);
+ return ok;
+}
#endif
@@ -687,6 +719,7 @@ int setup_tests(void)
ADD_TEST(dh_test);
ADD_TEST(rfc5114_test);
ADD_TEST(rfc7919_test);
+ ADD_ALL_TESTS(dh_test_prime_groups, OSSL_NELEM(prime_groups));
#endif
return 1;
}
diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c
index 57f5010381..4dfcd26c28 100644
--- a/test/evp_extra_test.c
+++ b/test/evp_extra_test.c
@@ -1444,16 +1444,25 @@ static int test_decrypt_null_chunks(void)
#ifndef OPENSSL_NO_DH
static int test_EVP_PKEY_set1_DH(void)
{
- DH *x942dh, *pkcs3dh;
- EVP_PKEY *pkey1, *pkey2;
+ DH *x942dh = NULL, *noqdh = NULL;
+ EVP_PKEY *pkey1 = NULL, *pkey2 = NULL;
int ret = 0;
+ BIGNUM *p, *g = NULL;
+
+ if (!TEST_ptr(p = BN_new())
+ || !TEST_ptr(g = BN_new())
+ || !BN_set_word(p, 9999)
+ || !BN_set_word(g, 2)
+ || !TEST_ptr(noqdh = DH_new())
+ || !DH_set0_pqg(noqdh, p, NULL, g))
+ goto err;
+ p = g = NULL;
x942dh = DH_get_2048_256();
- pkcs3dh = DH_new_by_nid(NID_ffdhe2048);
pkey1 = EVP_PKEY_new();
pkey2 = EVP_PKEY_new();
if (!TEST_ptr(x942dh)
- || !TEST_ptr(pkcs3dh)
+ || !TEST_ptr(noqdh)
|| !TEST_ptr(pkey1)
|| !TEST_ptr(pkey2))
goto err;
@@ -1462,17 +1471,18 @@ static int test_EVP_PKEY_set1_DH(void)
|| !TEST_int_eq(EVP_PKEY_id(pkey1), EVP_PKEY_DHX))
goto err;
-
- if(!TEST_true(EVP_PKEY_set1_DH(pkey2, pkcs3dh))
+ if(!TEST_true(EVP_PKEY_set1_DH(pkey2, noqdh))
|| !TEST_int_eq(EVP_PKEY_id(pkey2), EVP_PKEY_DH))
goto err;
ret = 1;
err:
+ BN_free(p);
+ BN_free(g);
EVP_PKEY_free(pkey1);
EVP_PKEY_free(pkey2);
DH_free(x942dh);
- DH_free(pkcs3dh);
+ DH_free(noqdh);
return ret;
}