@@ -5502,6 +5502,57 @@ static int test_wolfSSL_CTX_SetTmpDH_buffer(void)
55025502 return EXPECT_RESULT();
55035503}
55045504
5505+ static int test_wc_DhSetNamedKey(void)
5506+ {
5507+ EXPECT_DECLS;
5508+ #if !defined(HAVE_SELFTEST) && !defined(NO_DH) && \
5509+ !defined(WOLFSSL_NO_MALLOC) && defined(HAVE_FFDHE) && \
5510+ (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
5511+ DhKey *key = NULL;
5512+ key = (DhKey*)XMALLOC(sizeof(DhKey), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
5513+ ExpectNotNull(key);
5514+ if (key != NULL){
5515+ #ifdef HAVE_FFDHE_2048
5516+ if (wc_InitDhKey_ex(key, HEAP_HINT, INVALID_DEVID) == 0){
5517+ ExpectIntEQ(wc_DhSetNamedKey(key, WC_FFDHE_2048), 0);
5518+ ExpectIntEQ(wc_DhGetNamedKeyMinSize(WC_FFDHE_2048), 29);
5519+ wc_FreeDhKey(key);
5520+ }
5521+ #endif
5522+ #ifdef HAVE_FFDHE_3072
5523+ if (wc_InitDhKey_ex(key, HEAP_HINT, INVALID_DEVID) == 0){
5524+ ExpectIntEQ(wc_DhSetNamedKey(key, WC_FFDHE_3072), 0);
5525+ ExpectIntEQ(wc_DhGetNamedKeyMinSize(WC_FFDHE_3072), 34);
5526+ wc_FreeDhKey(key);
5527+ }
5528+ #endif
5529+ #ifdef HAVE_FFDHE_4096
5530+ if (wc_InitDhKey_ex(key, HEAP_HINT, INVALID_DEVID) == 0){
5531+ ExpectIntEQ(wc_DhSetNamedKey(key, WC_FFDHE_4096), 0);
5532+ ExpectIntEQ(wc_DhGetNamedKeyMinSize(WC_FFDHE_4096), 39);
5533+ wc_FreeDhKey(key);
5534+ }
5535+ #endif
5536+ #ifdef HAVE_FFDHE_6144
5537+ if (wc_InitDhKey_ex(key, HEAP_HINT, INVALID_DEVID) == 0){
5538+ ExpectIntEQ(wc_DhSetNamedKey(key, WC_FFDHE_6144), 0);
5539+ ExpectIntEQ(wc_DhGetNamedKeyMinSize(WC_FFDHE_6144), 46);
5540+ wc_FreeDhKey(key);
5541+ }
5542+ #endif
5543+ #ifdef HAVE_FFDHE_8192
5544+ if (wc_InitDhKey_ex(key, HEAP_HINT, INVALID_DEVID) == 0){
5545+ ExpectIntEQ(wc_DhSetNamedKey(key, WC_FFDHE_8192), 0);
5546+ ExpectIntEQ(wc_DhGetNamedKeyMinSize(WC_FFDHE_8192), 52);
5547+ wc_FreeDhKey(key);
5548+ }
5549+ #endif
5550+ XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
5551+ }
5552+ #endif
5553+ return EXPECT_RESULT();
5554+ }
5555+
55055556static int test_wolfSSL_CTX_SetMinMaxDhKey_Sz(void)
55065557{
55075558 EXPECT_DECLS;
@@ -68185,6 +68236,7 @@ TEST_CASE testCases[] = {
6818568236 TEST_DECL(test_ocsp_certid_enc_dec),
6818668237 TEST_DECL(test_tls12_unexpected_ccs),
6818768238 TEST_DECL(test_tls13_unexpected_ccs),
68239+ TEST_DECL(test_wc_DhSetNamedKey),
6818868240 /* This test needs to stay at the end to clean up any caches allocated. */
6818968241 TEST_DECL(test_wolfSSL_Cleanup)
6819068242};
0 commit comments