Skip to content

zephyr: build the FIPS v5 boundary - #11879

Open
jackctj117 wants to merge 2 commits into
wolfSSL:masterfrom
jackctj117:zephyr-fips-v5-build
Open

jackctj117 wants to merge 2 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(). zephyr/zephyr_fips_seed.c reads the zephyr,entropy device when its chosen node is enabled, or else the Zephyr CSPRNG; a board with neither fails the build unless CONFIG_TEST_RANDOM_GENERATOR is set. 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_LEGACY_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.

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_fips_seed.c compiled against stub Zephyr headers that reproduce the devicetree token macros, for each seed source, with no warnings under -Wall -Wextra: an enabled chosen node uses the entropy driver, a disabled or missing one falls back to the CSPRNG, and the #error fires with no source.
  • 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.
  • Not yet 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
Comment thread zephyr/user_settings.h Outdated
@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 Outdated
Comment thread zephyr/user_settings-fips-v5.2.3.h Outdated
Comment thread zephyr/user_settings-fips-v5.2.3.h Outdated

@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
Comment thread zephyr/user_settings.h
Comment thread zephyr/user_settings-fips-v5.2.3.h Outdated
Comment thread zephyr/user_settings-fips-v5.2.3.h Outdated
Comment thread zephyr/README.md Outdated
Comment thread zephyr/user_settings-fips-v5.2.3.h Outdated
Comment thread zephyr/user_settings-fips-v5.2.3.h Outdated
Comment thread zephyr/user_settings.h
@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 Outdated
Comment thread zephyr/CMakeLists.txt
Comment thread zephyr/user_settings-fips-v5.2.3.h
Comment thread zephyr/zephyr_fips_seed.c Outdated
Comment thread zephyr/Kconfig Outdated
Comment thread zephyr/zephyr_fips_seed.c Outdated
Comment thread zephyr/user_settings.h
Comment thread zephyr/zephyr_fips_seed.c Outdated
Comment thread zephyr/zephyr_fips_seed.c
Comment thread zephyr/zephyr_fips_seed.c Outdated
@Frauschi

Copy link
Copy Markdown
Member

@jackctj117 also, the Jenkins failure is legit.

@jackctj117
jackctj117 force-pushed the zephyr-fips-v5-build branch from 5398f40 to 922848a Compare October 28, 2026 12:25
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,entropy device or the Zephyr CSPRNG 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 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.

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.

3 participants