Skip to content

Pq fips fenrir - #11359

Open
jackctj117 wants to merge 12 commits into
wolfSSL:masterfrom
jackctj117:PQ-FIPS-Fenrir
Open

Pq fips fenrir#11359
jackctj117 wants to merge 12 commits into
wolfSSL:masterfrom
jackctj117:PQ-FIPS-Fenrir

Conversation

@jackctj117

Copy link
Copy Markdown
Contributor

This pull request introduces several FIPS 140-3 and SP 800-131A Rev. 2 compliance checks and test updates for cryptographic operations, mainly affecting ECC, HMAC, RNG/DRBG, and RSA code paths. The changes ensure that only CAVP-tested and standards-approved parameters, key sizes, and algorithms are permitted in approved mode, and that test suites properly verify these constraints.

FIPS 140-3 and SP 800-131A Compliance Enforcement

  • ECC Algorithm Restrictions:

    • Added checks to restrict ECC shared secret computation and key generation to only approved curves (P-256, P-384, P-521) and key sizes (≥224 bits) in FIPS v7+ mode, per SP 800-131A and FIPS 140-3 IG C.B. ECDSA signing is also gated to disallow curves with fewer than 224 bits. [1] [2] [3] [4] [5]
  • HMAC Key Length Enforcement:

    • Enforced a maximum HMAC key length of 1024 bits in FIPS v7+ mode, matching the module's CAVP-tested range, unless an explicit override is provided.
  • RNG/DRBG Entropy Source Enforcement:

    • Modified DRBG reseeding in FIPS v7+ mode to always obtain entropy from the module's internal seed source, per SP 800-90A, treating caller-supplied bytes as additional input only. [1] [2] [3]

Test Suite Updates for Compliance

  • HMAC Test Enhancements:

    • Updated HMAC test cases to verify rejection of overlong keys in FIPS v7+ mode and acceptance only when explicitly allowed, across all SHA and SHA3 variants. [1] [2] [3] [4] [5] [6]
  • RSA Test Adjustments:

    • Updated RSA test cases to expect and handle new FIPS_WRONG_API_E errors for disallowed PKCS#1 v1.5 key transport in FIPS v7+ mode, ensuring tests reflect current compliance rules. [1] [2] [3] [4] [5] [6]

These changes collectively ensure that cryptographic operations are restricted to approved parameters and algorithms in FIPS 140-3 approved mode and that the test suite robustly verifies these restrictions.

…since FIPS 198-1 Section 4 folds them to K0 = H(K) but they fall outside the module's CAVP-tested key range (Fenrir F-9546).
…elow 224 bits under FIPS v7 per SP 800-131A Rev. 2 Table 2, leaving signature verification with those curves available as legacy use (Fenrir F-7359).
…lidated curves P-256, P-384 and P-521 ahead of every crypto-callback and hardware dispatch (Fenrir F-9544).
… the caller's bytes as additional_input under FIPS v7, because SP 800-90A Rev. 1 Section 9.2 forbids consuming-application entropy input (Fenrir F-9547).
…tyle test vectors and keep them covered through the wc_HmacSetKey_ex allowFlag escape (Fenrir F-9546).
…vector under FIPS v7 per SP 800-132 Section 5.1 (Fenrir F-7779).
… wc_ecc_sign_set_k staging and for the signatures that consume the staged k per FIPS 186-5 Section 6.3 (Fenrir F-7778).
…idated KAS-ECC-SSC set and skip the composite flow for them like the existing key-size mismatch path (Fenrir F-9544).
…h under FIPS v7 per SP 800-131A Rev. 2 Section 6 (Table 5) (Fenrir F-7361).
@jackctj117 jackctj117 self-assigned this Sep 2, 2026
Copilot AI lite review requested due to automatic review settings September 2, 2026 20:05

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 ECC signing gate returns a misleading error code (SIG_TYPE_E) and the DRBG reseed helper should better align with existing SMALL_STACK_CACHE behavior and optional additional_input semantics.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR tightens FIPS 140-3 / SP 800-131A Rev. 2 enforcement in wolfCrypt (notably for ECC KAS/KeyGen/Sign, HMAC key sizing, and DRBG reseed entropy sourcing) and updates the wolfCrypt test suite to assert the new approved-mode behaviors and expected error codes.

Changes:

  • Enforces FIPS v7+ constraints: ECC KAS limited to P-256/P-384/P-521; ECC keygen/signing disallows <224-bit curves; HMAC rejects keys >1024 bits unless explicitly overridden.
  • Updates DRBG reseed in FIPS v7+ to always pull entropy from the module seed source and treat caller bytes as additional input.
  • Extends test coverage to validate new rejection/acceptance behaviors (HMAC long keys, RSA PKCS#1 v1.5 transport refusal, PBKDF2/HKDF/ECDSA “not approved” signaling).
File summaries
File Description
wolfssl/wolfcrypt/hmac.h Adds HMAC_FIPS_MAX_KEY constant for v7+ (1024-bit max) used to enforce approved-mode key-size limits.
wolfcrypt/src/hmac.c Enforces v7+ maximum HMAC key length when allowFlag is not set.
wolfcrypt/src/random.c Alters v7+ DRBG reseed to draw entropy internally and treat caller bytes as additional input; adds helper to reseed from seed source.
wolfcrypt/src/ecc.c Adds v7+ ECC curve gating for shared secret, shared secret (ex), key generation, and signing restrictions.
wolfcrypt/test/test.c Updates/extends tests for HMAC long-key rejection + override, RSA PKCS#1 v1.5 transport refusal behavior, and other v7+ non-approved indicators.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread wolfcrypt/src/ecc.c
Comment on lines +7739 to +7748
#if FIPS_VERSION3_GE(7,0,0)
/* SP 800-131A Rev. 2 Table 2: ECDSA digital signature generation with
* len(n) < 224 is disallowed, while signature verification with those
* curves remains legacy use, so only the signing path is gated. The
* curve is resolved from key->dp, never from ecc_sets[key->idx], so a
* custom-curve key (idx == ECC_CUSTOM_IDX) cannot index out of range. */
if (key->dp->size < WC_ECC_FIPS_GEN_MIN) {
return SIG_TYPE_E;
}
#endif
Comment thread wolfcrypt/src/random.c
Comment on lines +787 to +790
#if FIPS_VERSION3_GE(7,0,0)
/* Caller bytes become additional_input; entropy comes from the
* module's seed source (SP 800-90A Rev. 1 Section 9.2). */
return Rng_ReseedFromSeedSource(rng, seed, seedSz);
Comment thread wolfcrypt/src/random.c
Comment on lines +713 to +722
int ret;
#ifdef WOLFSSL_SMALL_STACK
byte* newSeed = (byte*)XMALLOC(SEED_SZ + SEED_BLOCK_SZ, rng->heap,
DYNAMIC_TYPE_SEED);
if (newSeed == NULL) {
return MEMORY_E;
}
#else
byte newSeed[SEED_SZ + SEED_BLOCK_SZ];
#endif
…e the software-only module cannot offload to an implementation that has not been CAVP tested per FIPS 140-3 IG C.B, leaving a hybrid software-plus-hardware module configuration to reintroduce it under its own build option (Fenrir F-9544).
…_NOT_APPROVED indicator is not delivered to the caller, instead of absorbing it wherever it appears, so the tests prove the module surfaces the FIPS 140-3 IG 2.4.C indicator (Fenrir F-7778, F-7779).
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