Commit Graph

29626 Commits

Author SHA1 Message Date
JacobBarthelmeh ecfd1174bb refactor sanity pointer set of session and clean up macro guards 2026-04-07 14:10:25 -06:00
Aidan Garske ebd0bf21e0 F-2207 - Add ForceZero of ECC private key before free in PKCS#11 2026-04-07 13:08:57 -07:00
Aidan Garske 8f2a3f9563 F-2203 - Add negative test for ECC ECIES HMAC authentication tag verification 2026-04-07 13:05:30 -07:00
Aidan Garske 081b5e363c F-2202 - Add negative test for SRP VerifyPeersProof authentication check 2026-04-07 13:01:16 -07:00
Aidan Garske 40b7dfc269 F-2194 - Add negative test for AES Key Unwrap IV verification 2026-04-07 12:59:20 -07:00
Aidan Garske 921f32f52e F-2193 - Add negative test for ASCON AEAD128 authentication tag verification 2026-04-07 12:52:04 -07:00
Aidan Garske 16ac556da8 F-2192 - Add negative test for AES-SIV authentication tag verification 2026-04-07 12:47:02 -07:00
Daniel Pouzzner 5fa8b1535a wolfssl/wolfcrypt/settings.h: for fips-ready, set WC_FIPS_186_4, not _5, to match v5/v6. 2026-04-07 14:35:15 -05:00
sebastian-carpenter faf93cba85 do not enable TLSX with --enable-ech 2026-04-07 12:40:38 -06:00
Daniel Pouzzner 60d1e222b2 globally fix all "BLAKE2" references (implicit BLAKE2B) to explicit "BLAKE2B":
* implement legacy compatibility in settings.h and configure.ac (adds --enable-blake2b while retaining --enable-blake2);
* fix incorrect Blake2 gates in wolfcrypt/src/hash.c wc_HashGetDigestSize() and wc_HashGetBlockSize();
* in wolfcrypt/test/test.c hash_test(), backfill missing Blake2 test coverage and separate blake2b from blake2s in typesHashBad[];
* in tests/api/test_hash.c, separate blake2b from blake2s in notCompiledHash[], sizeSupportedHash[], and sizeNotCompiledHash[].
2026-04-07 13:18:53 -05:00
sebastian-carpenter b9e1fafc4a key cannot be 0 length 2026-04-07 11:44:45 -06:00
sebastian-carpenter c8fff0a36c hpke testing - broke api testing into a different function 2026-04-07 10:52:11 -06:00
sebastian-carpenter 38a6d75641 faster key length validation when setting configs 2026-04-07 10:52:11 -06:00
sebastian-carpenter c887dc47a3 fixing bad state for ech->type 2026-04-07 10:52:11 -06:00
sebastian-carpenter cae12b7ffb mirror arg requirements from wc_HpkeContextSealBase 2026-04-07 10:52:06 -06:00
sebastian-carpenter 690b086edf add null check 2026-04-07 10:49:33 -06:00
sebastian-carpenter 48a0d410b8 improve GetMsgHash error checks 2026-04-07 10:49:33 -06:00
sebastian-carpenter b9ca065c95 increase TLS ECH inner hello lengths to word32 2026-04-07 10:49:33 -06:00
JacobBarthelmeh ad1cc4e87f adjust test case return value check after rebase 2026-04-07 10:26:16 -06:00
Paul Adelsbach c335f7dd6f Remove UTF-8 chars
Get rid of weird character

Fix warning found by CI

Style changes

