Skip to content

Add Silicon Labs EFR32xG25 Secure Element crypto callback port - #11267

Open
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:silabs_cryptocb
Open

Add Silicon Labs EFR32xG25 Secure Element crypto callback port#11267
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:silabs_cryptocb

Conversation

@dgarske

@dgarske dgarske commented Aug 25, 2026

Copy link
Copy Markdown
Member

Summary

Adds WOLFSSL_SILABS_CRYPTOCB, a crypto callback port for the EFR32 Series 2 Secure Element. Unlike the existing direct-hook WOLFSSL_SILABS_SE_ACCEL port, operations route by devId and anything the SE cannot do falls back to software instead of failing. Both ports share one set of SE Manager helpers.

Features

  • AES ECB/CBC/CTR/GCM/CCM, AES-CMAC, ChaCha20-Poly1305
  • SHA-1/224/256, TRNG, HKDF, PBKDF2
  • ECDSA sign/verify, ECDH, key generation
  • Secure Vault High keys: wrapped keys and built-in slots - the SE uses the key, the application never sees the material
  • Per-engine selection: offload a subset, the rest stays in software
  • Host compile test (--enable-silabs-cryptocb): builds and passes make check with no Simplicity SDK installed
  • Headless project in IDE/SimplicityStudio/xg25: slc-cli + GNU Arm, no GUI

Also adds ChaCha20-Poly1305 and PBKDF2 crypto callback dispatch to the core framework - neither existed before.

Testing

EFR32FG25B222F1920IM56, Secure Vault High, SE firmware 2.2.0: wolfcrypt_test full PASS.

HW vs SW
AES-256-GCM 9.1x
AES-CCM 5.2x
AES-256-ECB 4.4x
AES-256-CBC / CTR 4.2x
ECDSA verify 3.9x
SHA-256 3.0x
ECDH agree 2.8x
ECDSA sign 2.6x

Full per-algorithm table in wolfcrypt/src/port/silabs/README.md and IDE/SimplicityStudio/xg25/README.md. Both columns come from a single benchmark run on one part: WOLFSSL_SILABS_CRYPTOCB sets WC_USE_DEVID, so the stock benchmark measures each algorithm twice and labels the rows HW and SW.

Host: --enable-all --enable-cryptocb and --enable-silabs-cryptocb both make check clean, check-headers 232/0, check-source-text clean.

Reviewer note

The one-shot ChaCha20-Poly1305 API has no key object and therefore no devId, so it dispatches to whichever device holds callback slot 0 - the same keyless path wc_CryptoCb_RandomBlock() uses for a NULL rng. Existing crypto-callback devices must return CRYPTOCB_UNAVAILABLE for cipher one-shots they do not handle. Worth deciding whether this should instead be opt-in.

Notes

  • No RSA engine - Series 2 has no RSA hardware. No HMAC engine - wolfCrypt HMAC already runs its hashes on the SE.
  • SHA-384/512 offload is opt-in (WOLFSSL_SILABS_CRYPTOCB_SHA512_HW): no measured gain, and a wrong digest through wc_ShaXXXGetHash().
  • Fixes latent bugs in the shared SiLabs code, including pubkey.z never set after SE key generation and CCM reporting AES_GCM_AUTH_E.

@dgarske dgarske self-assigned this Aug 25, 2026
Copilot AI lite review requested due to automatic review settings August 25, 2026 19:16
@wolfSSL-Bot

Copy link
Copy Markdown

Can one of the admins verify this patch?

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.

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds a Silicon Labs EFR32 Series 2 Secure Element crypto callback port (WOLFSSL_SILABS_CRYPTOCB) that routes operations by devId and falls back to software when the SE declines, while sharing SE Manager helper code with the existing direct-hook port.

Changes:

  • Introduces SiLabs crypto-callback port sources/headers, host shim, and build-system integration (--enable-silabs-cryptocb).
  • Extends crypto callback framework to dispatch ChaCha20-Poly1305 one-shot and PBKDF2.
  • Refactors shared SiLabs SE helper code and settings gating (WOLFSSL_SILABS_SE_TYPES), plus documentation and example project.

Reviewed changes

