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
2 changes: 2 additions & 0 deletions .wolfssl_known_macro_extras
Original file line number Diff line number Diff line change
Expand Up @@ -773,11 +773,13 @@ WC_DRBG_BANKREF
WC_FIPS_AESGCM_NO_SHORT_NONCES
WC_FIPS_AESGCM_ONE_SHOT_EXT_IV_ALLOWED
WC_FIPS_ED25519CTX_NOT_APPROVED
WC_FIPS_RSA_VERIFY_MIN_2048
WC_FLAG_DONT_USE_AESNI
WC_FORCE_LINUXKM_FORTIFY_SOURCE
WC_HASH_CUSTOM_MAX_BLOCK_SIZE
WC_HASH_CUSTOM_MAX_DIGEST_SIZE
WC_HASH_CUSTOM_MIN_DIGEST_SIZE
WC_HAVE_FIPS_INDICATOR
WC_INIT_ERROR_WHEN_CONTENDED
WC_LINUXKM_NO_USE_HEAP_WRAPPERS
WC_LINUXKM_SVR_NO_BATCHING
Expand Down
6 changes: 6 additions & 0 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -30211,7 +30211,13 @@ static int test_wolfSSL_d2i_X509_REQ(void)
/*
* Verify the signature in the CSR
*/
#ifdef WC_FIPS_RSA_VERIFY_MIN_2048
/* certs/csr.ext.der has a 1024-bit RSA key; IG C.F requires at least
* 2048 bits for FIPS 186-5 signature verification. */
ExpectIntEQ(X509_REQ_verify(req, pub_key), 0);
#else
ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
#endif

#ifdef OPENSSL_ALL
ExpectNotNull(exts = (STACK_OF(X509_EXTENSION)*)X509_REQ_get_extensions(
Expand Down
9 changes: 9 additions & 0 deletions tests/api/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@

#include <wolfssl/wolfcrypt/hash.h>

/* A successful PQ seed-input call returns WC_FIPS_NOT_APPROVED from v7 module
* wrappers whose fips.h defines WC_HAVE_FIPS_INDICATOR, and 0 otherwise. */
#if defined(HAVE_FIPS) && defined(WC_HAVE_FIPS_INDICATOR) && \
FIPS_VERSION3_GE(7,0,0) && !defined(FIPS_NO_WRAPPERS)
#define SEED_OK WC_FIPS_NOT_APPROVED
#else
#define SEED_OK 0
#endif

/* Old FIPS headers don't allow comparisons with WC_MIN_DIGEST_SIZE_FOR_SIGN by
* the preprocessor, so we catch those builds with one of the first two
* clauses.
Expand Down
7 changes: 7 additions & 0 deletions tests/api/test_ed25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -1020,12 +1020,19 @@ int test_wc_ed25519_sign_verify_ctx_ph(void)

/* Ed25519ctx round trip: type==Ed25519ctx true side, real context. */
sigLen = sizeof(sig);
#ifdef WC_FIPS_ED25519CTX_NOT_APPROVED
/* A module whose fips.h defines WC_FIPS_ED25519CTX_NOT_APPROVED rejects
* Ed25519ctx signing with SIG_TYPE_E. */
ExpectIntEQ(wc_ed25519ctx_sign_msg(msg, sizeof(msg), sig, &sigLen, &key,
ctx, sizeof(ctx)), WC_NO_ERR_TRACE(SIG_TYPE_E));
#else
ExpectIntEQ(wc_ed25519ctx_sign_msg(msg, sizeof(msg), sig, &sigLen, &key,
ctx, sizeof(ctx)), 0);
verify_ok = 0;
ExpectIntEQ(wc_ed25519ctx_verify_msg(sig, sigLen, msg, sizeof(msg),
&verify_ok, &key, ctx, sizeof(ctx)), 0);
ExpectIntEQ(verify_ok, 1);
#endif

/* Ed25519ph round trip via hash and via full message, type==Ed25519ph
* true side, WC_SHA512_DIGEST_SIZE length check false side (equal). */
Expand Down
73 changes: 55 additions & 18 deletions tests/api/test_mldsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -7737,36 +7737,36 @@ int test_mldsa_make_key_from_seed(void)
ExpectIntEQ(wc_MlDsaKey_Init(key, NULL, INVALID_DEVID), 0);
#ifndef WOLFSSL_NO_ML_DSA_44
ExpectIntEQ(wc_MlDsaKey_SetParams(key, WC_ML_DSA_44), 0);
ExpectIntEQ(wc_MlDsaKey_MakeKeyFromSeed(key, seed_44), 0);
ExpectIntEQ(wc_MlDsaKey_MakeKeyFromSeed(key, seed_44), SEED_OK);
ExpectIntEQ(XMEMCMP(key->p, pk_44, sizeof(pk_44)), 0);
ExpectIntEQ(XMEMCMP(key->k, sk_44, sizeof(sk_44)), 0);
#ifdef WOLFSSL_MLDSA_FIPS204_DRAFT
ExpectIntEQ(wc_MlDsaKey_SetParams(key, WC_ML_DSA_44_DRAFT), 0);
ExpectIntEQ(wc_MlDsaKey_MakeKeyFromSeed(key, seed_44_draft), 0);
ExpectIntEQ(wc_MlDsaKey_MakeKeyFromSeed(key, seed_44_draft), SEED_OK);
ExpectIntEQ(XMEMCMP(key->p, pk_44_draft, sizeof(pk_44_draft)), 0);
ExpectIntEQ(XMEMCMP(key->k, sk_44_draft, sizeof(sk_44_draft)), 0);
#endif
#endif
#ifndef WOLFSSL_NO_ML_DSA_65
ExpectIntEQ(wc_MlDsaKey_SetParams(key, WC_ML_DSA_65), 0);
ExpectIntEQ(wc_MlDsaKey_MakeKeyFromSeed(key, seed_65), 0);
ExpectIntEQ(wc_MlDsaKey_MakeKeyFromSeed(key, seed_65), SEED_OK);
ExpectIntEQ(XMEMCMP(key->p, pk_65, sizeof(pk_65)), 0);
ExpectIntEQ(XMEMCMP(key->k, sk_65, sizeof(sk_65)), 0);
#ifdef WOLFSSL_MLDSA_FIPS204_DRAFT
ExpectIntEQ(wc_MlDsaKey_SetParams(key, WC_ML_DSA_65_DRAFT), 0);
ExpectIntEQ(wc_MlDsaKey_MakeKeyFromSeed(key, seed_65_draft), 0);
ExpectIntEQ(wc_MlDsaKey_MakeKeyFromSeed(key, seed_65_draft), SEED_OK);
ExpectIntEQ(XMEMCMP(key->p, pk_65_draft, sizeof(pk_65_draft)), 0);
ExpectIntEQ(XMEMCMP(key->k, sk_65_draft, sizeof(sk_65_draft)), 0);
#endif
#endif
#ifndef WOLFSSL_NO_ML_DSA_87
ExpectIntEQ(wc_MlDsaKey_SetParams(key, WC_ML_DSA_87), 0);
ExpectIntEQ(wc_MlDsaKey_MakeKeyFromSeed(key, seed_87), 0);
ExpectIntEQ(wc_MlDsaKey_MakeKeyFromSeed(key, seed_87), SEED_OK);
ExpectIntEQ(XMEMCMP(key->p, pk_87, sizeof(pk_87)), 0);
ExpectIntEQ(XMEMCMP(key->k, sk_87, sizeof(sk_87)), 0);
#ifdef WOLFSSL_MLDSA_FIPS204_DRAFT
ExpectIntEQ(wc_MlDsaKey_SetParams(key, WC_ML_DSA_87_DRAFT), 0);
ExpectIntEQ(wc_MlDsaKey_MakeKeyFromSeed(key, seed_87_draft), 0);
ExpectIntEQ(wc_MlDsaKey_MakeKeyFromSeed(key, seed_87_draft), SEED_OK);
ExpectIntEQ(XMEMCMP(key->p, pk_87_draft, sizeof(pk_87_draft)), 0);
ExpectIntEQ(XMEMCMP(key->k, sk_87_draft, sizeof(sk_87_draft)), 0);
#endif
Expand Down Expand Up @@ -12563,7 +12563,8 @@ int test_mldsa_sig_kats(void)
ExpectIntEQ(wc_MlDsaKey_ImportPrivRaw(key, sk_44, (word32)sizeof(sk_44)),
0);
sigLen = PARAMS_ML_DSA_44_SIG_SIZE;
ExpectIntEQ(wc_MlDsaKey_SignWithSeed(key, sig, &sigLen, msg_44, (word32)sizeof(msg_44), rnd_44), 0);
ExpectIntEQ(wc_MlDsaKey_SignWithSeed(key, sig, &sigLen, msg_44, (word32)sizeof(msg_44), rnd_44),
SEED_OK);
ExpectIntEQ(sigLen, PARAMS_ML_DSA_44_SIG_SIZE);
ExpectIntEQ(XMEMCMP(sig, sig_44, sizeof(sig_44)), 0);
#endif
Expand All @@ -12572,7 +12573,8 @@ int test_mldsa_sig_kats(void)
ExpectIntEQ(wc_MlDsaKey_ImportPrivRaw(key, sk_65, (word32)sizeof(sk_65)),
0);
sigLen = PARAMS_ML_DSA_65_SIG_SIZE;
ExpectIntEQ(wc_MlDsaKey_SignWithSeed(key, sig, &sigLen, msg_65, (word32)sizeof(msg_65), rnd_65), 0);
ExpectIntEQ(wc_MlDsaKey_SignWithSeed(key, sig, &sigLen, msg_65, (word32)sizeof(msg_65), rnd_65),
SEED_OK);
ExpectIntEQ(sigLen, PARAMS_ML_DSA_65_SIG_SIZE);
ExpectIntEQ(XMEMCMP(sig, sig_65, sizeof(sig_65)), 0);
#endif
Expand All @@ -12581,7 +12583,8 @@ int test_mldsa_sig_kats(void)
ExpectIntEQ(wc_MlDsaKey_ImportPrivRaw(key, sk_87, (word32)sizeof(sk_87)),
0);
sigLen = PARAMS_ML_DSA_87_SIG_SIZE;
ExpectIntEQ(wc_MlDsaKey_SignWithSeed(key, sig, &sigLen, msg_87, (word32)sizeof(msg_87), rnd_87), 0);
ExpectIntEQ(wc_MlDsaKey_SignWithSeed(key, sig, &sigLen, msg_87, (word32)sizeof(msg_87), rnd_87),
SEED_OK);
ExpectIntEQ(sigLen, PARAMS_ML_DSA_87_SIG_SIZE);
ExpectIntEQ(XMEMCMP(sig, sig_87, sizeof(sig_87)), 0);
#endif
Expand Down Expand Up @@ -16758,7 +16761,8 @@ int test_mldsa_sign_ctx_kats(void)
ExpectIntEQ(wc_MlDsaKey_SetParams(key, WC_ML_DSA_44), 0);
ExpectIntEQ(wc_MlDsaKey_ImportPrivRaw(key, sk_44, (word32)sizeof(sk_44)), 0);
sigLen = MLDSA_MAX_SIG_SIZE;
ExpectIntEQ(wc_MlDsaKey_SignCtxWithSeed(key, NULL, 0, sig, &sigLen, msg_44, (word32)sizeof(msg_44), rnd_44), 0);
ExpectIntEQ(wc_MlDsaKey_SignCtxWithSeed(key, NULL, 0, sig, &sigLen, msg_44, (word32)sizeof(msg_44), rnd_44),
SEED_OK);
ExpectIntEQ(sigLen, (word32)sizeof(sig_44_ctx0));
ExpectIntEQ(XMEMCMP(sig, sig_44_ctx0, sizeof(sig_44_ctx0)), 0);
wc_MlDsaKey_Free(key);
Expand All @@ -16768,7 +16772,8 @@ int test_mldsa_sign_ctx_kats(void)
ExpectIntEQ(wc_MlDsaKey_SetParams(key, WC_ML_DSA_44), 0);
ExpectIntEQ(wc_MlDsaKey_ImportPrivRaw(key, sk_44, (word32)sizeof(sk_44)), 0);
sigLen = MLDSA_MAX_SIG_SIZE;
ExpectIntEQ(wc_MlDsaKey_SignCtxWithSeed(key, ctx_44, (byte)sizeof(ctx_44), sig, &sigLen, msg_44, (word32)sizeof(msg_44), rnd_44), 0);
ExpectIntEQ(wc_MlDsaKey_SignCtxWithSeed(key, ctx_44, (byte)sizeof(ctx_44), sig, &sigLen, msg_44, (word32)sizeof(msg_44), rnd_44),
SEED_OK);
ExpectIntEQ(sigLen, (word32)sizeof(sig_44_ctx33));
ExpectIntEQ(XMEMCMP(sig, sig_44_ctx33, sizeof(sig_44_ctx33)), 0);
wc_MlDsaKey_Free(key);
Expand All @@ -16780,7 +16785,8 @@ int test_mldsa_sign_ctx_kats(void)
ExpectIntEQ(wc_MlDsaKey_SetParams(key, WC_ML_DSA_65), 0);
ExpectIntEQ(wc_MlDsaKey_ImportPrivRaw(key, sk_65, (word32)sizeof(sk_65)), 0);
sigLen = MLDSA_MAX_SIG_SIZE;
ExpectIntEQ(wc_MlDsaKey_SignCtxWithSeed(key, NULL, 0, sig, &sigLen, msg_65, (word32)sizeof(msg_65), rnd_65), 0);
ExpectIntEQ(wc_MlDsaKey_SignCtxWithSeed(key, NULL, 0, sig, &sigLen, msg_65, (word32)sizeof(msg_65), rnd_65),
SEED_OK);
ExpectIntEQ(sigLen, (word32)sizeof(sig_65_ctx0));
ExpectIntEQ(XMEMCMP(sig, sig_65_ctx0, sizeof(sig_65_ctx0)), 0);
wc_MlDsaKey_Free(key);
Expand All @@ -16790,7 +16796,8 @@ int test_mldsa_sign_ctx_kats(void)
ExpectIntEQ(wc_MlDsaKey_SetParams(key, WC_ML_DSA_65), 0);
ExpectIntEQ(wc_MlDsaKey_ImportPrivRaw(key, sk_65, (word32)sizeof(sk_65)), 0);
sigLen = MLDSA_MAX_SIG_SIZE;
ExpectIntEQ(wc_MlDsaKey_SignCtxWithSeed(key, ctx_65, (byte)sizeof(ctx_65), sig, &sigLen, msg_65, (word32)sizeof(msg_65), rnd_65), 0);
ExpectIntEQ(wc_MlDsaKey_SignCtxWithSeed(key, ctx_65, (byte)sizeof(ctx_65), sig, &sigLen, msg_65, (word32)sizeof(msg_65), rnd_65),
SEED_OK);
ExpectIntEQ(sigLen, (word32)sizeof(sig_65_ctx33));
ExpectIntEQ(XMEMCMP(sig, sig_65_ctx33, sizeof(sig_65_ctx33)), 0);
wc_MlDsaKey_Free(key);
Expand All @@ -16802,7 +16809,8 @@ int test_mldsa_sign_ctx_kats(void)
ExpectIntEQ(wc_MlDsaKey_SetParams(key, WC_ML_DSA_87), 0);
ExpectIntEQ(wc_MlDsaKey_ImportPrivRaw(key, sk_87, (word32)sizeof(sk_87)), 0);
sigLen = MLDSA_MAX_SIG_SIZE;
ExpectIntEQ(wc_MlDsaKey_SignCtxWithSeed(key, NULL, 0, sig, &sigLen, msg_87, (word32)sizeof(msg_87), rnd_87), 0);
ExpectIntEQ(wc_MlDsaKey_SignCtxWithSeed(key, NULL, 0, sig, &sigLen, msg_87, (word32)sizeof(msg_87), rnd_87),
SEED_OK);
ExpectIntEQ(sigLen, (word32)sizeof(sig_87_ctx0));
ExpectIntEQ(XMEMCMP(sig, sig_87_ctx0, sizeof(sig_87_ctx0)), 0);
wc_MlDsaKey_Free(key);
Expand All @@ -16812,7 +16820,8 @@ int test_mldsa_sign_ctx_kats(void)
ExpectIntEQ(wc_MlDsaKey_SetParams(key, WC_ML_DSA_87), 0);
ExpectIntEQ(wc_MlDsaKey_ImportPrivRaw(key, sk_87, (word32)sizeof(sk_87)), 0);
sigLen = MLDSA_MAX_SIG_SIZE;
ExpectIntEQ(wc_MlDsaKey_SignCtxWithSeed(key, ctx_87, (byte)sizeof(ctx_87), sig, &sigLen, msg_87, (word32)sizeof(msg_87), rnd_87), 0);
ExpectIntEQ(wc_MlDsaKey_SignCtxWithSeed(key, ctx_87, (byte)sizeof(ctx_87), sig, &sigLen, msg_87, (word32)sizeof(msg_87), rnd_87),
SEED_OK);
ExpectIntEQ(sigLen, (word32)sizeof(sig_87_ctx33));
ExpectIntEQ(XMEMCMP(sig, sig_87_ctx33, sizeof(sig_87_ctx33)), 0);
wc_MlDsaKey_Free(key);
Expand Down Expand Up @@ -27440,7 +27449,8 @@ int test_mldsa_sign_mu_kats(void)
ExpectIntEQ(wc_MlDsaKey_SetParams(key, WC_ML_DSA_44), 0);
ExpectIntEQ(wc_MlDsaKey_ImportPrivRaw(key, sk_44_mu, (word32)sizeof(sk_44_mu)), 0);
sigLen = MLDSA_MAX_SIG_SIZE;
ExpectIntEQ(wc_MlDsaKey_SignMuWithSeed(key, sig, &sigLen, mu_44, (word32)sizeof(mu_44), zeroSeed), 0);
ExpectIntEQ(wc_MlDsaKey_SignMuWithSeed(key, sig, &sigLen, mu_44, (word32)sizeof(mu_44), zeroSeed),
SEED_OK);
ExpectIntEQ(sigLen, (word32)sizeof(sig_44_mu));
ExpectIntEQ(XMEMCMP(sig, sig_44_mu, sizeof(sig_44_mu)), 0);
wc_MlDsaKey_Free(key);
Expand All @@ -27451,7 +27461,8 @@ int test_mldsa_sign_mu_kats(void)
ExpectIntEQ(wc_MlDsaKey_SetParams(key, WC_ML_DSA_65), 0);
ExpectIntEQ(wc_MlDsaKey_ImportPrivRaw(key, sk_65_mu, (word32)sizeof(sk_65_mu)), 0);
sigLen = MLDSA_MAX_SIG_SIZE;
ExpectIntEQ(wc_MlDsaKey_SignMuWithSeed(key, sig, &sigLen, mu_65, (word32)sizeof(mu_65), zeroSeed), 0);
ExpectIntEQ(wc_MlDsaKey_SignMuWithSeed(key, sig, &sigLen, mu_65, (word32)sizeof(mu_65), zeroSeed),
SEED_OK);
ExpectIntEQ(sigLen, (word32)sizeof(sig_65_mu));
ExpectIntEQ(XMEMCMP(sig, sig_65_mu, sizeof(sig_65_mu)), 0);
wc_MlDsaKey_Free(key);
Expand All @@ -27462,7 +27473,8 @@ int test_mldsa_sign_mu_kats(void)
ExpectIntEQ(wc_MlDsaKey_SetParams(key, WC_ML_DSA_87), 0);
ExpectIntEQ(wc_MlDsaKey_ImportPrivRaw(key, sk_87_mu, (word32)sizeof(sk_87_mu)), 0);
sigLen = MLDSA_MAX_SIG_SIZE;
ExpectIntEQ(wc_MlDsaKey_SignMuWithSeed(key, sig, &sigLen, mu_87, (word32)sizeof(mu_87), zeroSeed), 0);
ExpectIntEQ(wc_MlDsaKey_SignMuWithSeed(key, sig, &sigLen, mu_87, (word32)sizeof(mu_87), zeroSeed),
SEED_OK);
ExpectIntEQ(sigLen, (word32)sizeof(sig_87_mu));
ExpectIntEQ(XMEMCMP(sig, sig_87_mu, sizeof(sig_87_mu)), 0);
wc_MlDsaKey_Free(key);
Expand Down Expand Up @@ -31735,3 +31747,28 @@ int test_wc_MlDsaKey_SetPrecompA(void)
#endif
return EXPECT_RESULT();
}

/* ML-DSA keygen from a caller seed succeeds and returns SEED_OK, the service
* indicator for a seed-input call (api.h). */
int test_wc_MlDsaKey_seed_service_indicator(void)
{
EXPECT_DECLS;
#if defined(WOLFSSL_HAVE_MLDSA) && !defined(WOLFSSL_MLDSA_NO_MAKE_KEY) && \
!defined(WOLFSSL_MLDSA_VERIFY_ONLY)
wc_MlDsaKey key;
byte seed[MLDSA_SEED_SZ];

XMEMSET(&key, 0, sizeof(key));
XMEMSET(seed, 0x5a, sizeof(seed));

ExpectIntEQ(wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID), 0);
ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_44), 0);

