Skip to content

zephyr: build the FIPS v5 boundary - #11879

Merged
philljj merged 3 commits into
wolfSSL:masterfrom
jackctj117:zephyr-fips-v5-build
Nov 6, 2026
Merged

philljj merged 3 commits into
wolfSSL:masterfrom
jackctj117:zephyr-fips-v5-build

Conversation

@jackctj117

@jackctj117 jackctj117 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

Master's Zephyr module builds the v7 and FIPS Ready boundaries but not a v5 one. Dropping in a v5 bundle fails in three ways. This PR fixes all three without touching any source inside the boundary, and adds v5.2.3 as a Kconfig choice.

zephyr: build the FIPS v5 boundary

  • wc_PRF_fips, wc_PRF_TLSv12_fips, wc_Tls13_HKDF_Extract_fips and wc_SSH_KDF_fips are defined twice at link. The v5 kdf.c predates libwolfssl_sources.h, so nothing defines BUILDING_WOLFSSL. types.h then includes wc_compat.h, which reaches fips.h before kdf.c sets FIPS_NO_WRAPPERS. The module now defines BUILDING_WOLFSSL for the library sources only, as the top-level CMakeLists.txt already does.
  • random.c cannot find <random/rand32.h>. Under CONFIG_WOLFCRYPT_FIPS_V5, zephyr/fips-v5-compat/ is added to the library's include path. Its random/rand32.h and posix/time.h shims map onto the current headers; the module needs Zephyr 3.7 or later anyway, because CONFIG_WOLFCRYPT_FIPS selects STATIC_INIT_GNU.
  • The v5 branch of the settings sets only version numbers. It now also defines:
    • NO_THREAD_LS, because THREAD_LS_T is empty on Zephyr and HAVE_THREAD_LS would only drop the ECC/SP cache locks;
    • WOLFSSL_ECDSA_SET_K, which the ECDSA CAST needs;
    • WC_RNG_SEED_CB, with wolfssl_zephyr_seed as WC_GENERATE_SEED_DEFAULT, because both v5 bundles' wc_GenerateSeed() is a bare sys_rand_get(). The callback, in zephyr/zephyr_init.c, seeds from the Zephyr CSPRNG, which reads the zephyr,entropy device; a board with no entropy driver fails the build unless CONFIG_TEST_RANDOM_GENERATOR is set, and CMake stops a build whose CSPRNG is not the hardware-driver one, since Zephyr 4.4 routes both the CTR-DRBG and the PSA generators through PSA Crypto, so the seed never passes through a DRBG outside the module. wolfSSL_Init() registers it, and an APPLICATION-level SYS_INIT hook, which runs after the POST constructor, registers it for wolfCrypt-only builds and logs a failure.
  • The integrity-layout guards now apply to every FIPS boundary rather than only the v7 one, because v5 hashes the same two ranges. These guards are the CONFIG_LINKER_SORT_BY_ALIGNMENT check, the no-section-splitting flags and the dedicated rodata section. The Kconfig help and the README say to set CONFIG_LINKER_SORT_BY_ALIGNMENT=n, which Zephyr defaults on.
  • Symmetric assembly stays off under FIPS v2, v5 and v6 (WOLFCRYPT_FIPS_PRE_V7_ASM). Their aes.c/sha256.c expect the boundary's own armv8-*.c assembly, which this module does not build, and on x86_64 their sha256.c would call the tree's sha256_asm.S from outside the boundary. CONFIG_WOLFCRYPT_ASM still accelerates the SP math.
  • The ML-KEM, ML-DSA, XMSS and Falcon options are unavailable under v2 and v5, whose boundaries have no SHAKE, as Ed448 already was.

zephyr: add FIPS v5.2.3 as a Kconfig choice

  • CONFIG_WOLFCRYPT_FIPS_V5_2_3, under a new v5 bundle choice that defaults to 5.2.1, sets HAVE_FIPS_VERSION_PATCH 3. user_settings.h then includes user_settings-fips-v5.2.3.h for the --enable-fips=v5.2.3 algorithm set, the way v7 includes its own file. TLS, certificate and platform options keep following Kconfig.
  • The choice selects WOLFSSL_RSA, WOLFSSL_ECC and WOLFSSL_ECC_256, which user_settings.h would otherwise be able to disable after the set.
  • WOLFSSL_SP_SMALL_STACK moves the 4096-bit mod-exp temporaries to the heap. It only affects sp_*.c, which are outside the boundary.

zephyr: test RNG init without wolfcrypt_test()

  • The condvar ztest in zephyr/tests/wolfssl_condvar gains a case that calls wc_InitRng(). Its image calls neither wolfSSL_Init() nor wolfcrypt_test(), both of which register the seed callback themselves and so let the test sample pass with a broken boot hook; here nothing else registers it, and under FIPS v5 wc_InitRng() fails with DRBG_NO_SEED_CB unless the hook ran. CI already runs this test, plain and crypto-only, on native_sim without a bundle; the README shows the hand run with a 5.2.1 or 5.2.3 bundle. No new files.

