Skip to content

Commit

Permalink
Add test for generating safeprime DH parameters
Browse files Browse the repository at this point in the history
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #19635)
  • Loading branch information
t8m committed Nov 11, 2022
1 parent 990d280 commit 10119e7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/evp_extra_test2.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,30 @@ static int test_dh_tofrom_data_select(void)
EVP_PKEY_CTX_free(gctx);
return ret;
}

static int test_dh_paramgen(void)
{
int ret;
OSSL_PARAM params[3];
EVP_PKEY *pkey = NULL;
EVP_PKEY_CTX *gctx = NULL;
unsigned int pbits = 512; /* minimum allowed for speed */

params[0] = OSSL_PARAM_construct_uint(OSSL_PKEY_PARAM_FFC_PBITS, &pbits);
params[1] = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_FFC_TYPE,
"generator", 0);
params[2] = OSSL_PARAM_construct_end();

ret = TEST_ptr(gctx = EVP_PKEY_CTX_new_from_name(mainctx, "DH", NULL))
&& TEST_int_gt(EVP_PKEY_paramgen_init(gctx), 0)
&& TEST_true(EVP_PKEY_CTX_set_params(gctx, params))
&& TEST_true(EVP_PKEY_paramgen(gctx, &pkey))
&& TEST_ptr(pkey);

EVP_PKEY_CTX_free(gctx);
EVP_PKEY_free(pkey);
return ret;
}
#endif

#ifndef OPENSSL_NO_EC
Expand Down Expand Up @@ -1156,6 +1180,7 @@ int setup_tests(void)
#endif
#ifndef OPENSSL_NO_DH
ADD_TEST(test_dh_tofrom_data_select);
ADD_TEST(test_dh_paramgen);
#endif
ADD_TEST(test_rsa_tofrom_data_select);

Expand Down

0 comments on commit 10119e7

Please sign in to comment.