← ALL ADVISORIES

LOW BYTERAY-2026-0542Disclosed

wolfSSL — Secret-Indexed Operands in TFM Exponentiation Ladder Under ESP32 Platform Defaults

The ESP-IDF and Arduino ESP32 platform defaults define WC_NO_CACHE_RESISTANT. With it, the TFM exponentiation ladder _fp_exptmod_ct selects the operands of its multiply and square by the current secret exponent bit, and the variant that keeps operand addresses constant is compiled out.

Advisory
BYTERAY-2026-0542
CWE
CWE-1300
CVSS
2.0 (CVSS:3.1/AV:P/AC:H/PR:N/UI:N/S:U/C:L/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), TFM fast-math builds (USE_FAST_MATH) with WC_NO_CACHE_RESISTANT defined, as set by the ESP-IDF and Arduino ESP32 platform defaults
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

On ESP32 builds that use wolfSSL's ESP-IDF or Arduino platform defaults, private-key modular exponentiation runs in the TFM fast-math backend. Those defaults enable the timing-resistant ladder and also define WC_NO_CACHE_RESISTANT, which turns off the library's cache-resistant code.

With that macro defined, the ladder _fp_exptmod_ct() picks the memory operand of each multiply and square from the current bit of the secret exponent. The variant that copies through constant addresses is in the same function and is compiled out.

A TLS peer can start these computations by opening DHE handshakes. An attacker who also has physical access to the device can measure per-bit differences in power, electromagnetic or cache behaviour and attempt to reconstruct the ephemeral DH private exponent of a handshake. RSA private keys are in scope only where WC_RSA_BLINDING has been turned off. These are the default settings for the ESP-IDF and Arduino ESP32 platforms.

Affected Products and Versions

  • Component: wolfcrypt/src/tfm.c, _fp_exptmod_ct().
  • Required build: the TFM backend (USE_FAST_MATH) with WC_NO_CACHE_RESISTANT. The Arduino ESP32 defaults (wolfssl/wolfcrypt/settings.h:724-727) and the ESP-IDF defaults (wolfssl/wolfcrypt/settings.h:1060-1068) define the macro together with TFM_TIMING_RESISTANT. The ESP-IDF template selects TFM (IDE/Espressif/ESP-IDF/user_settings.h:165-166).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • Builds that do not define WC_NO_CACHE_RESISTANT compile the constant-address variant of this ladder.
  • Other releases were not checked.

Technical Details

Each iteration of _fp_exptmod_ct() takes the next exponent bit, y = (int)(buf >> (DIGIT_BIT - 1)) & 1 (wolfcrypt/src/tfm.c:2047). Under WC_NO_CACHE_RESISTANT it then runs:

    err = fp_mul(&R[0], &R[1], &R[y^1]);
    ...
    err = fp_sqr(&R[y], &R[y]);

at wolfcrypt/src/tfm.c:2052 and wolfcrypt/src/tfm.c:2063. The operand address is a function of the secret bit. The #else branch (wolfcrypt/src/tfm.c:2073-2126) uses a third temporary and masked addresses instead. Its own comment says that using R[y^1] for the multiply "leaks key bit to cache monitor" (wolfcrypt/src/tfm.c:2085-2087).

  1. wc_DhAgree_Sync loads the private exponent (wolfcrypt/src/dh.c:2300) and calls mp_exptmod_ex with the peer's public value as the base (wolfcrypt/src/dh.c:2323).
  2. fp_exptmod_ex() calls _fp_exptmod_ct() (wolfcrypt/src/tfm.c:3090).
  3. The ladder extracts each exponent bit (wolfcrypt/src/tfm.c:2047) and selects R[y^1] and R[y] with it (wolfcrypt/src/tfm.c:2050-2072).
  4. Each bit produces a different memory access pattern, visible in cache, power and electromagnetic measurements.

The ESP32 hardware accelerator does not remove the path. The wrappers fall back to the software ladder on WC_HW_WAIT_E, MP_HW_FALLBACK and MP_HW_VALIDATION_ACTIVE (wolfcrypt/src/tfm.c:2929-2959, wolfcrypt/src/tfm.c:3028-3051). RSA private operations use the same ladder with d, dP and dQ (wolfcrypt/src/rsa.c:3068, wolfcrypt/src/rsa.c:3108, wolfcrypt/src/rsa.c:3112); blinding randomizes the base only (wolfcrypt/src/rsa.c:3046-3060).

DH key generation with generator 2 takes a different routine, _fp_exptmod_base_2(), which has no hardened variant at all. That is BYTERAY-2026-0541. Removing WC_NO_CACHE_RESISTANT does not cover it.

Reachability and Preconditions

  • Build with TFM and WC_NO_CACHE_RESISTANT, which is what the ESP-IDF and Arduino ESP32 defaults produce.
  • The device negotiates DHE, or performs RSA private operations with WC_RSA_BLINDING disabled. A remote peer can start handshakes without authentication and supplies the base.
  • The attacker has physical or near-field access: a power or electromagnetic probe, or a shared power or cache domain.
  • The exponentiation runs in software, either by configuration or through the hardware fallback cases.

Impact

Recovery of the ephemeral DH private exponent of a handshake, and with it that session's key material. The exponent is fresh per handshake, so the loss is per session. RSA private key recovery applies only where blinding is disabled. Extraction needs physical access, capable equipment and single-trace or horizontal analysis.

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 remove the default WC_NO_CACHE_RESISTANT definition from the Arduino ESP32 and ESP-IDF platform blocks and from shipped templates, so that the constant-address ladder is compiled for private-key exponentiation. The base-2 path needs its own change. Where a configuration requires the hardware accelerator, failing closed is safer than a silent software fallback. Workaround: undefine WC_NO_CACHE_RESISTANT in the application's settings, keep WC_RSA_BLINDING on, and prefer the hardware accelerator for private-key operations. Undefining the macro costs some 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