Commit Graph

36226 Commits (master)

Author SHA1 Message Date
Daniele Lacamera dde6b7c761
Cover Ed25519 context and device key reference checks (#12339) 2026-12-03 17:54:55 +10:00
lealem47 cedb457c47
wolfEntropy: sliding-window persistent-failure detection (#12337)
* wolfEntropy: sliding-window persistent-failure detection

* Check the latch in Entropy_Init()
2026-12-03 16:24:10 +10:00
philljj e8c283a1bc
ssl: tiny comment only correction. (#12360) 2026-12-03 10:19:02 +10:00
philljj 99b82d8d91
Merge pull request #11857 from Frauschi/fix-brainpool-downgrade
Fix brainpool group and version downgrade handling for TLS 1.3, DTLS 1.3 and ECH
2026-12-02 16:45:42 -06:00
philljj 552a601da6
Merge pull request #12357 from LinuxJedi/se050-binary-object-size
Fix out of bounds length access in wc_se050_get_binary_object()
2026-12-02 16:02:15 -06:00
Reda Chouk 1e75e93428
Merge pull request #12350 from dgarske/puf_c28x
Fix SRAM PUF on targets with a char wider than 8 bits or a 16-bit int
2026-12-02 22:56:28 +01:00
philljj d5797a01d0
Merge pull request #12240 from aidankeefe2022/pkcs11-iv-stream
Pkcs11 AES-CBC streams properly
2026-12-02 13:33:00 -06:00
philljj 302b74c757
Merge pull request #12356 from holtrop-wolfssl/f-9145
Zeroize RSA private-key PEM wrappers before free
2026-12-02 12:18:02 -06:00
philljj bef15a31c2
Merge pull request #11809 from julek-wolfssl/forcezero-volatile-stores
ForceZero: inline stores for short wipes on x86, XMEMSET elsewhere
2026-12-02 11:24:02 -06:00
Andrew Hutchings a770f8dc8a Fix out of bounds length access in wc_se050_get_binary_object()
wc_se050_get_binary_object() takes the buffer length as a word32*, and
passed it to sss_key_store_get_key() cast to size_t*. Where size_t is 64
bits the SDK then reads and writes 8 bytes through a pointer to a 4 byte
object: the buffer size it is given includes whatever follows the caller's
length variable, and storing the length read zeroes those 4 bytes.

Give the SDK a local size_t and copy the length back to the caller on
success. 32-bit targets were not affected.
2026-12-02 16:26:46 +00:00
Juliusz Sosinowicz 5b3a209858 Address review: ForceZero uses XMEMSET off x86
Back to the inline store tree on x86 only and XMEMSET elsewhere.

Inline stores on all CPUs broke CI. Unaligned volatile word64 stores
become byte stores where unaligned access is slow, e.g. RISC-V. Inlined
at every call site they grew the ESP32-C3 Arduino sketches past the
flash size. GCC 11 also flagged the long-wipe branch with -Warray-bounds
where ForceZero is inlined on a 32-byte buffer (riscv64, PPC64).

A byte or word loop doesn't beat XMEMSET off x86. Where libc memset is
a byte loop, e.g. newlib-nano, a byte loop is no faster. GCC also turns
a plain word loop into a memset call. Where memset is tuned, any loop is
slower. Builds with a slow memset can define XMEMSET.
2026-12-02 15:19:40 +00:00
Juliusz Sosinowicz 7a9e3204ec Address review: ForceZero inline stores on non-x86 GCC and Clang
Embedded libc memset may be a byte loop, e.g. newlib-nano on Cortex-M,
which made XMEMSET slower than the old word loop. GCC and Clang now use
the volatile stores for every length on all CPUs. x86 keeps XMEMSET above
WC_FORCE_ZERO_INLINE_MAX; other CPUs use XMEMSET above it only when it is
defined.
2026-12-02 15:19:40 +00:00
Juliusz Sosinowicz 5416babc70 ForceZero: inline stores in kernel builds too
Kernel builds called the kernel's memset for every wipe. With return
thunks (here SRSO safe RET on Zen 3) that call costs more than a short
wipe. Kernel builds now use the inline stores for all lengths and never
call memset. The AVX2 helper stays off in the kernel.

Setup: linuxkm benchmark (--enable-linuxkm --enable-linuxkm-benchmarks
--enable-intelasm --enable-sp-asm --enable-all-crypto, BENCH_EMBEDDED,
1 s per row) loaded with insmod in Linux 7.3 KVM guests on a Ryzen 9
5950X, one vCPU each, pinned to its own physical core. Six guests each
ran master, the PR before this commit and the PR with it, once each, in
rotated order. Change is the median of the six per-guest ratios against
master, positive is faster; "faster in" counts guests where the build
beat master. Master's figure is the median over the six guests.

Layout: code placement alone moves single rows by several percent on
this CPU (op-cache set conflicts), which hid the real changes. So all
three modules are built with -ffunction-sections and linked with one
generated linker script that gives every text section the same fixed
slot in every build (slot = largest size in any build, 64-byte aligned).
Every function shared by the builds then sits at the same address. Two
builds of identical code that differ only by a 1 KiB shift then agree
to a median of 0.10% per row, with no row leaning one way in all six
guests apart from 3 of 298; with plain 64-byte alignment the same pair
showed AES-CTR at +4.9% and 39 rows leaning one way.

All 298 rows, median change:  before -0.03%, with this commit +0.07%.
Faster in all six guests: before 14, with 52. Slower in all six:
before 34, with 10.

                          master      before         with this commit
                                      change  faster  change  faster
AES-128-CTR               9747 MiB/s  -11.9%  0/6     -0.2%   1/6
AES-192-CTR               8902 MiB/s  -11.1%  0/6     +0.2%   4/6
AES-256-CTR               8084 MiB/s  -10.4%  0/6     -0.6%   1/6
AES-XTS-stream-enc        4686 MiB/s   -5.8%  0/6     +0.1%   3/6
AES-XTS-stream-dec        4705 MiB/s   -5.5%  0/6     +0.1%   3/6
AES-XTS-enc               9802 MiB/s   -0.1%  2/6     +0.3%   4/6
AES-XTS-dec               9889 MiB/s   +0.1%  3/6     +0.1%   3/6
AES-128-GCM-enc           5732 MiB/s   +0.2%  3/6     +0.2%   4/6
AES-128-GCM-dec           5658 MiB/s   +0.1%  3/6     +0.2%   5/6
AES-128-GCM-STREAM-enc    3584 MiB/s   +2.2%  6/6     +2.3%   6/6
AES-128-GCM-STREAM-dec    3492 MiB/s   -0.1%  2/6     +0.0%   3/6
AES-CCM-enc                431 MiB/s   -1.1%  0/6     -0.3%   1/6
AES-CCM-dec                431 MiB/s   -0.9%  0/6     -0.1%   2/6
AES-128-CBC-enc           1621 MiB/s   +0.0%  3/6     -0.4%   2/6
AES-128-CBC-dec          11552 MiB/s   -0.2%  2/6     -0.1%   3/6
AES-128-ECB-enc          16474 MiB/s   -0.2%  2/6     +0.1%   4/6
AES-128-ECB-dec          16327 MiB/s   -0.3%  0/6     -0.1%   3/6
AES-128-CFB-dec           4661 MiB/s   +0.1%  3/6     +0.8%   4/6
AES-256-SIV-enc            235 MiB/s   +0.9%  5/6     +6.2%   6/6
AES-256-SIV-dec            236 MiB/s   +0.5%  5/6     +5.6%   6/6
KDF 128 SRTP           2487738 op/s    -3.8%  0/6     +5.7%   6/6
KDF 256 SRTP           2246443 op/s    -4.3%  0/6     +6.1%   6/6
KDF 128 SRTCP          2488667 op/s    -5.6%  0/6     +6.8%   6/6
KDF 256 SRTCP          2202654 op/s    -6.1%  0/6     +5.5%   6/6
ChaCha20-Poly1305 enc     1004 MiB/s   -1.3%  0/6     +0.8%   6/6
ChaCha20-Poly1305 dec      976 MiB/s   -1.0%  1/6     +1.3%   6/6
SHA-256                   2103 MiB/s   +0.0%  4/6     +0.2%   3/6
SHA-512                    924 MiB/s   -0.0%  2/6     -0.1%   2/6
SHA3-256                   512 MiB/s   -0.0%  3/6     -0.0%   2/6
HMAC-SHA256               2057 MiB/s   -0.2%  2/6     +0.0%   3/6
HMAC-SHA512                904 MiB/s   -0.1%  3/6     -0.0%   2/6
PBKDF2                                 +0.5%  4/6     +0.3%   3/6
RNG SHA256 Init/Free      98.5 op/s    -0.0%  3/6     +0.1%   4/6
RNG SHA512 Init/Free      98.7 op/s    +0.0%  3/6     +0.1%   4/6
ML-KEM 768 key gen       79779 op/s    -0.1%  2/6     +0.8%   6/6
ML-KEM 768 encap         62676 op/s    +1.3%  6/6     +1.3%   6/6
ML-KEM 768 decap         61135 op/s    +1.1%  6/6     +1.5%   6/6
ML-DSA 65 key gen        30755 op/s    +0.7%  6/6     +0.8%   6/6
ML-DSA 65 sign           11012 op/s    +1.8%  5/6     +0.5%   6/6
ML-DSA 65 verify         25674 op/s    -0.1%  2/6     +0.1%   4/6
SLH-DSA-SHAKE-F 128 sign  80.4 op/s    -0.1%  2/6     +0.6%   6/6
SLH-DSA-SHAKE-F 128 vrfy  1180 op/s    +0.7%  4/6     +1.5%   5/6
ECDSA P-256 sign         62540 op/s    -0.5%  1/6     +0.2%   5/6
ECDSA P-256 verify       21329 op/s    -0.0%  2/6     +0.1%   4/6
RSA 2048 private          2425 op/s    +0.0%  3/6     -0.1%   3/6
Ed25519 sign             32064 op/s    -0.2%  0/6     +0.0%   4/6

Median change by family (rows):  before   with this commit
  KDF (5)                         -4.3%    +5.7%
  ML-KEM (9)                      +1.1%    +1.4%
  ML-DSA (9)                      +0.9%    +0.7%
  SLH-DSA (42)                    -0.0%    +0.5%
  ChaCha20-Poly1305 (5)           -1.3%    +0.3%
  ECC (38)                        -0.1%    +0.1%
  AES (60)                        -0.0%    +0.1%
  XMSS (42)                       +0.0%    +0.0%
  SHA-1/2 (7), SHA-3 (10), HMAC (9), RNG (2), DH (2), EdDSA (6)
                                  within 0.1% both ways
  LMS (32)                        -0.1%    -0.4%

The rows slowest with this commit are LMS sign and verify (up to
-10.5%). They are noise: the same rows swing from -17% to +27% between
two builds of identical code, and master alone varies by 25% between
guests. RSA key generation is random by nature and also left out.
2026-12-02 15:19:40 +00:00
Juliusz Sosinowicz 6d1525cbd0 AES-CCM: keep the A and B names
A and B now point into ab, so only the declarations, the sizeof()s and
the wipe differ from master.
2026-12-02 15:19:40 +00:00
Juliusz Sosinowicz 6125e17f7e Fix CI: skip PollAndReSeed newSeed wipe when NULL
With SMALL_STACK_CACHE, newSeed stays NULL when the DRBG state is missing.
ForceZero's inline stores made GCC flag this with -Wnull-dereference.
2026-12-02 15:19:40 +00:00
Juliusz Sosinowicz c143dff939 asm.c: undefine cpuid.h macro names before defining them
With --enable-intelasm --enable-fastmath and -DHAVE_INTEL_MULX, tfm.c
includes misc.c, which now includes cpuid.h for the ForceZero AVX2 path,
and then asm.c. asm.c defines its own CPUID_* and IS_INTEL_* macros, so
the build failed with redefinition errors under -Werror.
2026-12-02 15:19:40 +00:00
Juliusz Sosinowicz 8b6a43ac60 PBKDF2, KDA one-step KDF: wipe the whole digest buffer
With SHA-256 as the largest hash, WC_MAX_DIGEST_SIZE is 32. GCC 12
could not bound the digest size from wc_HashGetDigestSize(), so
-Warray-bounds flagged the inline ForceZero stores for longer wipes in
wc_PBKDF2_ex() and wc_KDA_KDF_onestep(). Wipe all WC_MAX_DIGEST_SIZE
bytes, as wc_CheckPrivateKey() now does with privDer.
2026-12-02 15:19:40 +00:00
Juliusz Sosinowicz d4d162d1eb ForceZero: one atomic load of the cached cpuid flags
cpuid_get_flags_atomic() loads the flags, and IS_INTEL_AVX2() loads them
again, so each 128 to 256-byte wipe made two loads, and the compare and
exchange inlined into every caller needed a stack slot. Load once, and
on the first call store cpuid_get_flags() with an atomic store. Threads
that race there store the same flags, so it stays race-free. The code
that runs once the flags are cached is now the same as before the
atomic cache.
2026-12-02 15:19:40 +00:00
Juliusz Sosinowicz 9dafafb7d1 ForceZero: fix CCM mem-zero build, AVX2 loop bound, cpuid cache race
- AES-CCM: register ab.a and ab.b with wc_MemZero_Add. The old A and B
  names broke the build with WOLFSSL_CHECK_MEM_ZERO.
- ForceZero_AVX2: compare zb against ze - 64. zb + 32 could point past
  the end of the buffer, which is undefined even without a store there.
- ForceZero_HaveAVX2: cache the cpuid flags in a cpuid_flags_atomic_t,
  read with cpuid_get_flags_atomic(), as sha256.c and sha512.c do. Two
  threads making their first wipe at once raced on the plain cache.
- wc_CheckPrivateKey: wipe all MAX_ECC_BYTES of privDer. With only P-256
  the buffer is 32 bytes, and GCC 12 could not bound privSz, so
  -Warray-bounds flagged the stores for longer wipes.
2026-12-02 15:19:40 +00:00
Juliusz Sosinowicz e032f48963 ForceZero: inline stores for short wipes on x86, XMEMSET elsewhere
Master's ForceZero is a byte loop up to 8-byte alignment, a word loop
and a byte tail. GCC and Clang make the word loop into memset. For a
constant size GCC's default x86 tuning expands it into an inline rep
stosq, which is slow to start: on a Ryzen 9 5950X a constant 64-byte
wipe took 7.1 ns and 1024 bytes 32.4 ns, against 1.9 and 6.8 ns for a
memset call. On AArch64 the byte loops run before and after the memset
call.

x86

With GCC and Clang on x86 (not WOLFSSL_NO_ASM, not kernel builds),
ForceZero zeroes up to WC_FORCE_ZERO_INLINE_MAX bytes (256 by default)
inline, with volatile stores, which the compiler must emit as written.
Their types are may_alias and MAYBE_UNALIGNED, so any buffer is fine.
Up to 32 bytes it makes two stores of 16, 8, 4 or 2 bytes, one at each
end, which may overlap. Larger sizes store 16 bytes at the start and 32
at the end, and above 48 bytes a loop from the next 16-byte boundary
zeroes the middle, 32 bytes per pass, then 16 if left. The stores come
from general registers, not SSE: the sp_*_avx2 table lookups leave the
upper halves of the vector registers dirty, and after them an SSE wipe
took about 100 ns longer on a Xeon. A test version with 16-byte SSE
stores took 55 ns for a 64-byte wipe after dirty AVX code on a Ryzen 9
5950X, where GCC put a pxor inside the loop.

With USE_INTEL_SPEEDUP on x86_64, and GCC 4.9+ or Clang, sizes from
WC_FORCE_ZERO_AVX2_MIN (128) up to WC_FORCE_ZERO_INLINE_MAX use 32-byte
AVX2 stores when cpuid.c reports AVX2. The stores at both ends cover up
to 64 bytes, and a loop zeroes any middle, so WC_FORCE_ZERO_AVX2_MIN may
be as low as 32. Below 128 the call costs more than it saves: on an EPYC
7763 a lone 64-byte wipe took 2.5 ns with the helper, against 0.9 ns
with the general-register stores. VEX stores have no penalty after dirty
AVX code. The stores are in a C helper built with target("avx2"),
with no inline asm. GCC at -O2 and above, and Clang at every level, end
it with vzeroupper; GCC at -O0, -O1 and -Os does not. On a Ryzen 9
5950X, legacy SSE code right after the helper was no slower without
vzeroupper, at -O2 and at -Os. Intel CPUs were not measured. Only
library sources (BUILDING_WOLFSSL) use it, as the shared library does
not export cpuid_get_flags(). Each file caches the flags with
cpuid_get_flags_ex(). With GCC the helper is noclone, or GCC clones it
for a known buffer and warns about the clone's stores even where the
length rules the call out. On an Emerald Rapids Xeon it zeroed 144 bytes
in 0.9 ns, against 2.1 ns for the general-register stores.

Above WC_FORCE_ZERO_INLINE_MAX bytes ForceZero calls XMEMSET. libc's
memset is as fast there and is tuned for each CPU. For a known len,
GCC's default x86 tuning would expand that memset into the inline rep
stosq above, so an empty asm hides len at the XMEMSET and it stays a
call. Define WC_FORCE_ZERO_SHOW_LEN to let the compiler see len. With
-march=native on Zen 3, GCC 12 calls memset either way.

Each branch tests len as passed in, so when ForceZero is inlined with a
known len, the compiler keeps only that branch.

Other builds

All other builds call XMEMSET between the barriers: other targets,
kernel builds, and x86 with WOLFSSL_NO_ASM, with other compilers or with
WC_FORCE_ZERO_LOOP. WC_FORCE_ZERO_FAST selects the x86 code. On the
AArch64 Neoverse-N2 runners, a memset call was faster than naturally
aligned C stores (volatile stores of 1 to 16 bytes, with DC ZVA from
256 bytes) at every size, except from 256 bytes at a start 8 mod 16,
where memset took up to 28% longer. A loop that GCC turns into memset
was tried too: it needs a len != 0 test before the call, and below -O2
and at -Os it stays a byte loop, slower than master's word loop.

GCC checks the inline stores against the buffer, so it warns when a
caller passes a len past the end of a buffer it knows. It checks each
size branch on its own, so it can also flag a buffer of 32 bytes or
less when it can't bound len. On x86 len is hidden from the XMEMSET
above WC_FORCE_ZERO_INLINE_MAX bytes, so GCC doesn't check that branch.
Callers that GCC flags must make the bound visible:

- WC_ASSUME(expr) is new in types.h, next to wc_static_assert. It tells
  an optimizing GCC 4.5+ or Clang that expr is always true, with a
  branch to __builtin_unreachable() that the compiler removes. It does
  nothing at -O0, where the branch would stay. Define WC_ASSUME to
  supply your own. Define WC_NO_ASSUME to turn it off, which brings back
  the warnings below.
- min() and max() state their bound with WC_ASSUME. The volatile mask
  that keeps their select constant time hides it otherwise. The select
  compiles the same at -O1 to -O3. This silences a false -Warray-bounds
  on ForceZero(buffer, halfSz) in wc_DsaSign_ex. It also lets GCC inline
  bounded copies, such as the memcpy in the hash update functions.
- SLH-DSA states that n, from the parameter table, fits its
  SLHDSA_MAX_N-byte sk buffers. This silences the same kind of false
  warning there.

AES-CCM

wc_AesCcmEncrypt and wc_AesCcmDecrypt keep A and B in one struct, so one
ForceZero clears both. With AES-NI the struct is 256 bytes, with both
members 128-byte aligned as before, and its wipe takes the AVX2 stores.
Two 64-byte wipes took 8 general-register stores each, where master's
memset made 4 SSE stores each, which left CCM encrypt 2.3% slower. The
members are used directly: pointers to them measured 2.4% slower for
encrypt on x86, from different register allocation.

Benchmarks

Single wipes: one ForceZero inlined into a loop that wipes the same
cached buffer, ns per wipe minus the same loop with the barriers only,
median of 21 interleaved rounds, 16-byte aligned start. "const" has a
constant len with the address hidden from the compiler, "var" a len
from a volatile. memset is a plain memset call (built with
-fno-builtin). This is the best case for a call: it is predicted and
the buffer is in cache.

x86: AMD Ryzen 9 5950X (Zen 3), Debian 12, GCC 12.2, glibc 2.36,
pinned to one core. Library: ./configure --enable-all-crypto
--enable-all-quantum-crypto --enable-all-asm --disable-shared.
            ---- const ----------   ---- var ------------
bytes     master    this  memset  master    this  memset
16          1.27    0.02    2.12    2.77    0.42    2.13
32          1.57    0.21    1.91    2.57    0.43    1.92
64          7.06    0.64    1.93    2.55    1.07    1.92
128         8.58    1.94    2.13    2.77    2.14    2.14
256        12.24    2.79    2.35    2.98    2.80    2.34
512        19.05    3.41    3.43    3.42    3.42    3.42
1024       32.44    6.82    6.82    6.80    6.81    6.81
2048       28.09   13.62   13.62   13.57   13.62   13.62
4096       41.68   40.58   40.64   40.83   40.51   40.27

AArch64: GitHub ubuntu-24.04-arm runner (Neoverse-N2), GCC 13.3,
glibc 2.39, ARM asm on (configure's default, with -mstrict-align).
All AArch64 builds start every function, loop and asm label at 64 bytes,
which takes away most, not all, of the effect of where code lands.
This change calls XMEMSET, which is memset.
            -- const --------   -- var ----------
bytes       master   memset     master   memset
16            2.07     1.03       1.65     1.03
32            1.77     1.12       1.72     1.24
64            2.15     1.59       1.80     1.52
128           2.18     1.83       2.25     1.84
256           3.32     3.24       3.28     3.24
512           3.54     3.54       3.54     3.54
1024          5.91     6.16       5.90     6.16
2048         10.85    10.71      10.87    10.74
4096         20.36    20.42      20.34    20.38

Per call: a loop calls each operation for 100 ms. Median ns per call,
and the median per-sample change in time against master (negative =
faster). x86: 5 rounds at each of 12 offsets of the library from the
benchmark code (padding linked between them), in rotating order on one
core; the ns are the median of the per-offset medians. AArch64: 24
rounds on CPU 0 of the runner, with the benchmark below on CPU 1.
All benchmarks ran on master 799bd1748, before the rebase onto
d139ee0c3, which did not change this patch.
drbg_sha256_32B uses wc_InitRng's default DRBG, which is the SHA-512
one in these builds.
                                 ---- x86 ------------   ---- AArch64 ---------
Operation                        master    this change   master    this change
srtp_kdf_128                      123.6   115.1  -8.0%    129.6   122.2  -5.6%
srtcp_kdf_128                     129.3   118.3  -8.2%    128.4   122.9  -4.2%
srtp_kdf_256                      160.7   149.8  -7.5%    160.6   155.1  -3.4%
aes_siv256_enc_16B                732.2   595.3 -18.9%    699.0   673.1  -3.9%
aes_siv256_enc_1KiB              1591.0  1456.9  -8.4%   1483.2  1459.0  -1.7%
drbg_sha256_32B                   863.0   841.8  -2.5%   1206.8  1204.0  -0.2%
aes128_init_setkey_free            58.1    37.5 -38.4%     63.9    60.2  -6.7%
sha256_init_32B_final_free         51.4    50.4  -1.8%     68.3    67.4  -1.0%
sha3_256_init_32B_final_free      290.2   290.8  +0.1%    280.7   280.0  -0.2%
hmac_sha256_key_14B_final_free    208.0   179.2 -13.8%    249.9   250.0  +0.0%
chacha20_poly1305_enc_16B         130.0   108.6 -16.2%    452.8   453.3  +0.1%
aes128_gcm_enc_16B                 27.2    27.6  +1.5%     30.1    30.1  +0.2%
poly1305_key_14B_final             28.0    28.1  -0.1%     35.0    34.9  -0.0%
sha512_init_32B_final_free        173.0   164.0  -5.3%    254.4   256.4  +0.9%
blake2s_key32_32B_final           323.2   312.3  +0.3%    473.3   473.4  +0.0%
blake2b_key32_32B_final           459.4   449.9  +0.2%    790.6   791.1  -0.2%
kmac128_key32_32B_final_free      804.1   789.6  -1.8%    842.1   837.2  -0.6%
hkdf_sha256_32B                   432.1   383.8 -11.1%    514.8   508.6  -1.3%
aes128_ccm_enc_16B                 85.5    85.8  +0.4%     70.4    69.8  -0.9%
aes128_ccm_dec_16B                 97.4    96.3  -0.9%     82.8    82.9  -0.1%

Some rows move with code placement, not with this change. On x86 each
run of BLAKE2s and BLAKE2b settles on one of two speeds, about 6%
apart. AES-GCM's code on x86 is the same as master's; its +1.5% comes
from other functions in aes.c changing size, and it was -0.2% when
every function started at 64 bytes. On AArch64, SHA-512's functions
are the same as in a build of the loop version where it was -0.7%.

x86 with --disable-asm (WOLFSSL_NO_ASM), same machine: GCC expands
XMEMSET with a known len inline, as SSE stores up to 64 bytes and rep
stosq above. Master's loop calls memset. The barriers in these builds
are locked instructions, which cost about 3 ns per wipe either way.
Single wipes, 21 rounds:
            ---- const --------   ---- var ----------
bytes       master   XMEMSET      master   XMEMSET
16            3.17     3.11         2.96     2.86
32            2.89     3.15         2.93     3.12
48            2.74     3.19         3.16     3.14
64            8.08     3.11         3.11     3.15
128           9.47     8.73         3.05     2.90
256          13.14    12.39         4.25     4.26
1024         34.59    33.68        11.33    11.36
Per call, 6 rounds at 12 offsets: against the same patch with master's
loop in ForceZero, no row is slower by more than placement moves it,
except BLAKE2b (+5.8% against master, +0.5% with the loop), whose only
changed function is wc_Blake2bHmacFinal, which the benchmark does not
call. Against master,
AES-GCM 16 B (+6.7%), AES-CCM 16 B (+3.1 to 3.4%), the SRTP KDFs (+5.0
to 6.1%) and AES-SIV 16 B (+4.2%) are slower, by about as much as with
master's loop (+5.8%, +3.9 to 4.1%, +6.3 to 7.8% and +5.7%), so this
comes from the rest of the patch, not from XMEMSET.

AArch64 benchmark: wolfcrypt/benchmark/benchmark -csv -dgst_full
-mac_final for 18 groups (DRBG, AES-CTR, -GCM, -SIV and -CCM, ChaCha20,
ChaCha20-Poly1305, Poly1305, SHA-256, SHA-512, SHA3-256, cSHAKE128,
BLAKE2s, BLAKE2b, CMAC, KMAC, HMAC-SHA256 and PBKDF2), master and this
change back to back in rotating order on CPU 1, 3 times. Geometric mean
over 48 lines of the fastest-of-3 throughput ratio: +0.8% at 16 B (17
lines faster and 8 slower in all 3 runs) and +0.5% at 256 B (27 and
9). AES-SIV is 4.2 to 5.4% faster at 16 B and 0.9 to 4.3% at 256 B,
and AES-128-CMAC 2.1% at 16 B. No line was slower in all 3 runs by more
than 0.9%. The largest is SHA-512 at 16 B: the bound that WC_ASSUME
gives min() changes how GCC lays out the update loops of SHA-512 and
CMAC; without WC_ASSUME SHA-512 at 16 B went from 1.0% to 0.2% slower,
and CMAC lost its 2.1%. SHA3-256, BLAKE2s and AES-CTR run the same code
as master; their slower lines, up to 0.3%, come from placement. The x86
benchmark was not rerun for this version.

Testing

test_ForceZero in tests/api.c now also wipes every size from 32 to 300
bytes at 16 offsets, which covers the inline stores and the XMEMSET
branch. Tests include misc.c without BUILDING_WOLFSSL, so it doesn't
reach the AVX2 stores. It catches a dropped tail store, a middle loop
that stops a pass early and a memset one byte short. It passes on
x86_64, on i386 and under qemu-aarch64.

x86_64, GCC 12.2: the library builds with no warnings and testwolfcrypt
passes, with the default configure and with --enable-all-crypto
--enable-all-quantum-crypto --enable-all-asm. A test that wipes every
size from 0 to 5000 bytes at 64 offsets, plus 51 constant sizes, and
checks the bytes around each wipe, passes at -O0, -O1, -O2, -O3 and
-Os, with the AVX2 stores on and off, also with WC_FORCE_ZERO_SHOW_LEN,
with WC_FORCE_ZERO_INLINE_MAX=64 and 8192, with WC_FORCE_ZERO_LOOP and
with WOLFSSL_NO_ASM, under GCC's ASan and UBSan at -O2, and with Clang
14 at -O0, -O2, -O3 and -Os. With the AVX2 stores on it also passes with
WC_FORCE_ZERO_AVX2_MIN at 32, 33, 48, 64 and 128, at -O0, -O2 and -Os,
with Clang 14 and under ASan and UBSan, and a minimum of 31 is a build
error. Counting calls showed the AVX2 stores ran for every wipe of 128
to 256 bytes, and of 128 to 5000 bytes with WC_FORCE_ZERO_INLINE_MAX=8192.
GCC 12's ASan crashed at startup (DEADLYSIGNAL) in about a third of
runs on this machine, with master's ForceZero as well; every run that
started passed.

AES-CCM: testwolfcrypt and the CCM tests in unit.test pass on x86_64
with AES-NI, on i386 and under qemu-aarch64, and testwolfcrypt passes
natively on the AArch64 runners.

i386 (-m32, run natively): the same wipe test passes with GCC 12.2 at
-O0, -O1, -O2, -O3 and -Os, also with -march=i686,
WC_FORCE_ZERO_SHOW_LEN, WC_FORCE_ZERO_INLINE_MAX=64, WC_FORCE_ZERO_LOOP
and UBSan, and with Clang 14 at -O0, -O2, -O3 and -Os. With
--enable-32bit --enable-all-crypto --enable-all-quantum-crypto the
library builds with no warnings and testwolfcrypt passes.

AArch64: the same wipe test, plus 51 constant sizes at unknown and known
alignment and in local arrays, passes under qemu-aarch64 with -cpu
neoverse-n2 and -cpu max, with GCC 13.3 at -O0 to -O3 and -Os, with
-mstrict-align, WOLFSSL_ARMASM, WOLFSSL_NO_ASM and NO_INLINE, and
without __linux__, and with Clang 14 at -O0, -O2, -O3 and -Os, also with
-mstrict-align and WOLFSSL_NO_ASM. At -O0 and -Os ForceZero is a
function that calls memset. With --enable-all-crypto the library builds
with no warnings, and testwolfcrypt, test_ForceZero and the CCM tests
pass under qemu, and testwolfcrypt natively on the runners.

On 0c7c5b440, after the rebase, the library builds with no warnings and
testwolfcrypt, test_ForceZero and the CCM tests pass on x86_64
(--enable-all-crypto --enable-all-quantum-crypto, with --enable-all-asm
and with --disable-asm) and under qemu-aarch64.

With XMEMSET for all builds outside x86's inline code, the library's
code is the same as with the memset call before it, for x86_64
--enable-all-asm and for AArch64 with and without ARM asm: every object
disassembles the same. The library builds with no warnings with
WOLFSSL_NO_ASM, WC_FORCE_ZERO_LOOP and WOLFSSL_KERNEL_MODE on x86_64
and AArch64. test_ForceZero and testwolfcrypt pass on x86_64 with
--enable-all-asm and with --disable-asm, and testwolfcrypt under
qemu-aarch64. The wipe test passes on x86_64 with WOLFSSL_NO_ASM,
WC_FORCE_ZERO_LOOP, WOLFSSL_KERNEL_MODE and the AVX2 stores, and on
AArch64 under qemu at -O0, -O2 and -Os, with -mstrict-align and with
WOLFSSL_KERNEL_MODE.
2026-12-02 15:19:39 +00:00
philljj 70ca260e4c
Merge pull request #12285 from julek-wolfssl/compat/store-ctx-ip-hostflags
Add four X509 OpenSSL compatibility APIs
2026-12-02 09:19:33 -06:00
Josh Holtrop 5d2ed7ab5c Zeroize RSA private-key PEM wrappers before free
Fixes F-9145, ANT-2026-3POF5TJJ
2026-12-02 09:52:15 -05:00
philljj cb84a040e0
Merge pull request #11649 from aidangarske/fenrir-fixes-14180-14638-14641
Fix EVP AEAD nonce handling and KCAPI DH agreement
2026-12-02 07:58:16 -06:00
Tobias Frauenschläger 4f68bf7ae6 Apply the DTLS version mask in every build
wolfSSL_set_options() stores the version mask in every build, and the
TLS version selection already honours it, but DtlsAllowedMinor() only
read it with OPENSSL_EXTRA, HAVE_WEBSERVER or WOLFSSL_WPAS_SMALL.
Without those, a DTLS 1.3 client or server with SSL_OP_NO_DTLSv1_3 set
still negotiated DTLS 1.3, and masking every compiled DTLS version did
not fail the handshake with VERSION_ERROR. The helper now always
passes the mask, so the version picked when the handshake starts and
the checks on the peer's version follow it as they do for TLS.

The SSL-level cases of test_dtls13_no_tls13_option and the helpers
they use now run without OPENSSL_EXTRA. The CTX-level cases stay
compat-only, since the version check at wolfSSL_new() is.
2026-12-02 13:36:35 +01:00
Tobias Frauenschläger 1027d03985 Hand off below TLS 1.3 on every retry and keep the setup ceiling
wolfSSL_connect_TLSv13() handed a TLS connection to wolfSSL_connect()
only when its own reconcile lowered the version. A direct caller that
got WANT_WRITE on the first flight came back with the version already
at TLS 1.2, skipped the hand-off and ran the TLS 1.3 state machine,
which reported success before the handshake finished. Hand off every
downgrade-capable connection that sits below TLS 1.3, on every call.

wolfSSL_accept_TLSv13() had the top hand-off for DTLS only. A TLS server
that went below TLS 1.3 and got WANT_WRITE came back into the TLS 1.3
state machine with a legacy accept state; AcceptState and
AcceptStateTls13 diverge from SERVER_HELLO_SENT on, so a retry at
CERT_REQ_SENT sent a TLS 1.3 Finished. Hand off TLS as well.

SslNewestVersion(), SslMaxMinor() and TLSv1_3_Capable() read the live
ctx->method->version. Raising the CTX maximum after wolfSSL_new() and
clearing WOLFSSL_OP_NO_TLSv1_3 on the SSL let it negotiate TLS 1.3 past
the maximum it was created under. Record the CTX method version in
Options.methodMinor when SetSSL_CTX() sets the SSL version and use that
instead. TLSv1_3_Capable() needs the same value, or a client held at
TLS 1.2 aborts on the server's downgrade sentinel, and the TLS 1.2
downgrade sentinel checks use it so they agree with TLSv1_3_Capable().

The reconcile path for fixed-version methods checked a session-lowered
version against the mask only. A fixed TLS 1.3 client that took a
TLS 1.2 session and then raised its minimum to TLS 1.3 still resumed
TLS 1.2. Check the session version against the minimum too and fall
back to the SSL's own version otherwise.

The TLS and DTLS 1.3 resumption tests need the server to issue tickets,
which WOLFSSL_NO_DEF_TICKET_ENC_CB prevents without an application
callback, so skip them in that build.
2026-12-02 13:36:35 +01:00
Tobias Frauenschläger f29390bc89 Reconcile the protocol version once when the handshake starts
The version setters used to move ssl->version, ssl->options.tls1_3 and the
suites as soon as they changed the mask. DTLS needed three modes for that
(start, lift and in-hello), and the TLS path in wolfSSL_set_options()
lowered the version without ever raising it again, so a TLS SSL that set
and then cleared WOLFSSL_OP_NO_TLSv1_3 sent a TLS 1.2 ClientHello, or as a
server marked its TLS 1.2 ServerHello as a downgrade, and the handshake
failed.

SslReconcileVersion() now settles the version once, in wolfSSL_connect(),
wolfSSL_accept(), wolfSSL_negotiate(), the TLS 1.3 entry points,
wolfSSL_write_early_data() and wolfSSL_read_early_data(), for TLS and
DTLS. wolfSSL_negotiate() settles it before it picks the TLS 1.3 or the
older state machine, so a handshake started by wolfSSL_write() or
wolfSSL_read() sends the same ClientHello as wolfSSL_connect(), and
wolfSSL_connect_TLSv13() hands a TLS client that its own reconcile moved
below TLS 1.3 to wolfSSL_connect() as it already did for DTLS; a masked
client would otherwise build its TLS 1.2 ClientHello on the TLS 1.3 path,
with the middlebox compatibility session ID. wolfSSL_read_early_data()
first makes an SSL with no side a server, as wolfSSL_accept() does, so it
settles and alerts like one. The reconcile picks the newest version that
the mask and the minimum allow, keeps a resumed session's version when it
is allowed and not past the ceiling below and drops the resumption
otherwise, rebuilds the suites when the version moves, clears
options.tls1_3 whenever the version ends below TLS 1.3, which a TLS 1.3
session set before a wolfSSL_SetVersion() maximum would otherwise leave
set, and creates the DTLS 1.3 cookie secret for a server lifted to DTLS
1.3. The ceiling is the newer of the SSL version and the CTX method
version, so an SSL is never lifted past the CTX maximum it was created
under, which TLSv1_3_Capable() and the supported_versions parser also
read, and a CTX maximum set later does not pull an existing SSL down. A
wolfSSL_SetVersion() maximum caps it too, since that setter leaves a range
when a minimum is set and records no mask bits. wolfSSL_SetSession()
refuses a session newer than that maximum, which for a fixed-version SSL
is its method version, as it already refused one below the minimum, and
both refusals now leave the extended master secret setting as it was; it
used to switch the SSL to the session version, past a CTX or
wolfSSL_SetVersion() maximum. A session without a recorded version leaves
the resumption alone.

With no version left a client fails right away, also when a fixed-version
method masks its own version, which used to send an empty
supported_versions. This now holds for fixed DTLS methods too, which used
to ignore a mask on their own version and complete a DTLS 1.2 handshake,
or send an empty supported_versions for DTLS 1.3, and for the DTLS minimum
and maximum setters on them. A fixed-version client that took an older
session whose version the options disable drops the resumption and settles
on its own version; it used to resume at the disabled version. A DTLS
server fails before it reads the ClientHello, which DTLS would otherwise
drop without an answer; a TLS server keeps its version and sends the
protocol_version alert when it answers the ClientHello.

The setters now only record their settings. wolfSSL_set_options() and
wolfSSL_clear_options() no longer touch the version or the suites, and
wolfSSL_SetSession() no longer reconciles but rebuilds the suites when it
raises the version, so a TLS 1.3 session set on an SSL that a CTX option
created at TLS 1.2 offers the TLS 1.3 suites. The DTLS minimum and maximum
check that some version is left without changing anything and restore
their settings when none is. A DTLS maximum that changes the mask is still
refused once the handshake has started: the downgrade sentinel reads the
live mask, so a lift there makes a server settled at DTLS 1.2 mark its
ServerHello as a downgrade.

DoClientHello() keeps a DTLS check that steps a server below a first
ClientHello version its options do not allow, as the TLS path below it
already does, and refuses with protocol_version on a fixed-version TLS
server whose options disable its own version. The SSLv2 ClientHello path
refuses any version the options disable, which a downgrade server with no
version left would otherwise reach by stepping down to the client version.
TLSX_SupportedVersions_Parse() skips a TLS version the server options
disable, as it already did for DTLS, which a build without TLS 1.2 needs
because its ClientHello never reaches the DoClientHello mask walk.
wolfSSL_set_options() used to move such a server off its version, and the
TLS mask walk only runs for a downgrade server. SetSSL_CTX() rebuilds the
suites when the CTX mask lowered the version at wolfSSL_new(), which
wolfSSL_set_options() used to do.

CipherMinMaxCheck() now checks TLS 1.0 and 1.1 suites below the minimum
against the mask too. SSL_get_cipher_list() returned no suite with every
version masked only because wolfSSL_set_options() had moved the version to
SSLv3 and rebuilt the suites.

Before the handshake starts, wolfSSL_version() reports the version from
before the options apply, as the TLS maximum already did. An SSL reused
with wolfSSL_clear() negotiates from the newest allowed version again
instead of the one it negotiated last.
2026-12-02 13:36:35 +01:00
Tobias Frauenschläger c711db87f8 Restore CTX version settings after any failed setter
wolfSSL_CTX_set_max_proto_version() clears the NO_TLSv1* options and
re-applies the minimum before Set_CTX_max_proto_version() can fail, and
wolfSSL_CTX_set_min_proto_version() clears them when the maximum is
below the requested minimum. CtxVersionRestore() undid this only for
DTLS and for methods that cannot downgrade, so on a wolfSSLv23_*() CTX
a failed call, such as a DTLS, unknown or unsupported SSLv3 version,
left the user's version options cleared, or every version masked off.
This predates the restore code.

Restore the mask, minimum and method version on every failure. A
failed maximum now leaves the earlier version range in place instead
of disabling the CTX, as OpenSSL does.

test_tls_ctx_proto_failed_keeps_options covers each failing maximum and
an unknown minimum on a v23 CTX capped at TLS 1.2, in any build with
OPENSSL_EXTRA and TLS 1.2.
2026-12-02 13:36:35 +01:00
Tobias Frauenschläger b0a36281f9 Keep a fixed TLS method's version under a maximum
Set_CTX_max_proto_version() rewrote the method version of a TLS CTX
whether or not the method may downgrade, so
wolfSSL_CTX_set_max_proto_version() with 0 turned a
wolfTLSv1_2_*_method() CTX into TLS 1.3 only, and with TLS1_1_VERSION
into TLS 1.1 only. It also undid wolfSSL_CTX_require_psk(), which pins a
v23 CTX at TLS 1.3 by clearing downgrade: a later TLS 1.2 maximum moved
the CTX to TLS 1.2. wolfSSL_set_max_proto_version() accepted a maximum
below the fixed version of an SSL and the handshake then ran at the
fixed version anyway. Both minimum setters accepted a minimum above the
fixed version, which masked it off, so wolfSSL_new() failed for a CTX.
The DTLS setters already keep a fixed version.

A fixed TLS method now keeps its version: a maximum at or above it
leaves the method alone, and a maximum below it or a minimum above it
fails in the CTX and SSL setters. This includes objects that
wolfSSL_CTX_require_psk(), wolfSSL_require_psk() or wolfSSL_SetVersion()
fixed. The checks run before the mask changes, through
FixedTlsVersionCmp(). The CTX setters restore the mask, minimum and
method version on failure, as they do for DTLS, so the version state
save and restore are no longer DTLS only.
wolfSSL_set_min_proto_version() also refuses a minimum above a fixed
DTLS version, which it accepted before and which then failed in
wolfSSL_connect(). wolfSSL_CTX_get_max_proto_version() reports the
fixed version of a fixed TLS method, or 0 when the mask or the minimum
excludes it, as it does for a fixed DTLS method.

An application that relied on a fixed method plus a higher maximum to
get TLS 1.3 now stays at the fixed version, which matches OpenSSL: it
stores no version bound for a version-specific method.
2026-12-02 13:36:35 +01:00
Tobias Frauenschläger a6b23d63d9 Keep the HRR version when a mask changes during ClientHello
The DTLS mask filter in TLSX_SupportedVersions_Parse() also ran on the
second ClientHello after a stateful HelloRetryRequest. An SNI callback
that sets SSL_OP_NO_DTLSv1_3 while the server parses the first
ClientHello made the second one skip DTLS 1.3, so the server took the
legacy DoClientHello() path after a DTLS 1.3 HRR and failed with
VERSION_ERROR. RFC 8446 4.1.4, applied to DTLS 1.3 by RFC 9147,
requires the ServerHello to keep the version selected in the HRR.

Skip the filter once the HRR has been sent. The first ClientHello
already applied the mask, and the stateless cookie exchange resets
serverState, so the ClientHello carrying the cookie is still checked.

test_dtls13_mask_in_client_hello gains a stateful HRR case.
2026-12-02 13:36:35 +01:00
Tobias Frauenschläger a067688b28 Keep a fixed DTLS method's version under a CTX maximum
protoVerTbl now lists DTLS1_3_VERSION, so
wolfSSL_CTX_set_max_proto_version() with 0 or DTLS1_3_VERSION turned a
wolfDTLSv1_2_*_method() CTX into DTLS 1.3, and the fixed method could
not downgrade back to 1.2. A maximum of DTLS1_VERSION already turned it
into DTLS 1.0. OpenSSL stores no maximum for a fixed method, and
wolfSSL_set_max_proto_version() already keeps the fixed version of an
SSL.

Set_CTX_max_proto_version() now moves the method version of a DTLS CTX
only when the method may downgrade. A maximum at or above a fixed
version leaves it, and one below it fails through CtxDtlsVersionLeft()
and restores the CTX, as the SSL setter does.
2026-12-02 13:36:35 +01:00
Tobias Frauenschläger afa8d66a23 Filter suites and sigalgs for the version from an unfiltered copy
ResetSuitesForVersion() removed the suites and sigalgs that the new
version lacks from a user-set list in place. Once a DTLS maximum or
option could be lifted again, that loss became permanent: capping a DTLS
1.3 SSL at DTLS 1.2 dropped the TLS 1.3 suites and the TLS 1.3-only
brainpool sigalgs, and lifting the cap left a DTLS 1.3 SSL without them.
Without a user list, the suites were rebuilt for the version but
InitSuites() keeps existing sigalgs, so a capped SSL still offered the
TLS 1.3-only brainpool and SLH-DSA sigalgs in its DTLS 1.2 ClientHello
or CertificateRequest.

The new FilterSuitesForVersion() filters ssl->suites for its version.
The first time it has to remove something, it keeps the unfiltered list
in suitesUser, and every later call filters that copy, so a lift
restores what a cap removed. It filters the suites of a user-set list
and the sigalgs of any list, user-set or default.
ResetSuitesForVersion() rebuilds the default suites and then calls it,
also on an SSL with no side yet once a copy exists, and so do
wolfSSL_SetVersion() and InitSSL_Suites(), which an either-side SSL runs
when it takes a side. If the copy cannot be allocated, the list is still
filtered in place. At the newest version nothing can be removed, so the
filter only copies back from the saved list there.

A suite or sigalg is removed only when the newest version's defaults
have it and this version's defaults lack it: TLS 1.3 suites below 1.3,
TLS 1.2 suites below 1.2, the TLS 1.3-only brainpool and SLH-DSA
sigalgs, and RSA-PSS before TLS 1.2. Anything else the user set, such as
the multicast WDM suite or ECDSA with SHA-224, DSA or SHA-1 sigalgs, is
kept, as before. If the filter would leave no sigalg, the list is kept
as it is, since an empty list means the defaults.

wolfSSL_set_cipher_list(), wolfSSL_set_cipher_list_bytes() and
wolfSSL_set1_sigalgs_list() write into the copy while it exists and
always filter afterwards, also when they fail, so the result depends
only on the version and not on whether the list was set before or after
a cap or whether a copy was made. A TLS 1.2 SSL given a list with TLS
1.3 suites now drops them, as a DTLS 1.2 SSL already did. A sigalgs
change made while capped keeps the user's suites. SetSuitesHashSigAlgo()
now parses into a local buffer, so a sigalgs list that fails to parse
leaves the previous one in place, on the CTX as well as on the SSL. On
an SSL whose list is still the default, the setters first rebuild the
defaults for the newest version the SSL can reach and its current key,
so with OPENSSL_EXTRA a TLS 1.2-only cipher list keeps the default TLS
1.3 suites, as OpenSSL does. SetCipherList_ex() builds the list for that
newest version too, the newer of the SSL's and the CTX method's, for TLS
and DTLS alike, so a keyword list such as HIGH set while capped still
has its TLS 1.3 suites for a lift, and one set after the CTX maximum was
lowered keeps them on an SSL still at DTLS 1.3.

The filter also built its table with the server's key flags. With an ECC
key, haveStaticECC cleared haveRSA and the RSA suites were removed;
without one, the static ECDH suites were. It now builds the table for
the client side with every key type, so only the version decides what is
removed. VerifyServerSuite() still skips a suite the server's key cannot
use when it matches suites.

test_dtls13_mask_lift_cipher_list caps and lifts a user-set list on the
client and on a server with an ECC key: the cap removes only the TLS 1.3
suite, and the lift restores the list with a sigalgs change (including
ECDSA with SHA-224), a TLS 1.2 cipher list, a list set by bytes or an
unrelated option made while capped. test_dtls13_mask_list_after_cap sets
the default list, a named list, a TLS 1.2-only list or HIGH after the
cap, and a cipher list and a byte list that fail to parse, and checks
that no TLS 1.3 suite or brainpool sigalg is left until the lift.
Further tests cover a DTLS and a TLS either-side SSL capped before it
becomes the client, a list set on a side-less SSL after
wolfSSL_SetVersion(), HIGH set after the CTX maximum was lowered, SHA-1
sigalgs kept where they are built, wolfSSL_SetVersion() restoring the
TLS 1.3 suites a TLS mask removed, also from a TLS 1.2 list set under
the mask, a capped list kept across wolfSSL_clear() and restored by a
lift, a CTX sigalgs list kept when a new one fails to parse, sigalgs set
on a default list across a cap, a failed set and a lift, a
brainpool-only sigalgs list kept under a cap, a capped TLS server
merging with defaults for a key loaded later, a TLS 1.2 SSL given a TLS
1.3 suite, and the multicast suite kept under a cap.
2026-12-02 13:36:35 +01:00
Tobias Frauenschläger 8086601ffa Let DTLS max proto and options lift an earlier cap
wolfSSL_set_max_proto_version() and wolfSSL_clear_options() only moved a
DTLS SSL down. After a maximum of DTLS 1.2, a maximum of DTLS 1.3 or 0
returned success and left the SSL on DTLS 1.2, and clearing
SSL_OP_NO_DTLSv1_3 did not bring DTLS 1.3 back. When a maximum loosens
the mask, or wolfSSL_clear_options() clears a DTLS version bit, the
version is now walked down from the CTX method version, so the SSL moves
back up. A lift never moves an allowed version down, and keeps an
allowed version when the walk finds none, so a CTX maximum lowered after
wolfSSL_new() does not reach the SSL that way. A resuming client keeps
its session's version while the mask allows it. wolfSSL_set_options()
and the checks at handshake start still only step down.
wolfSSL_SetSession() now fails when the suites cannot be rebuilt for the
version the mask moved it to; a session with no version left is still
reported when the handshake starts.

The DTLS maximum shares the WOLFSSL_OP_NO_TLSv1_2/_3 bits with
SSL_OP_NO_DTLSv1_2/_3. The new options field dtlsMaxMask records the
bits the maximum added itself, and a later maximum clears only those, so
a version the application or the CTX masked off stays off.
wolfSSL_set_options() and wolfSSL_clear_options() take a bit out of the
record.

The mask no longer moves the version while the first handshake is under
way. DtlsHandshakeStarted() reports that from handShakeDone, the connect
and accept states, got_client_hello, buffered output and, with async
crypto, an async state other than TLS_ASYNC_BEGIN or handler args kept
in ssl->async, since DoTls13ClientHello() clears got_client_hello when
it pends and can pend before it leaves TLS_ASYNC_BEGIN. Before, an async
accept that re-entered could switch to DTLS 1.2 partway through a DTLS
1.3 ClientHello, and a client could have its version raised between
WANT_WRITE and the retry that sent the ClientHello. In that window a
DTLS wolfSSL_set_max_proto_version() that would change the mask fails
without changing anything, since it could no longer take effect, and one
that changes nothing succeeds. A maximum of 0 on a DTLS SSL means the
newest DTLS version, so it fails there too instead of settling on the
current cap. The maximum also refuses a change after the handshake: a
lift there would make a later DTLS 1.2 renegotiation treat the server's
downgrade sentinel as an attack. wolfSSL_clear() lets it apply again,
and now resets the async handler state in builds without TLS 1.3 too,
where a stale one would leave the SSL looking started.
wolfSSL_clear_options() reports a failed suite rebuild but not
VERSION_ERROR, which the handshake start reports, as
wolfSSL_set_options() does.

wolfSSL_CTX_set_max_proto_version() raises a fixed-version DTLS method
to DTLS 1.3, as it does fixed TLS methods. A DTLS 1.3 method lowered to
DTLS 1.2 could not be restored before. A wolfDTLSv1_2_method() CTX given
a maximum of 0 now becomes DTLS 1.3-only, as a wolfTLSv1_2_method() CTX
becomes TLS 1.3-only.

wolfSSL_CTX_set_max_proto_version() with DTLS1_2_VERSION or
DTLS1_VERSION also sets WOLFSSL_OP_NO_TLSv1_3 and WOLFSSL_OP_NO_TLSv1_2,
as the TLS versions do (WOLFSSL_OP_NO_TLSv1_3 only when DTLS 1.3 is
built, at both levels, so a maximum of 0 adds no bit that means
nothing), so an SSL keeps the CTX maximum it was created with when the
CTX maximum is raised later. Before, such an SSL stayed on DTLS 1.2
while TLSv1_3_Capable() read DTLS 1.3 from the shared method, and it
rejected the server's downgrade sentinel.
wolfSSL_CTX_get_max_proto_version() returns DTLS versions for a DTLS
CTX, so its result can be passed back to the setter. It honors the CTX
minimum, and for a fixed-version DTLS method it returns that version, or
0 when the mask or the minimum excludes it. It shares the version walk
with DtlsAllowedMinor() through the new DtlsMaskAllowedMinor(), which
takes the mask directly.

wolfSSL_CTX_set_min_proto_version() and
wolfSSL_CTX_set_max_proto_version() fail on a DTLS CTX when the mask and
the minimum leave no DTLS version, or, for a fixed-version DTLS method,
leave out the method's own version, as the TLS setters do. Before, they
returned success and every later wolfSSL_new() failed with
VERSION_ERROR. A rejected DTLS call restores the mask, the minimum, the
method version and the min/max flags, so the CTX keeps working.

wolfSSL_set_max_proto_version() refuses a TLS version on a DTLS SSL,
like the CTX setter and OpenSSL. On a fixed-version DTLS SSL it also
refuses a maximum below the SSL's version, judged by the bits the
maximum adds, so an option the application set does not make every later
maximum fail. Before, the bit was set and the SSL kept its version, so
the ClientHello went out with an empty supported_versions list.

DtlsCheckVersionMask() takes a mode (handshake start, lift, or the
server's step-down inside DoClientHello()), so every caller goes through
the same checks, and the DTLS mask helpers move above the OPENSSL_EXTRA
block so the setters can use them. DtlsMaskVersion() no longer records
VERSION_ERROR itself, so the option setters that ignore it leave nothing
on the error queue; DoClientHello() records it where it sends the alert.

When DtlsCheckVersionMask() lifts a server SSL to DTLS 1.3, it runs
InitSSL_DtlsServer() again, since the DTLS 1.3 cookie secret and
ClientHello fragmentation are only set up for the version the SSL was
created with. Without them every DTLS 1.3 handshake of a server created
under SSL_OP_NO_DTLSv1_3 and lifted later fails with COOKIE_ERROR.
InitSSL_DtlsServer() only fills in what is missing.

Tests: a server created under a CTX SSL_OP_NO_DTLSv1_3 and lifted, with
a plain and a fragmented post-quantum ClientHello, a maximum of 0 after
a handshake and a lower one after wolfSSL_clear(), a DTLS 1.2 cap lifted
by a maximum, by a maximum of 0 and by clearing the option, a maximum
lifted by clearing the option, a DTLS 1.0 cap lifted to DTLS 1.2, a lift
under a CTX maximum lowered to DTLS 1.0 that keeps DTLS 1.2, the CTX
maximum of DTLS 1.0, fixed DTLS 1.3 and DTLS 1.2 CTXs raised to DTLS
1.3, a TLS 1.2 maximum refused on a DTLS SSL, CTX and user options that
survive later maximums, a maximum and option calls while the first
ClientHello waits on WANT_WRITE, a maximum after the ClientHello was
sent, maximums after the handshake and after wolfSSL_clear(), maximums
that repeat, lift or tighten from a server SNI callback, a maximum of 0
mid-handshake, the CTX maximum read back and set again, a lower maximum
refused and an equal one or 0 accepted on a fixed DTLS 1.3 SSL with
SSL_OP_NO_DTLSv1_3 set and on a fixed DTLS 1.2 SSL, a DTLS 1.3 CTX
minimum refused under SSL_OP_NO_DTLSv1_3 and a DTLS 1.2 CTX maximum
refused under a DTLS 1.3 minimum, both leaving a working CTX, a minimum
refused on a fixed DTLS 1.3 method that masks its own version, the CTX
maximum of a fixed DTLS 1.3 method that masks its own version, a CTX
maximum raised after wolfSSL_new(), option and maximum calls after the
CTX maximum was lowered, the return value of wolfSSL_clear_options()
when no version is left, the exact error for a DTLS 1.3-only client
against a DTLS 1.2 server, and a TLS 1.3 minimum refused on a DTLS
object without DTLS 1.3.
2026-12-02 13:36:35 +01:00
Tobias Frauenschläger c609059236 Hand pre-1.3 DTLS connections to the legacy handshake
wolfSSL_connect_TLSv13() and wolfSSL_accept_TLSv13() handed off to
wolfSSL_connect() and wolfSSL_accept() only when their own mask check
moved the version. wolfSSL_set_options(),
wolfSSL_set_max_proto_version() and CTX setup now move a DTLS SSL to
DTLS 1.2 before either entry point runs, so such an SSL went into the
TLS 1.3 state machine. With ECH built in, SendTls13ClientHello() failed,
since no ECH extension is added below TLS 1.3.

Both entry points now hand any DTLS SSL below 1.3 to the legacy
handshake, on every call. That also covers re-entry with non-blocking
I/O after the hand-off, which used to run the TLS 1.3 state machine on
the legacy connect or accept state. The hand-off clears tls1_3, since
wolfSSL_connect() and wolfSSL_accept() route on that flag: setting a
DTLS 1.3 session and then a DTLS 1.2 one left it set on a DTLS 1.2 SSL,
and the two entry points called each other until the stack overflowed.
The check only runs in builds with a pre-1.3 handshake.

Tests: both entry points, driven directly over memio, complete a DTLS
1.2 handshake after SSL-level and CTX-level masking, and a client given
a DTLS 1.3 session and then a DTLS 1.2 one completes a DTLS 1.2
handshake.
2026-12-02 13:36:35 +01:00
Tobias Frauenschläger a8a6ba1afd Add SSL_OP_NO_DTLSv1 and apply DTLS min and max proto versions
wolfSSL_set_max_proto_version() ignored DTLS1_VERSION and
DTLS1_2_VERSION on a DTLS SSL, so capping a DTLS 1.3 SSL at DTLS 1.2 did
nothing. A TLS version such as TLS1_2_VERSION set the mask bit but left
the SSL on DTLS 1.3 until the handshake started, so
wolfSSL_write_early_data() still accepted data. The DTLS versions now
set the matching mask bits, and the SSL moves to the newest allowed
version straight away, as wolfSSL_set_options() does. A call that fails
because no version is left restores the mask it found. DTLS1_VERSION
needs old TLS, as it already did for the minimum.

DTLS1_3_VERSION is accepted by the SSL and CTX min and max setters and
is in protoVerTbl, so a maximum of 0 walks to DTLS 1.3. Before, the walk
stopped at DTLS1_2_VERSION and capped a DTLS CTX at DTLS 1.2. On a
fixed-version DTLS method below DTLS 1.3, DTLS1_3_VERSION fails rather
than turning the method into DTLS 1.3, so a maximum of 0 walks on to
DTLS1_2_VERSION as before.

A TLS-numbered minimum on a DTLS SSL or CTX, from a min proto version of
0, a TLS version, or wolfSSL_SetMinVersion(), was compared as a DTLS
minor by supported_versions, so a DTLS 1.3 client sent an empty list and
the server answered decode_error. The min setters now store the DTLS
version that shares the mask bit. A DTLS version is refused as the
minimum of a TLS SSL or CTX, through the proto setters or
wolfSSL_SetMinVersion(), and as the maximum of a TLS SSL. The CTX max
setter refuses a version of the other kind before it sets any mask bit;
it used to set them first, so a failed TLS1_2_VERSION maximum on a DTLS
CTX still masked DTLS 1.3. GetMinProtoVersion() reports DTLS minimums,
so wolfSSL_CTX_set_max_proto_version() no longer drops one when it
restores the minimum, and a DTLS CTX minimum no longer clears the CTX's
version options, which compared TLS table positions with DTLS ones.
Without DTLS 1.3 built, a TLS 1.3 minimum on a DTLS SSL or CTX is
refused, since no version could meet it, and GetMinProtoVersion()
reports DTLS 1.3 only when it is built.

DtlsMaskVersion() kept the current version when the mask allowed it,
without checking the minimum, so WOLFSSL_OP_NO_TLSv1_3 followed by
wolfSSL_SetMinVersion(ssl, WOLFSSL_DTLSV1_3) ran a DTLS 1.2 handshake.
It now checks both and fails with VERSION_ERROR.

Add SSL_OP_NO_DTLSv1. It is WOLFSSL_OP_NO_TLSv1_1, which has OpenSSL's
SSL_OP_NO_DTLSv1 value and is the bit wolfSSL masks DTLS 1.0 with; on a
TLS object it masks TLS 1.1 rather than TLS 1.0. The
wolfSSL_CTX_set_options() table lists the three DTLS options.

Tests: a minimum set after the mask, through either setter, on the
client and the server; the SSL max proto version at DTLS 1.0, 1.2, 1.3,
a TLS version and 0; a CTX minimum and maximum of 0; a CTX maximum of 0
after a DTLS 1.2 maximum; a fixed DTLS 1.2 CTX under DTLS 1.0, DTLS 1.3
and 0 maximums; TLS 1.2, TLS 1.1 and TLS 1.3 minimums on a DTLS SSL and
CTX; a TLS maximum on a DTLS CTX; failed maximums leaving the SSL
unchanged; a TLS 1.1 maximum; the CTX DTLS 1.3 minimum surviving a later
maximum and keeping a masked DTLS 1.3 masked; and DTLS versions refused
on TLS objects.
2026-12-02 13:36:35 +01:00
Tobias Frauenschläger 1f04882725 Apply the DTLS mask when a session is set, not mid-ClientHello
wolfSSL_set_session() puts the SSL on the session's version, so with the
mask already set, a DTLS 1.3 session took a masked SSL back to DTLS 1.3
until the handshake started. wolfSSL_write_early_data() then started a
DTLS 1.3 handshake, the connect path moved it to DTLS 1.2, and every
non-blocking retry returned BAD_FUNC_ARG while the error still read
WANT_READ. SetSession() now applies the mask too, so the version is right
before any early data is written.

wolfSSL_set_options() no longer moves the version once a ClientHello has
arrived. A server callback that sets options while the ClientHello is
parsed, such as an SNI callback re-applying per-host options, moved an SSL
that ClientHello had already settled on DTLS 1.3.

Only a client resumption changes the walk and resets haveEMS. A server
reused through wolfSSL_clear() keeps a stale resuming flag, and the reset
would have forced EMS on before the ClientHello was read.

DtlsAllowedMinor() reads the mask only under OPENSSL_EXTRA, HAVE_WEBSERVER
or WOLFSSL_WPAS_SMALL, the builds where supported_versions honours it, so
other builds do not offer a version and then refuse it.

Tests: early data after a DTLS 1.3 session set behind the mask is refused
up front with nothing left pending, and an SNI callback that masks DTLS 1.3
leaves the handshake on DTLS 1.3.
2026-12-02 13:36:35 +01:00
Tobias Frauenschläger a2d05dc098 Pick only listed DTLS versions and share the server mask check
The DTLS server stepped down from the version supported_versions picked to
the next one its mask allowed, so a server masking DTLS 1.2 answered a
client that listed only DTLS 1.2 with DTLS 1.0.
TLSX_SupportedVersions_Parse() now skips DTLS versions the mask does not
allow on an SSL that may downgrade, so it picks the newest listed version
that is allowed or refuses with protocol_version, as OpenSSL does. The
step-down in DoClientHello() remains for a ClientHello without
supported_versions, and now calls DtlsCheckVersionMask() instead of
repeating it.

The ECH rejection in DoServerHello() detects the HelloRetryRequest through
msgsReceived.got_hello_retry_request. DoTls13ServerHello() sets serverState
to SERVER_HELLO_COMPLETE before it calls DoServerHello() for a TLS 1.2
ServerHello that carries extensions, so the serverState test missed it.

wolfSSL_connect_TLSv13() resets earlyData when the mask moves the SSL below
DTLS 1.3 and it hands over to wolfSSL_connect(). wolfSSL_write_early_data()
had set it, and nothing on the DTLS 1.2 path cleared it, so every write
after the handshake failed.

When the mask drops a resumption, haveEMS goes back to the default
wolfSSL_clear() uses instead of keeping the session's, so the full
handshake offers extended_master_secret again.

Tests: a server masking DTLS 1.2 against a client listing only DTLS 1.2,
early data written with a DTLS 1.3 session after the mask, and a dropped
resumption of a session without EMS.
2026-12-02 13:36:35 +01:00
Tobias Frauenschläger e2fa0155fe Start the DTLS mask walk from the method version when resuming
wolfSSL_set_session() lowers the SSL to the session's version, so with a
DTLS 1.2 session and DTLS 1.2 masked the walk started at DTLS 1.2 and a
client that allows DTLS 1.3 fell to DTLS 1.0 or failed with VERSION_ERROR.
A resumption now walks from the method's version, and the resumption is
dropped as before when its version is no longer the SSL's.

DtlsMaskVersion() only moves the version and DtlsCheckVersionMask() adds
the suite rebuild, so wolfSSL_set_options() rebuilds the suites once.
wolfSSL_connect() and wolfSSL_accept() check the mask only for the side
they serve, so a call on the wrong side fails with SIDE_ERROR without
changing the SSL first. The server check in DoClientHello() skips a
renegotiation, as the client's does.

Drop SSL_OP_NO_DTLSv1. OpenSSL defines it as the SSL_OP_NO_TLSv1 bit, while
wolfSSL masks DTLS 1.0 with WOLFSSL_OP_NO_TLSv1_1, so the alias would have
behaved differently from OpenSSL. SSL_OP_NO_DTLSv1_2 and SSL_OP_NO_DTLSv1_3
use the same bits as in OpenSSL and stay.

Adds a DTLS 1.2 session with DTLS 1.2 masked to the session cases.
2026-12-02 13:36:34 +01:00
Tobias Frauenschläger 1646a30213 Apply the DTLS version mask in set_options and on every ClientHello
DtlsCheckVersionMask() lowered the version but left options.tls1_3 and a
resumption of a DTLS 1.3 session in place. After wolfSSL_set_session() with
such a session, wolfSSL_connect() still went into the TLS 1.3 state machine,
where SendTls13ClientHello() compares the session version in TLS order and
put the SSL back on DTLS 1.3 to build the ClientHello. A move now clears
tls1_3 and drops a resumption whose version is no longer the SSL's.

wolfSSL_set_options() calls DtlsCheckVersionMask() as well, so a masked SSL
reports and acts as the older version before the handshake, as it does when
the mask comes from the CTX, and calls such as wolfSSL_write_early_data()
that check the version before the handshake see the older one. The check at
the start of the handshake stays and catches a session or option set later.
Neither moves the version once the handshake has begun.

The DTLS server mask check in DoClientHello() ran only when the server
stepped down to the legacy ClientHello version. A client whose
supported_versions offered DTLS 1.2 and nothing newer was negotiated at the
masked DTLS 1.2. The check now runs for every DTLS ClientHello that may
downgrade and rebuilds the suites through ResetSuitesForVersion() when it
moves.

The client's check in CheckVersion() skips a renegotiation, as the
handshake-start check does, so a mask set after the handshake does not break
it. The ECH HelloRetryRequest rejection in DoServerHello() returns
SOCKET_ERROR_E when the alert cannot be sent, like its neighbors.

Tests: the version right after wolfSSL_set_options(), a DTLS 1.3 session set
before or after the mask, and a ClientHello whose supported_versions offers
only DTLS 1.2 against a server that allows only DTLS 1.3.
2026-12-02 13:36:34 +01:00
Tobias Frauenschläger 2c774cb713 Rebuild suites and cover all entry points in the DTLS mask check
DtlsCheckVersionMask() lowered the version without rebuilding the cipher
suites, so a client or server moved to DTLS 1.2 or 1.0 kept the list built
for DTLS 1.3 and could negotiate a TLS 1.3 or TLS 1.2-only suite at DTLS
1.0. The suite rebuild at the end of wolfSSL_set_options() moves into
ResetSuitesForVersion(), unchanged, and DtlsCheckVersionMask() calls it
after a move.

wolfSSL_negotiate(), which wolfSSL_read() and wolfSSL_write() use, and
callers of wolfSSL_connect_TLSv13() or wolfSSL_accept_TLSv13() went straight
to the TLS 1.3 state machines and skipped the check. Both now run it at the
start of the handshake and hand over to wolfSSL_connect() or
wolfSSL_accept() when the version drops below DTLS 1.3.

The check keeps the current version whenever the mask allows it and only
applies the minimum when it has to step down, so a DTLS context left with a
TLS-numbered minimum by wolfSSL_CTX_set_min_proto_version(ctx, 0) no longer
fails every handshake once any option bit is set. It skips SSLs that already
completed a handshake, so a renegotiation cannot change the version.

A DTLS client now also checks the version the server chose against its own
mask in CheckVersion(), as the TLS client does. Before, a client that masked
DTLS 1.2 still completed a DTLS 1.2 handshake with a server that only spoke
DTLS 1.2.

Tests: no TLS 1.3 suite is left after a move, a handshake driven by
wolfSSL_negotiate() on a masked server, a client masking DTLS 1.2 against a
DTLS 1.2-only server, and builds without TLS 1.2 but with old TLS expect
DTLS 1.0 instead of no version.
2026-12-02 13:36:34 +01:00
Tobias Frauenschläger 29d2bd8675 Check the DTLS version mask when the handshake starts
wolfSSL_set_options() moved a DTLS SSL to an older version as each option
call came in, so the result depended on the order of the calls: three
separate calls left a masked DTLS 1.0, a server put back on DTLS 1.3 when
nothing was left negotiated it anyway because the server never checks its
own mask, and a call made during the handshake still changed the version.

Do it the way OpenSSL 4.1 does instead and look at the accumulated mask once,
when wolfSSL_connect() or wolfSSL_accept() starts a handshake.
DtlsCheckVersionMask() moves a DTLS SSL that may downgrade to the newest
built version that the mask and minimum allow, or fails with VERSION_ERROR
when none is left. wolfSSL_set_options() no longer changes the DTLS version.
Methods that cannot downgrade keep their version, as OpenSSL's fixed-version
methods ignore the mask too.

A DTLS server that steps down to the client's version in DoClientHello() now
checks that version against the mask as well, the way the TLS path already
walks it, and refuses with protocol_version when no allowed version is left.
Before, a DTLS server negotiated a masked DTLS 1.2 or 1.0 with a client that
offered only that version.

Dtls13DowngradeMinor() becomes DtlsAllowedMinor(), which also takes the
newest version to start from and is built with DTLS 1.2 alone.

The ECH check in DoServerHello() now applies only when this handshake had a
HelloRetryRequest. wolfSSL_clear() keeps echAccepted, so a reused SSL whose
last handshake accepted ECH failed a TLS 1.2 or older fallback. An empty
inner groups list no longer fails the ECH split. SSL_OP_NO_DTLSv1_3 is
defined only when DTLS 1.3 is built, like SSL_OP_NO_TLSv1_3.

test_dtls13_no_tls13_option now runs every mask case on the client and the
server, through SSL and CTX, with up to three separate calls, and checks the
version after the handshake. It adds a DTLS 1.2-only client against a server
that masks DTLS 1.2, and checks that a DTLS 1.3-only method and
wolfSSL_require_psk() keep DTLS 1.3 through wolfSSL_connect().
test_tls13_ech_hrr_tls11_server_hello adds a TLS 1.1 fallback with a stale
echAccepted.
2026-12-02 13:36:34 +01:00
Tobias Frauenschläger ef15c8534a Address review on DTLS 1.3 downgrade and ECH outer hello
wolfSSL_set_options(): when a later call masks DTLS 1.2 on an SSL that an
earlier WOLFSSL_OP_NO_TLSv1_3 moved there and no older DTLS version is left,
put the SSL back on DTLS 1.3 so the handshake fails, as it does after one
combined call. OpenSSL 4.1 checks the accumulated mask when the handshake
starts, so the order of the calls does not matter there either. The DTLS
branch now leaves the version alone once the handshake has started.

Add SSL_OP_NO_DTLSv1, SSL_OP_NO_DTLSv1_2 and SSL_OP_NO_DTLSv1_3. OpenSSL 4.1,
the first release with DTLS 1.3, defines SSL_OP_NO_DTLSv1_3 as the
SSL_OP_NO_TLSv1_3 bit. SSL_OP_NO_DTLSv1 maps to WOLFSSL_OP_NO_TLSv1_1, the
option wolfSSL masks DTLS 1.0 with.

TLSX_EchSplitSupportedGroups() removed the supported_groups extension and
pushed the inner list back at the head of ssl->extensions, so a real ECH
outer ClientHello wrote supported_groups first and could be told apart from
a GREASE ECH one by its extension order. It now builds the inner list in a
temporary list and swaps only the data into the existing extension.

DoServerHello(): a ServerHello for TLS 1.1 or older after a
HelloRetryRequest that accepted ECH now fails with illegal_parameter, as a
TLS 1.3 ServerHello that rejects ECH after an accepting HelloRetryRequest
does (RFC 9849 section 6.1.5). Otherwise the outer extensions are swapped
back in. A TLS 1.2 ServerHello there already fails the HelloRetryRequest
cipher suite check in DoTls13ServerHello().

Tests: separate set_options calls that leave no DTLS version, set_options
after the handshake, the SSL_OP_NO_DTLS names, the extension order of a real
ECH outer ClientHello against a GREASE ECH one, and
test_tls13_ech_hrr_tls11_server_hello.
2026-12-02 13:36:34 +01:00
Tobias Frauenschläger 729459453b Keep the RFC 7027 brainpool groups out of the ECH inner ClientHello
The inner ClientHello offers only TLS 1.3, as downgrade is cleared while it is
written, but it referenced the outer supported_groups through
ech_outer_extensions and so still carried the pre-1.3 brainpool codepoints.

When ECH is in use and a pre-1.3 version is reachable, the client now gives
the outer ClientHello its own default groups list in ech->extensions, the way
the public-name SNI is handled, and builds the inner list without the pre-1.3
groups. An extension with an outer-only copy is no longer referenced from
ech_outer_extensions.

A server that negotiates TLS 1.2 or older answers the outer ClientHello, so
DoServerHello() now swaps the outer extensions back in, as the TLS 1.3
rejection paths already do, unless a HelloRetryRequest accepted ECH. Without
that the client kept the inner list and could not use a brainpool client
certificate in the TLS 1.2 handshake.

A second ClientHello after a HelloRetryRequest keeps the lists the first one
sent, as RFC 8446 requires: the split is skipped then, and the default groups
are no longer added again to an existing supported_groups extension, which
would have put the pre-1.3 groups back into the inner list.

Adds ECH cases to the brainpool test: the inner list as the server parsed it,
the client's list after a TLS 1.2 ServerHello, and, with ECH accepted and
rejected, that the ClientHello after a HelloRetryRequest repeats the first
one's supported_groups and its position. supported_versions is left out of
the order check, as it already moves in every second ClientHello.
2026-12-02 13:36:34 +01:00
Tobias Frauenschläger f8f8281c08 Downgrade a DTLS 1.3 SSL when TLS 1.3 is masked off
wolfSSL_set_options() and SetSSL_CTX_CheckVersion() move an SSL from TLS 1.3
to TLS 1.2 when WOLFSSL_OP_NO_TLSv1_3 is set, but compare the version against
TLSv1_3_MINOR only. A DTLS 1.3 SSL (minor 0xFC) kept its version, so its
ClientHello offered only older DTLS versions in supported_versions while
still carrying a TLS 1.3 key_share and the TLS 1.3-only groups (ML-KEM
hybrids, RFC 8734 brainpool).

Add Dtls13DowngradeMinor(), which picks the newest older DTLS version that
the version mask and minimum still allow and that is built: DTLS 1.2, or
DTLS 1.0 when old TLS is built. The later TLS mask steps only match TLS
minors, so DTLS needs its own choice. wolfSSL_set_options() moves to it when
there is one and the SSL may downgrade, so wolfSSL_require_psk() and the
DTLS 1.3-only methods keep DTLS 1.3. It also steps down again when a later
call masks DTLS 1.2 on an SSL it already moved there, so separate calls end
where one combined call does. SetSSL_CTX_CheckVersion() returns
VERSION_ERROR when the method cannot downgrade or no DTLS version is left,
as it does for TLS.

Adds test_dtls13_no_tls13_option for the option on the client or server SSL
or CTX, with DTLS 1.2 also masked off in the same or a separate call or
below the minimum, with no DTLS version left, in builds without TLS 1.2, for
a DTLS 1.3-only method and after wolfSSL_require_psk(), and a DTLS case to
the brainpool supported_groups test.
2026-12-02 13:36:34 +01:00
Tobias Frauenschläger 76f8497b52 Offer the RFC 7027 brainpool groups only when TLS 1.2 or older is reachable
A TLS 1.3 client also lists the RFC 7027 brainpool codepoints when it may
fall back to an earlier version. The check compared minDowngrade against both
TLSv1_2_MINOR and DTLSv1_2_MINOR with <=, which is true for every TLS minor
and for DTLS 1.3, whose minor (0xFC) is below DTLS 1.2's. A client with TLS 1.3
or DTLS 1.3 as its minimum version therefore still offered the pre-1.3
codepoints.

Add TLSX_PreTls13Reachable(), which answers whether supported_versions would
also offer a version before 1.3, the same way TLSX_SupportedVersions_GetSize()
decides it: downgrade allowed, and TLS 1.2, TLS 1.1 (DTLS 1.0) or, with
WOLFSSL_ALLOW_TLSV10, TLS 1.0 at or above the minimum version and not masked
off with WOLFSSL_OP_NO_TLSv1_2, _1_1 or NO_TLSv1. A build with neither
TLS 1.2 nor old TLS never offers them. DTLS minors count down.

TLSX_PopulateSupportedGroups() also builds the list a TLS 1.3 server sends in
EncryptedExtensions when the client lacks its first choice. The version is
settled by then, so the helper answers 0 on the server side.

Adds a test for the P256, P384 and P512 brainpool codepoints a TLS, TLS
1.2-only, TLS 1.3-only and DTLS client offers with a minimum version set on
the SSL or the CTX, with versions masked off down to TLS 1.0 and DTLS 1.0,
and in the list a TLS 1.3 server sends back.
2026-12-02 13:35:24 +01:00
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
Juliusz Sosinowicz b1fe1028ad Fix CI: skip peer unknown ext cb test in dual alg builds
Dual alg builds decode all extensions when loading the server's own
certificate, so the server cannot load a certificate with an unknown
critical extension.
2026-12-02 05:22:46 +00: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