Skip to content

Fix SP and ASN build guards from a user_settings feature sweep - #12214

Merged
philljj merged 4 commits into
wolfSSL:masterfrom
Frauschi:zd22831-build-guards
Nov 21, 2026
Merged

philljj merged 4 commits into
wolfSSL:masterfrom
Frauschi:zd22831-build-guards

Conversation

@Frauschi

Copy link
Copy Markdown
Member

Description

Fixes guard mismatches found in a customer user_settings.h sweep 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() when WC_MP_TO_RADIX uses it, and the invmod helpers whenever WOLFSSL_SP_INVMOD is set.
  • asn.c, asn_orig.c: guard nsCertOID and the ACME identifier encoder like their data.
  • SP asm: mark sp_N_mod_M_cond() WC_MAYBE_UNUSED; it is unused with SP DH and no SP RSA.
  • SP Cortex-M/Thumb/ARM32: give the 4096-bit Karatsuba its own mask; RSA public-only with WOLFSSL_SP_4096 called an undeclared sp_2048_mask_64().
  • SP Thumb: emit 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-asm builds.
  • tests/api.c: build the wc_CheckPrivateKey public-only test only in static builds, so shared --enable-rsapub links.

Fixes zd#22831

Testing

  • multi-compiler: build-only clang-19 legs for SP asm DH without RSA and for x86_64 --enable-sp=4096 with RSA public-only.
  • multi-arch: RSA public-only SP 4096 legs for Cortex-M, ARM32 and Thumb, and --enable-sp=4096 legs for Aarch64, ARM32 and RISC-V 64, all running testwolfcrypt.
  • os-check: SP_MATH builds with OPENSSL_EXTRA or WOLFSSL_PUBLIC_MP and no DH/ECC, ACME without CERT_EXT (template and original ASN), and IGNORE_NETSCAPE_CERT_TYPE.

@Frauschi Frauschi self-assigned this Nov 20, 2026
Copilot AI balanced review requested due to automatic review settings November 20, 2026 16:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata +108 B, text +13,512 B (+4.8%, 296,092 B / 67,108,864 B, total: 0% used)
  • RAM: bss +49 B, datas +16 B (+0.1%, 58,423 B / 983,040 B, total: 6% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@Frauschi

Copy link
Copy Markdown
Member Author

@claude review

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_div can now be emitted without its wc_ prefix. The prototype guard at sp_int.h:1288-1290 gained || defined(WOLFSSL_SP_INVMOD). The matching #define sp_div wc_sp_div guard 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_MAP defined. settings.h:4811 sets it for WOLFSSL_KERNEL_MODE and WOLFSSL_KERNEL_MODE_DEFAULTS. The same build must have WOLFSSL_SP_INVMOD on through OPENSSL_EXTRA or !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 compiles sp_div because 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_div at sp_int.h:1134-1136 still uses the old condition, so the MP_API symbol is emitted as plain sp_div. The build still links, but an unprefixed global goes into the shared namespace that the prefix map exists to protect. On the base branch sp_div was 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_div at 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 named sp_div instead of wc_sp_div. The base did not compile it there.

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@Frauschi
Frauschi force-pushed the zd22831-build-guards branch from 42ba574 to 8c71a7e Compare November 20, 2026 17:02
@Frauschi Frauschi assigned wolfSSL-Bot and unassigned Frauschi Nov 20, 2026
@philljj philljj self-assigned this Nov 21, 2026
@philljj

philljj commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

tests good with multi-test with various wolfssl-all-*-sp-asm, asn-original, asn-template sanitizer scenarios, etc.

This fails to build on master

./configure --enable-sp=4096 --enable-sp-asm && make

It builds and passes make check on this PR branch.

@philljj philljj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge conflict, looks & tests good otherwise so far

@philljj philljj assigned Frauschi and unassigned wolfSSL-Bot Nov 21, 2026
_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.
@Frauschi
Frauschi force-pushed the zd22831-build-guards branch from 8c71a7e to 14b6fe2 Compare November 21, 2026 20:04
@Frauschi Frauschi removed their assignment Nov 21, 2026
@Frauschi
Frauschi requested a review from philljj November 21, 2026 21:34
@Frauschi

Copy link
Copy Markdown
Member Author

@philljj done

@philljj
philljj merged commit 206e9a5 into wolfSSL:master Nov 21, 2026
455 of 457 checks passed
@Frauschi
Frauschi deleted the zd22831-build-guards branch November 21, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants