@@ -5530,6 +5530,57 @@ static int test_wolfSSL_CTX_SetTmpDH_buffer(void)
55305530 return EXPECT_RESULT();
55315531}
55325532
5533+ static int test_wc_DhSetNamedKey(void)
5534+ {
5535+ EXPECT_DECLS;
5536+ #if !defined(HAVE_SELFTEST) && !defined(NO_DH) && \
5537+ !defined(WOLFSSL_NO_MALLOC) && defined(HAVE_FFDHE) && \
5538+ (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
5539+ DhKey *key = NULL;
5540+ key = (DhKey*)XMALLOC(sizeof(DhKey), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
5541+ ExpectNotNull(key);
5542+ if (key != NULL){
5543+ #ifdef HAVE_FFDHE_2048
5544+ if (wc_InitDhKey_ex(key, HEAP_HINT, INVALID_DEVID) == 0){
5545+ ExpectIntEQ(wc_DhSetNamedKey(key, WC_FFDHE_2048), 0);
5546+ ExpectIntEQ(wc_DhGetNamedKeyMinSize(WC_FFDHE_2048), 29);
5547+ wc_FreeDhKey(key);
5548+ }
5549+ #endif
5550+ #ifdef HAVE_FFDHE_3072
5551+ if (wc_InitDhKey_ex(key, HEAP_HINT, INVALID_DEVID) == 0){
5552+ ExpectIntEQ(wc_DhSetNamedKey(key, WC_FFDHE_3072), 0);
5553+ ExpectIntEQ(wc_DhGetNamedKeyMinSize(WC_FFDHE_3072), 34);
5554+ wc_FreeDhKey(key);
5555+ }
5556+ #endif
5557+ #ifdef HAVE_FFDHE_4096
5558+ if (wc_InitDhKey_ex(key, HEAP_HINT, INVALID_DEVID) == 0){
5559+ ExpectIntEQ(wc_DhSetNamedKey(key, WC_FFDHE_4096), 0);
5560+ ExpectIntEQ(wc_DhGetNamedKeyMinSize(WC_FFDHE_4096), 39);
5561+ wc_FreeDhKey(key);
5562+ }
5563+ #endif
5564+ #ifdef HAVE_FFDHE_6144
5565+ if (wc_InitDhKey_ex(key, HEAP_HINT, INVALID_DEVID) == 0){
5566+ ExpectIntEQ(wc_DhSetNamedKey(key, WC_FFDHE_6144), 0);
5567+ ExpectIntEQ(wc_DhGetNamedKeyMinSize(WC_FFDHE_6144), 46);
5568+ wc_FreeDhKey(key);
5569+ }
5570+ #endif
5571+ #ifdef HAVE_FFDHE_8192
5572+ if (wc_InitDhKey_ex(key, HEAP_HINT, INVALID_DEVID) == 0){
5573+ ExpectIntEQ(wc_DhSetNamedKey(key, WC_FFDHE_8192), 0);
5574+ ExpectIntEQ(wc_DhGetNamedKeyMinSize(WC_FFDHE_8192), 52);
5575+ wc_FreeDhKey(key);
5576+ }
5577+ #endif
5578+ XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
5579+ }
5580+ #endif
5581+ return EXPECT_RESULT();
5582+ }
5583+
55335584static int test_wolfSSL_CTX_SetMinMaxDhKey_Sz(void)
55345585{
55355586 EXPECT_DECLS;
@@ -68215,6 +68266,7 @@ TEST_CASE testCases[] = {
6821568266 TEST_DECL(test_ocsp_certid_enc_dec),
6821668267 TEST_DECL(test_tls12_unexpected_ccs),
6821768268 TEST_DECL(test_tls13_unexpected_ccs),
68269+ TEST_DECL(test_wc_DhSetNamedKey),
6821868270 /* This test needs to stay at the end to clean up any caches allocated. */
6821968271 TEST_DECL(test_wolfSSL_Cleanup)
6822068272};
0 commit comments