Skip to content

Add RealTek AmebaPro2 (RTL8735B) HUK crypto-callback port#10677

Draft
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:realtek_huk
Draft

Add RealTek AmebaPro2 (RTL8735B) HUK crypto-callback port#10677
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:realtek_huk

Conversation

@dgarske

@dgarske dgarske commented Jun 12, 2026

Copy link
Copy Markdown
Member

Add RealTek AmebaPro2 (RTL8735B) HUK crypto-callback port

Summary

Adds a wolfCrypt port that binds keys to the RealTek RTL8735B (AmebaPro2) silicon Hardware Unique Key (HUK) via the crypto-callback (CryptoCb) framework. A 256-bit "seed" is run through the AmebaPro2 HAL secure HKDF key-ladder against the HUK to derive a per-purpose working key in a secure key-storage slot; the working key never enters software.

It is a pure crypto-callback device -- no new wolfSSL core API, no new struct fields, and no changes to any shared core file (only the new port files plus configure.ac/include.am/zephyr build wiring). AES reads its seed from the standard aes->devKey; ECDSA reads a port-defined wc_AmebaPro2_EccKey (the HUK-wrapped scalar + seed) attached via the standard ecc_key->devCtx.

Features

  • AES-GCM (full payload), AES-ECB, AES-CBC, AES-CTR under the HUK-derived slot key. GCM/ECB use the HAL secure-key engine; CBC/CTR chain in software over the single-block ECB secure-key op (the HAL has no CBC/CTR secure-key variant), so the key still never leaves hardware. CBC handles in-place (in == out) and multi-call chaining; CTR maintains the partial-block keystream state across calls.
  • HUK-bound ECDSA sign (P-256): the wrapped scalar is unwrapped under the HUK into a short-lived buffer, signed, and scrubbed; the blob is device-bound (only unwraps on the silicon whose HUK produced the slot key).
  • Unaligned caller buffers are tolerated (the HAL needs 32-byte-aligned DMA buffers; the port bounces through aligned temporaries). A non-12-byte GCM IV is a hard error (no silent software fallback that would key off the seed).

Build options

  • WOLFSSL_REALTEK_HUK + WOLF_CRYPTO_CB enable the device (set in user_settings.h); slot/device IDs are overridable (WC_HUK_DEVID, WC_AMEBAPRO2_*).
  • --enable-amebapro2 builds a host compile-test against a HAL shim (no vendor SDK needed) to exercise the crypto-callback dispatch and build wiring.

Testing

  • Host: --enable-amebapro2 builds clean; default build unaffected.
  • RTL8735B silicon (RealTek FreeRTOS SDK and Zephyr): all of AES-GCM/ECB/CBC/CTR (incl. unaligned buffers, in-place + multi-call CBC, non-12-byte-IV reject) and HUK-bound ECDSA (P-256 signature verifies against the original public key; tampered hash fails) PASS.

Documentation

  • wolfcrypt/src/port/realtek/README.md -- hardware blocks used, enabling, API (AES + the devCtx ECDSA usage), config macros, notes/limitations, on-target benchmarks, and optimization notes (sp_cortexm.c, Thumb-2 asm).
  • wolfssl/wolfcrypt/port/realtek/amebapro2.h -- public API and the wc_AmebaPro2_EccKey context struct.
  • Companion SDK-integration example: wolfssl-examples AmebaPro2/.

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 introduces a new wolfCrypt crypto-callback device port for the RealTek AmebaPro2 (RTL8735B) Hardware Unique Key (HUK), enabling hardware-bound AES operations by deriving per-purpose working keys inside the SoC. It also extends shared DHUK (Device Hardware Unique Key) plumbing and improves STM32 bare-metal integration and robustness in related crypto paths.

Changes:

  • Add RealTek AmebaPro2 (RTL8735B) HUK CryptoCb device (AES-GCM/ECB/CBC/CTR) plus host compile-test shim and documentation.
  • Extend shared DHUK/CCB plumbing (ECC wrapped-private import API, key struct fields, scrubbing) and tighten STM32 family/build-path configuration.
  • Improve STM32 bare-metal support (headers/clock macros) and harden STM32 RNG polling/recovery to avoid infinite loops.

Reviewed changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
zephyr/CMakeLists.txt Adds the AmebaPro2 port source to Zephyr module build.
wolfssl/wolfcrypt/settings.h Adds STM32 family/build-path gating and implies WOLFSSL_DHUK for RealTek HUK builds.
wolfssl/wolfcrypt/port/st/stm32.h Expands STM32 bare-metal support macros, DHUK/CCB gating, and related prototypes.
wolfssl/wolfcrypt/port/realtek/amebapro2.h Public header for registering/unregistering the AmebaPro2 HUK CryptoCb device and config macros.
wolfssl/wolfcrypt/include.am Registers the new RealTek port header for distribution.
wolfssl/wolfcrypt/ecc.h Adds DHUK-related fields to ecc_key and declares wrapped-private import APIs.
wolfssl/wolfcrypt/aes.h Removes legacy STM32U5 DHUK fields and makes devId/devCtx purely CryptoCb-based.
wolfcrypt/src/random.c Adds bounded polling + recovery for STM32 RNG and pulls in STM32 bare clock-enable macros.
wolfcrypt/src/port/st/README.md Updates STM32 port documentation (families, BARE/CubeMX, DHUK, CCB).
wolfcrypt/src/port/realtek/README.md Documents AmebaPro2 HUK port, build options, API usage, and limitations.
wolfcrypt/src/port/realtek/amebapro2.c Implements the AmebaPro2 HUK CryptoCb device (AES paths; ECDSA sign stub).
wolfcrypt/src/port/realtek/amebapro2_shim.h Host compile-test HAL shim for --enable-amebapro2.
wolfcrypt/src/include.am Wires RealTek port sources/docs into the autotools build and distribution lists.
wolfcrypt/src/ecc.c Adds DHUK/CCB key import helpers, scrubbing, and STM32 PKA input-validation parity.
wolfcrypt/src/aes.c Routes STM32 bare AES ops through the bare driver, removes legacy DHUK flow, and stages devKey for CryptoCb.
configure.ac Adds --enable-amebapro2 host compile-test option and wires it to CryptoCb enablement.
.wolfssl_known_macro_extras Adds additional known macros for tooling/source checks related to new ports/STM32 work.

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

Comment thread wolfcrypt/src/ecc.c Outdated
Comment thread wolfcrypt/src/port/realtek/amebapro2.c
@dgarske dgarske force-pushed the realtek_huk branch 2 times, most recently from 4c51469 to 59f1d53 Compare June 15, 2026 21:36
@dgarske dgarske requested a review from Copilot June 15, 2026 21:37

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 2 comments.

Comment thread wolfcrypt/src/port/realtek/amebapro2.c Outdated
Comment thread wolfcrypt/src/port/realtek/amebapro2.c
Binds wolfCrypt AES (GCM/ECB/CBC/CTR) and HUK-bound ECDSA sign to the RTL8735B silicon Hardware Unique Key via the crypto-callback (CryptoCb) framework. A 256-bit seed runs through the HAL secure HKDF key-ladder against the HUK to land a device-bound working key in a secure key-storage slot; the working key never enters software.

Pure crypto-callback device: no new wolfSSL core API or struct fields, and no changes to shared core files. AES reads its seed from the standard aes->devKey; ECDSA reads a port-defined wc_AmebaPro2_EccKey (the HUK-wrapped scalar + seed) the caller attaches via the standard ecc_key->devCtx. The HAL needs 32-byte-aligned DMA buffers, so unaligned iv/aad/in/out are bounced through aligned temporaries.

Enabled with WOLFSSL_REALTEK_HUK + WOLF_CRYPTO_CB; --enable-amebapro2 builds a host compile-test against a HAL shim. Validated on RTL8735B silicon (FreeRTOS SDK and Zephyr): full wolfcrypt_test PASS, the HUK AES modes (incl. unaligned-buffer GCM), and HUK-bound ECDSA (P-256 signature verifies against the original public key). See wolfcrypt/src/port/realtek/README.md.
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