← ALL ADVISORIES

MEDIUM BYTERAY-2026-0407Disclosed

wolfSSL — Secret-Indexed Operands in TFM Non-Blocking RSA Exponentiation

The non-blocking TFM exponentiation fp_exptmod_nb selects the operands of its multiply and reduce steps by the current bit of the RSA private exponent in every build, and of its square steps when WC_NO_CACHE_RESISTANT is defined. The code is compiled only with WC_RSA_NONBLOCK.

Advisory
BYTERAY-2026-0407
CWE
CWE-1300
CVSS
5.7 (CVSS:3.1/AV:P/AC:H/PR:N/UI:N/S:U/C:H/I:H/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 with WC_RSA_NONBLOCK (--enable-rsa=nonblock)
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

The TFM fast-math backend has a non-blocking form of modular exponentiation, fp_exptmod_nb(), used for RSA private-key operations when the build defines WC_RSA_NONBLOCK. It is a state machine that walks the private exponent one bit at a time.

At each step it chooses which temporary to multiply, square or reduce from the value of the current secret bit. For the square and its reduction, a constant-address variant exists and is compiled out when WC_NO_CACHE_RESISTANT is defined, as the ESP-IDF and Arduino ESP32 platform defaults do. For the multiply and its reduction, no hardened variant exists in any build.

An attacker with physical or near-field access to a device can record traces during RSA private operations, which a TLS peer can trigger, and attempt to reconstruct the long-term RSA private key. WC_RSA_NONBLOCK is off by default and no shipped IDE or Zephyr template enables it, so exposure is limited to firmware built with that option.

Affected Products and Versions

  • Component: wolfcrypt/src/tfm.c, fp_exptmod_nb(), under the WC_RSA_NONBLOCK gate (wolfcrypt/src/tfm.c:1699).
  • Required build: TFM (USE_FAST_MATH) with WC_RSA_NONBLOCK, set by --enable-rsa=nonblock (configure.ac:6540). The option is documented as off by default (wolfcrypt/src/rsa.c:93-94).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • A default build does not compile this function. With WC_NO_CACHE_RESISTANT (wolfssl/wolfcrypt/settings.h:727, wolfssl/wolfcrypt/settings.h:1068) all four ladder states are secret-indexed; without it, two are.
  • Other releases were not checked.

Technical Details

Each iteration stores the current exponent bit in nb->y (wolfcrypt/src/tfm.c:1873) and then uses it as an array index in four states:

  • Multiply: fp_mul(&nb->R[0], &nb->R[1], &nb->R[nb->y^1]) (wolfcrypt/src/tfm.c:1879). There is no alternative form.
  • Multiply reduction: fp_montgomery_reduce(&nb->R[nb->y^1], P, nb->mp) (wolfcrypt/src/tfm.c:1884). There is no alternative form.
  • Square: fp_sqr(&nb->R[nb->y], &nb->R[nb->y]) under WC_NO_CACHE_RESISTANT (wolfcrypt/src/tfm.c:1893-1894).
  • Square reduction: fp_montgomery_reduce(&nb->R[nb->y], P, nb->mp) under WC_NO_CACHE_RESISTANT (wolfcrypt/src/tfm.c:1914-1915).

For the square and its reduction the file has two replacements: a conditional-copy variant (wolfcrypt/src/tfm.c:1895-1898, wolfcrypt/src/tfm.c:1916-1919) and a masked-address variant using wc_off_on_addr (wolfcrypt/src/tfm.c:1899-1904, wolfcrypt/src/tfm.c:1920-1925). Both are excluded when WC_NO_CACHE_RESISTANT is defined.

  1. A TLS peer sends an RSA key-exchange ciphertext.
  2. The RSA private operation passes key->d to fp_exptmod_nb() (wolfcrypt/src/rsa.c:2478).
  3. Each iteration reads one exponent bit into nb->y and indexes nb->R[] with it.
  4. Each bit produces a different operand address, visible in cache, power and electromagnetic measurements.

RSA blinding randomizes the base and not the exponent bits, so it does not hide the index. On ESP32 the hardware accelerator falls back to the software path when the engine is busy, forced into fallback or in validation mode.

Reachability and Preconditions

  • Build with TFM and WC_RSA_NONBLOCK. This is an operator choice; no shipped template sets it.
  • The device performs RSA private operations with the non-blocking API, for example in a TLS RSA key exchange that a remote peer starts without authentication.
  • The attacker has physical or near-field access: a power or electromagnetic probe, or a shared power or cache domain.
  • Thousands of traces are collected.

Impact

Recovery of the long-term RSA private exponent. With it the attacker can decrypt captured sessions that used RSA key exchange and impersonate the device. The required build flag and the need for physical access keep this outside the default attack surface.

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 has two parts. Removing WC_NO_CACHE_RESISTANT from the ESP32 and Arduino platform defaults brings the hardened square and square-reduction states back. That is not enough here: the multiply and multiply-reduction states need the same masked-address or conditional-copy treatment, so that no state takes an operand address from nb->y.

Workaround: do not combine WC_RSA_NONBLOCK with the TFM backend on physically exposed devices.

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