← ALL ADVISORIES

MEDIUM BYTERAY-2026-0409Disclosed

wolfSSL — Key-Dependent T-Table Lookups in Software AES

The default software AES in wolfCrypt indexes its T-tables with state bytes that are the round key XORed with the data. The two compile-time countermeasures are off by default, so on builds without AES hardware acceleration an attacker with power or electromagnetic measurement access can attempt to recover the key.

Advisory
BYTERAY-2026-0409
CWE
CWE-1300
CVSS
4.2 (CVSS:3.1/AV:P/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 using the C table-based AES without WOLFSSL_AES_TOUCH_LINES or WC_AES_BITSLICED and without AES hardware acceleration
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

The default software AES in wolfCrypt is a table-lookup implementation. Each round selects entries from four 256-entry tables using bytes of the cipher state, and the state is the secret key XORed with the data being processed. The memory locations touched therefore depend on the key.

The library has two compile-time countermeasures: WOLFSSL_AES_TOUCH_LINES, which equalizes cache-line access, and WC_AES_BITSLICED. Both are documented as off by default, and no shipped configuration enables either. On a build without AES hardware acceleration, every TLS record is processed through these lookups.

An attacker with physical or near-field access can record power or electromagnetic traces while a TLS peer supplies chosen plaintext or ciphertext, and attempt to recover the session key by differential power analysis. This is the default software AES path. The attack needs sustained physical measurement and many traces.

Affected Products and Versions

  • Component: wolfcrypt/src/aes.c, the ENC_ROUND_T_S and ENC_ROUND_S_T round macros used by the C implementation behind wc_AesEncrypt(), and the matching decryption rounds.
  • Required build: software AES with neither WOLFSSL_AES_TOUCH_LINES nor WC_AES_BITSLICED, on a target with no AES hardware acceleration, or in a software fallback case.
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • Both countermeasures are off by default (wolfcrypt/src/aes.c:92-94). The only automatic enable is for RISC-V (wolfcrypt/src/aes.c:2385-2386), inside #ifndef WC_NO_CACHE_RESISTANT (wolfcrypt/src/aes.c:2383).
  • Other releases were not checked.

Technical Details

Without WOLFSSL_AES_TOUCH_LINES, GetTable(t, o) is the plain index t[o] (wolfcrypt/src/aes.c:2637). The round macros (wolfcrypt/src/aes.c:2717-2743) pass state bytes straight to it:

    t0 = GetTable(Te[0], GETBYTE(s0, 3)) ^ GetTable(Te[1], GETBYTE(s1, 2)) ^   \
         GetTable(Te[2], GETBYTE(s2, 1)) ^ GetTable(Te[3], GETBYTE(s3, 0)) ^   \
         rk[(o)+4];                                                            \

The tables are Te[4][256] (wolfcrypt/src/aes.c:1712). Decryption has the same structure with Td and Td4 (wolfcrypt/src/aes.c:2256, wolfcrypt/src/aes.c:3861-3937). The initial AddRoundKey XORs the round key into the state (wolfcrypt/src/aes.c:2700-2703), so the first-round indices are the key XORed with the plaintext.

  1. A TLS peer sends records. The record layer calls AES-CBC (src/internal.c:22573, src/internal.c:23068) or AES-GCM (src/internal.c:22405, src/internal.c:23094-23096).
  2. Those reach the software block function with the session key schedule.
  3. AddRoundKey mixes the round key into the state, and the round macros index Te with the state bytes.
  4. The table lines read are a function of key and data, and show in power, electromagnetic and cache measurements.

Where WC_NO_CACHE_RESISTANT is defined, as in the ESP32 platform defaults, the PreFetchTe cache-touch helper is also compiled out (wolfcrypt/src/aes.c:2707-2715).

Reachability and Preconditions

  • Software AES is in use: a small microcontroller, a Zephyr or Arduino class target without an AES accelerator, or a fallback case such as an unsupported key size or a busy hardware engine.
  • The device processes TLS records under the target key. A remote peer chooses plaintext in one direction and ciphertext in the other.
  • The attacker has physical or near-field access to measure power or electromagnetic emissions, synchronized to record processing.
  • Many traces are needed, from hundreds to millions depending on signal quality.

Impact

Recovery of the AES key in use, for TLS the session key, which allows decryption of the captured session. Where a key is static or derivable, the exposure is wider. The attacker's traffic drives the computation; the leaked secret is the key. Exploitation needs laboratory equipment and physical access.

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 make a side-channel-resistant AES variant the default on platform configurations without AES hardware acceleration, instead of an opt-in. For high-assurance devices a masked implementation, validated by leakage assessment, goes further.

Workaround: define WOLFSSL_AES_TOUCH_LINES or WC_AES_BITSLICED in the build, do not define WC_NO_CACHE_RESISTANT on targets that rely on software AES, and use hardware AES where the chip provides it. The software countermeasures cost performance.

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