Skip to content

Commit 29c714f

Browse files
committed
Phase 3: Security and FIPS Compliance Audit
1 parent 5151a69 commit 29c714f

15 files changed

Lines changed: 567 additions & 22 deletions

File tree

fips-hash.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ then
1313
fi
1414

1515
OUT=$(./wolfcrypt/test/testwolfcrypt | sed -n 's/hash = \(.*\)/\1/p')
16-
NEWHASH=$(echo "$OUT" | cut -c1-64)
16+
# FIPS v7.0.0+ uses HMAC-SHA-512 (128 hex chars); older FIPS versions
17+
# use HMAC-SHA-256 (64 hex chars). Take the whole captured hash; the
18+
# static_assert on sizeof(verifyCore) guards against wrong length at
19+
# compile time after this script runs.
20+
NEWHASH=$(echo "$OUT" | head -n1 | tr -d '[:space:]')
1721
if test -n "$NEWHASH"
1822
then
1923
cp wolfcrypt/src/fips_test.c wolfcrypt/src/fips_test.c.bak

tests/api/test_evp_pkey.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ static int test_wolfSSL_EVP_PKEY_sign_verify(int keyType)
15261526
!defined(HAVE_SELFTEST)
15271527
#if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
15281528
{
1529-
ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
1529+
ExpectNotNull(rsa = RSA_generate_key(2048, 65537, NULL, NULL));
15301530
ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
15311531
}
15321532
#endif
@@ -2028,7 +2028,7 @@ int test_wolfSSL_EVP_PKEY_encrypt(void)
20282028
XMEMSET(outDec, 0, rsaKeySz);
20292029
}
20302030

2031-
ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
2031+
ExpectNotNull(rsa = RSA_generate_key(2048, 65537, NULL, NULL));
20322032
ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
20332033
ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
20342034
if (EXPECT_FAIL()) {

tests/api/test_mldsa.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,9 +752,20 @@ int test_wc_dilithium_sign_pubonly_fails(void)
752752
/* Import only the public key into a fresh key object. */
753753
ExpectIntEQ(wc_dilithium_import_public(pubBuf, pubLen, pubOnlyKey), 0);
754754

755-
/* Signing with a public-key-only object must fail. */
755+
/* Signing with a public-key-only object must fail.
756+
*
757+
* In FIPS v7.0.0 mode the ML-DSA sign wrappers enforce the
758+
* privateKeyReadEnable contract (FIPS 140-3 sec 7.10.2 CSP access
759+
* control); without unlocking, the wrapper short-circuits to
760+
* FIPS_PRIVATE_KEY_LOCKED_E before reaching the no-private-key
761+
* detection. Unlock briefly so this test exercises the underlying
762+
* BAD_FUNC_ARG path it is designed to verify. The
763+
* PRIVATE_KEY_UNLOCK / PRIVATE_KEY_LOCK macros expand to no-ops in
764+
* non-FIPS builds. */
765+
PRIVATE_KEY_UNLOCK();
756766
ExpectIntEQ(wc_dilithium_sign_ctx_msg(NULL, 0, msg, sizeof(msg), sig,
757767
&sigLen, pubOnlyKey, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
768+
PRIVATE_KEY_LOCK();
758769

759770
DoExpectIntEQ(wc_FreeRng(&rng), 0);
760771
wc_dilithium_free(pubOnlyKey);
@@ -1236,6 +1247,12 @@ int test_wc_dilithium_sign_vfy(void)
12361247

12371248
ExpectIntEQ(wc_InitRng(&rng), 0);
12381249

1250+
/* FIPS v7.0.0 ML-DSA sign wrappers enforce the privateKeyReadEnable
1251+
* contract (FIPS 140-3 sec 7.10.2 CSP access control); unlock for the
1252+
* duration of this test's signing operations and re-lock at the end.
1253+
* Macros expand to no-ops in non-FIPS builds. */
1254+
PRIVATE_KEY_UNLOCK();
1255+
12391256
#ifndef WOLFSSL_NO_ML_DSA_44
12401257
ExpectIntEQ(wc_dilithium_init(key), 0);
12411258
ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
@@ -1300,6 +1317,8 @@ int test_wc_dilithium_sign_vfy(void)
13001317
wc_dilithium_free(key);
13011318
#endif
13021319

1320+
PRIVATE_KEY_LOCK();
1321+
13031322
wc_FreeRng(&rng);
13041323
XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
13051324
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);

tests/api/test_ossl_rsa.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int test_wolfSSL_RSA(void)
6565

6666
RSA_free(rsa);
6767
rsa = NULL;
68-
ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
68+
ExpectNotNull(rsa = RSA_generate_key(2048, 65537, NULL, NULL));
6969
ExpectIntEQ(RSA_size(rsa), 256);
7070

7171
#if (!defined(HAVE_FIPS) || FIPS_VERSION3_GT(6,0,0)) && !defined(HAVE_SELFTEST)
@@ -306,7 +306,7 @@ int test_wolfSSL_RSA(void)
306306
rsa = NULL;
307307

308308
#if !defined(USE_FAST_MATH) || (FP_MAX_BITS >= (3072*2))
309-
ExpectNotNull(rsa = RSA_generate_key(3072, 17, NULL, NULL));
309+
ExpectNotNull(rsa = RSA_generate_key(3072, 65537, NULL, NULL));
310310
ExpectIntEQ(RSA_size(rsa), 384);
311311
ExpectIntEQ(RSA_bits(rsa), 3072);
312312
RSA_free(rsa);
@@ -461,7 +461,7 @@ int test_wolfSSL_RSA_print(void)
461461

462462
RSA_free(rsa);
463463
rsa = NULL;
464-
ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
464+
ExpectNotNull(rsa = RSA_generate_key(2048, 65537, NULL, NULL));
465465

466466
ExpectIntEQ(RSA_print(bio, rsa, 0), 1);
467467
ExpectIntEQ(RSA_print(bio, rsa, 4), 1);
@@ -626,11 +626,11 @@ int test_wolfSSL_RSA_meth(void)
626626
RSA_METHOD *rsa_meth = NULL;
627627

628628
#ifdef WOLFSSL_KEY_GEN
629-
ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
629+
ExpectNotNull(rsa = RSA_generate_key(2048, 65537, NULL, NULL));
630630
RSA_free(rsa);
631631
rsa = NULL;
632632
#else
633-
ExpectNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
633+
ExpectNull(rsa = RSA_generate_key(2048, 65537, NULL, NULL));
634634
#endif
635635

636636
ExpectNotNull(RSA_get_default_method());

0 commit comments

Comments
 (0)