Copilot reviewed 50 out of 50 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
wolfssl/wolfcrypt/types.h Adds PBKDF2 to KDF type enum for callback dispatch.
wolfssl/wolfcrypt/sha512.h Switches SiLabs hash header gating to WOLFSSL_SILABS_SE_TYPES.
wolfssl/wolfcrypt/sha256.h Adds SiLabs SE hash context member for cryptocb fallback model.
wolfssl/wolfcrypt/sha.h Adds SiLabs SE hash context member for cryptocb fallback model.
wolfssl/wolfcrypt/settings.h Adds WOLFSSL_SILABS_SE_TYPES umbrella and includes silabs_settings.h for cryptocb.
wolfssl/wolfcrypt/port/silabs/silabs_settings.h New macro-only settings header for engine selection and WC_USE_DEVID mapping.
wolfssl/wolfcrypt/port/silabs/silabs_random.h Switches to WOLFSSL_SILABS_SE_TYPES and includes settings.
wolfssl/wolfcrypt/port/silabs/silabs_hash.h Updates SiLabs hash types gating, adds host shim support, and status-returning helpers.
wolfssl/wolfcrypt/port/silabs/silabs_ecc.h Updates SiLabs ECC type gating and host shim support.
wolfssl/wolfcrypt/port/silabs/silabs_cryptocb.h New public header for registering device + wrapped/built-in key APIs + engine entry points.
wolfssl/wolfcrypt/port/silabs/silabs_aes.h Updates SiLabs AES type gating, adds shared SE helpers and key-set tracking.
wolfssl/wolfcrypt/include.am Installs new SiLabs cryptocb headers in build metadata.
wolfssl/wolfcrypt/ecc.h Embeds SE manager ECC fields under WOLFSSL_SILABS_SE_TYPES and adds silabsKeySet.
wolfssl/wolfcrypt/cryptocb.h Extends wc_CryptoInfo for ChaCha20-Poly1305 + PBKDF2 and exposes wc_CryptoCb_GetDevIdAtIndex for tests.
wolfssl/wolfcrypt/aes.h Embeds SE manager AES fields under WOLFSSL_SILABS_SE_TYPES.
wolfcrypt/test/test.c Adds cryptocb tests for ChaCha20-Poly1305 and PBKDF2 dispatch paths.
wolfcrypt/src/wc_port.c Autoregisters SiLabs cryptocb device in wolfCrypt_Init() and unifies SE init gating/message.
wolfcrypt/src/sha512.c Updates SiLabs hash copy fixups to use WOLFSSL_SILABS_SE_TYPES.
wolfcrypt/src/sha256.c Updates SiLabs hash copy fixups to use WOLFSSL_SILABS_SE_TYPES.
wolfcrypt/src/sha.c Updates SiLabs hash copy fixups to use WOLFSSL_SILABS_SE_TYPES.
wolfcrypt/src/random.c Updates SiLabs RNG include gating to WOLFSSL_SILABS_SE_TYPES.
wolfcrypt/src/pwdbased.c Adds PBKDF2 crypto-callback dispatch before software implementation.
wolfcrypt/src/port/silabs/silabs_shim.h New host compile-test shim for SE Manager APIs and device feature macros.
wolfcrypt/src/port/silabs/silabs_random.c Adds host shim support and includes error codes; updates gating to WOLFSSL_SILABS_SE_TYPES.
wolfcrypt/src/port/silabs/silabs_key.c New wrapped/built-in key management implementation for cryptocb port.
wolfcrypt/src/port/silabs/silabs_hash.c Refactors hash helpers to expose raw SE status and gates direct-replacement code to direct port only.
wolfcrypt/src/port/silabs/silabs_ecc.c Adds missing pubkey.z initialization after SE keygen and enables host-shim builds.
wolfcrypt/src/port/silabs/silabs_cryptocb.c New SiLabs cryptocb device registration and algorithm dispatcher.
wolfcrypt/src/port/silabs/silabs_cb_rng.c New SE TRNG crypto-callback engine.
wolfcrypt/src/port/silabs/silabs_cb_pk.c New ECC crypto-callback engine (ECDH/ECDSA/keygen) with SE constraints.
wolfcrypt/src/port/silabs/silabs_cb_kdf.c New Secure Vault High HKDF/PBKDF2 crypto-callback engine.
wolfcrypt/src/port/silabs/silabs_cb_hash.c New hash crypto-callback engine with lazy SE-context start and fallback behavior.
wolfcrypt/src/port/silabs/silabs_cb_cmac.c New AES-CMAC crypto-callback engine with multipart state and free-callback cleanup.
wolfcrypt/src/port/silabs/silabs_cb_cipher.c New cipher crypto-callback engine for AES modes and ChaCha20-Poly1305.
wolfcrypt/src/port/silabs/silabs_aes.c Splits shared AES SE descriptor + ECB/CBC helpers from direct-replacement AES hooks; fixes CCM auth error code.
wolfcrypt/src/port/silabs/README.md Documents direct vs cryptocb ports, engines, host test, wrapped keys, and benchmark results.
wolfcrypt/src/include.am Adds SiLabs cryptocb sources and shim to Automake build targets.
wolfcrypt/src/ecc.c Scrubs SiLabs SE key_raw buffer on ecc_key free.
wolfcrypt/src/cryptocb.c Adds ChaCha20-Poly1305 one-shot and PBKDF2 crypto-callback dispatch implementations.
wolfcrypt/src/chacha20_poly1305.c Adds crypto-callback boundary for ChaCha20-Poly1305 one-shot APIs.
configure.ac Adds --enable-silabs-cryptocb host compile-test option and build conditional.
IDE/SimplicityStudio/xg25/wolfcrypt_test.slcp Adds headless Simplicity Studio project definition for xG25.
IDE/SimplicityStudio/xg25/user_settings.h Adds example user settings enabling cryptocb port and algorithms for xG25.
IDE/SimplicityStudio/xg25/flash.sh Adds headless flashing script.
IDE/SimplicityStudio/xg25/build.sh Adds headless generation/build script using slc-cli + GNU Arm.
IDE/SimplicityStudio/xg25/app.c Adds embedded entrypoint printing SE info and running wolfcrypt_test/benchmark.
IDE/SimplicityStudio/xg25/README.md Documents headless build/flash workflow and expected output/results.
IDE/SimplicityStudio/xg25/.gitignore Ignores generated build output directory.
IDE/SimplicityStudio/README.md Points to xG25 headless project for cryptocb port.
.github/scripts/check-headers.sh Stops excluding silabs_aes.h from header checks.
Suppressed comments (2)

