Skip to content

Commit dd36c2f

Browse files
committed
Add RTL8735B HUK wrapped-key examples for ECC, AES and mutual TLS and fix stale docs
1 parent a342a4e commit dd36c2f

7 files changed

Lines changed: 845 additions & 81 deletions

File tree

‎rtl8735b/README.md‎

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ It is built inside the RealTek AmebaPro2 FreeRTOS SDK (which provides the startu
1111
- The key is device-bound and deterministic: the same seed yields the same key (so GMAC verifies and AES round-trips), and a different seed yields a different key (GCM decrypt returns `AES_GCM_AUTH_E`).
1212
- The port tolerates unaligned caller buffers (it bounces them to satisfy the HAL's 32-byte alignment); the example includes an explicitly-unaligned GCM check.
1313
- 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.
14-
- 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.
14+
- 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.
15+
- 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, wrapped scalar and public key (plus the IV and tag for GCM) 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. The example runs both wrap formats:
16+
- AES-GCM (recommended): a damaged tag or wrapped scalar fails with `AES_GCM_AUTH_E`.
17+
- AES-ECB: the same blob layout as the STM32 DHUK `wc_ecc_import_wrapped_private()`, for wrap code shared between the two parts. The port selects it when the key's `iv`, `ivSz`, `tag` and `tagSz` are all NULL/0. ECB has no integrity check: a damaged blob signs with a wrong scalar and the signature does not verify. Signing with an ECB blob needs wolfSSL PR #12056 or later.
18+
19+
Neither format covers the stored public key, so an application that relies on it needs its own integrity check; the example's verify of a fresh signature against the stored public key is one.
20+
- HUK-wrapped AES key in a key-storage slot: an application AES key, stored wrapped under the HUK, is loaded with `wc_KeyStore_ImportWrapped()` into a hardware key-storage slot and then used through an `Aes` made with `wc_AesInit_Id()`, so GCM/ECB run from the slot and the key is in RAM only during the import. Both wrap formats are shown: RFC 3394 (`WC_KEYWRAP_FORMAT_AESKW`, a damaged blob fails with `BAD_KEYWRAP_IV_E`) and raw ECB (`WC_KEYWRAP_FORMAT_VENDOR`, the STM32 DHUK style, no integrity check). Needs wolfSSL PR #12056 or later; with an older wolfSSL the test is not built.
1521
- HW ECDSA P-256 verify offload: the same signature is then verified through the HW engine (the public point is imported into a `WC_HUK_DEVID` key so `wc_ecc_verify_hash` dispatches to `hal_ecdsa`), and a tampered digest is shown to be rejected. No HUK context is needed to verify -- any P-256 public key.
1622
- **Plaintext-key AES (second device):** with `WOLFSSL_RTL8735B_AES` also enabled (see `user_settings.h`), the example registers a second crypto-callback device, `wc_Rtl8735b_AesRegister(WC_RTL8735B_AES_DEVID)`, that runs a caller-supplied AES key directly on the HW engine with no HUK binding. It reproduces a published AES-GCM test vector (proving the key is used verbatim), then encrypts the same 32 key bytes through both devices to show the plaintext-key ciphertext differs from the HUK device-bound ciphertext -- the two devices coexist and are selected per `Aes` by `devId`.
1723

@@ -78,6 +84,43 @@ Remove the J27 jumper and reset to boot. The console (UART, 115200) prints:
7884
[PASS] verify with software public key
7985
[PASS] HW ECDSA verify (good sig)
8086
[PASS] HW ECDSA verify (tampered -> reject)
87+
== HUK-wrapped ECDSA key: wrap, store, reload, sign ==
88+
[PASS] InitRng
89+
-- GCM-wrapped blob --
90+
[PASS] create wrapped key blob
91+
[PASS] sign with reloaded blob
92+
[PASS] verify with stored public key
93+
[PASS] tampered blob tag -> AES_GCM_AUTH_E
94+
-- ECB-wrapped blob --
95+
[PASS] create wrapped key blob
96+
[PASS] sign with reloaded blob
97+
[PASS] verify with stored public key
98+
[PASS] tampered ECB blob signs, signature does not verify
99+
== HUK-wrapped AES key in a key-storage slot ==
100+
[PASS] make key reference
101+
[PASS] software AES reference
102+
-- ECB-wrapped AES-256 key --
103+
[PASS] wrap key under the HUK
104+
[PASS] wc_KeyStore_ImportWrapped into slot
105+
[PASS] wc_KeyStore_GetInfo: AES-256
106+
[PASS] import into an occupied slot -> BAD_STATE_E
107+
[PASS] AES-ECB and AES-GCM from the slot match the software key
108+
[PASS] wc_KeyStore_Delete
109+
[PASS] AES from a deleted slot fails
110+
[PASS] damaged ECB blob imports
111+
[PASS] ... but the key is wrong
112+
-- RFC 3394-wrapped AES-256 key --
113+
[PASS] wrap key under the HUK
114+
[PASS] wc_KeyStore_ImportWrapped into slot
115+
[PASS] wc_KeyStore_GetInfo: AES-256
116+
[PASS] import into an occupied slot -> BAD_STATE_E
117+
[PASS] AES-ECB and AES-GCM from the slot match the software key
118+
[PASS] wc_KeyStore_Delete
119+
[PASS] AES from a deleted slot fails
120+
[PASS] damaged RFC 3394 blob -> BAD_KEYWRAP_IV_E
121+
-- re-import a different key, and AES-128 --
122+
[PASS] slot reused for a second key
123+
[PASS] AES-128 key from a slot matches the software key
81124
== AES-GCM with a plaintext key (devId=WC_RTL8735B_AES_DEVID) ==
82125
[PASS] AesInit(devId=WC_RTL8735B_AES_DEVID)
83126
[PASS] AesGcmSetKey(plaintext 128-bit key)
@@ -94,7 +137,7 @@ Remove the J27 jumper and reset to boot. The console (UART, 115200) prints:
94137
[PASS] ciphertext matches FIPS-197 vector
95138
[PASS] AesEcb round-trip
96139
== AES-GCM plaintext key, UNALIGNED buffers (port bounces) == ... round-trip PASS
97-
== AES-GCM plaintext key, non-12-byte IV must hard-fail == ... 16-byte IV rejected PASS
140+
== AES-GCM plaintext key, non-12-byte IV uses software GCM == ... matches software GCM PASS
98141
=== done ===
99142
```
100143

0 commit comments

Comments
 (0)