Skip to content

[feat][TBOR] ECC gen sign Host API - #699

Open
Rajesh Gali (rajesh-gali) wants to merge 7 commits into
mainfrom
user/rajeshgali/tbor-ecc-gen-sign-hostapi
Open

[feat][TBOR] ECC gen sign Host API#699
Rajesh Gali (rajesh-gali) wants to merge 7 commits into
mainfrom
user/rajeshgali/tbor-ecc-gen-sign-hostapi

Conversation

@rajesh-gali

@rajesh-gali Rajesh Gali (rajesh-gali) commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

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:
    • Refactored ecc_generate_key to dispatch between MBOR and TBOR flows, with TBOR now supporting explicit key_usage and key_label fields, 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]
    • Updated documentation to clarify the returned tuple for ECC key generation, now including device-returned key properties for both private and public keys.

TBOR Types and Test Updates

  • ddi/tbor/types/src/ecc_generate_key.rs:

    • Added key_usage (u64) and key_label (Vec) fields to TborEccGenerateKeyReq, with updated documentation and derive attributes. [1] [2]
    • Updated unit tests to cover the new fields and ensure proper encoding.
  • Test files (ddi/tbor/types/tests/commands/*.rs):

    • Updated all TBOR ECC key generation test helpers and cases to supply the new key_usage and key_label fields, 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:
    • Adjusted ECC scalar payload length calculation to ensure wire-format keys are zero-padded to a 4-byte-aligned length, matching the TBOR protocol (e.g., P-521: 66→68 bytes).

New Integration Test for TBOR ECC

  • api/tests/src/algo/ecc/sign_tests.rs:
    • Added a comprehensive test (test_ecc_sign_verify_tbor_all_curves) to validate TBOR ECC key generation, signing, and verification across all supported curves, including wire-format conversions.

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

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) and key_label propagation into masked-key metadata, enforcing valid usage combinations in firmware.
  • Update TBOR KeyUsage encoding from U8 to U64 and 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.

Comment thread ddi/tbor/types/tests/commands/ecc_generate_key.rs
@rajesh-gali
Rajesh Gali (rajesh-gali) force-pushed the user/rajeshgali/tbor-aes-keylabel-hostapi branch from cc8a54f to a79086d Compare September 5, 2026 02:27
@rajesh-gali
Rajesh Gali (rajesh-gali) force-pushed the user/rajeshgali/tbor-ecc-gen-sign-hostapi branch from 5122c56 to 035ff4f Compare September 5, 2026 02:46
@rajesh-gali
Rajesh Gali (rajesh-gali) force-pushed the user/rajeshgali/tbor-ecc-gen-sign-hostapi branch from 035ff4f to ba5f1ce Compare September 5, 2026 20:42
@rajesh-gali
Rajesh Gali (rajesh-gali) marked this pull request as ready for review September 5, 2026 20:42
@rajesh-gali
Rajesh Gali (rajesh-gali) changed the base branch from user/rajeshgali/tbor-aes-keylabel-hostapi to main September 5, 2026 20:43

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

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

Comment thread api/lib/src/ddi/ecc.rs Outdated
Comment thread api/lib/src/ddi/ecc.rs Outdated
Comment on lines +149 to +150
let key_label = alloc.dma_alloc(caller_label.len())?;
key_label.copy_from_slice(caller_label);
@rajesh-gali Rajesh Gali (rajesh-gali) changed the title User/rajeshgali/tbor ecc gen sign hostapi [feat][TBOR] ECC gen sign Host API Sep 8, 2026
Copilot AI review requested due to automatic review settings September 9, 2026 19:42

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

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

Comment thread api/lib/src/ddi/ecc.rs
Comment thread api/lib/src/ddi/ecc.rs
Comment thread fw/core/lib/src/ddi/tbor/ecc_generate_key.rs
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