← ALL ADVISORIES

LOW BYTERAY-2026-0526Disclosed

wolfSSL — Incomplete Bignum Zeroization in sp_clear on Non-FIPS Builds

In non-FIPS builds, sp_clear zeroes only the digits a big integer currently uses, with plain stores and no compiler barrier. Digits above the used count can keep residue of earlier values, and an optimizer may drop the stores. The library's own private-key teardowns use a separate full-buffer wipe.

Advisory
BYTERAY-2026-0526
CWE
CWE-733
CVSS
2.5 (CVSS:3.1/AV:L/AC:H/PR:L/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), non-FIPS builds using the SP math big-integer backend (the default math library)
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

sp_clear() is the SP math routine behind mp_clear(). It runs whenever the library releases a big integer. In FIPS builds it wipes the whole digit array with ForceZero(). In non-FIPS builds, which are the default, it zeroes only the digits currently in use, with ordinary stores.

Two gaps follow. Digits between the used count and the allocated size are not touched, so they can keep residue of a larger value the same integer held earlier. And because the memory is not read again, a compiler is permitted to remove the zeroing stores.

The library's own private-key and shared-secret teardowns do not use this path. They call mp_forcezero(), which wipes the full buffer. No call site in a standard build was identified that destroys a secret-bearing integer with mp_clear(). The exposure is to application code, or to library paths not yet identified, and it needs a separate memory-disclosure bug to have any effect.

Affected Products and Versions

  • Component: wolfcrypt/src/sp_int.c, sp_clear(), reached through the mp_clear macro (wolfssl/wolfcrypt/sp_int.h:1384).
  • Required build: the SP math big-integer backend without HAVE_FIPS.
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • Default builds contain this code. SP math is the default math library (configure.ac:474-477) and FIPS is off by default.
  • Other releases were not checked.

Technical Details

sp_clear() is compiled in two forms (wolfcrypt/src/sp_int.c:5386-5404). With HAVE_FIPS it calls sp_forcezero(). Without it, the body is:

        /* Only clear the digits being used. */
        for (i = 0; i < a->used; i++) {
            a->dp[i] = 0;
        }

sp_forcezero() clears a->size digits with ForceZero() (wolfcrypt/src/sp_int.c:5419). The comment above that call gives the reason for using the full size: "data not zeroed when used decreases". The non-FIPS form of sp_clear() stops at a->used and uses plain assignments with no barrier.

  1. A value is loaded into an sp_int and occupies n digits.
  2. Later arithmetic or a copy leaves a shorter value in the same integer. a->used drops below n, and the upper digits keep their old content.
  3. The integer is released with mp_clear(). The loop clears a->used digits only (wolfcrypt/src/sp_int.c:5396-5398).
  4. The digits from a->used up to n remain in the released buffer. If the optimizer removes the loop as a dead store, the lower digits remain as well.

Secret-bearing teardowns in the library call mp_forcezero() instead: RSA private components in wolfcrypt/src/rsa.c, ECC private scalars and ECDH temporaries in wolfcrypt/src/ecc.c, and DH private keys and shared secrets in wolfcrypt/src/dh.c (for example wolfcrypt/src/dh.c:1043). ML-KEM, Dilithium and Ed25519 keys are byte arrays and are wiped with ForceZero() directly.

Reachability and Preconditions

  • Build: SP math, non-FIPS. This is the default configuration.
  • A code path must release an sp_int that holds, or earlier held, secret digits with mp_clear() and not mp_forcezero(). None was identified inside the library. Application code that uses the mp_ API directly can do this.
  • The attacker needs an independent way to read the released memory, such as a heap over-read or access to a core dump.
  • No network input reaches this condition on its own.

Impact

Residual big-integer digits can stay in memory after mp_clear(). If those digits belong to a secret value, and a separate bug or artifact exposes that memory, part of the value can be recovered. In the library as shipped, the secret values that were checked are wiped through the full-buffer path, so this is a gap in the default teardown and not a direct key leak.

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 HAVE_FIPS split so that sp_clear() always calls sp_forcezero(), or otherwise wipes all a->size digits with ForceZero(). Library callers that release secret-bearing integers with mp_clear() should move to mp_forcezero(). Until then, applications that keep secrets in mp_int values should release them with mp_forcezero().

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