/* Valid key, valid seed: the operation is performed, and in an approved
* build it is reported non-approved rather than refused. */
ExpectIntEQ(wc_MlDsaKey_MakeKeyFromSeed(&key, seed), SEED_OK);

wc_MlDsaKey_Free(&key);
#endif
return EXPECT_RESULT();
}
2 changes: 2 additions & 0 deletions tests/api/test_mldsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ int test_wc_MldsaFeatureCoverage(void);
* defined. */
int test_mldsa_legacy_shim(void);
int test_wc_MldsaDecisionCoverage2(void);
int test_wc_MlDsaKey_seed_service_indicator(void);
int test_wc_MldsaDerDecisionCoverage(void);
int test_mldsa_cb_free(void);

Expand Down Expand Up @@ -101,6 +102,7 @@ int test_wc_MlDsaKey_SetPrecompA(void);
TEST_DECL_GROUP("mldsa", test_wc_MldsaFeatureCoverage), \
TEST_DECL_GROUP("mldsa", test_mldsa_legacy_shim), \
TEST_DECL_GROUP("mldsa", test_wc_MldsaDecisionCoverage2), \
TEST_DECL_GROUP("mldsa", test_wc_MlDsaKey_seed_service_indicator), \
TEST_DECL_GROUP("mldsa", test_wc_MldsaDerDecisionCoverage), \
TEST_DECL_GROUP("mldsa", test_mldsa_cb_free), \
TEST_DECL_GROUP("mldsa", test_wc_MlDsaKey_SetPrecompA)
Expand Down
42 changes: 36 additions & 6 deletions tests/api/test_mlkem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ int test_wc_mlkem_make_key_kats(void)
#ifndef WOLFSSL_NO_ML_KEM_512
ExpectIntEQ(wc_MlKemKey_Init(key, WC_ML_KEM_512, NULL, INVALID_DEVID), 0);
ExpectIntEQ(wc_MlKemKey_MakeKeyWithRandom(key, seed_512, sizeof(seed_512)),
0);
SEED_OK);
ExpectIntEQ(wc_MlKemKey_EncodePublicKey(key, pubKey,
WC_ML_KEM_512_PUBLIC_KEY_SIZE), 0);
ExpectIntEQ(wc_MlKemKey_EncodePrivateKey(key, privKey,
Expand All @@ -1466,7 +1466,7 @@ int test_wc_mlkem_make_key_kats(void)
#ifndef WOLFSSL_NO_ML_KEM_768
ExpectIntEQ(wc_MlKemKey_Init(key, WC_ML_KEM_768, NULL, INVALID_DEVID), 0);
ExpectIntEQ(wc_MlKemKey_MakeKeyWithRandom(key, seed_768, sizeof(seed_768)),
0);
SEED_OK);
ExpectIntEQ(wc_MlKemKey_EncodePublicKey(key, pubKey,
WC_ML_KEM_768_PUBLIC_KEY_SIZE), 0);
ExpectIntEQ(wc_MlKemKey_EncodePrivateKey(key, privKey,
Expand All @@ -1478,7 +1478,7 @@ int test_wc_mlkem_make_key_kats(void)
#ifndef WOLFSSL_NO_ML_KEM_1024
ExpectIntEQ(wc_MlKemKey_Init(key, WC_ML_KEM_1024, NULL, INVALID_DEVID), 0);
ExpectIntEQ(wc_MlKemKey_MakeKeyWithRandom(key, seed_1024,
sizeof(seed_1024)), 0);
sizeof(seed_1024)), SEED_OK);
ExpectIntEQ(wc_MlKemKey_EncodePublicKey(key, pubKey,
WC_ML_KEM_1024_PUBLIC_KEY_SIZE), 0);
ExpectIntEQ(wc_MlKemKey_EncodePrivateKey(key, privKey,
Expand Down Expand Up @@ -2440,7 +2440,7 @@ int test_wc_mlkem_encapsulate_kats(void)
ExpectIntEQ(wc_MlKemKey_Init(key, WC_ML_KEM_512, NULL, INVALID_DEVID), 0);
ExpectIntEQ(wc_MlKemKey_DecodePublicKey(key, ek_512, sizeof(ek_512)), 0);
ExpectIntEQ(wc_MlKemKey_EncapsulateWithRandom(key, ct, ss, seed_512,
sizeof(seed_512)), 0);
sizeof(seed_512)), SEED_OK);
ExpectIntEQ(XMEMCMP(ct, c_512, WC_ML_KEM_512_CIPHER_TEXT_SIZE), 0);
ExpectIntEQ(XMEMCMP(ss, k_512, WC_ML_KEM_SS_SZ), 0);
wc_MlKemKey_Free(key);
Expand All @@ -2449,7 +2449,7 @@ int test_wc_mlkem_encapsulate_kats(void)
ExpectIntEQ(wc_MlKemKey_Init(key, WC_ML_KEM_768, NULL, INVALID_DEVID), 0);
ExpectIntEQ(wc_MlKemKey_DecodePublicKey(key, ek_768, sizeof(ek_768)), 0);
ExpectIntEQ(wc_MlKemKey_EncapsulateWithRandom(key, ct, ss, seed_768,
sizeof(seed_768)), 0);
sizeof(seed_768)), SEED_OK);
ExpectIntEQ(XMEMCMP(ct, c_768, WC_ML_KEM_768_CIPHER_TEXT_SIZE), 0);
ExpectIntEQ(XMEMCMP(ss, k_768, WC_ML_KEM_SS_SZ), 0);
wc_MlKemKey_Free(key);
Expand All @@ -2458,7 +2458,7 @@ int test_wc_mlkem_encapsulate_kats(void)
ExpectIntEQ(wc_MlKemKey_Init(key, WC_ML_KEM_1024, NULL, INVALID_DEVID), 0);
ExpectIntEQ(wc_MlKemKey_DecodePublicKey(key, ek_1024, sizeof(ek_1024)), 0);
ExpectIntEQ(wc_MlKemKey_EncapsulateWithRandom(key, ct, ss, seed_1024,
sizeof(seed_1024)), 0);
sizeof(seed_1024)), SEED_OK);
ExpectIntEQ(XMEMCMP(ct, c_1024, WC_ML_KEM_1024_CIPHER_TEXT_SIZE), 0);
ExpectIntEQ(XMEMCMP(ss, k_1024, WC_ML_KEM_SS_SZ), 0);
wc_MlKemKey_Free(key);
Expand Down Expand Up @@ -4650,6 +4650,36 @@ int test_wc_mlkem_encode_key_len_decision(void)
return EXPECT_RESULT();
} /* END test_wc_mlkem_encode_key_len_decision */

