wolfSSL — Keystream Reuse from All-Zero IV in EVP AES-OFB Initialization Without an IV
In the wolfSSL EVP compatibility layer, initializing AES-OFB with a key and a NULL IV on a fresh context succeeds and leaves the start block at zero. OFB derives its keystream from the key and that block alone, so every message under the key is encrypted with the same keystream.
- Advisory
- BYTERAY-2026-0381
- 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 and WOLFSSL_AES_OFB where an application initializes EVP AES-OFB with a key and a NULL IV
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
wolfSSL_EVP_CipherInit() in wolfcrypt/src/evp.c is the common initialization function behind the EVP cipher API. Its AES-128/192/256-OFB branches accept a NULL IV together with a key and return success.
On a fresh context nothing supplies an IV in that case. The context is zero-filled, the key setup keeps the zeroed register, and the fallback that reuses a stored IV only applies to a context that was initialized before. The OFB data paths then run with no check that an IV was ever set.
OFB generates its keystream from the key and the start block only. With the start block fixed at zero, every message under the same key is XORed with the same keystream. An observer who captures two such ciphertexts and knows or guesses part of one plaintext recovers the keystream for that range and can decrypt the same range of every other message. The condition is created by the application that omits the IV, not by a remote party. Builds without the OpenSSL compatibility layer do not include this code.
Affected Products and Versions
- Component:
wolfcrypt/src/evp.c,wolfSSL_EVP_CipherInit(), AES-OFB branches. - Required build: the OpenSSL compatibility layer with
WOLFSSL_AES_OFB. - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- Builds without the OpenSSL compatibility layer do not include the EVP API. Other releases were not checked.
Technical Details
The AES-128-OFB branch (wolfcrypt/src/evp.c:8227-8254) sets the key with whatever IV pointer it was given and programs an IV only in the IV-without-key case (wolfcrypt/src/evp.c:8242-8253). The two conditions are disjoint, so a key with a NULL IV never reaches wc_AesSetIV(). The AES-192 and AES-256 branches are the same (wolfcrypt/src/evp.c:8256-8283, wolfcrypt/src/evp.c:8285-8317).
if (key) {
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
iv, AES_ENCRYPTION, 0);
if (ret != 0)
return WOLFSSL_FAILURE;
}
if (iv && key == NULL) {
ret = wc_AesSetIV(&ctx->cipher.aes, iv);
What happens when the application passes a key and a NULL IV on a fresh context:
- The context is zero-filled, so
ctx->ivSzis 0 and the fallbackif (!iv && ctx->ivSz) { iv = ctx->iv; }does not apply (wolfcrypt/src/evp.c:7622-7626). AesSetKey_ex()is called withiv == NULL. It saves the register before key setup and restores it afterwards (wolfcrypt/src/evp.c:7159-7174). The saved register is zero, and the call returns success.evpCipherBlock()sends OFB data towc_AesOfbEncrypt()orwc_AesOfbDecrypt()(wolfcrypt/src/evp.c:644-652).wolfSSL_EVP_Cipher()has the same call (wolfcrypt/src/evp.c:9061-9071). Neither checks that an IV was set.- The OFB routine produces the keystream from
aes->regalone (wolfcrypt/src/aes.c:17378-17449). Starting from zero, the keystream is the encryption of the zero block, then the encryption of that result, and so on. It is the same for every message under the key.
Reachability and Preconditions
- Build: OpenSSL compatibility layer with
WOLFSSL_AES_OFB. - An application calls
EVP_EncryptInit_ex()or an equivalent withEVP_aes_128_ofb(),EVP_aes_192_ofb()orEVP_aes_256_ofb(), a key and a NULL IV on a fresh context. Code written for a library that generates an IV on its own is the likely source. - More than one message is encrypted under the same key.
- Attacker position: a passive observer who captures at least two ciphertexts. The attacker cannot cause the condition. No authentication is involved.
Impact
Complete keystream reuse across messages. A known or guessable part of one plaintext, such as a protocol header or a repeated field, gives the keystream for that range, and the keystream decrypts the same range of every other message under the key. The result is full plaintext recovery for the affected messages. The impact is on confidentiality only.
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 from the report: in each OFB branch, fail the initialization when a key is supplied with a NULL IV on a context that has no stored IV. As a second line, the OFB data paths in evpCipherBlock() and wolfSSL_EVP_Cipher() should return an error when no IV was programmed. The change should cover all three key sizes. Workaround: applications should generate a fresh random IV for every message, for example with wolfSSL_RAND_bytes(), and pass it at initialization.
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.
References
- AES-OFB branches of
wolfSSL_EVP_CipherInitat the tested commit AesSetKey_exat the tested commit- Related advisories for other modes in the same function: BYTERAY-2026-0377, BYTERAY-2026-0378, BYTERAY-2026-0379, BYTERAY-2026-0380, BYTERAY-2026-0382, BYTERAY-2026-0383