fix(libsodium): disable C11 Annex K declarations to fix build with picolibc and update library to 1.0.22#730
Conversation
dc2e917 to
e76ac0e
Compare
|
@Lapshin PTAL |
|
@hrushikesh430 , thank you for the PR. I found it difficult to follow the description due to factual inconsistencies introduced by AI.
Could not find if Espressif's own implementation exists. Could you add a link? Looks like it is "safe" for now, because original libsodium defines HAVE_MEMSET_S and others based on OS which looks wrong to me. It should be defined by configure script or something similar to their build system. It could be a task to send a patch to upstream (cc @mahavirj )
From your description, it sounds like
Could you please share a minimal example that reproduces the issue? |
|
Include file dependency is coming from the CMakeLists include injection here: idf-extra-components/libsodium/CMakeLists.txt Lines 196 to 197 in 84363b0 The fix from this PR should work well. @hrushikesh430 Can you please update the PR description and also bump the component version? CC @Ashish285 |
|
LGTM! The fix is similar as mbedTLS 4.1 (with tf-psa-crypto 1.1). @Lapshin, is it safe to set |
|
@Ashish285 , toolchains are not required to have this feature supported. I think this can be disabled by default |
e76ac0e to
fa50372
Compare
|
@mahavirj @Ashish285 @AdityaHPatwardhan Updated the PR, PTAL. |
…colibc Upstream libsodium's utils.c defines __STDC_WANT_LIB_EXT1__=1, which requests C11 Annex K bounds-checking types (errno_t, rsize_t) from the C library. With ESP-IDF v6.0+ (which uses picolibc instead of newlib), this can cause build failures when sys/_types.h is transitively included by other component headers before utils.c sets the macro. The include guard in sys/_types.h prevents re-inclusion, so the conditional Annex K type definitions (__errno_t, __rsize_t) are never reached. Set __STDC_WANT_LIB_EXT1__=0 as a compile definition so the flag is applied before any header is processed, avoiding the issue regardless of include order. This is safe because libsodium does not use any Annex K functions on ESP-IDF.
308b3be to
c8e87bd
Compare
c8e87bd to
a3dcc6f
Compare
Problem
Building libsodium with ESP-IDF v6.0+ (picolibc) fails with:
Root Cause
libsodium's
utils.cdefines__STDC_WANT_LIB_EXT1__=1to request C11 Annex K types. In picolibc those types (__errno_t,__rsize_t) live insys/_types.h, gated behind that same macro.Via the force-include in
libsodium/CMakeLists.txt, the PSA → mbedTLS → libc chain pullssys/_types.hin beforeutils.csets the macro:Once the include guard fires,
__errno_t/__rsize_tare never declared, and latererrno.h/string.hfail. The libsodium test app doesn't reach this chain, so CI never tripped on it.Fix
Add
-D__STDC_WANT_LIB_EXT1__=0as a compile definition inlibsodium/CMakeLists.txt. The-Dapplies before any source, overridingutils.c, so picolibc skips the Annex K declarations regardless of include order. libsodium on ESP-IDF does not use Annex K functions.Component version bumped to
1.0.22.References
__STDC_WANT_LIB_EXT1__Update libsodium to v1.0.22
This PR also bumps the libsodium submodule from
1.0.21-RELEASEto1.0.22-RELEASE, so the1.0.22component version actually matches the underlying source.What changed:
1.0.22-RELEASEtag.crypto_kem_*API, and SHA-3.sbom_libsodium.ymlupdated with the new version and commit hash.kem,kem_mlkem768,kem_xwing) added to the test app to verify ML-KEM and X-Wing on target.Found no CVE using command
esp-idf-sbom manifest check --local-db --extended-scan libsodium/