Repository navigation
zephyr: build the FIPS v5 boundary - #11879
Conversation
|
There was a problem hiding this comment.
🟡 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_WOLFSSLfor 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
|
retest this please |
|
@claude review |
There was a problem hiding this comment.
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.
Frauschi
left a comment
There was a problem hiding this comment.
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.
0add508 to
5398f40
Compare
Frauschi
left a comment
There was a problem hiding this comment.
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.
|
@jackctj117 also, the Jenkins failure is legit. |
922848a to
e43b6e5
Compare
Frauschi
left a comment
There was a problem hiding this comment.
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.
|
Jenkins retest this please. |
460b98f to
3a28217
Compare
3a28217 to
3a837a0
Compare
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.
3a837a0 to
213f0cc
Compare
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().
213f0cc to
9337815
Compare
|
Retest this please. (generic config toolchain) |


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_fipsandwc_SSH_KDF_fipsare defined twice at link. The v5kdf.cpredateslibwolfssl_sources.h, so nothing definesBUILDING_WOLFSSL.types.hthen includeswc_compat.h, which reachesfips.hbeforekdf.csetsFIPS_NO_WRAPPERS. The module now definesBUILDING_WOLFSSLfor the library sources only, as the top-levelCMakeLists.txtalready does.random.ccannot find<random/rand32.h>. UnderCONFIG_WOLFCRYPT_FIPS_V5,zephyr/fips-v5-compat/is added to the library's include path. Itsrandom/rand32.handposix/time.hshims map onto the current headers; the module needs Zephyr 3.7 or later anyway, becauseCONFIG_WOLFCRYPT_FIPSselectsSTATIC_INIT_GNU.NO_THREAD_LS, becauseTHREAD_LS_Tis empty on Zephyr andHAVE_THREAD_LSwould only drop the ECC/SP cache locks;WOLFSSL_ECDSA_SET_K, which the ECDSA CAST needs;WC_RNG_SEED_CB, withwolfssl_zephyr_seedasWC_GENERATE_SEED_DEFAULT, because both v5 bundles'wc_GenerateSeed()is a baresys_rand_get(). The callback, inzephyr/zephyr_init.c, seeds from the Zephyr CSPRNG, which reads thezephyr,entropydevice; a board with no entropy driver fails the build unlessCONFIG_TEST_RANDOM_GENERATORis 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-levelSYS_INIThook, which runs after the POST constructor, registers it for wolfCrypt-only builds and logs a failure.CONFIG_LINKER_SORT_BY_ALIGNMENTcheck, the no-section-splitting flags and the dedicated rodata section. The Kconfig help and the README say to setCONFIG_LINKER_SORT_BY_ALIGNMENT=n, which Zephyr defaults on.WOLFCRYPT_FIPS_PRE_V7_ASM). Theiraes.c/sha256.cexpect the boundary's ownarmv8-*.cassembly, which this module does not build, and on x86_64 theirsha256.cwould call the tree'ssha256_asm.Sfrom outside the boundary.CONFIG_WOLFCRYPT_ASMstill accelerates the SP math.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, setsHAVE_FIPS_VERSION_PATCH 3.user_settings.hthen includesuser_settings-fips-v5.2.3.hfor the--enable-fips=v5.2.3algorithm set, the way v7 includes its own file. TLS, certificate and platform options keep following Kconfig.WOLFSSL_RSA,WOLFSSL_ECCandWOLFSSL_ECC_256, whichuser_settings.hwould otherwise be able to disable after the set.WOLFSSL_SP_SMALL_STACKmoves the 4096-bit mod-exp temporaries to the heap. It only affectssp_*.c, which are outside the boundary.zephyr: test RNG init without wolfcrypt_test()
zephyr/tests/wolfssl_condvargains a case that callswc_InitRng(). Its image calls neitherwolfSSL_Init()norwolfcrypt_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 v5wc_InitRng()fails withDRBG_NO_SEED_CBunless 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
user_settings.h, each with its Kconfig defaults: no warnings with-Wall, no symbol defined in more than one object,ssl.oreferences the seed callback for both,CONFIG_WOLFSSL_CERT_GENhonoured, and no SHAKE symbol in the v5.2.3sha3.o.zephyr_init.ccompiled against stub Zephyr headers with no warnings under-Wall -Wextrain every combination ofCONFIG_WOLFSSL_SYS_INIT,CONFIG_WOLFCRYPT_FIPS_V5and crypto-only, with the CSPRNG and withCONFIG_TEST_RANDOM_GENERATOR; the#errorfires with neither.WC_RNG_SEED_CB, through a stand-inztest.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()returnsRNG_FAILURE_Eand the test fails. Not yet built under Zephyr.Checklist