Testing

  • Reviewer: master with the v5.2.3 boundary built and the native_sim POST and wolfCrypt tests passed, on native_sim and on a Cortex-A53, with the first round of build fixes.
  • Host compile of the v5.2.3 and the v5.2.1 bundle sources through user_settings.h, each with its Kconfig defaults: no warnings with -Wall, no symbol defined in more than one object, ssl.o references the seed callback for both, CONFIG_WOLFSSL_CERT_GEN honoured, and no SHAKE symbol in the v5.2.3 sha3.o.
  • zephyr_init.c compiled against stub Zephyr headers with no warnings under -Wall -Wextra in every combination of CONFIG_WOLFSSL_SYS_INIT, CONFIG_WOLFCRYPT_FIPS_V5 and crypto-only, with the CSPRNG and with CONFIG_TEST_RANDOM_GENERATOR; the #error fires with neither.
  • Kconfig parsed with kconfiglib for v2, v5.2.1, v5.2.3, v6, v7 and Ready: v5.2.3 keeps RSA, ECC and P-256 on when they are set off, the four PQC options are off under v2 and v5, and the symmetric assembly is off under v2, v5 and v6 and on under v7 and Ready.
  • The condvar test file compiled on the host against the tree's wolfCrypt, built with WC_RNG_SEED_CB, through a stand-in ztest.h, and run three ways: with the tree's default seed callback and with one registered from a constructor it passes; with the callback cleared, which is the state of a v5 bundle before registration, wc_InitRng() returns RNG_FAILURE_E and the test fails. Not yet built under Zephyr.
  • The bundle build itself has not yet been run under Zephyr after the rework.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

Copilot AI balanced review requested due to automatic review settings October 23, 2026 18:12
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

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.

🟡 Changes recommended

Legacy Zephyr header compatibility and concurrent initialization behavior need correction before approval.

2 open issues
What changed in this PR

This PR enables the Zephyr module to build a FIPS v5 bundle without modifying sources inside the FIPS boundary.

Changes:

  • Defines BUILDING_WOLFSSL for library sources to prevent duplicate KDF wrapper symbols.
  • Adds and distributes compatibility headers for legacy random and time includes.
  • Enables configuration macros needed by v5 initialization and ECDSA self-tests.
File Description
zephyr/​user_settings.h Adds FIPS v5 thread-local and ECDSA settings.
zephyr/​include.am Includes both compatibility headers in source distributions.
zephyr/​fips-v5-compat/​random/​rand32.h Maps the legacy random include to newer Zephyr headers.
zephyr/​fips-v5-compat/​posix/​time.h Maps the legacy time include to available headers.
zephyr/​CMakeLists.txt Adds library-only build definitions and the v5 compatibility include path.

Review effort: Balanced

Comment thread zephyr/CMakeLists.txt Resolved
Comment thread zephyr/user_settings.h Resolved
@jackctj117
jackctj117 marked this pull request as draft October 23, 2026 18:21
@jackctj117 jackctj117 self-assigned this Oct 23, 2026
@jackctj117
jackctj117 marked this pull request as ready for review October 23, 2026 18:33
@github-actions

Copy link
Copy Markdown

retest this please

@jackctj117

Copy link
Copy Markdown
Contributor 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.

Beyond the inline findings, I checked whether adding BUILDING_WOLFSSL only to the library in zephyr/CMakeLists.txt could make the library and the app disagree on struct layout. It can't: in the headers, that define only changes visibility, WARN_UNUSED_RESULT and deprecation attributes on declarations, and the top-level CMakeLists.txt already sets it the same way (PRIVATE).

Extended reasoning...

The PR changes Zephyr module build glue, adds two include shims and adds a FIPS v5.2.3 user_settings file. The inline findings already flag the settings-file problems. The hunt stopped at its bug limit rather than running out of candidates, so this is not an approval. The note above records one more concern that was checked and ruled out: the library-only define changes no struct layout.

Findings marked 🟡 are optional suggestions and need no follow-up push.

Comment thread zephyr/user_settings.h Resolved
Comment thread zephyr/user_settings-fips-v5.2.3.h Resolved
Comment thread zephyr/user_settings-fips-v5.2.3.h Resolved

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice to have the v5 boundary building. The two things I'd like sorted before this goes in are the integrity-layout guards, which v5 doesn't get yet, and the assembly that is still reachable through the Kconfig path. The rest are smaller.

