← ALL ADVISORIES

HIGH BYTERAY-2026-0322Disclosed

wolfSSL — Nonce Reuse Across Messages in EVP AES-CCM Finalization

After each AES-CCM message, the EVP layer zeroes the context IV and then copies the unchanged nonce from the AES state back into it. The control that would advance the nonce is not implemented for CCM. A context reused for further messages without a new IV encrypts them under the first message's key and nonce.

Advisory
BYTERAY-2026-0322
CWE
CWE-323
CVSS
7.4 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:N)
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-27
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 (tested at master commit d95483f), builds with OPENSSL_EXTRA and HAVE_AESCCM (--enable-opensslextra --enable-aesccm) whose applications process more than one AES-CCM message on one EVP context
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

In wolfSSL's OpenSSL compatibility layer, an AES-CCM message is buffered by the Update calls and processed in one step by wolfSSL_EVP_CipherFinal(), with the context's IV buffer ctx->iv as the nonce.

After that step, Final clears ctx->iv, with a comment that IV reuse is not recommended for AES-CCM. It then calls wolfSSL_StoreExternalIV(), whose CCM case copies the nonce held in the AES state back into ctx->iv. That value was written once, at init. The only code that would advance it runs when ctx->authIncIv is set, and for CCM nothing sets that flag: EVP_CTRL_CCM_IV_GEN appears in a comment and has no handler. The clear has no effect.

An application that sends another message on the same context without a new IV seals it under the first message's key and nonce, and all calls return success. CCM encrypts in counter mode, so two such messages share a keystream. AES-CCM is off by default, and wolfSSL's own TLS record layer does not use the EVP layer.

Affected Products and Versions

  • Component: wolfcrypt/src/evp.c, the WC_AES_128_CCM_TYPE, WC_AES_192_CCM_TYPE and WC_AES_256_CCM_TYPE cases of wolfSSL_EVP_CipherFinal(); and src/ssl.c, the AES-CCM case of wolfSSL_StoreExternalIV().
  • Required build: OPENSSL_EXTRA (--enable-opensslextra) and HAVE_AESCCM (--enable-aesccm, disabled by default, configure.ac:4092). The EVP CCM code is compiled for non-FIPS builds and for FIPS version 2 and later (wolfcrypt/src/evp.c:1411-1412).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • A default ./configure build does not include this code. Other releases were not checked.

Technical Details

The end of the AES-CCM case in wolfSSL_EVP_CipherFinal() (wolfcrypt/src/evp.c:1458-1470):

            if (ret == WOLFSSL_SUCCESS) {
                if (ctx->authIncIv) {
                    ctx->authIncIv = 0;
                }
                else {
                    /* Clear IV, since IV reuse is not recommended
                     * for AES CCM. */
                    XMEMSET(ctx->iv, 0, WC_AES_BLOCK_SIZE);
                }
                if (wolfSSL_StoreExternalIV(ctx) != WOLFSSL_SUCCESS) {
                    ret = WOLFSSL_FAILURE;
                }
            }

The AES-CCM case of wolfSSL_StoreExternalIV() (src/ssl.c:10850-10855):

            case WC_AES_128_CCM_TYPE :
            case WC_AES_192_CCM_TYPE :
            case WC_AES_256_CCM_TYPE :
                WOLFSSL_MSG("AES CCM");
                XMEMCPY(ctx->iv, &ctx->cipher.aes.reg, ctx->ivSz);
                break;

ctx->cipher.aes.reg is written by wc_AesCcmSetNonce() during init, when an IV is supplied (wolfcrypt/src/evp.c:7449-7453). The increment that would change it afterwards is conditional on ctx->authIncIv (wolfcrypt/src/evp.c:1450-1453). The CCM init code mentions EVP_CTRL_CCM_IV_GEN in a comment (wolfcrypt/src/evp.c:7455-7458), and no definition or handler for that control exists in the tree. wolfSSL has no streaming CCM mode that would move the counter as a side effect.

The sequence for two messages:

  1. The application calls EVP_CipherInit(ctx, EVP_aes_128_ccm(), key, iv1, 1). The nonce is written to ctx->cipher.aes.reg (wolfcrypt/src/evp.c:7449-7453).
  2. Message one: wolfSSL_EVP_CipherFinal() (wolfcrypt/src/evp.c:1313) calls wc_AesCcmEncrypt() or wc_AesCcmDecrypt() with ctx->iv as the nonce (wolfcrypt/src/evp.c:1422-1435).
  3. The increment does not run, so aes.reg still holds iv1.
  4. Final zeroes ctx->iv (wolfcrypt/src/evp.c:1462-1466) and calls wolfSSL_StoreExternalIV() (wolfcrypt/src/evp.c:1467-1469).
  5. wolfSSL_StoreExternalIV() copies iv1 from aes.reg back into ctx->iv (src/ssl.c:10854).
  6. Message two repeats step 2 under the same key and iv1.

Reachability and Preconditions

  • Build with OPENSSL_EXTRA and HAVE_AESCCM.
  • An application that pushes two or more messages through one AES-CCM EVP context without setting a fresh IV for each. ByteRay's test separated the messages with EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, NULL), the OpenSSL idiom for starting a new message with the stored key and IV; the init code then takes the IV from ctx->iv (wolfcrypt/src/evp.c:7623-7625).
  • The attacker is a passive observer of the ciphertexts and tags. They need two or more messages under the same key and supply no input to the context.
  • No access to the process is needed.

Impact

Every message after the first on such a context repeats the first message's key and nonce pair. The counter-mode keystream repeats, so the XOR of two ciphertexts is the XOR of their plaintexts and one known plaintext decrypts the others up to its length. An identical plaintext produces an identical ciphertext and tag. ByteRay's assessment is that the repeated key and nonce also undermine tag authenticity for that key; beyond replay, forgery was not demonstrated.

ByteRay reproduced this through the public EVP API on a build with --enable-opensslextra --enable-aesccm. After Final the context IV again held the first message's nonce, a retransmitted plaintext gave a byte-identical ciphertext and tag, two different messages had the same keystream, and a decrypting context accepted the same ciphertext and tag twice.

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 advance the nonce and not merely clear the IV buffer: increment ctx->cipher.aes.reg after each CCM message on the Final path, and let wolfSSL_StoreExternalIV() carry the incremented value into ctx->iv. The alternative is to make the restore skip CCM after an intentional clear and fail a second Final until a fresh nonce is set. EVP_CTRL_CCM_IV_GEN should be implemented, or the comment that refers to it removed, so the code does not describe a control that is absent.

Applications can avoid the issue by passing an explicit, unique IV to the init call for every message on an AES-CCM context.

Timeline

  • 2026-09-27 — Reported to wolfSSL.
  • 2026-12-03 — Public disclosure.

Credits

Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.

References