Skip to content

Commit 28a9c59

Browse files
committed
tests: fix shared-CI link and FIPS build for math/kdf MC/DC tests
kdf: wc_Tls13_HKDF_Extract_ex / wc_Tls13_HKDF_Expand_Label_ex postdate the frozen FIPS/selftest kdf.h and are undeclared there. Gate every _ex call site behind WOLFSSL_TEST_HKDF_EX (!HAVE_FIPS && !HAVE_SELFTEST); the thin non-_ex wrappers, which exist everywhere, keep their coverage. wolfmath: test_wc_TfmDecisionCoverage / test_wc_TfmExptModDecisionCoverage / test_wc_IntegerDecisionCoverage called library-internal fp_* and s_mp_* functions that carry no MP_API decoration, so under -fvisibility=hidden they are not exported from the shared library and unit.test failed to link them (undefined reference to fp_set / s_mp_mul_digs / ...) in the default shared CI build. Relocate those decision drivers into the tests/unit-mcdc white-boxes, which reach the internals legally by #including tfm.c / integer.c; tests/api now uses only the public mp_* interface. mp_rand_prime calls are gated by WOLFSSL_KEY_GEN (and, for integer, !NO_DH || !NO_DSA) to match where the library declares and defines it.
1 parent 2f5ae6c commit 28a9c59

5 files changed

Lines changed: 904 additions & 874 deletions

File tree

tests/api/test_kdf.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@
4444
#include <tests/api/api.h>
4545
#include <tests/api/test_kdf.h>
4646

47+
/* The _ex TLS 1.3 HKDF variants (wc_Tls13_HKDF_Extract_ex /
48+
* wc_Tls13_HKDF_Expand_Label_ex) postdate the frozen FIPS/selftest kdf.h and
49+
* are neither declared nor exported in those build contexts, so only exercise
50+
* them outside FIPS/selftest. The thin non-_ex wrappers exist everywhere. */
51+
#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
52+
#define WOLFSSL_TEST_HKDF_EX
53+
#endif
54+
4755
/* ------------------------------------------------------------------ */
4856
/* WOLF_CRYPTO_CB support for wc_KDA_KDF_twostep_cmac's dispatch guard */
4957
/* ------------------------------------------------------------------ */
@@ -179,7 +187,7 @@ int test_wc_KdfDecisionCoverage(void)
179187
/* ---------------------------------------------------------------- */
180188
/* wc_Tls13_HKDF_Extract_ex(): switch(digest) default arm. */
181189
/* ---------------------------------------------------------------- */
182-
#if defined(HAVE_HKDF) && !defined(NO_HMAC)
190+
#if defined(HAVE_HKDF) && !defined(NO_HMAC) && defined(WOLFSSL_TEST_HKDF_EX)
183191
{
184192
byte prk[WC_MAX_DIGEST_SIZE] = {0};
185193
byte salt[8] = {0};
@@ -195,7 +203,8 @@ int test_wc_KdfDecisionCoverage(void)
195203
/* ---------------------------------------------------------------- */
196204
/* wc_Tls13_HKDF_Expand_Label_ex(): label-buffer size guard. */
197205
/* ---------------------------------------------------------------- */
198-
#if defined(HAVE_HKDF) && !defined(NO_HMAC) && !defined(NO_SHA256)
206+
#if defined(HAVE_HKDF) && !defined(NO_HMAC) && !defined(NO_SHA256) && \
207+
defined(WOLFSSL_TEST_HKDF_EX)
199208
{
200209
byte okm[64] = {0};
201210
byte prk[WC_SHA256_DIGEST_SIZE] = {0};
@@ -744,22 +753,25 @@ int test_wc_KdfFeatureCoverage(void)
744753
byte ikm[WC_MAX_DIGEST_SIZE] = {0};
745754

746755
#ifndef NO_SHA256
747-
/* ikmLen == 0: internal zero-fill branch. */
756+
ikm[0] = 0x11;
757+
#ifdef WOLFSSL_TEST_HKDF_EX
758+
/* ikmLen == 0: internal zero-fill branch (ikm ignored when len 0). */
748759
ExpectIntEQ(wc_Tls13_HKDF_Extract_ex(prk, salt, sizeof(salt), ikm, 0,
749760
WC_SHA256, HEAP_HINT, INVALID_DEVID), 0);
750761
/* ikmLen != 0: caller-supplied IKM used as-is. */
751-
ikm[0] = 0x11;
752762
ExpectIntEQ(wc_Tls13_HKDF_Extract_ex(prk, salt, sizeof(salt), ikm,
753763
WC_SHA256_DIGEST_SIZE, WC_SHA256, HEAP_HINT, INVALID_DEVID), 0);
764+
#endif
754765
/* Thin (non-_ex) wrapper. */
755766
ExpectIntEQ(wc_Tls13_HKDF_Extract(prk, salt, sizeof(salt), ikm,
756767
WC_SHA256_DIGEST_SIZE, WC_SHA256), 0);
757768
#endif
758-
#ifdef WOLFSSL_SHA384
769+
#if defined(WOLFSSL_SHA384) && defined(WOLFSSL_TEST_HKDF_EX)
759770
ExpectIntEQ(wc_Tls13_HKDF_Extract_ex(prk, salt, sizeof(salt), ikm, 0,
760771
WC_SHA384, HEAP_HINT, INVALID_DEVID), 0);
761772
#endif
762-
#if defined(WOLFSSL_TLS13_SHA512) && defined(WOLFSSL_SHA512)
773+
#if defined(WOLFSSL_TLS13_SHA512) && defined(WOLFSSL_SHA512) && \
774+
defined(WOLFSSL_TEST_HKDF_EX)
763775
ExpectIntEQ(wc_Tls13_HKDF_Extract_ex(prk, salt, sizeof(salt), ikm, 0,
764776
WC_SHA512, HEAP_HINT, INVALID_DEVID), 0);
765777
#endif
@@ -777,6 +789,7 @@ int test_wc_KdfFeatureCoverage(void)
777789
byte label[8] = { 'l','a','b','e','l',0,0,0 };
778790
byte info[8] = {0};
779791

792+
#ifdef WOLFSSL_TEST_HKDF_EX
780793
/* All three zero. */
781794
ExpectIntEQ(wc_Tls13_HKDF_Expand_Label_ex(okm, sizeof(okm), prk,
782795
sizeof(prk), protocol, 0, label, 0, info, 0, WC_SHA256,
@@ -785,11 +798,12 @@ int test_wc_KdfFeatureCoverage(void)
785798
ExpectIntEQ(wc_Tls13_HKDF_Expand_Label_ex(okm, sizeof(okm), prk,
786799
sizeof(prk), protocol, 6, label, 5, info, 4, WC_SHA256,
787800
HEAP_HINT, INVALID_DEVID), 0);
801+
#endif
788802
/* Thin (non-_ex) wrapper. */
789803
ExpectIntEQ(wc_Tls13_HKDF_Expand_Label(okm, sizeof(okm), prk,
790804
sizeof(prk), protocol, 6, label, 5, info, 4, WC_SHA256), 0);
791805

792-
#ifdef WOLFSSL_SHA384
806+
#if defined(WOLFSSL_SHA384) && defined(WOLFSSL_TEST_HKDF_EX)
793807
ExpectIntEQ(wc_Tls13_HKDF_Expand_Label_ex(okm, sizeof(okm), prk,
794808
sizeof(prk), protocol, 6, label, 5, info, 4, WC_SHA384,
795809
HEAP_HINT, INVALID_DEVID), 0);

0 commit comments

Comments
 (0)