Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion fips-hash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ then
fi

OUT=$(./wolfcrypt/test/testwolfcrypt | sed -n 's/hash = \(.*\)/\1/p')
NEWHASH=$(echo "$OUT" | cut -c1-64)
# FIPS v7.0.0+ uses HMAC-SHA-512 (128 hex chars); older FIPS versions
# use HMAC-SHA-256 (64 hex chars). Take the whole captured hash; the
# static_assert on sizeof(verifyCore) guards against wrong length at
# compile time after this script runs.
NEWHASH=$(echo "$OUT" | head -n1 | tr -d '[:space:]')
if test -n "$NEWHASH"
then
cp wolfcrypt/src/fips_test.c wolfcrypt/src/fips_test.c.bak
Expand Down
4 changes: 2 additions & 2 deletions tests/api/test_evp_pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ static int test_wolfSSL_EVP_PKEY_sign_verify(int keyType)
!defined(HAVE_SELFTEST)
#if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
{
ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
ExpectNotNull(rsa = RSA_generate_key(2048, 65537, NULL, NULL));
ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
}
#endif
Expand Down Expand Up @@ -2028,7 +2028,7 @@ int test_wolfSSL_EVP_PKEY_encrypt(void)
XMEMSET(outDec, 0, rsaKeySz);
}

ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
ExpectNotNull(rsa = RSA_generate_key(2048, 65537, NULL, NULL));
ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
if (EXPECT_FAIL()) {
Expand Down
21 changes: 20 additions & 1 deletion tests/api/test_mldsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,9 +752,20 @@ int test_wc_dilithium_sign_pubonly_fails(void)
/* Import only the public key into a fresh key object. */
ExpectIntEQ(wc_dilithium_import_public(pubBuf, pubLen, pubOnlyKey), 0);

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

DoExpectIntEQ(wc_FreeRng(&rng), 0);
wc_dilithium_free(pubOnlyKey);
Expand Down Expand Up @@ -1236,6 +1247,12 @@ int test_wc_dilithium_sign_vfy(void)

ExpectIntEQ(wc_InitRng(&rng), 0);

/* FIPS v7.0.0 ML-DSA sign wrappers enforce the privateKeyReadEnable
* contract (FIPS 140-3 sec 7.10.2 CSP access control); unlock for the
* duration of this test's signing operations and re-lock at the end.
* Macros expand to no-ops in non-FIPS builds. */
PRIVATE_KEY_UNLOCK();

#ifndef WOLFSSL_NO_ML_DSA_44
ExpectIntEQ(wc_dilithium_init(key), 0);
ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
Expand Down Expand Up @@ -1300,6 +1317,8 @@ int test_wc_dilithium_sign_vfy(void)
wc_dilithium_free(key);
#endif

PRIVATE_KEY_LOCK();

wc_FreeRng(&rng);
XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
Expand Down
10 changes: 5 additions & 5 deletions tests/api/test_ossl_rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int test_wolfSSL_RSA(void)

RSA_free(rsa);
rsa = NULL;
ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
ExpectNotNull(rsa = RSA_generate_key(2048, 65537, NULL, NULL));
ExpectIntEQ(RSA_size(rsa), 256);

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

#if !defined(USE_FAST_MATH) || (FP_MAX_BITS >= (3072*2))
ExpectNotNull(rsa = RSA_generate_key(3072, 17, NULL, NULL));
ExpectNotNull(rsa = RSA_generate_key(3072, 65537, NULL, NULL));
ExpectIntEQ(RSA_size(rsa), 384);
ExpectIntEQ(RSA_bits(rsa), 3072);
RSA_free(rsa);
Expand Down Expand Up @@ -461,7 +461,7 @@ int test_wolfSSL_RSA_print(void)

RSA_free(rsa);
rsa = NULL;
ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
ExpectNotNull(rsa = RSA_generate_key(2048, 65537, NULL, NULL));

ExpectIntEQ(RSA_print(bio, rsa, 0), 1);
ExpectIntEQ(RSA_print(bio, rsa, 4), 1);
Expand Down Expand Up @@ -626,11 +626,11 @@ int test_wolfSSL_RSA_meth(void)
RSA_METHOD *rsa_meth = NULL;

#ifdef WOLFSSL_KEY_GEN
ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
ExpectNotNull(rsa = RSA_generate_key(2048, 65537, NULL, NULL));
RSA_free(rsa);
rsa = NULL;
#else
ExpectNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
ExpectNull(rsa = RSA_generate_key(2048, 65537, NULL, NULL));
#endif

ExpectNotNull(RSA_get_default_method());
Expand Down
Loading
Loading