Skip to content

Conversation

@sameehj
Copy link
Contributor

@sameehj sameehj commented Jan 14, 2026

…ests

Add CryptoCB-based AES proxy-key support to enable Secure Element offload without exposing raw AES key material to wolfCrypt.

This change introduces a new optional CryptoCB hook (WOLF_CRYPTO_CB_AES_SETKEY) that allows AES keys to be imported into external devices (e.g. Secure Elements or HSMs) and referenced via an opaque handle stored in aes->devCtx. When this mode is active, wolfCrypt stores only key metadata and routes AES-GCM operations through CryptoCB, bypassing software key storage and GCM table generation.

Key points:

  • Add wc_CryptoCb_AesSetKey() callback for AES key import
  • Update AES SetKey paths to support proxy-key mode with graceful fallback to software when CryptoCB is unavailable
  • Skip GCM H/M table generation when AES-GCM is handled by the device
  • Preserve existing software AES behavior when devId is INVALID_DEVID

Testing:

  • Add unit test for CryptoCB AES SetKey proxy-key behavior
  • Add end-to-end AES-GCM offload unit test that verifies:
    • SetKey, Encrypt, Decrypt, and Free are routed via CryptoCB
    • Correct ciphertext/auth tag generation
    • Correct plaintext recovery after decrypt
    • Proper lifecycle handling of proxy-key handles
  • Tests use a mock Secure Element that internally performs software AES to validate routing without requiring hardware

This enables dual-mode operation:

  • Software AES for normal builds and testing
  • Secure Element–backed AES for TLS and crypto offload use cases

Description

Please describe the scope of the fix or feature addition.

Fixes zd#

Testing

How did you test?

Checklist

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

@sameehj sameehj requested a review from douzzer January 14, 2026 14:35
@devin-ai-integration
Copy link
Contributor

🛟 Devin Lifeguard found 2 likely issues in this PR

  • check-all-return-codes snippet snippet: Capture the return value of wc_CryptoCb_UnRegisterDevice() in each test (e.g., ret = wc_CryptoCb_UnRegisterDevice(TEST_CRYPTOCB_AES_DEVID); ExpectIntEQ(ret, 0);) to ensure any error is detected.
  • limit-stack-usage snippet snippet: Use the WOLFSSL_SMALL_STACK pattern in the two newly added test functions: dynamically allocate the large local objects (Aes aes, the plaintext/ciphertext/authTag buffers, etc.) with XMALLOC/XFREE (guarded by #ifdef WOLFSSL_SMALL_STACK) instead of placing them on the stack.

@sameehj
please take a look at the above issues which Devin flagged. Devin will not fix these issues automatically.

@sameehj
Copy link
Contributor Author

sameehj commented Jan 14, 2026

retest this please

…ests

Add CryptoCB-based AES proxy-key support to enable Secure Element
offload without exposing raw AES key material to wolfCrypt.

This change introduces a new optional CryptoCB hook
(WOLF_CRYPTO_CB_AES_SETKEY) that allows AES keys to be imported into
external devices (e.g. Secure Elements or HSMs) and referenced via an
opaque handle stored in aes->devCtx. When this mode is active, wolfCrypt
stores only key metadata and routes AES-GCM operations through CryptoCB,
bypassing software key storage and GCM table generation.

Key points:
- Add wc_CryptoCb_AesSetKey() callback for AES key import
- Update AES SetKey paths to support proxy-key mode with graceful
  fallback to software when CryptoCB is unavailable
- Skip GCM H/M table generation when AES-GCM is handled by the device
- Preserve existing software AES behavior when devId is INVALID_DEVID

Testing:
- Add unit test for CryptoCB AES SetKey proxy-key behavior
- Add end-to-end AES-GCM offload unit test that verifies:
  * SetKey, Encrypt, Decrypt, and Free are routed via CryptoCB
  * Correct ciphertext/auth tag generation
  * Correct plaintext recovery after decrypt
  * Proper lifecycle handling of proxy-key handles
- Tests use a mock Secure Element that internally performs software AES
  to validate routing without requiring hardware

This enables dual-mode operation:
- Software AES for normal builds and testing
- Secure Element–backed AES for TLS and crypto offload use cases

Signed-off-by: Sameeh Jubran <sameeh@wolfssl.com>
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.

1 participant