wolfSSL — Keystream Reuse from All-Zero Initial Counter in EVP AES-CTR Initialization Without an IV
In the wolfSSL EVP compatibility layer, initializing AES-CTR with a key and a NULL IV on a fresh context succeeds and leaves the counter block at zero. Every message initialized this way under the same key is encrypted with the same keystream, and no error is reported.
- Advisory
- BYTERAY-2026-0379
- 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, WOLFSSL_AES_COUNTER and WOLFSSL_AES_DIRECT where an application initializes EVP AES-CTR 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-CTR branches accept a NULL IV together with a key and return success.
On a fresh context nothing supplies a counter block in that case. The context is zero-filled, the key setup keeps the zeroed register, and the fallback that reuses a stored IV does not apply. The CTR data paths read the starting counter from that register.
Every message initialized this way under the same key starts its keystream at counter block zero. The messages share one keystream. The XOR of two ciphertexts equals the XOR of the two plaintexts, and any predictable content recovers the keystream and with it the other messages. This is worse than a fixed IV in CBC mode, where only the first block is affected. 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-CTR branches. - Required build: the OpenSSL compatibility layer with
WOLFSSL_AES_COUNTERandWOLFSSL_AES_DIRECT. WithoutWOLFSSL_AES_DIRECTthe key setup returnsNOT_COMPILED_INand EVP AES-CTR initialization fails, so the issue exists exactly where EVP AES-CTR works. - 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-CTR branch (wolfcrypt/src/evp.c:7775-7805) 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:7794-7804). The AES-192 and AES-256 branches are the same (wolfcrypt/src/evp.c:7808-7840, wolfcrypt/src/evp.c:7841-7872).
if (key) {
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
iv, AES_ENCRYPTION, 1);
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 on entry and the fallbackif (!iv && ctx->ivSz) { iv = ctx->iv; }does not apply (wolfcrypt/src/evp.c:7622-7626). - The branch sets
ctx->ivSzto the AES block size whether or not an IV was provided (wolfcrypt/src/evp.c:7783). 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.wc_AesSetIV()does not run, because a key was supplied.evpCipherBlock()callswc_AesCtrEncrypt()(wolfcrypt/src/evp.c:627-632), andwolfSSL_EVP_Cipher()does the same (wolfcrypt/src/evp.c:9122-9129). Neither checks that a counter block was ever set.wc_AesCtrEncrypt()takes its starting counter fromaes->reg(wolfcrypt/src/aes.c:7952,wolfcrypt/src/aes.c:8075). The keystream starts at counter block zero, so messages initialized this way under one key are XORed with the same keystream.
Reachability and Preconditions
- Build: OpenSSL compatibility layer with
WOLFSSL_AES_COUNTERandWOLFSSL_AES_DIRECT. - An application calls
EVP_EncryptInit_ex()or an equivalent withEVP_aes_128_ctr(),EVP_aes_192_ctr()orEVP_aes_256_ctr(), a key and a NULL IV. 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
Keystream reuse across messages. With two ciphertexts the observer has the XOR of the two plaintexts without knowing the key or any plaintext. Guessable content such as a protocol header or a known format then recovers the keystream for that range, and the same keystream decrypts every further message protected this way. The result is full plaintext recovery for the affected messages. Integrity and availability are not affected by this issue.
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 CTR branch, fail the initialization when a key is supplied and no IV is available after the stored-IV fallback, and have the CTR data paths return an error when no counter block was programmed. ctx->ivSz should be set only once an IV has been provided, so the fallback cannot hide a missing IV. If a missing IV is to be tolerated, it should be replaced by a random value that the application can read back, never by a zero counter. Workaround: applications should pass an explicit, unique IV at initialization for every message encrypted under a key.
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-128-CTR branch 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-0380, BYTERAY-2026-0381, BYTERAY-2026-0382, BYTERAY-2026-0383