Add test for generating safeprime DH parameters
@@ -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
@@ -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);
