wolfSSL — All-Zero IV Substituted on Two-Phase EVP Cipher Initialization
wolfSSL_EVP_CipherInit keeps a previously set IV when a context is re-initialized without one, but it decides that an IV exists from the IV size field, which is set whether or not an IV was given. A cipher-then-key initialization with no IV programs sixteen zero bytes as the IV and returns success.
- Advisory
- BYTERAY-2026-0383
- CWE
- CWE-329
- CVSS
- 5.9 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N)
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-28
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 (tested at master commit d95483f), builds with the OpenSSL compatibility layer (OPENSSL_EXTRA) where an application initializes an EVP cipher context in two calls and never supplies an IV
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
The OpenSSL compatibility layer lets an application initialize a cipher context in steps: one call selects the cipher, a later call supplies the key. wolfSSL_EVP_CipherInit() has a fallback for this pattern. When a call passes no IV, it reuses the IV held in the context so that an earlier IV is not lost.
The fallback tests the wrong field. It treats a non-zero ctx->ivSz as proof that an IV was configured. The AES-CBC branch sets ctx->ivSz on every init, with or without an IV, and the context's IV buffer is zero-filled until an IV is stored in it. An application that selects the cipher, then sets the key, and passes no IV in either call gets a pointer to sixteen zero bytes as its IV. Key setup accepts it and both calls return success.
Every message encrypted through that context then uses the same all-zero IV. Someone who can read the ciphertexts can tell when two messages start with the same block. The EVP compatibility layer is not part of a default build.
Affected Products and Versions
- Component:
wolfcrypt/src/evp.c,wolfSSL_EVP_CipherInit(), and the EVP wrappers that call it (EVP_EncryptInit_ex,EVP_CipherInit_exand related). - Required build: the OpenSSL compatibility layer (
OPENSSL_EXTRA, for example--enable-opensslextra). The fallback is compiled whenever the compatibility header is used, becauseHAVE_WOLFSSL_EVP_CIPHER_CTX_IVis defined unconditionally atwolfssl/openssl/evp.h:749. - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild does not include the EVP compatibility layer. Other releases were not checked.
Technical Details
The fallback sits near the top of wolfSSL_EVP_CipherInit() (wolfcrypt/src/evp.c:7622-7626):
if (!iv && ctx->ivSz) {
iv = ctx->iv;
}
Two facts make the test unreliable:
ctx->ivSzrecords the IV length of the selected cipher. The AES-128-CBC branch assignsctx->ivSz = WC_AES_BLOCK_SIZEatwolfcrypt/src/evp.c:7639on every pass, and other branches do the same (wolfcrypt/src/evp.c:8329,wolfcrypt/src/evp.c:8632). It says nothing about whether an IV was supplied.ctx->ivis filled only when a call passes a non-NULL IV (wolfcrypt/src/evp.c:8730-8735). The context is zero-filled when it is created (wolfcrypt/src/evp.c:6665), so until then the buffer holds zeros.
The sequence for AES-128-CBC:
- The application calls
EVP_EncryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, NULL, NULL).ctx->ivSzis zero on entry, so the fallback does nothing. The CBC branch setsctx->ivSzto 16. No IV is stored. The call returns success. - The application calls
EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL).ivis NULL andctx->ivSzis 16, soivnow points atctx->iv, sixteen zero bytes. - The key branch passes that pointer to
AesSetKey_ex()(wolfcrypt/src/evp.c:7647-7652). The cipher is keyed with an all-zero IV. The call returns success. wolfSSL_EVP_CipherUpdate()andwolfSSL_EVP_Cipher()encrypt with that state (wolfcrypt/src/evp.c:615-762,wolfcrypt/src/evp.c:9006-9180). Neither checks that an IV was ever configured.
ByteRay traced the AES-CBC branches. Other cipher branches that assign ctx->ivSz during init behave the same way. Branches that leave ctx->ivSz at zero do not take the fallback. The fallback works as intended only when an earlier call stored a real IV.
Reachability and Preconditions
- Build with the OpenSSL compatibility layer. The application, not a remote party, triggers the condition. It must initialize the context in more than one call and pass a NULL IV each time.
- The attacker only needs to observe ciphertexts produced by that context under the same key. No authentication or interaction is involved.
- The resulting state is the same zero-IV encryption an application gets by omitting the IV on a fresh context. The fallback does not create a new capability. It fails to catch the omission and reports success.
Impact
CBC encryption under a fixed, publicly known IV is deterministic for the first block. Messages that begin with the same plaintext block produce the same first ciphertext block under the same key, and an observer who knows or can guess likely first blocks can confirm them. Stream-style modes that take the same path reuse their keystream across messages. Integrity and availability are not affected. The library gives the integrator no signal: both init calls succeed, so the missing IV can stay unnoticed in production.
ByteRay did not build a proof of concept for this issue. The analysis is from source review.
Remediation and Mitigation
ByteRay has not confirmed a fixed wolfSSL release for this issue as of 2026-12-03, and has not checked it against wolfSSL changes made after the tested commit.
The fix direction is to track IV presence explicitly. A flag set only when a non-NULL IV is processed, and cleared on context reset, should replace the ctx->ivSz test. A re-init with no IV and no stored IV should fail, and the data paths should refuse to run a mode that needs an IV when none was configured.
Workaround for applications: always pass an explicit, unpredictable IV to one of the init calls for every message, and do not rely on the context to supply one.
Timeline
- 2026-09-28 — Reported to wolfSSL.
- 2026-12-03 — Public disclosure.
Credits
Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.