/* ML-KEM keygen from caller randomness succeeds and returns SEED_OK, the
* service indicator for a seed-input call (api.h). */
int test_wc_MlKemKey_seed_service_indicator(void)
{
EXPECT_DECLS;
#if defined(WOLFSSL_HAVE_MLKEM) && !defined(WOLFSSL_MLKEM_NO_MAKE_KEY) && \
!defined(WOLFSSL_NO_ML_KEM)
MlKemKey key;
byte rand[WC_ML_KEM_MAKEKEY_RAND_SZ];
#ifndef WOLFSSL_NO_ML_KEM_768
const int mlkemType = WC_ML_KEM_768;
#elif !defined(WOLFSSL_NO_ML_KEM_512)
const int mlkemType = WC_ML_KEM_512;
#else
const int mlkemType = WC_ML_KEM_1024;
#endif

XMEMSET(&key, 0, sizeof(key));
XMEMSET(rand, 0x5a, sizeof(rand));

ExpectIntEQ(wc_MlKemKey_Init(&key, mlkemType, NULL, INVALID_DEVID), 0);
/* Valid key, valid randomness: performed, and reported non-approved. */
ExpectIntEQ(wc_MlKemKey_MakeKeyWithRandom(&key, rand, (int)sizeof(rand)),
SEED_OK);

wc_MlKemKey_Free(&key);
#endif
return EXPECT_RESULT();
}

