Repository navigation
Set key callback extended - #11754
night1rider wants to merge 2 commits into
Conversation
|
There was a problem hiding this comment.
🟡 Changes recommended
XTS assembly can reuse stale software keys after hardware-only rekeying, and new tests fail in supported configurations.
3 open findings
What changed in this PR
Extends wolfCrypt’s SetKey callbacks to distinguish software-held keys from hardware-only keys and prevent invalid software fallback.
Changes:
- Adds key-location tracking and a callback-facing setter.
- Updates AES and HMAC fallback handling.
- Adds regression tests for hardware-only keys and software rekeying.
| File | Description |
|---|---|
| wolfssl/wolfcrypt/hmac.h | Declares HMAC key-location state and setter. |
| wolfssl/wolfcrypt/cryptocb.h | Exposes key-location constants and API. |
| wolfssl/wolfcrypt/aes.h | Declares AES key-location state and setter. |
| wolfcrypt/src/hmac.c | Rejects fallback with hardware-only keys. |
| wolfcrypt/src/cryptocb.c | Dispatches key-location updates. |
| wolfcrypt/src/aes.c | Tracks key location and adjusts GCM setup. |
| tests/api/test_hmac.h | Registers the HMAC regression test. |
| tests/api/test_hmac.c | Tests hardware-only HMAC behavior. |
| tests/api/test_aes.h | Registers the AES regression test. |
| tests/api/test_aes.c | Tests hardware-only AES behavior. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11754
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Coverage: 3 of 8 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_aes.c, tests/api/test_hmac.c, wolfcrypt/src/cryptocb.c, wolfssl/wolfcrypt/cryptocb.h, wolfssl/wolfcrypt/hmac.h
Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Lite
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11754
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Coverage: 3 of 3 in-scope changed file(s) opened by the reviewer
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
Fenrir's latest completed scan found no issues; clearing the prior automated change request.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11754
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Coverage: 2 of 3 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_aes.c
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11754
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Coverage: 2 of 2 in-scope changed file(s) opened by the reviewer
Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Lite
|
Hi @night1rider, This PR overlaps quite a bit with my #11666, which fixes the same AES problem: a SETKEY callback that keeps the key on the device without building a schedule still leaves the context marked as keyed, so software modes run on an empty or stale schedule. #11666 handles that without an opt-in. A callback that returns 0 and leaves A trial merge of the two gives three conflicts in aes.c (the SETKEY branch of What I would suggest: land #11666 for AES, then rebase this one on top and keep the HMAC part, which #11666 doesn't touch. Once #11666 is in, |
6e52aac to
4efbe40
Compare
|
Thanks for rebasing on #11666. I tried this head with HMAC is different and worth landing. A callback may run the software Could the AES side shrink to recording the location in |
Thank you for testing it @Frauschi . I dropped the separate AES checks in I kept one thing on the AES side. When a key is marked HW stored, HMAC is unchanged. |
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11754
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .wolfssl_known_macro_extras, tests/api/test_aes.h, tests/api/test_hmac.h
Coverage: 3 of 6 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_aes.c, tests/api/test_hmac.c, wolfcrypt/src/cryptocb.c
Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Lite
|
Thanks, the HMAC side looks right. On the AES side, only the test reads That also settles the Fenrir comment, since the mark then carries no AES state in any build. Gating on Could you also add a short PR description? |
A callback can mark an HMAC key as kept on the device only.
Covers wc_CryptoCb_SetKeyLocation and AES and HMAC device-only keys.
1c87ec7 to
ac28935
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11754
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .wolfssl_known_macro_extras, tests/api/test_aes.h, tests/api/test_hmac.h
Coverage: 4 of 6 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_aes.c, tests/api/test_hmac.c
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
Fenrir's latest completed scan found no issues; clearing the prior automated change request.


Description
Adds
wc_CryptoCb_SetKeyLocation(), so a SetKey crypto callback can say where the key it took is kept:WC_KEY_SW_STORED(default) orWC_KEY_HW_STORED(on the device only). It is one API for every key type.WC_KEY_HW_STOREDis stored inHmac.keyLocation. If the device then declineswc_HmacUpdateorwc_HmacFinal, they returnMISSING_KEYinstead of running in software without the key. Opt out withWOLFSSL_NO_HMAC_KEY_LOCATION.NOT_COMPILED_IN.Builds with
WOLF_CRYPTO_CBandWOLF_CRYPTO_CB_SETKEY.Testing
test_wc_HmacNoSwKey_CryptoCb: a HW-stored HMAC key makes Update and Final returnMISSING_KEY; a declined key still works in software.test_wc_CryptoCb_SetKeyLocation: bad arguments, AES accepts both locations, andNOT_COMPILED_INfor a type with no support. Runs in every SetKey build.test_wc_CryptoCb_AesNoSwKey: an AES key the callback marks HW stored is refused by CBC, streaming GCM and XTS. A key the device declines works in software../tests/unit.test --api --group aes --group hmacon: base cryptocb,--enable-all,WOLF_CRYPTO_CB_FIND,WOLFSSL_NO_AES_KEY_SET_CHECK,WOLFSSL_NO_HMAC_KEY_LOCATION, AES-only SetKey callback, ARM32 asm (qemu) and PPC64 asm (qemu).