Skip to content

Add RTL8735B HUK wrapped-key reload example and fix stale test and docs - #655

Open
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:rtl8735b_wrap_doc
Open

dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:rtl8735b_wrap_doc

Conversation

@dgarske

@dgarske dgarske commented Nov 5, 2026

Copy link
Copy Markdown
Member

Description

Adds a wrap, store, reload and sign example for a HUK-wrapped ECC key to the rtl8735b example, and corrects two places where the example disagreed with the wolfSSL RealTek port.

What it adds

  • huk_key_blob - the seed, IV, tag, wrapped scalar and public key an application stores
  • huk_blob_create() - generates a P-256 key and wraps its scalar under the HUK with a fresh seed and IV
  • huk_blob_load() - sets up a signing key from a stored blob through ecc_key->devCtx
  • huk_ecdsa_reload_test() - signs from the blob, verifies with the stored public key, and checks that a damaged blob fails with AES_GCM_AUTH_E

Corrections

The README and the comment above huk_ecdsa_test() described the scalar wrap as ECB. The code and the port's wc_Rtl8735b_EccKey use AES-GCM with an IV and tag, and both now say so.

plain_gcm_badiv_test() required a non-12-byte IV to fail on the plaintext-key AES device. The port deliberately declines that request so software GCM serves it with the same literal key, so the encrypt succeeds and the test printed [FAIL]. It is now plain_gcm_long_iv_test(), which requires the encrypt to succeed and its output to match software GCM with the same key. The HUK device still hard-fails a non-12-byte IV because its key bytes are a derivation seed, and huk_gcm_badiv_test() is unchanged.

Testing

Built with the RealTek FreeRTOS SDK against current wolfSSL master and run on an RTL8735B EVB with all checks passing. A blob wrapped by one flashed image also loaded and signed correctly in a later image after a power-on reset, using a temporary test build of the example. Moving a blob to a second device was not tested, because only one board was available.

@dgarske dgarske self-assigned this Nov 5, 2026
Copilot AI balanced review requested due to automatic review settings November 5, 2026 19:31

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

The damaged-blob guarantee overstates integrity protection because qx and qy are neither authenticated nor read during loading; the documentation and test description need to distinguish authenticated scalar-wrap protection from public-key integrity.

1 open issue
What changed in this PR

Adds a HUK-wrapped P-256 key reload example to the RTL8735B demo and aligns existing tests and documentation with the RealTek port’s behavior.

Changes:

  • Adds a stored-key blob format and helpers to wrap, reload, and sign, with signature verification and tag-tampering checks.
  • Replaces plaintext AES-GCM long-IV rejection expectations with a software-fallback comparison.
  • Corrects scalar-wrapping descriptions from ECB to AES-GCM and updates sample output.
File Description
rtl8735b/​README.md Documents wrapped-key storage, corrects the wrapping mode, and updates expected output.
rtl8735b/​main.c Adds blob creation and reload tests, corrects the long-IV test, and updates comments.

Review effort: Balanced

Comment thread rtl8735b/README.md
- HMAC-SHA256 under the HUK (`wc_HmacInit` with `devId = WC_HUK_DEVID`, then `wc_HmacSetKey`/`wc_HmacUpdate`/`wc_HmacFinal`): the MAC is deterministic for a given seed and differs for a wrong seed.
- HUK-bound ECDSA P-256 sign: a key is generated in software, its private scalar is wrapped under the HUK (ECB-encrypted with the HUK device), and signing then goes through the HUK device (unwrap + sign); the signature verifies against the software public key.
- HUK-bound ECDSA P-256 sign: a key is generated in software, its private scalar is wrapped under the HUK (AES-GCM-encrypted with the HUK device), and signing then goes through the HUK device (unwrap + sign); the signature verifies against the software public key.
- HUK-wrapped key storage: `huk_blob_create()` and `huk_blob_load()` in `main.c` show how to wrap a P-256 key, keep the seed, IV, tag, wrapped scalar and public key as a stored blob, and sign with a key set up from that blob alone. The blob only unwraps on the device that wrapped it, and a damaged blob fails with `AES_GCM_AUTH_E`.
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