Addressed 1 and 2.
2026-04-07 10:07:12 -06:00
Anthony Hu 2e32094545 Add regression tests for fixes 2026-04-07 10:05:56 -06:00
Anthony Hu 5bd5f36dff Fix RSA exponent printing (ZD 21426)
Increase buff size from 8 to 24 bytes in PrintPubKeyRSA and related
EVP PKEY print functions.
2026-04-07 10:05:48 -06:00
Anthony Hu 985cceaa97 Fix session cache restore dangling pointer (ZD 21423)
Reinitialize pointer fields in WOLFSSL_SESSION after raw XMEMCPY or
XFREAD in wolfSSL_memrestore_session_cache and
wolfSSL_restore_session_cache. After restore, ticket is reset to
staticTicket, ticketLenAlloc to 0, and peer to NULL.
2026-04-07 10:05:31 -06:00
Anthony Hu c563f3932a Fix PKCS7 CBC padding oracle in EnvelopedData and EncryptedData (ZD 21422)
Replace single last-byte padding check with full PKCS#5/PKCS#7
validation: verify padLen is non-zero and within block size.
Both wc_PKCS7_DecodeEnvelopedData and wc_PKCS7_DecodeEncryptedData
paths are fixed.
2026-04-07 10:05:21 -06:00
Anthony Hu d14b506c51 Fix Dilithium with USE_INTEL_SPEEDUP (ZD 21417)
Add check before word32 addition in dilithium_hash256() that
could wrap to zero, bypassing the size check.
Also reject absurdly large msgLen (> UINT32_MAX/2) in
wc_dilithium_verify_ctx_msg.
2026-04-07 10:04:41 -06:00
Anthony Hu b3278af8dc Fix wc_*_delete() functions (ZD 21415)
Save key->heap before calling wc_*_free(), which zeros the entire key
structure via ForceZero. The saved heap pointer is then passed to XFREE
instead of the now-zeroed key->heap.
2026-04-07 10:04:35 -06:00
Anthony Hu e0421828ff Fix TLS 1.3 PQC key share over heap read (ZD 21413)
Validate that the received key share data length (keLen) is at least
as large as the expected ciphertext size (ctSz) before passing it to
wc_KyberKey_Decapsulate. A malicious TLS 1.3 server could send a
short ML-KEM key share.
2026-04-07 10:04:19 -06:00
Juliusz Sosinowicz 8d54e2213f Guard OCSP signature params with WC_RSA_PSS ifdef
OCSPBASICRESPASN_IDX_SIGNATURE_PARAMS is only defined when WC_RSA_PSS
is enabled but was used unconditionally in EncodeBasicOcspResponse,
causing a build error when WC_RSA_PSS is not defined.
2026-04-07 17:30:30 +02:00
JacobBarthelmeh 7aac9e5766 Merge pull request #10139 from philljj/fix_nightly_mem
Fix nightly mem
2026-04-07 09:08:01 -06:00
Juliusz Sosinowicz a96f20e26b Add documentation for new OCSP responder and cert accessor APIs 2026-04-07 14:25:35 +02:00
Tobias Frauenschläger 06e63f0a7b ECC curve validation follow-up 2026-04-07 12:40:44 +02:00
philljj b5874a6d9e Merge pull request #10132 from douzzer/20260404-default_rng_bank
20260404-default_rng_bank
2026-04-06 22:54:20 -05:00
Daniel Pouzzner efe6ad4bd6 Merge pull request #10116 from Frauschi/zd21457
Additional fixes
2026-04-06 20:23:25 -05:00
Daniel Pouzzner 9347c895fc Merge pull request #10133 from Frauschi/ecc_curve_validation
Improved ECC curve validation
2026-04-06 20:20:35 -05:00
Daniel Pouzzner ede15b4ff4 Merge pull request #10137 from JacobBarthelmeh/acert
fix for acert builds
2026-04-06 19:17:48 -05:00
Daniel Pouzzner 32502e9963 Merge pull request #10102 from Frauschi/zd21460
Various fixes
2026-04-06 18:41:31 -05:00
Daniel Pouzzner 995092362f Merge pull request #10126 from julek-wolfssl/fenrir/20260302
Fenrir fixes
2026-04-06 18:40:11 -05:00
Daniel Pouzzner 0afd9f8819 Merge pull request #10127 from rlm2002/coverity
Coverity change 03042026
2026-04-06 18:24:22 -05:00
Daniel Pouzzner 4924402051 Merge pull request #10125 from kareem-wolfssl/zd21521
Add sz check to ChachaAEADDecrypt to prevent potential underflow.
2026-04-06 18:23:25 -05:00
Daniel Pouzzner 53a3d23ce6 Merge pull request #10131 from douzzer/20260403-WC_FIPS_186
20260403-WC_FIPS_186

approved by @JacobBarthelmeh, @Frauschi, and @dgarske.
2026-04-06 18:22:27 -05:00
Daniel Pouzzner 1d6f295113 wolfssl/wolfcrypt/md2.h and wolfssl/wolfcrypt/md4.h: fix stray commas in compat #defines. 2026-04-06 18:09:48 -05:00
Lealem Amedie 8e263292eb Address Copilot feedback 2026-04-06 14:03:24 -06:00
Tobias Frauenschläger e32e926f4e evp: fix EVP_PKEY2PKCS8 returning NULL for private-key-only EC keys
When an EC_KEY is created via EC_KEY_new + EC_KEY_set_group +
EC_KEY_set_private_key (no public point set), SetECKeyInternal
incorrectly marks the internal ecc_key as ECC_PRIVATEKEY (instead of
ECC_PRIVATEKEY_ONLY) because pub_key is always non-NULL — EC_KEY_new
always allocates it as an empty, zero-initialised EC_POINT.

