Commit Graph

36156 Commits (master)

Author SHA1 Message Date
Aidan Garske 7dfe3edfd7
F-19096 - Stop marking PKCS#11 generated ML-KEM keys as locally private (#12347) 2026-12-02 22:02:24 +10:00
Josh Holtrop b9ff9a409e
LMS: fix W=1 checksum digits for SHAKE256/192 without SHA-256/192 (#12325)
Make the ls == 7 test unconditional.

wc_lmots_q_expand() (non-small implementation) emits a ninth checksum
digit for w = 1 only when ls == 7 (n = 32). That test was previously
compiled only when WOLFSSL_LMS_SHA256_192 was defined, but the
SHAKE256/192 parameter sets are also n = 24 (ls = 8, p = 200). In a
build with WOLFSSL_LMS_SHAKE256 and without WOLFSSL_LMS_SHA256_192
(--enable-lms=shake256), the extra digit was always written. The
checksum digits shifted by one and the lowest bit of the checksum was
dropped. The build verified its own signatures, but its
LMOTS_SHAKE_N24_W1 signatures failed with conforming RFC 8554 /
SP 800-208 verifiers, and it rejected conforming ones (SIG_VERIFY_E).

Affected: WC_LMS_PARM_SHAKE192_L1_H{5,10,15,20,25}_W1 in non-small
builds with SHAKE256 but not SHA-256/192. Other widths, the
WOLFSSL_WC_LMS_SMALL implementation and builds with SHA-256/192 were
correct.

Add lms_test_kat() to testwolfcrypt: known-answer verify tests for
L1-H5-W1 with SHA-256/192 and SHAKE256/192. Each signature is also
verified by an RFC 8554 verifier independent of wolfCrypt. A test that
signs and verifies in the same build cannot catch a checksum encoding
error. The test also checks that flipped message and signature bits are
rejected.

Add a pq-all CI config, lms-shake256-no-sha256-192
(--enable-lms=yes,shake256), so the SHAKE256/192 KAT runs in the
configuration that had the bug.
2026-12-02 21:27:18 +10:00
yosuke-wolfssl f019d1b27a
crl: treat a NULL CRL object as a missing CRL (#12327)
- CheckCertCRLCm() skips the CRL lookups when crl is NULL and takes
  the CRL_MISSING path, which calls cbMissingCRL and crlCb.
- CheckCertCRL() and CheckCertCRL_ex() take the cert manager; the
  handshake callers pass SSL_CM(ssl).
- Notes the NULL crl on crlErrorCb and updates the
  wolfSSL_CertManagerFreeCRL() docs (en, ja).
- tests: CheckCRL and VerifyBuffer after FreeCRL return CRL_MISSING;
  new test_wolfSSL_CertManagerFreeCRL_handshake covers both callbacks
  after FreeCRL and loads crl.der without PEM support. The MC/DC
  white-box fakes take the cert manager.

Issue: F-8881
2026-12-02 21:24:32 +10:00
philljj fbc9aeb6dc
Merge pull request #12324 from dgarske/ecc_pct_no_dhe
Fix FIPS ECC keygen pairwise test build without ECDH or public key order checks
2026-12-01 21:01:50 -06:00
Takashi Kojo f54566ebeb
Add MLDSA for set1_sigalgs_list (#12137)
* Add pqc algorithms for set1_sigalgs_list

* Reject ML-DSA tokens for schemes disabled at build time
2026-12-02 11:18:32 +10:00
Mattia Moffa e3f3f73720
Merge pull request #12349 from night1rider/fix-max3266x-maa-sqrmod
MAX3266X: fix MAA sqrmod operand placement and fallback
2026-12-02 01:59:10 +01:00
philljj 29458299db
Merge pull request #12089 from SparkiDev/aes_gcm_ghash_int_mul
AES-GCM: add GCM_INT_MUL GHASH and make it default
2026-12-01 16:39:46 -06:00
David Garske f29035a56a Fix FIPS ECC keygen pairwise test build without ECDH or public key order checks 2026-12-01 13:55:48 -08:00
philljj 3fdff6299e
Merge pull request #12338 from padelsbach/external-test-rsa4096
Skip RSA-4096 certs in external.test when RSA-4096 is not supported
2026-12-01 13:59:53 -06:00
night1rider 6e4bad75bc MAX3266X: fix MAA sqrmod operand placement and fallback
MAX32665/66 MAA SQ computes b^2 mod m (MAA_B); pass input in MAA_B too.
2026-12-01 12:32:01 -07:00
Paul Adelsbach 94f99f7f66 Skip RSA-4096 certs in external.test when RSA-4096 is not supported 2026-12-01 10:24:04 -08:00
philljj b0659deff8
Merge pull request #12224 from mattia-moffa/20261120-dtls-issue12136
DTLS 1.3: resend HelloRetryRequest on a stateful server
2026-12-01 11:38:05 -06:00
Aidan Keefe fdf133022d
Merge pull request #12261 from MarkAtwood/crl-walk-tests
test: walk every entry of the static revoked list
2026-12-01 09:52:55 -07:00
philljj 5701d7747c
Merge pull request #12329 from yosuke-wolfssl/fix/f-buffer-free
Free private-key materials in freed heap or dead stack memory
2026-12-01 10:18:54 -06:00
philljj 225c8558e4
Merge pull request #12114 from douzzer/20261112-fips-dev-exemptions
20261112-fips-dev-exemptions
2026-12-01 10:01:29 -06:00
philljj 10427ba7e5
Merge pull request #12330 from yosuke-wolfssl/fix/openwrt
Docker/OpenWrt: fetch package indexes from archive.openwrt.org
2026-12-01 09:54:16 -06:00
Daniel Pouzzner 8f801ae8ef
Merge pull request #12122 from MarkAtwood/linuxkm-install-headers
linuxkm: install headers needed by installed wolfssl headers
2026-12-01 09:31:47 -06:00
yosuke-wolfssl a927e14ed5
wolfcrypt: return the full nonzero result from 64-bit fe_isnonzero (#12326)
- Regenerate x86_64 (fe_x25519_asm.S/.asm) and AArch64
  (armv8-curve25519.S/.asm, armv8-curve25519_c.c) fe_isnonzero().
- test_wc_ed25519_check_key_edgecases() imports two off-curve
  Ed25519 public keys and expects PUBLIC_KEY_E.

Issue: F-19041
2026-12-01 22:16:20 +10:00
Emma Stensland 2a1eb755bd
openssl: wipe the unblinded scalar after reading an EC_KEY (#12322)
Under WOLFSSL_ECC_BLIND_K, wc_ecc_key_get_priv() leaves a plain copy.
FIPS copies of ecc.h lack ecc_put_k(), so wipe ku directly there.
2026-12-01 22:13:44 +10:00
yosuke-wolfssl a79ad38bb7
pkcs7: copy each streamed chunk from the current callback offset (#12316)
- wc_PKCS7_EncodeContentStream() copies each full octet-string chunk
  from buf + amtWritten inside the split loop.
- Extend GetContentCB, test_wc_PKCS7_EncodeSignedData and
  test_wc_PKCS7_EncodeDecodeEnvelopedData for the issue case.

Issue: F-19028
2026-12-01 22:10:14 +10:00
yosuke-wolfssl 7f3ccd660f
asn_orig: size the ECDSA signature DER from the headers written (#12315)
- StoreECC_DSA_Sig_Bin() checks *outLen against the INTEGER sizes
  from SetASNInt() and the SEQUENCE header size from SetSequence().
- test_wc_EccDecisionCoverage3() gains new test vectors.

Issue: F-19125
2026-12-01 22:07:11 +10:00
Emma Stensland f08cfddef8
Espressif: cap the error queue at 16 entries (#12221)
* Free error nodes read from the global error queue

ERR_get_error_line() only moved the cursor, so read errors kept places
in a full queue. The per-thread queue already removes them.

* Espressif: cap the error queue at 16 entries

ESP builds set WOLFSSL_MAX_ERROR_SZ to 200 or 500, so an uncleared
queue at the default cap of 100 could hold about 100 KB.

* Remove the global error queue read cursor

Pulls now free their node, so wc_current_node was always the head.
2026-12-01 21:53:52 +10:00
Aidan Garske 41682e9751 Drop Frosted from the MDK thread wizard options 2026-12-01 10:08:23 +01:00
Aidan Garske e556cfdd50 Recognize retired frosted macros in source checks 2026-12-01 10:08:23 +01:00
Aidan Garske c343dcf768 Remove Frosted OS support 2026-12-01 10:08:23 +01:00
Tobias Frauenschläger 5303fea31c
PKCS#7: fix SignedData verify state across cert reload and reuse (#12286)
* Keep the PKCS#7 verify content pointer across the signer cert reload

When the eContent is a constructed OCTET STRING and streaming is
disabled, PKCS7_VerifySignedData() joins the parts into
pkcs7->contentDynamic and points its local content at that buffer.
Stage 5 then frees the structure with wc_PKCS7_Free() and reinitializes
it with the signer certificate, restoring a copy of contentDynamic, but
content still pointed at the freed original. The content digest and
pkcs7->content were then taken from freed memory.

Point content at the restored copy when it pointed at contentDynamic.
An offset bug, fixed separately, keeps a well-formed message from
reaching stage 5, but a crafted one gets there by placing the
certificate set inside the last part. The constructed eContent test
added with that fix reaches this path in builds without streaming, and
ASan reports the use after free there when this change is left out.

Fixes F-19104.

* Step over a constructed PKCS#7 eContent by its encoded length

Without streaming, PKCS7_VerifySignedData() advanced past a constructed
eContent OCTET STRING by the number of content bytes it collected, not
by the encoded length of the string. The inner OCTET STRING headers were
left in front of the parse position, so the certificate set and the
signerInfos were read from the wrong offset and a valid message with a
definite-length constructed eContent failed with ASN_PARSE_E. A string
whose parts are all empty was not stepped over at all.

Advance by the encoded length once the parts are collected, and by the
content length only for a primitive OCTET STRING. Indefinite-length
messages were not affected because wc_BerToDer() flattens the string
first, and streaming builds parse the parts separately.

A constructed string holding a single part failed in both builds: the
part was then read as a primitive OCTET STRING, but from the position of
its tag, so the tag byte was taken as the length. Start that read after
the tag.

The new test signs a message, wraps its eContent in a constructed OCTET
STRING of one part and of two parts, and verifies both in both builds.

* Use the streamed PKCS#7 digest only for streamed content

In stream-out mode, stage 7 of PKCS7_VerifySignedData() replaced the
digest with the one hashed while the content was streamed whenever a
stream-out callback was set. Only embedded eContent goes through the
callback, so a detached verify, or a header/footer verify through
wc_PKCS7_VerifySignedData_ex(), checked the messageDigest attribute
against the digest of no content and failed with SIG_VERIFY_E.

Use the streamed digest only when the content was streamed, and refuse
to stream content out during a detached verify, where the signature
covers the caller's content.

* Keep the PKCS#7 stream mode callbacks across the signer cert reload

When a SignedData carries certificates, PKCS7_VerifySignedData() frees
and reinitializes the structure in stage 5 to load the signer
certificate. It restores the stream, the DER copy, the content and the
degenerate policy, but not the callbacks set with
wc_PKCS7_SetStreamMode(). In stream-out mode stage 3 has already handed
the content to streamOutCb and hashed it without keeping a copy, so
stage 7 found no callback, skipped the streamed digest and checked the
messageDigest attribute against missing content. The verify failed
with SIG_VERIFY_E, and the caller's stream mode was gone afterwards.

Save getContentCb, streamOutCb, streamCtx and the encodeStream flag
before the reload and put them back with the other restored fields.

Fixes F-18631.

* Fail a PKCS#7 verify when the stream-out callback fails

PKCS7_VerifySignedData() ignored the return value of the stream-out
callback, so content the callback could not take was dropped and the
verify still succeeded. Fail the verify with BUFFER_E when the callback
returns a negative value. Zero or a positive byte count continues, the
values wc_PKCS7_WriteOut() accepts. The wc_PKCS7_SetStreamMode()
documentation now says how a verify and a decode treat the return.

* Drop PKCS#7 certificate pointers before freeing the stream copy

In streaming builds, stage 5 of PKCS7_VerifySignedData() copies the
certificate set into stream->tmpCert, and the reload with the first
certificate points singleCert, cert[], issuer, the certificate list
and later verifyCert into that copy. The copy outlives the call, so the
pointers stay valid for the application.

When the same object verifies another message with a certificate set,
stage 5 frees the old copy before it has accepted the new set, and only
the reload replaces the pointers. An error in between, such as a
certificate length past the end of the set, returned with every pointer
still aimed at the freed copy. A following message without certificates
then parsed the freed memory as its signer certificate.

Clear those references before freeing the copy when one of them points
into it, and keep its allocated size in a new stream field for that
check. A set rejected before any reload leaves a copy behind with the
certificate the caller loaded still in place, so dropping the references
on any non-NULL tmpCert would lose that certificate at the next rejected
set.

Fixes F-18632.

* Clear the PKCS#7 verify certificate when a verify starts

pkcs7->verifyCert names the certificate whose signature a verify
checked, and callers such as wolfSSL_PKCS7_verify() treat a NULL value
as "nothing was signed". It was only reset when the stage 5 reload
reinitialized the structure, so a certificates-only bundle without a
certificate set, which skips that reload, verified with the previous
message's signer still in place.

Clear verifyCert and verifyCertSz with the other per-message state at
WC_PKCS7_START. The new test checks a verify that fails after the reset
in every build, and the certificates-only bundle without streaming,
where a bundle that short completes a verify.

Fixes F-16374.

* Free the DER copy of a previous PKCS#7 message when a verify starts

Without streaming, PKCS7_VerifySignedData() converts an
indefinite-length message into pkcs7->der and parses that copy. The
copy outlived the call, and every later call replaced its input with
pkcs7->der whenever derSz was set. After a BER message without a
certificate set, the next verify on the same object therefore parsed
the old message instead of its own input, returned 0 and handed back
the old content. Each further BER message also leaked the previous
copy. Messages with certificates escaped only because the stage 5
reload restored der but not derSz.

At WC_PKCS7_START, free the previous copy instead of parsing it. Content
and certificate references that a verify pointed into the copy are
dropped with it, and derSz now survives the reload so those references
can be recognized. Content and certificates the caller set are kept. An
input or footer inside the copy, such as the content a BER message
returned, is rejected with BAD_FUNC_ARG rather than freed under the
call. A header/footer verify keeps the contentSz the caller set. A
message without certificates can no longer verify against the
certificates of a previous BER message, as they went with its copy;
streaming builds keep the previous set in stream->tmpCert as before.

The BER conversion now writes into a local buffer and stores it only
once wc_BerToDer() succeeds, and the MEMORY_E exit of the stage 5
reload puts the copy back in pkcs7->der instead of leaking it. The new
test runs without streaming, the only build that makes the copy.

Fixes F-18637.

* Copy the caller hash when a PKCS#7 verify starts

wc_PKCS7_VerifySignedData_ex() checks the messageDigest attribute
against a content hash the caller passes in. A hash taken from memory
the object owns, such as the messageDigest attribute, plainDigest,
pkcs7Digest or signature left by a verify that returned
PKCS7_SIGNEEDS_CHECK, was freed by the stage 5 signer cert reload and
read again in stage 7.

Copy the caller hash when a verify starts, so no buffer the verify frees
can lie under it, and refuse a hash longer than WC_MAX_DIGEST_SIZE.
The hash is copied before the DER copy of a previous BER message is
freed, so a hash inside it is covered too. Streaming builds keep the
copy in the stream state and use it on the later calls of the same
verify, because a chunked verify can run the reload and stage 7 in
different calls, with the caller's pointer already freed by the time of
the second. The copy is taken on the first call of a message only, since
the start state itself can span several calls and its first call frees
the content copy of the previous verify.

* Reject a PKCS#7 verify input inside a buffer the object owns

After a verify, pkcs7->content can point into a buffer the wc_PKCS7
owns: stream->content in streaming builds, contentDynamic for an
eContent joined from several parts, or the DER copy of a BER message.
Verifying that content on the same object, as an application might for
a nested SignedData, freed the buffer during the call while the input
still pointed into it. Both builds free contentDynamic when the next
verify starts, and streaming builds also release stream->content in
stage 2 and then parse freed memory in wc_PKCS7_HandleOctetStrings().
The DER copy is already refused.

Refuse an input or footer inside any of these buffers with BAD_FUNC_ARG
on every call.

When a verify starts, content left by the previous verify was dropped
only while pkcs7->content still equalled the pointer that verify left.
A pointer the caller had advanced into contentDynamic or stream->content
survived the free and was taken as content the caller set: the next
verify of a valid message failed with SIG_VERIFY_E and handed the
dangling pointer back. Drop any pointer inside those buffers. The
checks use the allocated sizes, kept in a new stream field and a new
wc_PKCS7 member contentDynamicSz at the end of the structure, so a
pointer into the middle of a buffer is caught however the caller changed
pkcs7->content. The documentation says the content has to be copied or
verified with another structure. Content that points into the caller's
own buffer is not affected, so a nested verify without streaming of a
message the caller holds still works.
2026-12-01 18:03:17 +10:00
Tobias Frauenschläger 666db43563
Validate the hash input of the signature hash APIs (#12263)
* Validate the hash input of the signature hash APIs

wc_SignatureGenerateHash_ex() signed whatever it was given. For
WC_SIGNATURE_TYPE_RSA_W_ENC a bare digest produced PKCS#1 v1.5
padding without a DigestInfo, which no other implementation accepts,
and the default self-verify then failed with ASN_PARSE_E after the
signature buffer was already written. For ECC and plain RSA a hash of
the wrong length for hash_type was signed as-is.

wc_SignatureVerifyHash() parsed the DigestInfo but skipped the
AlgorithmIdentifier OID and ignored trailing data, so a DigestInfo
for another hash, or one followed by extra bytes, passed validation.

Both functions now apply the same checks. For RSA_W_ENC, hash_data must
be exactly one DER DigestInfo whose AlgorithmIdentifier holds the OID of
hash_type with absent or NULL (05 00) parameters, and whose digest has
the hash_type size. The OID and parameters are compared byte for byte,
because GetAlgoId() matches only an OID sum in NO_VERIFY_OID builds and
for hashes OidFromId() does not know, and the template GetAlgoId() reads
an indefinite-length NULL (05 80) as an empty one. For the other types,
hash_len must be the hash_type digest size. WC_HASH_TYPE_MD5_SHA returns
HASH_TYPE_E, since MD5||SHA-1 has no DigestInfo OID and wc_HashGetOID()
maps it to the MD5 OID. A hash type whose OID OidFromId() does not
know, such as SM3, also returns HASH_TYPE_E. Without ASN support, the
RSA_W_ENC hash APIs return SIG_TYPE_E, as the data APIs already do.

Fixes #12231.
Fixes F-16574.
Fixes F-16575.

* Check the RSA_W_ENC DigestInfo by encoding and comparing

wc_SignatureCheckDigestInfo() parsed the DigestInfo field by field and
had to reject each malformed shape on its own: OID sum collisions,
indefinite-length NULL parameters, a digest nested in the
AlgorithmIdentifier and trailing data. It now encodes the trailing
digest-size bytes with wc_EncodeSignature() and compares the result
with the whole input, as ConfirmSignature() does for certificate
signatures, so only that exact encoding is accepted.

Every mismatch now returns ASN_PARSE_E, since a byte comparison cannot
tell a wrong OID from a wrong length. A DigestInfo with absent
parameters, which the parser accepted, is rejected because
wc_EncodeSignature() always writes NULL parameters for a hash.

The documentation drops ASN_SIG_OID_E, limits BAD_LENGTH_E to ECC and
plain RSA, and lists HASH_TYPE_E for the data APIs, which return it
for MD5_SHA. The tests keep one case per branch of the new check.

* Test the remaining signature hash rejections and align the docs

Plain RSA with verify set to 0 used to sign a hash of any length and
now returns BAD_LENGTH_E, and wc_SignatureGenerate() with
WC_HASH_TYPE_MD5_SHA and RSA_W_ENC now returns HASH_TYPE_E. Both
behaviour changes get a test again.

The HASH_TYPE_E entries of the hash APIs now use the same wording as
the data APIs and limit the missing DigestInfo OID case to RSA_W_ENC,
since ECC and plain RSA accept such hash types. The locals of
wc_SignatureCheckDigestInfo() follow the snake_case naming of the file.
2026-12-01 17:53:42 +10:00
Tobias Frauenschläger 8d72b74727
Add LMS/HSS key generation, signing and verification over PKCS#11 (#12283)
wc_Pkcs11_CryptoDevCb now handles the stateful signature callbacks for
LMS keys, using the PKCS#11 HSS mechanisms. Key generation passes
CKA_HSS_LEVELS with the per-level lists CKA_HSS_LMS_TYPES and
CKA_HSS_LMOTS_TYPES in the private key template, as PKCS#11 3.1, 3.2 and
the 3.3 draft define it; the single-value CKA_HSS_LMS_TYPE and
CKA_HSS_LMOTS_TYPE are attributes the token gives the public key. The
private key is a token object, private, sensitive, not extractable and
not copyable, since the token keeps the one-time-signature state; the
public key is kept on the token too so a later process can verify by id
or label.

Keys without an id or label are declined, so software LMS keys that
carry a devId still sign in software, and a token key without a name
would be left behind on the token. Key generation also fails with
BAD_STATE_E when an HSS object, token or session, already has the key's
id or label, as a later lookup by name could otherwise find the older
key; with
WC_PKCS11_FIND_WITH_ID_ONLY the id check covers every private and public
key, whatever its type, as the lookups do, and Pkcs11FindKeyOfClass now
tells a failed search apart from no match so either stops key
generation. Keys are always found by id or label; no object handle is
kept in devCtx, as a handle no longer names the key once the library is
set up again. A key whose state software holds signs and counts its
signatures in software. These declines, and every XMSS
request, are decided from the key before a session is opened, so a token
that cannot be opened or logged into never fails an operation software
can do, and never leaves a software LMS key marked bad.

Before signing or counting signatures left, the token key's
CKA_HSS_LEVELS and type lists are compared with the LmsKey's parameters,
and a mismatch fails with WC_KEY_MISMATCH_E before the token uses a
one-time key, so SigsLeft reports 0 for a key Sign refuses. That includes a
token key with more levels than the build supports, whose type lists
come back CKR_BUFFER_TOO_SMALL. CKR_KEY_EXHAUSTED
maps to KEY_EXHAUSTED_E; any other signing failure, including a
signature whose length does not match the parameters, is reported as
WC_HW_E and wolfCrypt treats the key as bad. Signatures left come from
CKA_KEYS_REMAINING, the PKCS#11 3.3 name, added with
CKA_HSS_KEYS_REMAINING as an alias.

Verification uses the public key held by the LmsKey when it has one,
falling back to software when no session opens, or the token does not
take it or fails with it, and otherwise the public key named on the
token.
CKR_SIGNATURE_LEN_RANGE is reported as SIG_VERIFY_E like
CKR_SIGNATURE_INVALID. There is no free handler, as generated private
keys are always token objects and freeing a key never destroys one.

wc_LmsKey_Reload and wc_XmssKey_Reload now leave a key named by id or
label on the device even when a read callback is set, when a device is
registered for its devId, as key generation already does, so a named key
is never reloaded in software from storage its key generation never
wrote. A named key whose devId has no registered device is generated in
software and still reloads from its read callback. The exception is
WOLF_CRYPTO_CB_KEYGEN_SW_FALLBACK without WOLF_CRYPTO_CB_ONLY_LMS/XMSS:
there a device may decline a named key's generation and leave its state
in software, so the read callback still decides. A devId on an unnamed
key with a read callback still means the caller holds the state. The
keygen-sw-fallback cryptocb-only CI leg now also builds LMS, XMSS and
PKCS#11 to cover it.

NO_PKCS11_LMS leaves LMS out; verify-only LMS builds only get
verification. The HSS constants and CKR_BUFFER_TOO_SMALL are added to
pkcs11.h.
2026-12-01 17:52:04 +10:00
Yosuke Shimizu d94468807a Docker/OpenWrt: fetch package indexes from archive.openwrt.org
- runTests.sh rewrites the release feeds in distfeeds.conf from
  downloads.openwrt.org to archive.openwrt.org before opkg update.
- runCMD takes an optional try count, waiting 5s between tries;
  opkg update runs with 3 tries.
- The 21.02 kmods feed workaround is removed.
- The compile_container job timeout is raised from 2 to 4 minutes.
2026-12-01 14:10:56 +09:00
philljj 4760a1b1ea
Merge pull request #12105 from SparkiDev/rsa_oeap_compiler_ct
RSA OAEP unpad: make separator search constant time
2026-11-30 23:47:52 -05:00
Yosuke Shimizu c8f6cc0fd4 pk: clear private key PEM read buffers before releasing them
- pem_read_file_key() zeroes the file buffer with ForceZero()
  before freeing it when reading a private key.
- pem_read_bio_key() zeroes the buffer and the copy of the leftover
  with ForceZero() before freeing it when reading a private key.

Issue: F-9148
2026-12-01 11:48:49 +09:00
Yosuke Shimizu d27e3cdbad ssl_load: clear the ProcessFile() file buffer before releasing it
- ProcessFile() zeroes content.buffer with ForceZero() before
  static_buffer_free(), for every file type, so a combined
  certificate and key file is cleared too.

Issue: F-9149
2026-12-01 11:17:18 +09:00
Yosuke Shimizu aafd51d343 pk_ec: clear the EC private key BIGNUM when it is freed or replaced
- wolfSSL_EC_KEY_free() and wolfSSL_EC_KEY_set_private_key(),
  including its SetECKeyInternal() failure path, release
  key->priv_key with wolfSSL_BN_clear_free().

Issue: F-9142
2026-12-01 11:14:19 +09:00
Yosuke Shimizu fb5d2d3e45 pk: clear the DSA private key BIGNUM when it is freed or replaced
- wolfSSL_DSA_free() and wolfSSL_DSA_set0_key() release
  dsa->priv_key with wolfSSL_BN_clear_free().

Issue: F-9140
2026-12-01 11:12:44 +09:00
Yosuke Shimizu 845b8634ca pk: clear the DH private key BIGNUM when it is freed or replaced
- wolfSSL_DH_free() and wolfSSL_DH_generate_key() release
  dh->priv_key with wolfSSL_BN_clear_free().

Issue: F-9141
2026-12-01 11:05:33 +09:00
Mark Atwood 19c3ef0b1a linuxkm: install headers needed by installed wolfssl headers
In a --enable-linuxkm build, the installed wolfssl/wolfcrypt/wc_port.h
includes ../../linuxkm/linuxkm_wc_port.h and memory.h includes
../../linuxkm/linuxkm_memory.h. Neither file was installed, so an
out-of-tree kernel module that includes wolfSSL headers from the
install prefix failed with "No such file or directory".

Install both under $(includedir)/linuxkm for linuxkm builds only.
2026-11-30 17:31:46 -08:00
Sean Parkinson 7c865a8ead AES-GCM: add GCM_INT_MUL GHASH and make it default
Table-free GHASH multiply using integer multiplies on operands masked to
every fourth bit. Variants (GCM_IM_64, GCM_IM_32W, GCM_IM_32): 64x64
multiplies on 64-bit CPUs, 32x32->64 on 32-bit CPUs, and 32x32->32 only
(GCM_INT_MUL_32_ONLY, default on M-profile Arm without DSP, e.g.
Cortex-M0/M3). The key prepared from H is stored in Gcm.M0, sized for
the variant.

settings.h now picks the GHASH implementation when none is chosen, so
the PPC, RISC-V and Arm assembly, which include only settings.h, agree
with the C code:
- GCM_TABLE_4BIT when cache resistance is off (WC_NO_CACHE_RESISTANT,
  e.g. --disable-harden, or the new AES_GCM_GMULT_NO_CACHE_RESIST) and
  for Arm/PPC/RISC-V asm builds.
- GCM_SMALL where the CPU multiply may take data-dependent time
  (WC_GCM_MUL_VAR_TIME): Armv4/Armv5, MIPS, 32-bit PowerPC, RISC-V
  without Zkt, and 16-bit or multiplier-less CPUs (AVR, MSP430).
- GCM_INT_MUL otherwise. Choosing it explicitly asserts the CPU
  multiply is constant time.

configure and CMake compile settings.h and aes.h to get the GHASH and
the GCM_INT_MUL variant and record both in options.h, also for an
explicit GCM_INT_MUL, as the Gcm layout depends on them and the CPU
macros depend on flags like -march. aes.h uses a recorded variant as is.

Arm/PPC asm GCM_SMALL bulk GHASH helpers no longer branch on H.

AES-GCM-SIV POLYVAL uses the GCM_INT_MUL multiply when it is compiled.

configure/CMake: add --enable-aesgcm=intmul, rejected with armasm.
--enable-aesgcm=word now selects the word64 GHASH (new GCM_WORD64);
CMake gains "word" too. FIPS before v7 keeps GCM_TABLE_4BIT. CMake no
longer forces 4bit over an explicit choice on little-endian, and
WOLFSSL_HARDEN=no defines WC_NO_CACHE_RESISTANT, recorded in options.h,
as configure does.

CI: multi-arch armhf leg for GCM_INT_MUL with 32x32->32 multiplies.

mcapi: CRYPT_AES_CTX grows to fit the larger Aes.
2026-12-01 11:27:17 +10:00
Mark Atwood b8775f65c9 test: walk every entry of the static revoked list
test_wolfSSL_CRL_static_revoked_list reaches the revoked entries only
through FindRevokedSerial, which indexes the array directly. The
compatibility layer reaches them through next instead, so a static array
chained only at its first entry passes every assertion in that test
today.

Add a pass over the same three-entry CRL through
wolfSSL_X509_CRL_get_REVOKED and wolfSSL_X509_CRL_print, asserting the
count and that all three serials appear in the printed output.

No source change; LinkCRL_CertList already does the chaining. Verified
by mutation: the count assertion fails when changed from 3 to 99, so the
block is reached and is not compiled out by its guards.
2026-11-30 17:05:13 -08:00
philljj c6c048423a
Merge pull request #12314 from SparkiDev/pkcs12_oom_afalg
tests: skip the PKCS#12 parse OOM test with AF_ALG
2026-11-30 19:56:10 -05:00
Sean Parkinson 1a6a003848 RSA OAEP unpad: make separator search constant time
The separator scan in RsaUnPad_OAEP() used a 0/1 mask that Clang turns
into a branch on each byte being zero on PowerPC, Thumb-1 and x86_64
when optimizing. This leaked which bytes are zero and, through the loop
timing, the separator position. The separator byte was then loaded by
its index, putting the separator position on the address bus.

Find the separator with one masked pass that records its index and
value, so no load depends on the separator position. Pass the byte and
the per-byte mask through volatiles so the compiler can't tell the byte
is less than 256 or that the mask is either 0 or all ones, which is what
let it turn the masking back into a branch.

Clear the volatile copies after the scan so the last decoded byte does
not outlive the block.

Reject blocks longer than RSA_MAX_SIZE bits in RsaUnPad_OAEP(), as
RsaUnPad_PSS() already does. Without WOLFSSL_SMALL_STACK the scratch
buffer is sized for RSA_MAX_SIZE, and wc_RsaUnPad_ex() could be given a
larger block.

Add tests for the separator at every position, malformed padding,
labels, zero-length results with and without
WOLFSSL_RSA_DECRYPT_TO_0_LEN, and the block length limit.
2026-12-01 10:26:15 +10:00
philljj b79bccbeb6
Merge pull request #11905 from ohki-saito/fix/F10621
Fix: Fenrir F-10621
2026-11-30 12:39:19 -05:00
David Garske da0abcc010
Merge pull request #12289 from yosuke-wolfssl/fix/f-rsa-state
Fix RSA state machine for the pending crypto operations
2026-11-30 09:16:28 -08:00
Sean Parkinson 292e6aa30b tests: skip the PKCS#12 parse OOM test with AF_ALG
test_wolfSSL_PKCS12_parse_main_cert_oom fails each allocation of
wolfSSL_PKCS12_parse() in turn, so it repeats the PBKDF2 key
derivations once per allocation. With AF_ALG every hash is a round
trip to the kernel: the test takes 46s instead of 0.1s, and the
all-afalg configuration of the afalg workflow now hits its 10 minute
run deadline in make check.

The allocation-failure handling it checks does not depend on the
crypto backend, and every other build still runs it.
2026-11-30 16:16:23 +10:00
Takashi Kojo 85e32e6f7c
PKCS7: accept any BIO type for detached content in PKCS7_verify (#12300)
* PKCS7: accept any BIO type for detached content in PKCS7_verify

* Check retry flags throughout the BIO chain

* Preserve non-NULL pointers for empty BIO content
2026-11-30 15:22:46 +10:00
yosuke-wolfssl 889d000027
Fix used digit handling on fast math (#12278)
* tfm: negate only the digits below bmax in fp_mod_2d()

- The negation loop in fp_mod_2d() stops at bmax.
- test.c gains mp_test_no_digits_above_used(). mp_test_mod_2d() runs
  on fast math, uses two-digit negative operands, and checks each
  result with it.

Issue: F-18451

* tfm: clear the digit above the modulus in the CT modular helpers

- fp_addmod_ct(), fp_submod_ct() and fp_div_2_mod_ct() zero the
  destination's digit at the modulus length after writing the
  result.
- mp_test_addsubmod_ct() runs on fast math and starts each
  destination one digit wider than the modulus; it and
  mp_test_mont() check the result with
  mp_test_no_digits_above_used().
- os-check-linux.json gains a fastmath-mont-red-ct leg.

Issue: F-18450, F-18447

* wolfmath: zero the fast math mp_int in mp_rand() before filling it

- mp_rand() calls mp_zero() before setting used on fast math.
- test_mp_rand checks the digits above used on fast math.

Issue: F-18454
2026-11-30 15:21:52 +10:00
yosuke-wolfssl a6f01aff20
tests: run the wolfCrypt self-test once per make check and ctest (#12280)
* tests: run the wolfCrypt self-test once per make check and ctest

- testsuite_test() runs wolfcrypt_test() in every build, with its own
  func_args, before the TLS tests.
- configure.ac sets UNIT_TEST_WC_ARG to --no-wc when testsuite.test is
  built (examples enabled, leantls disabled), and scripts/unit.test
  passes it to tests/unit.test.
- CMake passes --no-wc to the unit_test ctest entry when
  WOLFSSL_CRYPT_TESTS registers wolfcrypttest.

* tests/unit.c: find the malloc fail count after leading options

- unit_test() takes the fail count from the first argument after the
  leading options, skipping a --group name, when it starts with a
  digit.
- The option loop skips the count argument instead of stopping at it.
- The usage text lists <number> in WOLFSSL_FORCE_MALLOC_FAIL_TEST
  builds.
2026-11-30 15:18:28 +10:00
yosuke-wolfssl eeb77430bb
Fix state issues in ML-DSA/ML-KEM key objects (#12291)
* wc_mldsa: tie the cached matrix A to the public seed it came from

- struct wc_MlDsaKey gains aRho under WC_MLDSA_CACHE_MATRIX_A.
- Key generation, wc_MlDsaKey_ImportPubRaw() and mldsa_set_priv_key()
  record aRho whenever they expand into key->a.
- The cached matrix is used only when aRho is the corresponding public seed.
- mldsa_make_key_reuse_test() gains new test cases.

Issue: F-19053

* wc_mldsa, wc_mlkem: release or refuse key changes under a non-blocking operation

- wc_MlDsaKey_SetParams() returns BAD_STATE_E while a non-blocking
  operation is in flight on the key, before changing anything.
- wc_MlDsaKey_ImportPubRaw() and mldsa_set_priv_key() release the
  operation in flight after their argument checks, as do
  wc_MlKemKey_DecodePrivateKey() and wc_MlKemKey_DecodePublicKey()
  after their length checks.
- Update the corresponding header comments and docs.
- Extend mldsa_nonblock_test_level() and mlkem_nonblock_test_type().

Issue: F-19143
2026-11-30 12:59:42 +10:00
yosuke-wolfssl 6c5e28f4ee
Fix fastmath issues for edge cases (#12311)
* tfm: keep the divisor length in fp_div when the quotient overwrites it

- fp_div() saves b->used before writing any output and trims the
  remainder to that saved length.
- mp_test_div() divides with the quotient written over the divisor,
  using a remainder with more digits than the quotient, and checks
  both outputs.

Issue: F-18449

* tfm: bound fp_read_radix_16 by the destination's digit count

- fp_read_radix_16() stops at a->size digits under ALT_ECC_SIZE or
  HAVE_WOLF_BIGINT.

Issue: F-18448
2026-11-30 12:58:30 +10:00
yosuke-wolfssl c3fcf530cb
Fix sp math issues for edge cases (#12312)
* sp_int: copy the remainder before clearing the quotient in sp_div_2d

- sp_div_2d() copies a into rem before zeroing r when every bit is
  shifted out, and gives rem a positive sign.
- tests: test_wc_SpIntConvDecisionCoverage checks the quotient and
  remainder values of sp_div_2d() when e exceeds the bit length of a,
  including in place and for a negative a.

Issue: F-18453

* sp_int: reduce a negative base in _sp_exptmod_ex

- Both _sp_exptmod_ex() variants reduce the base modulo m when it is
  negative as well.
- tests: test_mp_exptmod_neg_base covers mp_exptmod_nct() with an
  even modulus.

Issue: F-18456
2026-11-30 12:55:32 +10:00
Andrew Hutchings 17d4fd3d46
Run the STM32Sim F417 wolfCrypt test in the STM32 simulator workflow (#12290)
The H753, U585 and MP135 firmware all set NO_DES3 and use
WOLFSSL_STM32_RNG_NOLIB, so CI never builds the STM32 hardware DES/TDES
code or the CubeMX HAL arm of wc_GenerateSeed(). Add an F417 entry that
runs the STM32Sim STM32F417 wolfCrypt test, which covers both (DES/TDES
in CBC and ECB modes), along with the F4 CRYP AES without hardware GCM
and the F4 HASH register layout (SHA-1, MD5).

Move SIMULATORS_REF to the merge of wolfSSL/simulators#27, which carries
the F417 target and run-wolfcrypt-f417.sh.
2026-11-30 12:44:15 +10:00