Repository navigation
Conversation
1 of 4 tasks
|
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12053
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs
Coverage: 4 of 4 in-scope changed file(s) opened by the reviewer
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Max
Without -fwrapv, signed overflow in ML-DSA reduction, SP bit lookups, ECC packing, and C32 RSA/DH Toom-3 and Karatsuba interpolation is reported by UBSan. Keep required low-word products and subtractions unsigned until carries can be normalized without overflow. Document bounds for multiplication and squaring, including Karatsuba sums. Numerical results retain the previous two's-complement behavior. Exercise software P-256 sign/verify and seeded ML-DSA key generation in wolfCrypt tests. Add near-maximum 2048-, 3072- and 4096-bit modular exponentiation known-answer tests through wc_RsaFunction(). Exclude validated FIPS/selftest RSA implementations and encode test errors consistently. Skip the final-standard public-key digest in FIPS 204 draft mode. Add a ChangeLog entry. Test with Clang UBSan and -fno-wrapv on both C SP backends, including small/nonblocking, SAKKE, ML-DSA feature variants, FIPS 204 draft, SIGN_CHECK_Y, SIGN_CHECK_W0 and native 32-bit builds. testwolfcrypt passes all thirteen runnable configurations; configuration 1 make check retains only the unrelated PemToDer null-pointer finding.
Skip the fixed 32-byte hash regression when the configured signing or verification digest range excludes that size. Check the limits before allocating or initializing a key.
…ach square column
dgarske
force-pushed
the
sp_ubsan_fixes
branch
from
November 6, 2026 23:32
3441090 to
ea7f744
Compare
-fwrapv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Supersedes #11808 (incorporating work by @armpribb).
Fixes undefined behavior (UBSan) in
sp_c32.c,sp_c64.c, andsp_int.cwhen compiling without-fwrapv(e.g., in CMake, IDE, and vendor builds; Autotools masked this by defaulting to-fwrapvvia hardening flags). The new regression test then found a wrong result in the ARM32 and Cortex-M SP assembly, fixed here as well.Issues Addressed
num_bits) helpers.sp_to_unsigned_bin_at_pos()before validatingout.sp_3072_sqr_12,sp_384_sqr_12,sp_521_sqr_17andsp_1024_sqr_16, the first product of a column is added twice into a three-word accumulator, and themovthat clears the stale top word was emitted in both steps, so the second step discarded the carry of the first. Needs a run of limbs at2^32 - 1in the four lowest or four highest columns;sp_RsaPublic_3072()withm = 2^3072 - 189hit it. The 8-limb squares use UMAAL/UMLAL and were correct.Commits
wolfcrypt: avoid signed overflow in ML-DSA and C SP arithmetic(@armpribb)Adds core fixes and regression tests (RSA modexp near-max moduli, P-256 sign/verify, and ML-DSA-65 public-key digest).
test: respect digest limits in P-256 SP regression(@armpribb)Skips P-256 tests in digest-restricted configurations.
SP C: regenerate with unsigned limb packing, subtraction and bit countingSystematic fix applied directly to the generator (wolfSSL/scripts#710) and regenerated
sp_c32.c/sp_c64.c. Uses unsigned arithmetic across all limb subtractions, normalizers, and bit-counting helpers.Check the output buffer before offsetting it in sp_to_unsigned_bin_at_posValidates
aandoutbefore pointer arithmetic, returningMP_VALon NULL.SP ARM32 and Thumb2: keep the carry of the first doubled product in each square columnGenerator fix in the same wolfSSL/scripts#710 and regenerated
sp_arm32.c/sp_cortexm.c; the only change is the removed secondmovin the four squares above.Testing
Tested with Clang 18 using
-fsanitize=undefined -fno-sanitize-recover=all -fno-wrapv:--disable-sp --enable-sp-math-all).testwolfcryptpasses cleanly. (Master previously aborted insp_256_mod_mul_norm_5,sp_2048_sub_24, andsp_int.c.)--enable-all --disable-asm),make check(C SP backend), andcheck-source-textall pass.--enable-sp-asmbuilds under qemu-arm, ARM32 with thearmel-o0CI flags (-marm -DWOLFSSL_SP_ARM_ARCH=6 -O0) and Cortex-M with-mthumb, both with SP P-384/P-521/SAKKE. Before the last commit the four squares disagree with the multiplies for all-0xffffffffand all-0xfffffffeoperands andrsa_sp_modexp_test()fails at 3072 bits; after it they agree andtestwolfcryptpasses. x86_64 and AArch64 assembly pass the new test unchanged.