Comment thread zephyr/CMakeLists.txt Resolved
Comment thread zephyr/user_settings.h Resolved
Comment thread zephyr/user_settings-fips-v5.2.3.h Resolved
Comment thread zephyr/user_settings-fips-v5.2.3.h Resolved
Comment thread zephyr/README.md Resolved
Comment thread zephyr/user_settings-fips-v5.2.3.h Resolved
Comment thread zephyr/user_settings-fips-v5.2.3.h Resolved
Comment thread zephyr/user_settings.h Resolved
@jackctj117
jackctj117 force-pushed the zephyr-fips-v5-build branch from 0add508 to 5398f40 Compare October 26, 2026 20:30

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the quick rework, the earlier comments all look addressed. A few new things came up, mostly around the 5.2.1 and v6 paths and the Kconfig options that still reach into the v5.2.3 set.

Comment thread zephyr/Kconfig Resolved
Comment thread zephyr/CMakeLists.txt Resolved
Comment thread zephyr/user_settings-fips-v5.2.3.h Resolved
Comment thread zephyr/zephyr_fips_seed.c Resolved
Comment thread zephyr/Kconfig Resolved
Comment thread zephyr/zephyr_fips_seed.c Resolved
Comment thread zephyr/user_settings.h Resolved
Comment thread zephyr/zephyr_fips_seed.c Resolved
Comment thread zephyr/zephyr_fips_seed.c Resolved
Comment thread zephyr/zephyr_fips_seed.c Resolved
@Frauschi

Copy link
Copy Markdown
Member

@jackctj117 also, the Jenkins failure is legit.

@jackctj117
jackctj117 force-pushed the zephyr-fips-v5-build branch 2 times, most recently from 922848a to e43b6e5 Compare October 28, 2026 15:09

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, only Jenkins failure is this:

unrecognized macros used:
CONFIG_WOLFCRYPT_FIPS_LEGACY_ASM
CONFIG_WOLFCRYPT_FIPS_V5_2_3
add well-formed but unknown macros to .wolfssl_known_macro_extras at top of source tree.

@jackctj117

jackctj117 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Jenkins retest this please.

@jackctj117
jackctj117 requested a review from Frauschi November 3, 2026 20:36
@jackctj117
jackctj117 force-pushed the zephyr-fips-v5-build branch 2 times, most recently from 460b98f to 3a28217 Compare November 4, 2026 17:13
Comment thread zephyr/zephyr_fips_seed.c Resolved
Comment thread zephyr/CMakeLists.txt Resolved
@jackctj117
jackctj117 requested a review from philljj November 5, 2026 16:17
@philljj philljj assigned jackctj117 and unassigned philljj and wolfSSL-Bot Nov 6, 2026
Define BUILDING_WOLFSSL for the library sources so the v5 kdf.c, which
predates libwolfssl_sources.h, no longer defines its wc_*_fips wrappers
twice. Map the v5 random.c's <random/rand32.h> and <posix/time.h> onto
the current headers; the module needs Zephyr 3.7 or later anyway, as
CONFIG_WOLFCRYPT_FIPS selects STATIC_INIT_GNU. Define NO_THREAD_LS,
since THREAD_LS_T is empty on Zephyr, and WOLFSSL_ECDSA_SET_K for the
ECDSA CAST.

The v5 wc_GenerateSeed() is a bare sys_rand_get(), so seed the DRBG
from the Zephyr CSPRNG, which reads the zephyr,entropy device, instead:
through wolfSSL_Init() and, for wolfCrypt-only builds, from an
APPLICATION-level hook after the power-on self test.

Apply the integrity-layout guards to every FIPS boundary instead of
only the one with assembly, and keep the symmetric assembly off under
FIPS v2, v5 and v6, whose in-boundary assembly this module does not
build. Keep the PQC options off under v2 and v5, whose boundaries have
no SHAKE.
Select the bundle under CONFIG_WOLFCRYPT_FIPS_V5 with
CONFIG_WOLFCRYPT_FIPS_V5_2_3. user_settings.h then sets the 5.2.3
version and includes user_settings-fips-v5.2.3.h for the algorithm set
of --enable-fips=v5.2.3, as it does user_settings-fips-v7.h for v7;
TLS, certificate and platform options keep following Kconfig. The
choice selects the RSA, ECC and P-256 options, which user_settings.h
would otherwise disable after the set.
@jackctj117
jackctj117 force-pushed the zephyr-fips-v5-build branch from 3a837a0 to 213f0cc Compare November 6, 2026 17:12
Both wolfSSL_Init() and wolfcrypt_test() register the DRBG seed callback
themselves, so the test sample passes even when the port's own
registration in zephyr_init.c is broken, and under FIPS v5 that is the
only registration a wolfCrypt-only image has. Call wc_InitRng() from the
condvar ztest, whose image does neither, instead. Without a bundle,
which is how CI runs it, it covers the tree's Zephyr wc_GenerateSeed().
@jackctj117
jackctj117 force-pushed the zephyr-fips-v5-build branch from 213f0cc to 9337815 Compare November 6, 2026 18:06
@philljj

philljj commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Retest this please.

(generic config toolchain)

@philljj
philljj merged commit ab5573c into wolfSSL:master Nov 6, 2026
422 of 423 checks passed
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.

6 participants