ECC_populate_EVP_PKEY only calls wc_ecc_make_pub for ECC_PRIVATEKEY_ONLY
keys, so the zero public-key point was serialised into the DER stored in
pkey->pkey.ptr.  After commit 929dd9913 made wc_ecc_import_x963_ex always
pass untrusted=1, the re-decode inside wolfSSL_EVP_PKEY2PKCS8 →
wolfSSL_d2i_PrivateKey_EVP correctly rejected that zero point with an
on-curve failure, causing EVP_PKEY2PKCS8 to return NULL.

Fix: in ECC_populate_EVP_PKEY, also call wc_ecc_make_pub when the key
type is ECC_PRIVATEKEY but pubkey.x is zero (meaning the public key was
never actually populated).  This reconstructs the public key from the
private scalar so that the encoded DER contains a valid on-curve point.
2026-04-06 21:18:32 +02:00
Tobias Frauenschläger 0fb2d2ec11 ecc: fix invalid-curve attack via missing on-curve validation
wc_ecc_import_x963_ex2 only checked whether an imported public point
lies on the intended curve when both USE_ECC_B_PARAM was compiled in
and the caller passed untrusted=1. In a default ./configure build,
USE_ECC_B_PARAM is not defined, so the check was compiled out entirely.
Additionally, the legacy wrapper wc_ecc_import_x963_ex unconditionally
passed untrusted=0, meaning ECIES (wc_ecc_decrypt), PKCS#7 KARI, and
the EVP ECDH layer never triggered the check even when the macro was
present. In the OpenSSL compatibility layer, wolfSSL_ECPoint_d2i
guarded its on-curve check behind !wolfSSL_BN_is_one(point->Z), but
wc_ecc_import_point_der_ex always sets Z=1 for uncompressed points,
making the check dead code.

An attacker who can supply an EC public key (e.g. via an ECIES
ciphertext, PKCS#7 enveloped-data, EVP_PKEY_derive, or
EC_POINT_oct2point + ECDH_compute_key) can choose a point on a twist
of the target curve with a smooth-order subgroup. Each ECDH query
leaks the victim's static private scalar modulo a small prime; CRT
reconstruction across enough queries recovers the full key
(Biehl-Meyer-Müller invalid-curve attack). Static-key ECIES and PKCS#7
KARI are directly affected; TLS is affected in default builds because
the USE_ECC_B_PARAM gate defeated the untrusted=1 flag that the
handshake does pass.

Four changes close the attack:

1. Remove the USE_ECC_B_PARAM gate completely in the code base so that
   wc_ecc_point_is_on_curve() is compiled in all builds, not only
   those with HAVE_COMP_KEY or OPENSSL_EXTRA (only set for legacy FIPS
   builds in settings.h).

2. wc_ecc_import_x963_ex: pass untrusted=1 to wc_ecc_import_x963_ex2
   so that ECIES, PKCS#7 KARI, and EVP callers that go through the
   four-argument wrapper always validate the imported point.

3. wc_ecc_import_x963_ex2: use the lightweight sp_ecc_is_point_NNN
   helpers (curve-equation check only) instead of sp_ecc_check_key_NNN
   (which additionally performs a full point*order scalar multiply).
   For prime-order curves (P-256, P-384, P-521, SM2) the on-curve
   equation check y^2 = x^3 + ax + b is sufficient to defeat
   invalid-curve attacks — every non-identity point on a prime-order
   curve has the full group order, so the expensive order-multiply
   check is unnecessary. This avoids the ~50% ECDH performance
   regression caused by the redundant scalar multiplication.

4. wolfSSL_ECPoint_d2i (pk_ec.c): add unconditional on-curve
   validation via wolfSSL_EC_POINT_is_on_curve after import. The
   existing check was gated on !wolfSSL_BN_is_one(point->Z) and
   therefore dead code for all uncompressed-point imports. This closes
   the OpenSSL compat layer attack path (EC_POINT_oct2point followed
   by ECDH_compute_key).

Non-SP curves fall back to wc_ecc_point_is_on_curve which performs the
same equation check using mp_int arithmetic.

Reported by: Nicholas Carlini (Anthropic) & Thai Duong (Calif.io)
2026-04-06 21:18:32 +02:00
Daniel Pouzzner 31d0fcef81 wolfcrypt/src/rng_bank.c and wolfssl/wolfcrypt/rng_bank.h: add new wc_rng_bank_default facility:
* wc_rng_bank_default_set()
  * wc_rng_bank_default_checkout()
  * wc_rng_bank_default_checkin()
  * wc_rng_bank_default_clear()

  * Added additional argument error checking to existing APIs, with a new
    rng_inst_matches_bank() helper function.

  * Implemented feature gates WC_RNG_BANK_DEFAULT_SUPPORT and
    WC_RNG_BANK_NO_DEFAULT_SUPPORT.  When WC_RNG_BANK_DEFAULT_SUPPORT, the new
    APIs are available, and a NULL bank passed to APIs implicitly refers to the
    default bank.

wolfcrypt/test/test.c: in random_bank_test() add comprehensive smoke test coverage of new APIs and argument checking.

wolfssl/wolfcrypt/wc_port.h and wolfcrypt/src/wc_port.c:

  * Add wolfSSL_RefInc2(), wolfSSL_RefDec2(), wolfSSL_RefWithMutexInc2(), and
    wolfSSL_RefWithMutexDec2(), returning the atomically determined new count in
    the second arg;

  * Fix type of second arg in the fallback definition of
    wolfSSL_Atomic_Ptr_CompareExchange().

linuxkm/lkcapi_sha_glue.c:

  Refactor the _REGISTER_HASH_DRBG / _REGISTER_HASH_DRBG_DEFAULT facility around
  the new wc_rng_bank_default facility, eliminating post-init use of
  kernel-native crypto_default_rng, crypto_get_default_rng(), and
  crypto_put_default_rng(), and eliminating all use on kernel 7.1+ (where these
  will become unexported kernel-native statics).  With the refactor, the
  LINUXKM_DRBG_GET_RANDOM_BYTES facility uses only direct native wolfCrypt
  objects and calls to fulfill requests.

wolfssl/wolfcrypt/error-crypt.h, wolfcrypt/src/error.c, wolfcrypt/test/test.c, tests/api.c: add WC_SUCCESS = 0 "wolfCrypt generic success".
2026-04-06 14:06:20 -05:00
Lealem Amedie c01c43448d Add testing for the new ED paths in EVP_PKEY layer 2026-04-06 13:05:16 -06:00
jordan 01689b837f tests api: use XFREE instead of free in dual_alg tests. 2026-04-06 14:00:08 -05:00
jordan f48fd9595d test_pkcs7: use XFREE instead of free. 2026-04-06 13:53:11 -05:00
Lealem Amedie d385ae9c29 add Ed25519 and Ed448 support to the EVP_PKEY layer
- Add WC_EVP_PKEY_ED25519 / WC_EVP_PKEY_ED448 type constants and
   matching EVP_PKEY_ED25519 / EVP_PKEY_ED448 OpenSSL aliases.
  - Extend WOLFSSL_EVP_PKEY with ed25519/ed448 fields and ownership
   bits, and free them in wolfSSL_EVP_PKEY_free().
  - Add d2i probe functions that accept both SubjectPublicKeyInfo /
   PKCS#8 PrivateKeyInfo encodings and raw 32/57-byte key material,
   and hook them into the d2i_evp_pkey_try() chain.
  - Map the Ed25519/Ed448 signature OIDs in the relevant lookups and
   teach the PEM key-format dispatch and SSL_CTX_use_PrivateKey
   switch about the new types.
2026-04-06 12:32:25 -06:00
Lealem Amedie 89dac98b95 fix d2iTryAltDhKey short-circuiting the d2i probe chain
When wc_DhKeyDecode() rejected the input, d2iTryAltDhKey() returned 0
 after freeing the DH object. d2i_evp_pkey_try() treats any value >= 0
 as success, so a non-DH input would stop the probe chain at the DH
 step and never reach the Falcon, Dilithium, Ed25519, or Ed448 probes
 that follow. d2i_PUBKEY()/d2i_PrivateKey() consequently returned NULL
 for any key type past DH in the chain.
2026-04-06 12:28:28 -06:00