← ALL ADVISORIES

HIGH BYTERAY-2026-0319Disclosed

wolfSSL — Unpopulated AES-GCM Record Nonce in WOLFSSL_THREADED_CRYPT Async Encryption

With WOLFSSL_THREADED_CRYPT, the per-record AES-GCM nonce field that the worker-thread encrypt call reads is populated from the connection IVs only in old FIPS builds and is otherwise left at zero. The worker's error return is discarded and eight bytes of that field are copied into the record. In ByteRay's tests the peer rejected these records while wolfSSL_write reported success.

Advisory
BYTERAY-2026-0319
CWE
CWE-323
CVSS
8.1 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H)
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-27
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 (tested at master commit d95483f), builds with WOLFSSL_THREADED_CRYPT that send application data over an AES-GCM cipher suite through the worker-thread encrypt flow
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

WOLFSSL_THREADED_CRYPT lets an application move record encryption to worker threads. SendData() stages each outgoing record in a slot, and a worker calls wolfSSL_AsyncEncrypt() to run AES-GCM over it. The slot carries its own nonce field, ThreadCrypt.nonce.

The code that fills that field and the code that reads it sit behind different preprocessor conditions. The copy from the connection's negotiated IVs is compiled only for FIPS or selftest builds older than FIPS version 2. In every other build the field keeps the zero it was given when the WOLFSSL object was cleared. The reader passes the field to the AES-GCM call and then copies bytes 4 to 11 of it into the record as the explicit IV, whatever the encrypt call returned.

The result depends on the build. Where the reader selects wc_AesGcmEncrypt(), the field is the nonce input, and it is twelve zero bytes for every record. With the default macro set on TLS 1.3 the encrypt call fails, the failure is ignored, and eight zero bytes overwrite the start of a record that was already encrypted. WOLFSSL_THREADED_CRYPT has no configure option and is off by default.

Affected Products and Versions

  • Component: the threaded-crypt record path, SendData() in src/internal.c and wolfSSL_AsyncEncrypt() in src/ssl.c.
  • Required build: WOLFSSL_THREADED_CRYPT, defined by hand (CFLAGS or user_settings.h). The source lists it as default off (src/ssl.c:261).
  • Required use: an AES-GCM cipher suite, and the worker flow registered with wolfSSL_AsyncEncryptSetSignal().
  • The fixed zero nonce case additionally needs a non-FIPS build with NO_GCM_ENCRYPT_EXTRA defined. No file in the tree defines that macro.
  • The TLS 1.3 record corruption case occurs with the default macro set (non-FIPS, or FIPS version 2 and later).
  • 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 writer of the nonce field is in SendData() (src/internal.c:29816-29822). There is no #else:

#if !defined(NO_PUBLIC_GCM_SET_IV) && \
    ((defined(HAVE_FIPS) || defined(HAVE_SELFTEST)) && \
    (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2)))
        XMEMCPY(encrypt->nonce, ssl->keys.aead_enc_imp_IV, AESGCM_IMP_IV_SZ);
        XMEMCPY(encrypt->nonce + AESGCM_IMP_IV_SZ, ssl->keys.aead_exp_IV,
            AESGCM_EXP_IV_SZ);
#endif

The reader is wolfSSL_AsyncEncrypt() (src/ssl.c:10459-10479). It selects wc_AesGcmEncrypt_ex or wc_AesGcmEncrypt by a second condition, passes encrypt->nonce to it (src/ssl.c:10470), and then:

        XMEMCPY(out, encrypt->nonce + AESGCM_IMP_IV_SZ, AESGCM_EXP_IV_SZ);
#endif
        encrypt->done = 1;

The copy at src/ssl.c:10477 and the done flag at src/ssl.c:10479 do not depend on the return value of the encrypt call.

The two calls treat the argument differently. wc_AesGcmEncrypt() takes it as the nonce. wc_AesGcmEncrypt_ex() treats it as an output and fills it from the cipher's own counter, and it returns BAD_FUNC_ARG when that counter was never seeded (wolfcrypt/src/aes.c:15152-15157). SetKeys() seeds the counter only when the connection is not TLS 1.3 (src/keys.c:2731-2739).

The path of a record:

  1. The application calls wolfSSL_write(), which enters SendData() (src/internal.c:29423).
  2. For TLS 1.2, BuildMessage() returns without encrypting when threaded crypt is active (src/internal.c:27512-27529). For TLS 1.3, BuildTls13Message() has no such bypass and encrypts the record in full.
  3. SendData() stages the record in a ThreadCrypt slot. The nonce copy is compiled out, so encrypt->nonce (wolfssl/internal.h:5281) stays zero.
  4. SendData() signals the worker and returns the record size to the caller (src/internal.c:29835-29838). wolfSSL_write() reports success at this point.
  5. The worker calls wolfSSL_AsyncEncrypt() (src/ssl.c:10449). It runs the AES-GCM call with encrypt->nonce, copies nonce[4..11] over the first eight bytes of the record body and marks the slot done.
  6. SendAsyncData() sends the record (src/internal.c:29332).

Reachability and Preconditions

  • Build with WOLFSSL_THREADED_CRYPT. This is a manual, non-default setting.
  • The connection negotiates an AES-GCM suite and the application uses the worker flow: wolfSSL_AsyncEncryptSetSignal(), then wolfSSL_AsyncEncrypt() from the worker when signalled. This is the documented way to use the feature.
  • No attacker input is involved. The defect is in what the sender puts on the wire. A passive observer of the connection, or the peer, sees the result.
  • No authentication state matters. Every application-data record sent through the worker flow is affected.

Impact

From the source, the consequence splits by build. In a non-FIPS build with NO_GCM_ENCRYPT_EXTRA, the worker encrypts every record under the session key with a nonce of twelve zero bytes. Two records under one key and nonce share a keystream, so the XOR of two ciphertexts is the XOR of their plaintexts, and a repeated GCM nonce exposes the authentication subkey and allows forged records under that key. In the default macro set, a TLS 1.3 record is sent with its first eight ciphertext bytes replaced by zeros after wolfSSL_write() has already returned success, and the peer cannot authenticate it.

ByteRay tested this over real TLS connections with a worker thread. With the default macro set on TLS 1.3, the worker's encrypt call returned BAD_FUNC_ARG, eight zero bytes were written over the record, and the server failed the record with an AES-GCM authentication error while wolfSSL_write() had returned success; on TLS 1.2 the server rejected every worker-encrypted record with a MAC verification error. The build with NO_GCM_ENCRYPT_EXTRA failed its handshake before any application data was sent, so the fixed zero nonce case was not observed on a live connection.

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 make the writer and the reader of the nonce agree. Either fill encrypt->nonce in every build in which wolfSSL_AsyncEncrypt() runs, or build the nonce inside wolfSSL_AsyncEncrypt() from the negotiated implicit IV and the per-record explicit IV, so the two sides cannot diverge. The per-slot cipher counter should be seeded for TLS 1.3 as well, the explicit IV copy should be skipped for TLS 1.3 records, which carry no explicit IV and are already encrypted, and the slot should not be marked done when the encrypt call returned an error.

The workaround is to build without WOLFSSL_THREADED_CRYPT. Record encryption then runs on the calling thread.

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