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:
- Mechanisms in ta/pkcs11/include/pkcs11_ta.h:
- PKCS11_CKM_HKDF_DERIVE (0x402)
- PKCS11_CKM_HKDF_DATA (0x403)
- PKCS11_CKM_HKDF_KEY_GEN(0x401)
- Parameters: serialize CK_HKDF_PARAMS (extract/expand flags, PRF hash, salt source — DATA/KEY/NULL, info) over the existing TA params-blob format.
- 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.
- Token capabilities / mechanism info: advertise the mechanisms with CKF_DERIVE in token_capabilities.c.
- 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
- 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.
- Preferred mechanism numbering — adopt the v3.0 standard values (0x401–0x403) directly, as done for other v3.0-era mechanisms?
- 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?
- 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.
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:
older per-hash TEE_ALG_HKDF__DERIVE_KEY family). The crypto is there; only the PKCS#11 surface is missing.
Proposal
Add the standard PKCS#11 v3.0 HKDF surface to the PKCS#11 TA:
- PKCS11_CKM_HKDF_DERIVE (0x402)
- PKCS11_CKM_HKDF_DATA (0x403)
- PKCS11_CKM_HKDF_KEY_GEN(0x401)
Open questions for upstream
If there's interest, I'll work on and submit the PRs.