Skip to content

Add ECB-wrapped ECC keys and AES key-store slots to the RTL8735B HUK port - #12056

Merged
night1rider merged 1 commit into
wolfSSL:masterfrom
dgarske:rtl8735b_ecb_wrap
Nov 17, 2026
Merged

night1rider merged 1 commit into
wolfSSL:masterfrom
dgarske:rtl8735b_ecb_wrap

Conversation

@dgarske

@dgarske dgarske commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Description

The RTL8735B HUK ECDSA sign path (wc_Rtl8735b_EccKey via ecc_key->devCtx) only accepted an AES-GCM-wrapped scalar, so a blob wrapped with AES-ECB under the HUK, the layout STM32 DHUK uses for wc_ecc_import_wrapped_private(), could not be signed with. It now treats a key with iv, ivSz, tag and tagSz all NULL/0 as ECB-wrapped (block-padded, scalar in the first plainLen bytes), rejects a partial IV/tag set, and leaves GCM unchanged and recommended.

The HUK device also implements the key-store interface (WOLF_CRYPTO_CB_KEYSTORE): wc_KeyStore_ImportWrapped() unwraps an AES key wrapped under the HUK (RFC 3394, or raw ECB like STM32 DHUK blobs) into a hardware key-storage slot, and an Aes made with wc_AesInit_Id() then runs GCM, ECB, CBC or CTR from that slot, so the key is in RAM only during the import. Each operation re-checks its slot under the crypto mutex, so a slot deleted or re-imported while an operation is pending fails with BAD_STATE_E.

Testing

Tested on an RTL8735B EVB with both ECC wrap formats and both AES key-store formats (AES-128 and AES-256), using the example in wolfSSL/wolfssl-examples#655. Host self-test cases cover the format checks, key references, slot bookkeeping, import checks and a round trip through the public wc_KeyStore_* and wc_AesInit_Id() calls, and the rtl8735b CI workflow gains key-store (with and without WOLFSSL_SMALL_STACK) and ECB-only ECC builds.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata +28 B, text +11,720 B (+4.2%, 294,220 B / 67,108,864 B, total: 0% used)
  • RAM: bss +49 B, datas +16 B (+0.1%, 58,423 B / 983,040 B, total: 6% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@dgarske dgarske self-assigned this Nov 6, 2026
@dgarske dgarske changed the title Accept ECB-wrapped ECC scalars in the RTL8735B HUK sign path Add ECB-wrapped ECC keys and AES key-store slots to the RTL8735B HUK port Nov 9, 2026
@dgarske dgarske assigned wolfSSL-Bot and night1rider and unassigned dgarske Nov 11, 2026
@dgarske
dgarske requested a review from night1rider November 11, 2026 21:10

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

Some initial items:

Comment thread wolfcrypt/src/port/realtek/rtl8735b.c Resolved
Comment thread wolfcrypt/src/port/realtek/rtl8735b.c Resolved
Comment thread wolfcrypt/src/port/realtek/rtl8735b.c Resolved
Comment thread wolfcrypt/src/port/realtek/rtl8735b.c Resolved
Comment thread wolfcrypt/src/port/realtek/rtl8735b.c Resolved
Copilot AI balanced review requested due to automatic review settings November 12, 2026 20:57
@dgarske
dgarske requested a review from night1rider November 12, 2026 21:02

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 critical race between key-slot validation and AES execution allows concurrent deletion to zero the key before use, potentially causing successful encryption with an all-zero key.

1 open issue
What changed in this PR

This PR extends the RTL8735B HUK port with ECB-wrapped ECC scalars and hardware-slot AES keys through wolfCrypt’s key-store interface, while retaining GCM as the recommended ECC wrapping format.

Changes:

  • Adds ECB scalar unwrapping and rejects partial IV/tag parameters.
  • Adds AES key import, deletion and slot-backed GCM, ECB, CBC and CTR operations.
  • Expands documentation, host self-tests and CI coverage.
File Description
wolfssl/​wolfcrypt/​port/​realtek/​rtl8735b.h Defines slot configuration, key references and wrapping contracts.
wolfcrypt/​src/​port/​realtek/​rtl8735b.c Implements wrapping support, key-store operations and host checks.
wolfcrypt/​src/​port/​realtek/​rtl8735b_shim.h Adds a host stub for hardware key-slot writes.
wolfcrypt/​src/​port/​realtek/​README.md Documents ECB-wrapped scalars and slot-backed AES usage.
.github/​workflows/​rtl8735b.yml Adds key-store build and self-test coverage.

Review effort: Balanced

Comment thread wolfcrypt/src/port/realtek/rtl8735b.c Resolved
@dgarske
dgarske force-pushed the rtl8735b_ecb_wrap branch 2 times, most recently from 436284b to b87d4f3 Compare November 13, 2026 21:52
@dgarske

dgarske commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Jenkins retest this please

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

Some last items I saw, along with:

Key-store slots are never exercised through the public API by any in-repo test, is this something we need?

Comment thread wolfcrypt/src/port/realtek/rtl8735b.c Resolved
Comment thread .github/workflows/rtl8735b.yml Resolved
@dgarske dgarske self-assigned this Nov 16, 2026
@dgarske
dgarske requested a review from night1rider November 16, 2026 17:34
@dgarske dgarske removed their assignment Nov 16, 2026
@night1rider

Copy link
Copy Markdown
Contributor

Jenkins Retest this please

@night1rider
night1rider merged commit 94efa96 into wolfSSL:master Nov 17, 2026
449 checks passed
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