Skip to content

feat(tbor): implement SdSealingKeyGen (masked sealing key)#536

Merged
vsonims merged 3 commits into
mainfrom
sd/sealing-key-gen
Jul 13, 2026
Merged

feat(tbor): implement SdSealingKeyGen (masked sealing key)#536
vsonims merged 3 commits into
mainfrom
sd/sealing-key-gen

Conversation

@vsonims

@vsonims vsonims commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implement the firmware TBOR SdSealingKeyGen command (previously schema-only). Within an active Crypto-Officer session on an Initialized partition, it generates a fresh P-384 ECC sealing keypair for ECDH key agreement and returns the masked private key plus the public key. Maps to manticore CreateSDSealingKey -> ..., MaskedSDSealingKey.

The private key is not stored on the device: it is masked (AEAD-GCM-256) under the masking key associated with the requested KeyScope, and the masked blob is returned so the caller re-imports it (unmask-on-use) when the key is later needed. Because nothing is persisted, the command records no rollback (no undo-log dependency).

Handler (fw/core/lib/src/ddi/tbor/sd_sealing_key_gen.rs)

  • Gate: Crypto-Officer-only (InvalidPermissions); session Active; partition Initialized (the scope masking keys are provisioned by PartFinal).
  • Scope → masking key: Ephemeral → PartitionEphemeralMaskingKey, Local → PartitionLocalMaskingKey. Session and SecurityDomain (and any other) are rejected with the new UnsupportedKeyScope error until their masking keys exist (session-key masking / CreateSD's SDKMK).
  • Generate the P-384 keypair (KeyAgreement PCT), mask the private scalar under the scope's key, and return (masked_key 180 B, pub_key 96 B). The SdSealing vault kind is retained as the masked blob's metadata key_kind; it is no longer stored.
  • Structured into focused helpers: generate_sealing_keypair / mask_sealing_private_key / encode_sealing_response.

Schema + dispatch

  • Response masked_key (180 B AEAD envelope) replaces key_handle in both the firmware and host crates; add MASKED_SEALING_KEY_LEN.
  • Add HsmError::UnsupportedKeyScope (0x08700102) + TborStatus mirror.
  • Wire SD_SEALING_KEY_GEN (0x09) into the opcode table, dispatcher, is_known_opcode / is_in_session / session-id cross-check classifiers.
  • Add the SdSealing vault key kind (P-384 private) to the PAL traits enum, std PAL, and Uno key_vault length tables.

Tests + docs

  • emu tests (ddi/tbor/types): happy-path roundtrip for Ephemeral + Local (distinct keypair per call, non-zero 180 B masked key + 96 B pub key), unsupported-scope reject (Session/SecurityDomain), before-finalize reject (InvalidArg), CU-session reject (InvalidPermissions), and default-PSK gate reject.
  • Update docs/tbor-ddi/commands/sd_sealing_key_gen.md.

Notes

Validation

  • Full host workspace build + Uno firmware (thumbv7em) build.
  • tbor-emu suite: 88/88 (7 SdSealingKeyGen tests).
  • clippy -D warnings + nightly fmt clean.

Copilot AI review requested due to automatic review settings July 11, 2026 15:21

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

Implements the firmware-side TBOR SdSealingKeyGen command (opcode 0x09) end-to-end across firmware, host types, docs, and emu tests. The command generates a fresh P-384 sealing keypair and returns a masked private key blob plus the public key (with scope-gated masking key selection), rather than persisting the private key on-device.

Changes:

  • Add the firmware handler and wire the opcode into session control classification + TBOR dispatcher known/in-session/cross-check gates.
  • Update TBOR schemas/host wrappers to return (masked_key[180], pub_key[96]) and introduce UnsupportedKeyScope status/error for unimplemented scope backing keys.
  • Extend vault key-kind enums + key length tables (std PAL + Uno key_vault) and add emu integration tests and documentation updates.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
fw/core/lib/src/ddi/tbor/sd_sealing_key_gen.rs New firmware handler that generates a P-384 keypair, masks the private scalar under a scope MK, and encodes the response.
fw/core/lib/src/ddi/tbor/mod.rs Registers the new handler and classifies the opcode as known/in-session/needs session-id cross-check.
fw/core/lib/src/op.rs Classifies SD_SEALING_KEY_GEN as SessionCtrl::InSession.
fw/pal/traits/src/error.rs Adds HsmError::UnsupportedKeyScope for well-formed but not-yet-supported scopes.
ddi/tbor/types/src/status.rs Adds TborStatus::UnsupportedKeyScope mirroring the new firmware error.
fw/core/ddi/tbor/types/src/sd_sealing_key_gen.rs Updates firmware-side TBOR schema to return masked key + public key; exports pinned length consts and tests them.
ddi/tbor/types/src/sd_sealing_key_gen.rs Updates host-side wrapper schema/response to return fixed-size masked key + public key arrays.
fw/pal/traits/src/vault.rs Adds HsmVaultKeyKind::SdSealing and documents the sealing-key kind.
fw/plat/std/pal/src/drivers/vault.rs Adds size mapping + tests for SdSealing (48-byte P-384 scalar).
fw/plat/uno/fw/crates/key_vault/src/kind.rs Extends Uno key-kind length table + tests for SdSealing.
ddi/tbor/types/tests/commands/sd_sealing_key_gen.rs Adds emulator integration tests covering happy paths, unsupported scopes, pre-finalize reject, CU reject, and default-PSK gate.
ddi/tbor/types/tests/commands/mod.rs Exposes the new command test module.
docs/tbor-ddi/README.md Marks SdSealingKeyGen as implemented (not schema-only).
docs/tbor-ddi/commands/sd_sealing_key_gen.md Updates command documentation to match masked-key response and new gating/errors.

Comment thread fw/core/lib/src/ddi/tbor/sd_sealing_key_gen.rs Outdated
Comment thread fw/core/lib/src/ddi/tbor/mod.rs Outdated
Comment thread fw/core/lib/src/ddi/tbor/sd_sealing_key_gen.rs
Comment thread fw/pal/traits/src/vault.rs

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 14 out of 14 changed files in this pull request and generated 2 comments.

Comment thread fw/core/lib/src/ddi/tbor/mod.rs
Comment thread docs/tbor-ddi/commands/sd_sealing_key_gen.md Outdated
Copilot AI review requested due to automatic review settings July 11, 2026 16:05
@vsonims vsonims force-pushed the sd/sealing-key-gen branch from 152754c to a67ca71 Compare July 11, 2026 16:05

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 14 out of 14 changed files in this pull request and generated 2 comments.

Comment thread fw/pal/traits/src/vault.rs
Comment thread docs/tbor-ddi/commands/sd_sealing_key_gen.md Outdated
Copilot AI review requested due to automatic review settings July 11, 2026 16:21
@vsonims vsonims force-pushed the sd/sealing-key-gen branch from a67ca71 to b8212fe Compare July 11, 2026 16:21

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 14 out of 14 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 11, 2026 16:33
@vsonims vsonims force-pushed the sd/sealing-key-gen branch from b8212fe to a144d5c Compare July 11, 2026 16:33

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 14 out of 14 changed files in this pull request and generated 1 comment.

Comment thread fw/core/lib/src/ddi/tbor/sd_sealing_key_gen.rs Outdated
Copilot AI review requested due to automatic review settings July 11, 2026 16:44
@vsonims vsonims force-pushed the sd/sealing-key-gen branch from a144d5c to 34d2dcc Compare July 11, 2026 16:44

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 16 out of 16 changed files in this pull request and generated 4 comments.

Comment thread fw/core/ddi/tbor/types/src/sd_sealing_key_gen.rs Outdated
Comment thread fw/core/ddi/tbor/types/src/sd_sealing_key_gen.rs Outdated
Comment thread ddi/tbor/types/src/sd_sealing_key_gen.rs Outdated
Comment thread docs/tbor-ddi/commands/sd_sealing_key_gen.md Outdated
Copilot AI review requested due to automatic review settings July 11, 2026 16:50
@vsonims vsonims force-pushed the sd/sealing-key-gen branch from 34d2dcc to e833504 Compare July 11, 2026 16:50
radutta99
radutta99 previously approved these changes Jul 13, 2026

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

Looks good.

@vsonims vsonims enabled auto-merge July 13, 2026 20:42
@vsonims vsonims marked this pull request as draft July 13, 2026 20:42
auto-merge was automatically disabled July 13, 2026 20:42

Pull request was converted to draft

@vsonims vsonims marked this pull request as ready for review July 13, 2026 20:42
@vsonims

vsonims commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot resolve the merge conflicts in this pull request

Co-authored-by: vsonims <39780523+vsonims@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 13, 2026 20:49
@vsonims vsonims removed the request for review from Copilot July 13, 2026 20:49

Copilot AI commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Resolved the merge conflict and merged origin/main into this branch in baf44c10.

@vsonims vsonims enabled auto-merge July 13, 2026 20:50
@radutta99 radutta99 self-requested a review July 13, 2026 20:52
radutta99
radutta99 previously approved these changes Jul 13, 2026
@vsonims

vsonims commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot resolve the merge conflicts in this pull request

Co-authored-by: vsonims <39780523+vsonims@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 13, 2026 21:26
@vsonims vsonims removed the request for review from Copilot July 13, 2026 21:26

Copilot AI commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Resolved the new merge conflicts and merged the current origin/main into this branch in c1b9b67.

@vsonims vsonims added this pull request to the merge queue Jul 13, 2026
@vsonims vsonims removed this pull request from the merge queue due to a manual request Jul 13, 2026
@vsonims vsonims added this pull request to the merge queue Jul 13, 2026
Merged via the queue into main with commit a165ce6 Jul 13, 2026
25 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