Skip to content

v7.0.0-user-space: EMS refusal in wc_PRF, hybrid group constants, RAND_load_file single reseed, -209 comment - #12248

Closed
jackctj117 wants to merge 1 commit into
wolfSSL:v7.0.0-user-spacefrom
jackctj117:v7-lealem-followups
Closed

jackctj117 wants to merge 1 commit into
wolfSSL:v7.0.0-user-spacefrom
jackctj117:v7-lealem-followups

Conversation

@jackctj117

Copy link
Copy Markdown
Contributor

Follow-ups from the #12170 review, against v7.0.0-user-space.

EMS refusal in the module

wc_PRF() now refuses (BAD_FUNC_ARG) a PRF seed that starts with "master secret" under FIPS v7, where it used to derive the secret and have the wrapper flag it WC_FIPS_NOT_APPROVED (FIPS 140-3 IG D.Q, RFC 7627). wc_PRF_TLS() and wc_PRF_TLSv1() both pass label || seed into wc_PRF(), so this one check covers the label argument, the label split across label and seed, and OpenSSL-style callers that put the label in the seed. "extended master secret" is unaffected.

The TLS-layer refusal (WOLFSSL_EMS_ALWAYS_REQUIRED) is unchanged.

tls12_kdf_test now expects the refusal on v7 and still runs the KAT on other builds.

Must merge together with a wolfSSL/fips change. In wolfSSL/fips#441, the TLS 1.2 KDF CAST (TLSv12_KDF_KnownAnswerTest in fips_test.c) derives with "master secret" through wc_PRF_TLS_fips(). With this PR, that CAST gets BAD_FUNC_ARG, and a v7 module would fail its self-test. The fips side has to:

  • move the CAST to an extended-master-secret vector
  • turn Tls12KdfResult() in fips.c into an up-front refusal, or drop it, since the module now refuses the request before deriving anything

Hybrid group constants

Adds WC_SECP256R1MLKEM768 (4587), WC_X25519MLKEM768 (4588) and WC_SECP384R1MLKEM1024 (4589) to wolfssl/wolfcrypt/kdf.h. They replace the bare numbers in kdf.c, test_kdf.c, test_curve25519.c and wolfcrypt/test/test.c. tls.c static-asserts that they equal the WOLFSSL_* values in ssl.h.

RAND_load_file: one reseed per file

Under v7 there is no wc_RNG_DRBG_Stir(), and wc_RNG_DRBG_Reseed() draws fresh entropy from the module on every call. That meant RAND_load_file() did a full reseed for every 256-byte chunk, which is up to 4096 reseeds for a 1 MB file. It now hashes the file as it reads it (SHA-256, or SHA-512 when there is no SHA-256) and passes the digest as additional input to a single reseed at the end. Builds that have stir are unchanged.

RAND_egd() needs no change: it is compiled out under HAVE_FIPS, and it already reseeds once with at most 255 bytes.

Added a portable RAND_load_file case that reads a cert file over several chunks. The existing data-reading cases only run on Linux and FreeBSD.

-208 / -209 comments

Rewords the comments in error-crypt.h:

  • DRBG_KAT_FIPS_E (-208) is the DRBG self-test (CAST) failure, which rerunning the self-test can recover from.
  • DRBG_CONT_FIPS_E (-209) is the health-test failure, which latches the module failed until it is reloaded.

Testing

  • --enable-all --enable-debug CFLAGS=-Werror: make check passes.
  • Builds cleanly with --disable-mlkem, with --enable-cryptonly, and with opensslextra + ML-KEM + X25519 and WOLFSSL_NO_TLS12.
  • The v7-only paths can't be built from a git tree, so I tested them in a throwaway copy with the v7 guards forced on and stir removed from random.h, using --enable-all --enable-smallstack:
    • testwolfcrypt passes, including the TLS 1.2 KDF refusal.
    • The kdf and ossl_rand API groups pass.
    • Instrumenting RAND_load_file showed exactly one reseed per file (600 and 1286 bytes).
  • Not tested: a real FIPS v7 bundle build, which needs the companion fips change above.

Copilot AI balanced review requested due to automatic review settings November 24, 2026 16:23
@jackctj117 jackctj117 closed this Nov 24, 2026
@jackctj117
jackctj117 deleted the v7-lealem-followups branch November 24, 2026 16:25
@jackctj117

Copy link
Copy Markdown
Contributor Author

Superseded by the PR from branch v7-followups (branch renamed).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new assertions break ML-KEM builds by referencing constants absent from frozen FIPS v6 headers and comparing different enum types when GCC enum-comparison warnings are treated as errors.

2 open issues
What changed in this PR

This PR follows up on the FIPS v7 user-space work in #12170, tightening key derivation behavior and reducing file-based RNG reseeding overhead. The EMS refusal requires the companion changes in wolfSSL/fips#441.

Changes:

  • Refuse non-EMS master-secret derivation in FIPS v7 and update test expectations.
  • Introduce named hybrid-group constants and verify alignment with TLS group values.
  • Hash file input before a single reseed where stir is unavailable, add portable coverage, and clarify DRBG error comments.
File Description
wolfssl/​wolfcrypt/​kdf.h Define named ML-KEM hybrid-group constants.
wolfssl/​wolfcrypt/​error-crypt.h Clarify self-test and health-test failure comments.
wolfcrypt/​test/​test.c Update EMS refusal expectations and hybrid constants.
wolfcrypt/​src/​kdf.c Enforce FIPS v7 EMS refusal and use named constants.
tests/​api/​test_ossl_rand.c Add multi-chunk regular-file loading coverage.
tests/​api/​test_kdf.c Use wolfCrypt hybrid-group constants.
tests/​api/​test_curve25519.c Replace numeric hybrid groups with named constants.
src/​tls.c Assert agreement between wolfCrypt and TLS group values.
src/​ssl_crypto.c Hash file input and reseed once when stir is unavailable.

Review effort: Balanced

Comment thread src/tls.c

#ifndef NO_TLS

#ifdef WOLFSSL_HAVE_MLKEM
Comment thread src/tls.c
Comment on lines +168 to +170
wc_static_assert(WC_SECP256R1MLKEM768 == WOLFSSL_SECP256R1MLKEM768);
wc_static_assert(WC_X25519MLKEM768 == WOLFSSL_X25519MLKEM768);
wc_static_assert(WC_SECP384R1MLKEM1024 == WOLFSSL_SECP384R1MLKEM1024);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants