Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Failed hardware deletion can leave revoked keys usable, and concurrent slot replacement can bypass ownership checks.
2 open findings
What changed in this PR
Expands wolfHSM hardware-key support from key wrapping to reference-based AES and CMAC operations, with optional client-managed loading.
Changes:
- Adds hardware-key records, ownership and usage checks, and load/clear/info APIs.
- Routes hardware-key operations through wolfCrypt callbacks.
- Updates tests, CI configurations, and provisioning documentation.
| File | Description |
|---|---|
| wolfhsm/wh_settings.h | Adds hardware-keystore options and dependency checks. |
| wolfhsm/wh_server_keystore.h | Declares hardware-key loading API. |
| wolfhsm/wh_message.h | Adds hardware-key actions. |
| wolfhsm/wh_message_keystore.h | Defines hardware-key messages. |
| wolfhsm/wh_keyid.h | Updates hardware-key comments. |
| wolfhsm/wh_hwkeystore.h | Defines key records and lifecycle APIs. |
| wolfhsm/wh_common.h | Adds hardware-key information structure. |
| wolfhsm/wh_client.h | Declares client hardware-key APIs. |
| tools/whnvmtool/README.md | Clarifies trusted KEK provisioning. |
| test/wh_test_check_struct_padding.c | Includes new message padding checks. |
| test/config/wolfhsm_cfg.h | Disables legacy hardware-keystore coverage. |
| test/config/user_settings.h | Enables private key references. |
| test-refactor/wh_test_list.c | Registers hardware crypto test. |
| test-refactor/server/wh_test_hwkeystore_server.c | Tests registration and policy checks. |
| test-refactor/README.md | Updates test migration status. |
| test-refactor/posix/Makefile | Adds hardware-loading build option. |
| test-refactor/misc/wh_test_transport_mem_autopoll.h | Declares auto-polling test transport. |
| test-refactor/misc/wh_test_transport_mem_autopoll.c | Implements single-threaded request polling. |
| test-refactor/misc/wh_test_hwkeystore.c | Tests reference-based hardware KEKs. |
| test-refactor/misc/wh_test_check_struct_padding.c | Includes new message padding checks. |
| src/wh_she_crypto.c | Uses callback-compatible AES-ECB. |
| src/wh_server.c | Formats hardware-action error responses. |
| src/wh_server_she.c | Replaces direct AES with ECB calls. |
| src/wh_server_keystore.c | Adds loading, copy cleanup, and reference-based KEKs. |
| src/wh_server_crypto.c | Supports hardware references in AES and CMAC. |
| src/wh_message_keystore.c | Translates hardware-key messages. |
| src/wh_hwkeystore.c | Implements records, policy checks, and lifecycle operations. |
| src/wh_client.c | Implements client hardware-key requests. |
| docs/src/9-Configuration.md | Documents hardware-keystore options. |
| docs/src/5-Features.md | Explains hardware-key architecture and usage. |
| .github/workflows/build-and-test-refactor.yml | Adds hardware-loading CI configurations. |
| .clang-format | Enables structure-array alignment. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+242
to
+244
| *outKeyId = entry->id; | ||
| } | ||
| (void)_Unlock(context); |
Comment on lines
+1297
to
+1298
| (void)wh_HwKeystore_ClearSource(server->hwKeystore, server->devId, | ||
| keyId); |
…d tests in test-refactor/misc
bigbrett
force-pushed
the
hw-keystore-improvements
branch
from
November 4, 2026 21:17
11f3571 to
a0def9d
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A slot-reassignment race can cause crypto operations to use another client’s key under stale authorization, and unnormalized import/delete errors can leave blocking client APIs polling indefinitely.
5 open issues
Slot reassignment can use another client's key during crypto · New Erase/revoke ignores cleanup failures and leaves keys authorized Authorized key slot can be replaced before crypto use Key load retries indefinitely when import returns NOTREADY · New Clear retries indefinitely when delete returns NOTREADY · New
Review effort: Balanced
| *outKeyId = entry->id; | ||
| *inout_keySz = 0; | ||
| } | ||
| (void)_Unlock(context); |
Comment on lines
+374
to
+378
| uint8_t ref[WH_PORTKEY_REF_SIZE]; | ||
|
|
||
| wh_PortKey_KeyIdToRef(keyId, ref); | ||
| return wc_KeyStore_ImportPlain(devId, ref, sizeof(ref), WC_KEYSTORE_KEY_AES, | ||
| key, keySz, 0, NULL); |
| wh_PortKey_KeyIdToRef(entry->id, ref); | ||
| ret = wc_KeyStore_Delete(devId, ref, sizeof(ref), NULL); | ||
| _Empty(entry); | ||
| return ret; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Adds unified abstraction for port-specific keys, allowing clients to refer to them by (flagged) ID when using them in cryptographically relevant operations.
Port keys and associated usage restrictions are registered with the wolfHSM server when the server app boots, enabling the core library to check usage on the keys before control is passed to the port's crypto callback.
How keys are used/loaded with applicable cryptographic hardware is entirely delegated to the port crypto callback.
Reviewers: I had Claude generate this interactive visualization of the feature that walks through what happens where/when during typical usage on an example port.