Skip to content

Implement client api to generate and cache a random key#437

Open
AlexLanzano wants to merge 2 commits into
wolfSSL:mainfrom
AlexLanzano:gen-rng-key
Open

Implement client api to generate and cache a random key#437
AlexLanzano wants to merge 2 commits into
wolfSSL:mainfrom
AlexLanzano:gen-rng-key

Conversation

@AlexLanzano

@AlexLanzano AlexLanzano commented Jul 8, 2026

Copy link
Copy Markdown
Member
  • Add wh_Client_KeyCacheRandom client API to have the server generate a key from its RNG, cache it, and return only the keyId

  • Add the client request/response/blocking triplet: wh_Client_KeyCacheRandomRequest_ex, wh_Client_KeyCacheRandomRequest, wh_Client_KeyCacheRandomResponse, and the blocking wh_Client_KeyCacheRandom

  • Add WH_KEY_CACHE_RANDOM keystore action and whMessageKeystore_CacheRandomRequest message (reusing CacheResponse) with its wh_MessageKeystore_TranslateCacheRandomRequest translation function

  • Add server handler for WH_KEY_CACHE_RANDOM plus the _KeystoreCacheRandomKey helper, generating random bytes directly into a cache slot via wc_RNG_GenerateBlock

  • Add whTest_KeyCacheRandom test (generate → export-verify size/label/non-zero → uniqueness → evict) wired into the crypto client test suite

  • Document the new API in docs/

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.

Pull request overview

This PR adds a new keystore operation and client API for server-side generation of random key material directly into the keystore cache, returning only the assigned keyId to the client. This fits into wolfHSM’s key-management workflow by enabling “generate-on-server then use-by-ID” flows without uploading key bytes from the client.

Changes:

  • Introduces wh_Client_KeyCacheRandom* request/response/blocking APIs and corresponding wire message + translation.
  • Adds server keystore handling for WH_KEY_CACHE_RANDOM, generating random bytes into a cache slot via the server RNG.
  • Adds a crypto client test for key generation + basic validation, and documents the new API in the manual/API reference.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
wolfhsm/wh_message.h Adds WH_KEY_CACHE_RANDOM action ID.
wolfhsm/wh_message_keystore.h Defines CacheRandom request message + translator prototype.
wolfhsm/wh_client.h Declares new wh_Client_KeyCacheRandom* public APIs with docstrings.
src/wh_client.c Implements the new client request/response/blocking helpers.
src/wh_server_keystore.c Adds _KeystoreCacheRandomKey() and server handler for the new action.
src/wh_message_keystore.c Implements request translation for CacheRandom.
test/wh_test_crypto.c Adds whTest_KeyCacheRandom and wires it into the crypto client test flow.
docs/src/chapter05.md Adds a user-facing example and conceptual documentation for server RNG key caching.
docs/src/appendix01.md Adds API reference documentation for the new functions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/wh_client.c Outdated
Comment thread src/wh_server_keystore.c Outdated
Comment thread docs/src/chapter05.md Outdated
Comment thread wolfhsm/wh_client.h Outdated
Comment thread wolfhsm/wh_client.h Outdated
Comment thread wolfhsm/wh_client.h Outdated
@AlexLanzano AlexLanzano marked this pull request as draft July 8, 2026 20:07
@AlexLanzano AlexLanzano force-pushed the gen-rng-key branch 2 times, most recently from 8c0dc0e to 8bb2ab6 Compare July 8, 2026 20:46
@AlexLanzano AlexLanzano requested a review from Copilot July 8, 2026 20:50

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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Comment thread src/wh_server_keystore.c
Comment thread src/wh_server_keystore.c
Comment thread src/wh_client.c Outdated
Comment thread docs/src/5-Features.md

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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comment thread src/wh_server_keystore.c Outdated
Comment thread docs/src/5-Features.md
Comment thread wolfhsm/wh_client.h Outdated
@AlexLanzano AlexLanzano assigned bigbrett and unassigned AlexLanzano Jul 9, 2026
@AlexLanzano AlexLanzano requested a review from bigbrett July 9, 2026 14:43
@AlexLanzano AlexLanzano marked this pull request as ready for review July 9, 2026 14:50

@bigbrett bigbrett 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.

overall looks good, just a few tweaks

Comment thread src/wh_server_keystore.c Outdated
Comment thread test/wh_test_crypto.c
Comment thread wolfhsm/wh_client.h Outdated
@bigbrett bigbrett assigned AlexLanzano and unassigned bigbrett Jul 9, 2026
@AlexLanzano AlexLanzano requested a review from bigbrett July 9, 2026 18:56
@AlexLanzano AlexLanzano assigned bigbrett and unassigned AlexLanzano Jul 10, 2026
@bigbrett bigbrett removed their assignment Jul 10, 2026
@bigbrett bigbrett requested a review from rizlik July 10, 2026 21:51
Comment thread src/wh_server_keystore.c
}

memcpy((uint8_t*)slotMeta, (uint8_t*)meta, sizeof(whNvmMetadata));
_MarkKeyCommitted(_GetCacheContext(server, meta->id), meta->id, 0);

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.

@AlexLanzano Just noticed this. Why are we marking this as committed? Is it because we never want it to go to NVM and it is meant to be cache-only and auto-evictable? I'm wondering if we want to actually have this just be treated like any other key?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like Im setting it as uncommitted here, no? I used the same logic as the regular key cache handler

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.

4 participants