[feat][TBOR] ECC gen sign Host API - #699
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new firmware-enforced ECC key_usage contract is not covered by a negative integration test case, risking silent regressions.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR extends the SDK’s TBOR (V2) ECC flow so hosts can generate ECC keys with explicit usage (sign vs derive) and an optional key label, and then sign using caller-held masked keys while handling TBOR wire endianness/padding differences.
Changes:
- Add TBOR ECC keygen support for
key_usage(u64 bitfield) andkey_labelpropagation into masked-key metadata, enforcing valid usage combinations in firmware. - Update TBOR
KeyUsageencoding fromU8toU64and adjust host-side constants/tests accordingly. - Fix TBOR masked-key parsing and add host-side conversions for TBOR ECC public keys/signatures (LE wire format, P-521 padding).
File summaries
| File | Description |
|---|---|
| fw/core/lib/src/ddi/tbor/ecc_generate_key.rs | Enforces TBOR ECC key_usage contract and stores caller key_label into masked metadata. |
| fw/core/ddi/tbor/types/src/unwrap_key.rs | Changes key_usage wire type to #[tbor(U64)]. |
| fw/core/ddi/tbor/types/src/key_props.rs | Expands KeyUsage storage/bit constants from u8 to u64. |
| fw/core/ddi/tbor/types/src/ecc_generate_key.rs | Adds key_usage + key_label to the TBOR ECC keygen schema. |
| ddi/tbor/types/tests/commands/unwrap_key.rs | Updates unwrap-key test helpers to use u64 usage. |
| ddi/tbor/types/tests/commands/rsa_mod_exp.rs | Updates helper signature to accept u64 usage. |
| ddi/tbor/types/tests/commands/hkdf_derive.rs | Supplies TBOR ECC keygen key_usage/key_label in derive-related tests. |
| ddi/tbor/types/tests/commands/ecdh_derive.rs | Supplies TBOR ECC keygen key_usage/key_label in ECDH tests. |
| ddi/tbor/types/tests/commands/ecc_sign.rs | Supplies TBOR ECC keygen key_usage/key_label for signing tests. |
| ddi/tbor/types/tests/commands/ecc_generate_key.rs | Updates ECC keygen tests to populate new request fields. |
| ddi/tbor/types/tests/commands/concat_kdf_derive.rs | Supplies TBOR ECC keygen key_usage/key_label in concat-KDF tests. |
| ddi/tbor/types/src/unwrap_key.rs | Updates host-facing unwrap-key request to use u64 usage bits/constants. |
| ddi/tbor/types/src/ecc_generate_key.rs | Adds host-facing TBOR ECC keygen request fields (key_usage, key_label). |
| api/tests/src/algo/ecc/sign_tests.rs | Adds end-to-end TBOR ECC sign/verify test across all supported curves. |
| api/lib/src/ddi/masked_key.rs | Adjusts TBOR ECC scalar payload length to 4-byte-aligned wire length (P-521 66→68). |
| api/lib/src/ddi/ecc.rs | Implements TBOR ECC keygen/sign paths and wire↔DER/signature conversions. |
Review details
- Files reviewed: 16/16 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
cc8a54f to
a79086d
Compare
5122c56 to
035ff4f
Compare
035ff4f to
ba5f1ce
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The V2 DERIVE path is unusable through the public ECDH API, and TBOR public-key responses need exact length validation.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (1)
api/lib/src/ddi/ecc.rs:369
- As with the public-key response, this minimum-length check accepts noncanonical signature lengths even though firmware defines one exact wire size per curve (64/96/136 bytes). An oversized response with zero extension can pass
strip_leading_zero_pad; reject any size other than two word-aligned curve components.
let coord = curve.component_size();
let half = wire_sig.len() / 2;
if half < coord {
return Err(HsmError::InternalError);
- Files reviewed: 11/11 changed files
- Comments generated: 3
- Review effort level: Balanced
| let key_label = alloc.dma_alloc(caller_label.len())?; | ||
| key_label.copy_from_slice(caller_label); |
There was a problem hiding this comment.
🟡 Changes recommended
TBOR signing rejects supported digest and curve combinations, and new validation paths need coverage.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 11/11 changed files
- Comments generated: 3
- Review effort level: Balanced
This pull request introduces significant improvements to the ECC (Elliptic Curve Cryptography) key generation and signing flows, especially for the V2 (TBOR) protocol, and updates the relevant types, helpers, and tests to support these changes. The main changes include adding explicit key usage and label fields to TBOR ECC key generation, handling wire-format conversions for keys and signatures, and ensuring that the public and private key properties are correctly mapped and validated.
TBOR ECC Key Generation and Signing Enhancements
api/lib/src/ddi/ecc.rs:ecc_generate_keyto dispatch between MBOR and TBOR flows, with TBOR now supporting explicitkey_usageandkey_labelfields, and proper conversion of wire-format keys to DER. Added helpers for key usage mapping, curve discriminant translation, and public key property derivation. Also, implemented TBOR-specific signing, including digest and signature byte order conversions. [1] [2] [3] [4]TBOR Types and Test Updates
ddi/tbor/types/src/ecc_generate_key.rs:key_usage(u64) andkey_label(Vec) fields toTborEccGenerateKeyReq, with updated documentation and derive attributes. [1] [2]Test files (
ddi/tbor/types/tests/commands/*.rs):key_usageandkey_labelfields, using the appropriate constants for signing or derivation. [1] [2] [3] [4] [5] [6] [7] [8] [9]Wire Format and Padding Handling
api/lib/src/ddi/masked_key.rs:New Integration Test for TBOR ECC
api/tests/src/algo/ecc/sign_tests.rs:test_ecc_sign_verify_tbor_all_curves) to validate TBOR ECC key generation, signing, and verification across all supported curves, including wire-format conversions.