wolfssl/wolfcrypt/cryptocb.h:1

  • wc_CryptoCb_GetDevIdAtIndex was previously WOLFSSL_LOCAL and is now declared with WOLFSSL_TEST_VIS in a public header. This risks unintentionally exporting an internal symbol (ABI surface growth) and also relies on WOLFSSL_TEST_VIS being defined consistently in all consumer builds. A more robust approach is to keep this declaration behind a dedicated test-only compile gate (e.g., #if defined(WOLFSSL_TEST) / existing unit-test macro) or provide a separate test header so production builds don't gain a new exported-ish entry point.
    wolfssl/wolfcrypt/sha256.h:1
  • This hunk introduces a preprocessor #endif inside struct wc_Sha256 immediately before adding the WOLFSSL_SILABS_CRYPTOCB member. As shown, there is no matching #if in the immediate hunk, making it easy to accidentally unbalance conditionals or close the wrong block and break compilation under certain feature combinations. Please double-check the surrounding conditional structure and, if needed, refactor so the software members remain properly guarded and the SiLabs context is added without relying on a fragile close/reopen pattern.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +75 to +80
if (aes->ctx.keySet) {
return 0;
}
if (aes->keylen <= 0 || (word32)aes->keylen > sizeof(aes->devKey)) {
return WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
}
Comment on lines +118 to +119
* import. */
if (key->silabsKeySet) {
Comment on lines +199 to +202
if (!silabs_pk_digest_ok(info->pk.eccsign.key,
info->pk.eccsign.inlen)) {
return WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
}
Comment thread configure.ac
Comment on lines +3807 to +3808
AC_MSG_NOTICE([--enable-silabs-cryptocb also enables AES-ECB build-wide (HAVE_AES_ECB)])
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SILABS_CRYPTOCB -DWOLFSSL_SILABS_HOST_TEST -DHAVE_AES_ECB"
@dgarske
dgarske force-pushed the silabs_cryptocb branch 3 times, most recently from a5d331b to 9d1267f Compare August 25, 2026 22:47
@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown

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