Skip to content

RFC: Add HKDF Key Derivation to the PKCS11 TA #7825

Description

@Hussainity

Hi all,

The OP-TEE PKCS#11 TA currently supports a small set of C_DeriveKey mechanisms: CKM_ECDH1_DERIVE and CKM_AES_{ECB,CBC}_ENCRYPT_DATA. HKDF (RFC 5869) is missing, even though:

  • HKDF is a standard KDF for many modern protocols
  • OP-TEE already implements HKDF in libutee as a GlobalPlatform extension (TEE_ALG_HKDF, TEE_ATTR_HKDF_{SALT,INFO}, plus the
    older per-hash TEE_ALG_HKDF__DERIVE_KEY family). The crypto is there; only the PKCS#11 surface is missing.
  • PKCS#11 v3.0 standardized CKM_HKDF_DERIVE, CKM_HKDF_DATA, and CKM_HKDF_KEY_GEN with CK_HKDF_PARAMS.

Proposal

Add the standard PKCS#11 v3.0 HKDF surface to the PKCS#11 TA:

  1. Mechanisms in ta/pkcs11/include/pkcs11_ta.h:
    - PKCS11_CKM_HKDF_DERIVE (0x402)
    - PKCS11_CKM_HKDF_DATA (0x403)
    - PKCS11_CKM_HKDF_KEY_GEN(0x401)
  2. Parameters: serialize CK_HKDF_PARAMS (extract/expand flags, PRF hash, salt source — DATA/KEY/NULL, info) over the existing TA params-blob format.
  3. Wiring: route PKCS11_FUNCTION_DERIVE for these mechanisms through a new derive_key_hkdf() in processing.c, backed by TEE_ALG_HKDF from libutee. Validate base-key type (CKK_GENERIC_SECRET / CKK_HKDF) and CKA_DERIVE.
  4. Token capabilities / mechanism info: advertise the mechanisms with CKF_DERIVE in token_capabilities.c.
  5. Tests: extend the optee_test xtest PKCS#11 suite with RFC 5869 test vectors (extract-only, expand-only, and combined; salt-as-key vs salt-as-data).

Open questions for upstream

  1. Scope — all three mechanisms, or just CKM_HKDF_DERIVE? CKM_HKDF_DERIVE covers the protocol-KDF use case on its own. CKM_HKDF_DATA (output as raw data, not a key object) and CKM_HKDF_KEY_GEN (generate an HKDF base key) round out the v3.0 surface but aren't strictly required for the motivating use cases. Happy to land just CKM_HKDF_DERIVE first if that's acceptable.
  2. Preferred mechanism numbering — adopt the v3.0 standard values (0x401–0x403) directly, as done for other v3.0-era mechanisms?
  3. Should CKK_HKDF be added as a distinct key type, or is folding HKDF base keys onto CKK_GENERIC_SECRET (current practice for HMAC keys here) acceptable?
  4. Any objection to depending on the OP-TEE TEE_ALG_HKDF extension rather than implementing HKDF inside the TA from the per-hash TEE_ALG_HKDF__DERIVE_KEY primitives?

If there's interest, I'll work on and submit the PRs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions