Skip to content

feat(fw): add InitBk3 firmware handler with masked key codec#372

Open
jaygmsft wants to merge 2 commits into
fwfrom
user/jayg/init_bk3
Open

feat(fw): add InitBk3 firmware handler with masked key codec#372
jaygmsft wants to merge 2 commits into
fwfrom
user/jayg/init_bk3

Conversation

@jaygmsft
Copy link
Copy Markdown
Contributor

@jaygmsft jaygmsft commented May 6, 2026

Add the InitBk3 DDI command handler and supporting infrastructure for BK3 initialization and masked key operations.

New modules:

  • fw/core/lib/src/masked_key.rs: AES-CBC-256 + HMAC-SHA-384 masked key envelope codec (mask_cbc/unmask_cbc) using zerocopy for wire-format header serialization
  • fw/core/lib/src/lm_key_derive.rs: live migration key derivation primitives (BK_BOOT key gen, BK_BOOT masking key, session BK, etc.)
  • fw/core/lib/src/ddi/init_bk3.rs: InitBk3 handler — generates BK_BOOT, masks BK3, masks BK_BOOT, stores masked BK_BOOT, returns masked BK3
  • fw/core/ddi/mbor/types/src/masked_key.rs: masked key metadata DDI types

PAL changes:

  • Add derive_masking_key to HsmPartitionManager — KBKDF with BKS1/BKS2 context, keeping device secrets (BKS1, BKS2, fw_secret) inside PAL
  • Add part_masked_bk_boot/part_set_masked_bk_boot for masked BK_BOOT storage on partitions (cleared on free, persists across disable/enable)

DDI integration test results with --features emu (566 total):
32 passed, 534 failed, 0 skipped

DDI smoke test results with --features emu (9 total):
9 passed, 0 failed, 0 skipped

Comment thread fw/core/crypto/key-derive/src/lib.rs Outdated
Comment thread fw/core/crypto/key-mask/src/lib.rs Outdated
Comment thread fw/core/lib/src/masked_key.rs Outdated
Comment thread fw/core/crypto/key-derive/src/lib.rs Outdated
@jaygmsft jaygmsft force-pushed the user/jayg/init_bk3 branch 3 times, most recently from 431438e to 8882e7c Compare May 13, 2026 00:31
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jaygmsft jaygmsft force-pushed the user/jayg/init_bk3 branch 2 times, most recently from 88f83cb to 3b25628 Compare May 19, 2026 03:26
Adds the firmware-side InitBk3 DDI handler that masks a 48-byte BK3
against the partition's 80-byte BK_BOOT using AES-CBC-256 +
HMAC-SHA-384 (encrypt-then-MAC), producing an mcr-hsm-compatible
244-byte MaskedKey wire-format blob.

New crate fw/core/crypto/masked-key/ hosts the wire format and
encode logic.  Public surface:

  - mask_cbc(pal, io, masking_key, plaintext, metadata, out)
  - MASKING_KEY_AES_CBC_256_HMAC_384_LEN

The encoder uses zerocopy-derived #[repr(C)] header structs as the
single layout-of-truth and writes the blob directly into a caller-
supplied DMA buffer (zero-init precondition checked via
plaintext staging.

Also includes:

  - fw/core/ddi/mbor/types/src/masked_key.rs: DdiMaskedKeyMetadata
  - Integration smoke tests in ddi/lib/tests/integration/init_bk3_smoke.rs
  - Copyright/format fixes in unrelated touched crypto files

Validated:
  - 4/4 init_bk3 smoke tests pass against emu
  - 10/10 emu smoke tests pass
  - fmt + copyright clean

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jaygmsft jaygmsft force-pushed the user/jayg/init_bk3 branch from 3b25628 to 822a07d Compare May 19, 2026 03:37
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