Skip to content

HW keystore improvements - #544

Draft
bigbrett wants to merge 23 commits into
wolfSSL:mainfrom
bigbrett:hw-keystore-improvements
Draft

bigbrett wants to merge 23 commits into
wolfSSL:mainfrom
bigbrett:hw-keystore-improvements

Conversation

@bigbrett

@bigbrett bigbrett commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

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.

@bigbrett bigbrett self-assigned this Oct 16, 2026
Copilot AI balanced review requested due to automatic review settings October 16, 2026 19:45

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.

🟡 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 thread src/wh_portkey.c Outdated
Comment on lines +242 to +244
*outKeyId = entry->id;
}
(void)_Unlock(context);
Comment thread src/wh_server_keystore.c Outdated
Comment on lines +1297 to +1298
(void)wh_HwKeystore_ClearSource(server->hwKeystore, server->devId,
keyId);
@bigbrett
bigbrett force-pushed the hw-keystore-improvements branch from 11f3571 to a0def9d Compare November 4, 2026 21:17

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.

🟡 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

Review effort: Balanced

Comment thread src/wh_portkey.c
*outKeyId = entry->id;
*inout_keySz = 0;
}
(void)_Unlock(context);
Comment thread src/wh_portkey.c
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);
Comment thread src/wh_portkey.c
wh_PortKey_KeyIdToRef(entry->id, ref);
ret = wc_KeyStore_Delete(devId, ref, sizeof(ref), NULL);
_Empty(entry);
return ret;
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.

2 participants