Repository navigation
Fix SP and ASN build guards from a user_settings feature sweep - #12214
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the SP math and ASN feature-configuration build fixes.
No open issues 🎉
What changed in this PR
Fixes feature-dependent build failures in wolfCrypt’s single-precision (SP) math and ASN certificate code, improving support for custom user_settings.h configurations across platforms.
Changes:
- Align SP helper guards and preserve 2048-bit dependencies required by 4096-bit assembly implementations.
- Correct ASN extension and API-test guards for disabled features and shared builds.
- Add targeted CI configurations and document the SP dependency behavior.
| File | Description |
|---|---|
wolfssl/wolfcrypt/sp_int.h |
Expose sp_div when SP modular inversion requires it. |
wolfssl/wolfcrypt/settings.h |
Retain 2048-bit code needed by 4096-bit assembly paths. |
wolfcrypt/src/sp_x86_64.c |
Mark conditionally unused modular helpers. |
wolfcrypt/src/sp_riscv64.c |
Mark conditionally unused modular helpers. |
wolfcrypt/src/sp_int.c |
Align radix-copy and modular-inversion helper guards. |
wolfcrypt/src/sp_cortexm.c |
Add a dedicated 4096-bit mask helper and unused annotations. |
wolfcrypt/src/sp_armthumb.c |
Correct conditional-subtraction guards, add a mask helper, and annotate unused helpers. |
wolfcrypt/src/sp_arm64.c |
Mark conditionally unused modular helpers. |
wolfcrypt/src/sp_arm32.c |
Add a dedicated 4096-bit mask helper and unused annotations. |
wolfcrypt/src/asn.c |
Align Netscape and ACME extension guards with their data. |
wolfcrypt/src/asn_orig.c |
Require certificate-extension support for ACME encoding. |
tests/api.c |
Align ACME test guards and restrict the public-only private-key test to static builds. |
doc/ASM_AND_MATH_DEFINES.md |
Document when assembly dependencies override WOLFSSL_SP_NO_2048. |
.github/workflows/multi-compiler.yml |
Add Clang build cases for DH-only and public-only RSA SP assembly. |
.github/configs/os-check-linux.json |
Add regression configurations for SP math and ASN feature combinations. |
.github/configs/multi-arch.json |
Add cross-architecture SP 4096-bit build and runtime cases. |
Review effort: Balanced
|
|
@claude review |
There was a problem hiding this comment.
Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.
Additional findings (outside the current diff — GitHub can't attach inline comments there):
-
🟡
wolfssl/wolfcrypt/sp_int.h— Nit: in prefix-mapped builds (WOLFSSL_API_PREFIX_MAP, kernel mode),sp_divcan now be emitted without itswc_prefix. The prototype guard at sp_int.h:1288-1290 gained|| defined(WOLFSSL_SP_INVMOD). The matching#define sp_div wc_sp_divguard at sp_int.h:1134-1136 did not. Fix: add|| defined(WOLFSSL_SP_INVMOD)to the prefix-map guard so it matches the definition guard (sp_int.c:9283) and the prototype guard.Why this was flagged
The trigger is a build with
WOLFSSL_API_PREFIX_MAPdefined. settings.h:4811 sets it forWOLFSSL_KERNEL_MODEandWOLFSSL_KERNEL_MODE_DEFAULTS. The same build must haveWOLFSSL_SP_INVMODon throughOPENSSL_EXTRAor!NO_DSA(settings.h:3701), with no SP_MATH_ALL, no DH, no ECC, and RSA off or public-only. In that build, sp_int.c now compilessp_divbecause its guard gained|| defined(WOLFSSL_SP_INVMOD), and sp_int.h:1288-1290 declares it under the same condition. The rename#define sp_div wc_sp_divat sp_int.h:1134-1136 still uses the old condition, so theMP_APIsymbol is emitted as plainsp_div. The build still links, but an unprefixed global goes into the shared namespace that the prefix map exists to protect. On the base branchsp_divwas not compiled in this configuration, so no unprefixed symbol was produced.Verification: The diff widens the sp_div definition guard in sp_int.c and the prototype guard at sp_int.h:1288-1290 with
|| defined(WOLFSSL_SP_INVMOD). The guard before#define sp_div wc_sp_divat sp_int.h:1134-1136 is untouched. With WOLFSSL_API_PREFIX_MAP and WOLFSSL_SP_INVMOD on, sp_div is newly compiled as an MP_API symbol namedsp_divinstead ofwc_sp_div. The base did not compile it there.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12214
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .github/configs/multi-arch.json, .github/configs/os-check-linux.json, .github/workflows/multi-compiler.yml, doc/ASM_AND_MATH_DEFINES.md, wolfcrypt/src/sp_arm32.c, wolfcrypt/src/sp_arm64.c, wolfcrypt/src/sp_armthumb.c, wolfcrypt/src/sp_cortexm.c, wolfcrypt/src/sp_x86_64.c
Coverage: 7 of 7 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
42ba574 to
8c71a7e
Compare
|
tests good with multi-test with various This fails to build on master ./configure --enable-sp=4096 --enable-sp-asm && makeIt builds and passes |
philljj
left a comment
There was a problem hiding this comment.
merge conflict, looks & tests good otherwise so far
_sp_copy() is compiled only when RSA, DH, ECC, key generation or compressed keys need it, but sp_todecimal() calls it whenever WC_MP_TO_RADIX is set, which WOLFSSL_PUBLIC_MP turns on. A WOLFSSL_SP_MATH build with WOLFSSL_PUBLIC_MP and no RSA, DH or ECC failed on an implicit declaration of _sp_copy. Add WC_MP_TO_RADIX to its guard. EncodeExtensions() declares nsCertOID for every WOLFSSL_CERT_EXT build, but its only use is under !IGNORE_NETSCAPE_CERT_TYPE, so -Werror builds with IGNORE_NETSCAPE_CERT_TYPE failed on an unused variable. Guard the declaration the same way.
Regenerated from wolfSSL/scripts with the matching generator changes. sp_N_mod_M_cond() is only called by sp_RsaPublic_N() but is emitted wherever that size is built, so SP DH without SP RSA leaves it unused. Clang rejects that even for static inline under -Werror (--disable-rsa --enable-sp --enable-sp-asm), and compilers that do not inline, such as IAR, warn. Mark it WC_MAYBE_UNUSED. A WOLFSSL_HAVE_SP_RSA guard does not work here: the first division emitted also emits helpers that the DH division reuses. The non-small 4096-bit Karatsuba multiply reuses the 2048-bit add and multiply, and also called sp_2048_mask_64(), which only the 2048-bit private key and DH division emits. RSA public-only builds with WOLFSSL_SP_4096 on Cortex-M, Thumb and ARM32 failed on an implicit declaration. Emit sp_4096_mask_64() with the 4096-bit multiply instead. The Thumb Montgomery reduction is all assembly and never calls sp_N_cond_sub(), but the generator emitted it as a dependency, leaving it unused in Thumb RSA public-only builds without DH. Its real callers are all under (RSA && !RSA_PUBLIC_ONLY) || DH, so emit it under that guard. Add a build-only clang-19 multi-compiler leg for SP asm with DH and no RSA, and multi-arch legs that build RSA public-only with SP 4096 on the Cortex-M, ARM32 and Thumb SP assembly and run testwolfcrypt.
The SP assembly implementations build parts of their 4096-bit code on the 2048-bit functions. On x86_64 the assembly 4096-bit multiply and square always call the 2048-bit ones. Elsewhere the RSA private key CRT calls the 2048-bit reduction and exponentiation, and the non-small Karatsuba multiply and square call the 2048-bit add, multiply and square. All of those are compiled only without WOLFSSL_SP_NO_2048, so WOLFSSL_SP_4096 with WOLFSSL_SP_NO_2048 failed on undeclared functions or undefined symbols in those builds. That is what ./configure --enable-sp=4096 --enable-sp-asm sets. Undefine WOLFSSL_SP_NO_2048 in settings.h for exactly those cases: every x86_64 SP assembly build, and on Aarch64, ARM32, Thumb, Cortex-M and RISC-V 64 RSA private keys using the CRT or a non-small build. RSA_LOW_MEM forces the small build and, like SP_RSA_PRIVATE_EXP_D, skips the CRT. Builds that already worked there, such as small RSA public-only or DH-only builds, keep WOLFSSL_SP_NO_2048 and do not grow. The C implementations do not share code between sizes and are unaffected. Note the exception in doc/ASM_AND_MATH_DEFINES.md. Add multi-arch legs that build --enable-sp=4096 --enable-sp-asm for Aarch64, ARM32 and RISC-V 64 and run testwolfcrypt, and a build-only clang-19 multi-compiler leg for x86_64 with RSA public-only.
sp_invmod() is built whenever WOLFSSL_SP_INVMOD is set, which settings.h does for OPENSSL_EXTRA and DSA as well as ECC and RSA private keys. The functions it and sp_div() call, _sp_cmp_abs(), _sp_set(), _sp_sub_off(), sp_lshb(), sp_div(), sp_mod(), sp_mul(), sp_sub() and sp_rshb(), were built only for MATH_ALL, DH, ECC or RSA, so a WOLFSSL_SP_MATH build with OPENSSL_EXTRA and without DH or ECC (no RSA, or RSA public-only or verify-only) failed on implicit declarations or undefined symbols. Add WOLFSSL_SP_INVMOD to their guards and to the sp_div() prototype and prefix-map rename. _sp_cmp() had OPENSSL_EXTRA in its guard although none of its callers are built for it, which left it unused in the same builds, so drop that term. The ACME identifier extension data in struct Cert and DerCert is under WOLFSSL_CERT_EXT, but the code in EncodeExtensions(), the original ASN encoder and its API test was guarded by WOLFSSL_ACME_OID alone, so WOLFSSL_CERT_GEN with WOLFSSL_ACME_OID and without WOLFSSL_CERT_EXT did not compile. Guard them with both. test_wc_CheckPrivateKey_RSA_pub_only calls wc_CheckPrivateKey(), which is WOLFSSL_LOCAL, so a shared --enable-rsapub build did not link the unit test. Build it only with WOLFSSL_TEST_STATIC_BUILD, like the other tests of local functions. Add os-check legs for these builds, the ACME one also through the original ASN encoder, and for the WOLFSSL_PUBLIC_MP and IGNORE_NETSCAPE_CERT_TYPE builds fixed earlier on this branch.
8c71a7e to
14b6fe2
Compare
|
@philljj done |
Description
Fixes guard mismatches found in a customer
user_settings.hsweep over RSA/ECC/DH/SHA/ML-DSA, plus related SP and ASN build breaks found while testing them. The SP files are regenerated from wolfSSL/scripts#723.sp_int.c: build_sp_copy()whenWC_MP_TO_RADIXuses it, and the invmod helpers wheneverWOLFSSL_SP_INVMODis set.asn.c,asn_orig.c: guardnsCertOIDand the ACME identifier encoder like their data.sp_N_mod_M_cond()WC_MAYBE_UNUSED; it is unused with SP DH and no SP RSA.WOLFSSL_SP_4096called an undeclaredsp_2048_mask_64().sp_N_cond_sub()only with its callers.settings.h: keep the 2048-bit SP code where the asm 4096-bit code calls it, so--enable-sp=4096 --enable-sp-asmbuilds.tests/api.c: build thewc_CheckPrivateKeypublic-only test only in static builds, so shared--enable-rsapublinks.Fixes zd#22831
Testing
--enable-sp=4096with RSA public-only.--enable-sp=4096legs for Aarch64, ARM32 and RISC-V 64, all running testwolfcrypt.OPENSSL_EXTRAorWOLFSSL_PUBLIC_MPand no DH/ECC, ACME withoutCERT_EXT(template and original ASN), andIGNORE_NETSCAPE_CERT_TYPE.