-
Notifications
You must be signed in to change notification settings - Fork 917
cryptocb: add AES CryptoCB key import support and tests #9658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
🛟 Devin Lifeguard found 2 likely issues in this PR
@sameehj |
|
retest this please |
b3bcd1c to
fd6d469
Compare
julek-wolfssl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see "proxy-key" appearing multiple times in the PR. What does it mean?
The ORIGINAL: comments should be cleaned up.
wolfssl/wolfcrypt/cryptocb.h
Outdated
| WOLFSSL_API void wc_CryptoCb_UnRegisterDevice(int devId); | ||
| WOLFSSL_API int wc_CryptoCb_UnRegisterDevice(int devId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly to satisfy Devin's comment on the PR, but maybe we shouldn't break the API to do so.
Thank you
wolfssl/wolfcrypt/cryptocb.h
Outdated
| /** | ||
| * \brief Import an AES key into a CryptoCB device (proxy-key mode). | ||
| * | ||
| * This function allows AES keys to be handled by an external device | ||
| * (e.g. Secure Element or HSM) without exposing raw key material to | ||
| * wolfCrypt. When supported, the device callback stores the key internally | ||
| * and sets an opaque handle in aes->devCtx. | ||
| * | ||
| * When CryptoCB AES SetKey support is enabled | ||
| * (WOLF_CRYPTO_CB_AES_SETKEY), wolfCrypt will route AES-GCM operations | ||
| * through the CryptoCB interface and avoid storing key bytes or | ||
| * generating GCM tables in software. | ||
| * | ||
| * \param aes AES context | ||
| * \param key Pointer to raw AES key material | ||
| * \param keySz Size of key in bytes | ||
| * | ||
| * \return 0 on success | ||
| * \return CRYPTOCB_UNAVAILABLE if device does not support this operation | ||
| * \return BAD_FUNC_ARG on invalid parameters | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong place for docs.
| static int g_ccAesSetKeyCalled = 0; | ||
| static int g_ccAesFreeCalled = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this g_ prefix?
| #else | ||
| /* ORIGINAL: Copy key to devKey for existing CryptoCB users */ | ||
| if (keylen > sizeof(aes->devKey)) { | ||
| return BAD_FUNC_ARG; | ||
| } | ||
| XMEMCPY(aes->devKey, userKey, keylen); | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why move this up here instead of allowing aes->devId != INVALID_DEVID section to handle it?
wolfcrypt/src/aes.c
Outdated
| /* ORIGINAL: Copy to devKey */ | ||
| if (len > sizeof(aes->devKey)) { | ||
| return BAD_FUNC_ARG; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
len is already checked on function entry. Why this check here?
| ret = wc_CryptoCb_Free(aes->devId, WC_ALGO_TYPE_CIPHER, | ||
| WC_CIPHER_AES, (void*)aes); | ||
| /* If they want the standard free, they can call it themselves */ | ||
| /* via their callback setting devId to INVALID_DEVID */ | ||
| /* otherwise assume the callback handled it */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this comment being removed?
|
Is it possible to setup a gh action that tests this with wolfHSM? At the very least this new config should be added to |
519cd36 to
be96866
Compare
Add CryptoCB-based AES key import 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 key import 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 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 device context handles - Tests use a mock Secure Element that internally performs software AES to validate routing without requiring hardware Signed-off-by: Sameeh Jubran <sameeh@wolfssl.com>
Dropped proxy-key terminology |
Uh oh!
There was an error while loading. Please reload this page.