#if defined(WOLFSSL_HAVE_MLKEM) && !defined(WOLFSSL_NO_ML_KEM) && \
defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_FREE)
#define TEST_MLKEM_CB_FREE
Expand Down
2 changes: 2 additions & 0 deletions tests/api/test_mlkem.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <tests/api/api_decl.h>

int test_wc_mlkem_make_key_kats(void);
int test_wc_MlKemKey_seed_service_indicator(void);
int test_wc_mlkem_encapsulate_kats(void);
int test_wc_mlkem_decapsulate_kats(void);
int test_wc_mlkem_decapsulate_pubonly_fails(void);
Expand All @@ -41,6 +42,7 @@ int test_wc_mlkem_cb_pending_rejected(void);

#define TEST_MLKEM_DECLS \
TEST_DECL_GROUP("mlkem", test_wc_mlkem_make_key_kats), \
TEST_DECL_GROUP("mlkem", test_wc_MlKemKey_seed_service_indicator), \
TEST_DECL_GROUP("mlkem", test_wc_mlkem_encapsulate_kats), \
TEST_DECL_GROUP("mlkem", test_wc_mlkem_decapsulate_kats), \
TEST_DECL_GROUP("mlkem", test_wc_mlkem_decapsulate_pubonly_fails), \
Expand Down
Loading
Loading