Skip to content

Add CryptoEngine and KeyVault HAL interfaces#387

Open
Ulrond wants to merge 5 commits intodevelopfrom
feature/385-add-cryptoengine-and-keyvault
Open

Add CryptoEngine and KeyVault HAL interfaces#387
Ulrond wants to merge 5 commits intodevelopfrom
feature/385-add-cryptoengine-and-keyvault

Conversation

@Ulrond
Copy link
Copy Markdown
Collaborator

@Ulrond Ulrond commented Apr 1, 2026

Summary

  • Adds CryptoEngine HAL (com.rdk.hal.cryptoengine) — standalone crypto operations with TEE or software backend. Session-based streaming model and one-shot convenience methods.
  • Adds KeyVault HAL (com.rdk.hal.keyvault) — secure key storage with named vault instances. Keys stay inside the TEE; callers interact through opaque aliases.

Design

  • Separation of concerns: KeyVault manages key storage and lifecycle. CryptoEngine performs crypto operations. The vault attaches a CryptoEngine for operations on vault-managed keys. The CryptoEngine has no awareness of the vault.
  • TEE architecture: CryptoEngine is the only REE component that talks to the TA. KeyVault delegates all crypto to the attached engine. Key material never enters REE memory in plaintext.
  • Per-vault encryption: Each vault has its own encryption key derived from OTP root by the TA. Encrypted blobs stored on persistent storage by the KeyVault HAL.
  • Key metadata: KeyDescriptor carries algorithm, type, usages, digest — bound at creation time.
  • IV auto-generation: When IV is null, engine generates a random IV and prepends it to ciphertext. Caller stores the whole blob.

New Files (27)

CryptoEngine (17 files)

  • ICryptoEngine.aidl — service manager, capabilities, session open/close
  • ICryptoEngineController.aidl — streaming and one-shot operations (encrypt, decrypt, sign, verify, hash, HMAC, derive, random)
  • ICryptoOperation.aidl — in-progress operation handle (update/finish/abort)
  • Enums: Algorithm, BlockMode, Digest, EcCurve, KeyDerivation, KeyPurpose, KeyType, PaddingMode, SecurityLevel
  • Parcelables: CryptoConfig, EngineCapabilities
  • HFP + metadata + CMakeLists.txt

KeyVault (10 files)

  • IKeyVault.aidl — vault enumeration, session open/close, runtime vault create/destroy
  • IKeyVaultController.aidl — key lifecycle (generateKey, generateKeyPair, importKey, exportKey, deleteKey, rotateKey), crypto engine attachment, deriveIntoVault
  • IKeyVaultEventListener.aidl — async callbacks for state changes, key expiry/invalidation/rotation
  • Parcelables: KeyDescriptor, DerivedKeySpec, VaultCapabilities
  • Enum: VaultState
  • HFP + metadata + CMakeLists.txt

Test plan

  • AIDL compiles with compile_aidl from the repo root CMake
  • KeyVault CMakeLists.txt correctly resolves cross-module CryptoEngine imports
  • Review all Javadoc for completeness and accuracy
  • Validate HFP YAML against schema

Closes #385
Relates to #130

Introduces two new HAL modules for platform cryptography:

CryptoEngine (com.rdk.hal.cryptoengine):
- Standalone crypto operations with TEE or software backend
- Session-based streaming (begin/update/finish) and one-shot methods
- AES, RSA, EC, HMAC, ChaCha20-Poly1305, key derivation (HKDF, PBKDF2, DH, NFLX-DH)
- IV auto-generation with prepend convention
- Hardware RNG support

KeyVault (com.rdk.hal.keyvault):
- Secure key storage with named vault instances
- Key material stays inside TEE via attached CryptoEngine
- Key metadata (algorithm, type, usages) bound at creation time
- Keypair generation for asymmetric algorithms
- Generic derive-into-vault for all KDF types
- Per-vault OTP-derived encryption, HMAC-authenticated keystores
- Platform-provisioned and application-created vaults via HFP

Closes #385
Relates to #130
Copilot AI review requested due to automatic review settings April 1, 2026 21:07
@Ulrond Ulrond linked an issue Apr 1, 2026 that may be closed by this pull request
@github-project-automation github-project-automation bot moved this to Architecture Review Required in halif_aidl Apr 1, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds two new AIDL-based HAL modules to the repo: CryptoEngine (com.rdk.hal.cryptoengine) for cryptographic operations, and KeyVault (com.rdk.hal.keyvault) for key storage/lifecycle with vault instances, along with their build (CMake), metadata, and HFP definitions.

Changes:

  • Introduces the CryptoEngine AIDL API surface (manager, controller, operation handle, enums, and parcelables) plus its HFP and module metadata.
  • Introduces the KeyVault AIDL API surface (manager, controller, event listener, parcelables/enums) plus its HFP and module metadata.
  • Adds module-level CMake integration for AIDL compilation for both new modules.

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
cryptoengine/metadata.yaml Adds CryptoEngine module metadata (scope/ownership/dependencies).
cryptoengine/current/hfp-cryptoengine.yaml Adds CryptoEngine HAL Feature Profile (supported algorithms/modes/digests/etc.).
cryptoengine/current/CMakeLists.txt Adds module CMake to compile CryptoEngine AIDL.
cryptoengine/current/com/rdk/hal/cryptoengine/ICryptoEngine.aidl Defines CryptoEngine manager interface (capabilities, open/close).
cryptoengine/current/com/rdk/hal/cryptoengine/ICryptoEngineController.aidl Defines per-session crypto operations (begin/update/finish via ICryptoOperation + one-shot APIs).
cryptoengine/current/com/rdk/hal/cryptoengine/ICryptoOperation.aidl Defines streaming operation handle (update/finish/abort).
cryptoengine/current/com/rdk/hal/cryptoengine/CryptoConfig.aidl Defines operation configuration parcelable (algo/mode/iv/aad/kdf/etc.).
cryptoengine/current/com/rdk/hal/cryptoengine/EngineCapabilities.aidl Defines runtime capabilities parcelable for CryptoEngine instances.
cryptoengine/current/com/rdk/hal/cryptoengine/Algorithm.aidl Adds algorithm enum.
cryptoengine/current/com/rdk/hal/cryptoengine/BlockMode.aidl Adds block mode enum.
cryptoengine/current/com/rdk/hal/cryptoengine/Digest.aidl Adds digest enum.
cryptoengine/current/com/rdk/hal/cryptoengine/EcCurve.aidl Adds elliptic curve enum.
cryptoengine/current/com/rdk/hal/cryptoengine/KeyDerivation.aidl Adds key derivation function enum.
cryptoengine/current/com/rdk/hal/cryptoengine/KeyPurpose.aidl Adds key purpose enum (used for operation type / key usages).
cryptoengine/current/com/rdk/hal/cryptoengine/KeyType.aidl Adds key type enum.
cryptoengine/current/com/rdk/hal/cryptoengine/PaddingMode.aidl Adds padding mode enum.
cryptoengine/current/com/rdk/hal/cryptoengine/SecurityLevel.aidl Adds security level enum (SOFTWARE/TEE).
keyvault/metadata.yaml Adds KeyVault module metadata (scope/ownership/dependencies).
keyvault/current/hfp-keyvault.yaml Adds KeyVault HAL Feature Profile (vault instances and constraints).
keyvault/current/CMakeLists.txt Adds module CMake to compile KeyVault AIDL (with CryptoEngine imports).
keyvault/current/com/rdk/hal/keyvault/IKeyVault.aidl Defines KeyVault manager interface (enumeration, open/close, create/destroy vault).
keyvault/current/com/rdk/hal/keyvault/IKeyVaultController.aidl Defines per-session vault controller (key lifecycle, derivation, engine attachment, listeners).
keyvault/current/com/rdk/hal/keyvault/IKeyVaultEventListener.aidl Defines async vault/key event listener interface.
keyvault/current/com/rdk/hal/keyvault/KeyDescriptor.aidl Defines key metadata parcelable (alias, algorithm, usages, etc.).
keyvault/current/com/rdk/hal/keyvault/DerivedKeySpec.aidl Defines derive-into-vault output key specification parcelable.
keyvault/current/com/rdk/hal/keyvault/VaultCapabilities.aidl Defines vault capability parcelable (limits, persistence, storage usage).
keyvault/current/com/rdk/hal/keyvault/VaultState.aidl Defines vault state enum.

Comment on lines +32 to +45
ENCRYPT = 0,
DECRYPT = 1,
SIGN = 2,
VERIFY = 3,
/** Key agreement (ECDH, DH). */
AGREE_KEY = 4,
/** Wrap a key for transport or storage (AES-KW, RSA-OAEP). */
WRAP_KEY = 5,
/** Unwrap a wrapped key. */
UNWRAP_KEY = 6,
/** Derive a new key from this key (HKDF, PBKDF2, NFLX-DH). */
DERIVE_KEY = 7,
/** Derive raw secret bits from a key. */
DERIVE_BITS = 8,
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KeyPurpose is documented and used as a bitmask (e.g. KeyDescriptor.usages / DerivedKeySpec.usages), but the enum values here are sequential (ENCRYPT=0, DECRYPT=1, …). With a bitmask, each purpose must be a distinct power-of-two flag (and typically 0 means "no purposes"), otherwise OR-ing values will lose information (e.g. ENCRYPT|DECRYPT collapses to 1). Consider either (a) changing KeyPurpose values to bit flags (1<<n) and updating docs, or (b) changing the APIs to use KeyPurpose[] (or a dedicated KeyUsageFlags enum) instead of int bitmasks.

Suggested change
ENCRYPT = 0,
DECRYPT = 1,
SIGN = 2,
VERIFY = 3,
/** Key agreement (ECDH, DH). */
AGREE_KEY = 4,
/** Wrap a key for transport or storage (AES-KW, RSA-OAEP). */
WRAP_KEY = 5,
/** Unwrap a wrapped key. */
UNWRAP_KEY = 6,
/** Derive a new key from this key (HKDF, PBKDF2, NFLX-DH). */
DERIVE_KEY = 7,
/** Derive raw secret bits from a key. */
DERIVE_BITS = 8,
/** No permitted purposes (empty usage bitmask). */
NONE = 0,
ENCRYPT = 1 << 0,
DECRYPT = 1 << 1,
SIGN = 1 << 2,
VERIFY = 1 << 3,
/** Key agreement (ECDH, DH). */
AGREE_KEY = 1 << 4,
/** Wrap a key for transport or storage (AES-KW, RSA-OAEP). */
WRAP_KEY = 1 << 5,
/** Unwrap a wrapped key. */
UNWRAP_KEY = 1 << 6,
/** Derive a new key from this key (HKDF, PBKDF2, NFLX-DH). */
DERIVE_KEY = 1 << 7,
/** Derive raw secret bits from a key. */
DERIVE_BITS = 1 << 8,

Copilot uses AI. Check for mistakes.
* @brief Handle for an in-progress cryptographic operation.
* @author Gerald Weatherup
*
* Returned by ICryptoEngineController.begin() or IKeyVaultController.begin().
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docstring says ICryptoOperation is returned by IKeyVaultController.begin(), but IKeyVaultController does not define a begin() method. Please update the comment to reference only existing APIs (or add the missing begin() method if that is the intended design).

Suggested change
* Returned by ICryptoEngineController.begin() or IKeyVaultController.begin().
* Returned by ICryptoEngineController.begin().

Copilot uses AI. Check for mistakes.
Comment on lines +234 to +237
* (referenced by alias in config.keyAlias) and have DERIVE_KEY usage.
*
* @param config Crypto configuration for the derivation (kdf, digest, salt, info, etc.).
* config.keyData is ignored — the source key is taken from the vault.
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deriveIntoVault() docs reference config.keyAlias, but CryptoConfig does not have a keyAlias field. This is confusing for callers and makes the source-key selection rules unclear. Please update the documentation to match the actual API (it looks like sourceKeyAlias is the authoritative parameter) and remove/replace the keyAlias reference.

Suggested change
* (referenced by alias in config.keyAlias) and have DERIVE_KEY usage.
*
* @param config Crypto configuration for the derivation (kdf, digest, salt, info, etc.).
* config.keyData is ignored the source key is taken from the vault.
* (referenced by the sourceKeyAlias parameter) and have DERIVE_KEY usage.
*
* @param config Crypto configuration for the derivation (kdf, digest, salt, info, etc.).
* config.keyData is ignored the source key is taken from the vault using sourceKeyAlias.

Copilot uses AI. Check for mistakes.
* @brief Register for vault lifecycle events (deep sleep, key invalidation).
*
* @param listener The event listener to register.
* @post listener receives onDeviceSuspending/onDeviceResumed/onKeyInvalidated callbacks.
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

registerEventListener() documentation lists callbacks onDeviceSuspending/onDeviceResumed, but IKeyVaultEventListener does not define these methods. Please either add the missing callbacks to IKeyVaultEventListener or update the @post text to only mention callbacks that actually exist.

Suggested change
* @post listener receives onDeviceSuspending/onDeviceResumed/onKeyInvalidated callbacks.
* @post listener receives the appropriate lifecycle and key invalidation callbacks defined by IKeyVaultEventListener.

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +28
* @brief Asynchronous event listener for KeyVault state changes.
* @author Gerald Weatherup
*
* Registered via IKeyVaultController to receive notifications about
* vault lifecycle events, key expiry, and power state transitions.
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IKeyVaultEventListener is documented as covering "power state transitions", but there are no callbacks for suspend/resume (only state/key lifecycle events). This is misleading for API consumers; either add explicit power-state callbacks or tighten the description to match the current method set.

Suggested change
* @brief Asynchronous event listener for KeyVault state changes.
* @author Gerald Weatherup
*
* Registered via IKeyVaultController to receive notifications about
* vault lifecycle events, key expiry, and power state transitions.
* @brief Asynchronous event listener for KeyVault state and key lifecycle changes.
* @author Gerald Weatherup
*
* Registered via IKeyVaultController to receive notifications about
* vault lifecycle events and key lifecycle changes (expiry, invalidation, rotation).

Copilot uses AI. Check for mistakes.

notes:
owners: "Architecture + Security"
dependencies: "Shared enums from KeyVault HAL (com.rdk.hal.keyvault)"
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

metadata.yaml lists a dependency on "Shared enums from KeyVault HAL", but the AIDL sources in this module do not import from com.rdk.hal.keyvault (KeyVault imports CryptoEngine types, not the other way around). Please correct/remove this dependency entry to avoid misleading dependency tracking.

Suggested change
dependencies: "Shared enums from KeyVault HAL (com.rdk.hal.keyvault)"
dependencies: "None"

Copilot uses AI. Check for mistakes.
Comment on lines +39 to +43
* The vault is purely a key store — it holds key material, manages
* key metadata, and controls access. To perform crypto operations on
* vault-managed keys, attach a configured ICryptoEngineController to
* this vault. The engine then uses the vault's keys for its operations
* based on its own crypto configuration.
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interface documentation says attaching an ICryptoEngineController enables crypto operations on vault-managed keys, but IKeyVaultController currently exposes no methods to invoke encrypt/decrypt/sign/verify using a vault key alias (only key lifecycle + deriveIntoVault). As written, non-extractable keys cannot be used for crypto at all via this HAL. Consider adding explicit operation entry points on IKeyVaultController (e.g. beginWithKeyAlias()/encryptWithKeyAlias()/signWithKeyAlias()) so callers can use vault-resident keys without exporting raw material.

Copilot uses AI. Check for mistakes.
BlockMode[] blockModes = {};
/** Supported digests. */
Digest[] digests = {};
/** Supported key sizes in bits. */
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EngineCapabilities.keySizes is a flat int[] which loses the association between supported algorithms and their valid key sizes (e.g. AES 128/192/256 vs RSA 2048/3072/4096). This makes capability-driven client validation ambiguous. Consider modelling key sizes per algorithm (e.g. an array of parcelables like {Algorithm algorithm; int[] sizes;}) or otherwise documenting that keySizes is a union and how callers should interpret it.

Suggested change
/** Supported key sizes in bits. */
/**
* @brief Supported key sizes in bits across all algorithms.
*
* This array is the union of all key sizes supported by the engine
* for the algorithms listed in {@link #algorithms}. It is not a
* per-algorithm mapping.
*
* Callers MUST NOT assume that every value in {@code keySizes}
* applies to every algorithm. For example, if {@code algorithms}
* contains AES and RSA and {@code keySizes} contains
* {128, 192, 256, 2048, 3072, 4096}, this does not imply that all
* sizes are valid for both AES and RSA.
*
* To validate support for a specific (Algorithm, keySize) pair,
* callers should consult algorithm-specific documentation for this
* platform or attempt the desired operation and handle failures.
*/

Copilot uses AI. Check for mistakes.
.
)

compile_aidl(${SRC} INCLUDE_DIRECTORY ${INCLUDE_DIRECTORY})
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module CMakeLists does not forward the root-level AIDL_GEN_DIR / AIDL_BIN variables into compile_aidl(). Most other modules build a COMPILE_AIDL_ARGV list and pass TARGET_DIRECTORY ${AIDL_GEN_DIR} (and AIDL_BIN when set) so generated sources go under gen/ rather than the module source tree (e.g. avbuffer/current/CMakeLists.txt:56-67). As-is, building with the repo-root CMake will generate output into cryptoengine/current/, which is likely unintended and can dirty the working tree.

Suggested change
compile_aidl(${SRC} INCLUDE_DIRECTORY ${INCLUDE_DIRECTORY})
set(COMPILE_AIDL_ARGV
INCLUDE_DIRECTORY ${INCLUDE_DIRECTORY}
TARGET_DIRECTORY ${AIDL_GEN_DIR}
)
if (AIDL_BIN)
list(APPEND COMPILE_AIDL_ARGV AIDL_BIN ${AIDL_BIN})
endif()
compile_aidl(${SRC} ${COMPILE_AIDL_ARGV})

Copilot uses AI. Check for mistakes.
${CMAKE_CURRENT_SOURCE_DIR}/../../cryptoengine/${CRYPTOENGINE_VERSION}
)

compile_aidl(${SRC} INCLUDE_DIRECTORY ${INCLUDE_DIRECTORY})
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module CMakeLists does not forward the root-level AIDL_GEN_DIR / AIDL_BIN variables into compile_aidl(). In most existing modules, TARGET_DIRECTORY ${AIDL_GEN_DIR} is passed so generated output lands in gen// (see avbuffer/current/CMakeLists.txt:56-67). As written, a root-level build will generate output into keyvault/current/ instead, which is likely unintended and can dirty the working tree.

Suggested change
compile_aidl(${SRC} INCLUDE_DIRECTORY ${INCLUDE_DIRECTORY})
compile_aidl(${SRC}
INCLUDE_DIRECTORY ${INCLUDE_DIRECTORY}
TARGET_DIRECTORY ${AIDL_GEN_DIR}
)

Copilot uses AI. Check for mistakes.
Ulrond added 2 commits April 1, 2026 23:50
- Add CMAC = 5 to Algorithm enum (AES-128 CMAC, required by Widevine
  OEMCrypto v16/v19 for OPKI_DeriveKeyWithCMAC key ladder)
- Add CONCAT_KDF = 4 to KeyDerivation enum (NIST SP 800-56A, used for
  ECDH key agreement and cert store derivation)
- Add CMAC_KDF = 5 to KeyDerivation enum (NIST SP 800-108 counter-mode
  CMAC-AES-128, required by Widevine OEMCrypto for key ladder derivation)
- Update HFP to include CMAC in supportedAlgorithms and CONCAT_KDF +
  CMAC_KDF in supportedKeyDerivations

Relates to #385
- Rename cryptoengine/ -> crypto_engine/
- Rename keyvault/ -> key_vault/
- Add crypto_engine.md design doc (session model, use cases, IV handling)
- Add key_vault.md design doc (architecture, TEE/TA model, cold boot,
  vault access control, use cases)
- Fix CMakeLists.txt cross-module path reference

Relates to #385
Copilot AI review requested due to automatic review settings April 1, 2026 22:53
- Remove ## Overview heading (content follows # Title directly)
- Remove duplicate References/Related Pages sections from key_vault.md
- Fix Related Pages link in crypto_engine.md to point to key_vault path
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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

*
* Stateless, one-shot operation. Does not require a key.
*
* @param digest The digest algorithm to use (SHA-1, SHA-2-256, SHA-3-256, etc.).
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The computeDigest() documentation lists SHA-1 as a supported digest option, but the Digest enum does not include SHA_1. Please either add SHA_1 to Digest (and update HFP/capabilities accordingly) or update the docs to reflect the actual supported values.

Suggested change
* @param digest The digest algorithm to use (SHA-1, SHA-2-256, SHA-3-256, etc.).
* @param digest The digest algorithm to use (e.g. SHA-2-256, SHA-3-256).

Copilot uses AI. Check for mistakes.
## Related Pages

!!! tip "Related Pages"
- [KeyVault HAL](../../key_vault/current/key_vault.md) — key storage and lifecycle; attaches a CryptoEngine for operations on vault-managed keys
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The related-page link points to ../../keyvault/current/document.md, but this repository uses key_vault/current/key_vault.md (and MkDocs sources are under docs/). As written, this link is likely broken; please update it to the correct published documentation location.

Suggested change
- [KeyVault HAL](../../key_vault/current/key_vault.md) — key storage and lifecycle; attaches a CryptoEngine for operations on vault-managed keys
- [KeyVault HAL](../key_vault/current/key_vault.md) — key storage and lifecycle; attaches a CryptoEngine for operations on vault-managed keys

Copilot uses AI. Check for mistakes.
- **Key agreement** — ECDH (P-256, P-384, X25519)
- **Key wrapping** — AES-KW, RSA-OAEP
- **Key derivation** — HKDF, PBKDF2, DH, NFLX-DH
- **Digest** — SHA-1, SHA-2-224, SHA-2-256, SHA-2-384, SHA-2-512
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This document states the engine supports SHA-1, but the Digest enum and HFP don’t include SHA-1. Please either add SHA-1 support to the API/HFP or update this list to match the actual supported digests.

Suggested change
- **Digest** — SHA-1, SHA-2-224, SHA-2-256, SHA-2-384, SHA-2-512
- **Digest** — SHA-2-224, SHA-2-256, SHA-2-384, SHA-2-512

Copilot uses AI. Check for mistakes.
Comment on lines +102 to +110
Platform vendors customize the engine via the HAL Feature Profile ([hfp-cryptoengine.yaml](./hfp-cryptoengine.yaml)):

- **Security level** — `TEE` or `SOFTWARE`
- **Supported algorithms, block modes, padding modes, digests, EC curves, KDFs**
- **Supported key sizes** per algorithm
- **Maximum concurrent operations**
- **Hardware acceleration** availability

The `EngineCapabilities` parcelable returned by `getCapabilities()` reflects these settings at runtime.
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section says EngineCapabilities “reflects these settings”, including padding modes, EC curves, KDFs, and per-algorithm key sizes, but EngineCapabilities.aidl currently only exposes algorithms/blockModes/digests and a flat keySizes array. Either extend EngineCapabilities to include these advertised capability dimensions (and allow per-algorithm key size reporting) or adjust the documentation/HFP expectations to avoid a mismatch.

Suggested change
Platform vendors customize the engine via the HAL Feature Profile ([hfp-cryptoengine.yaml](./hfp-cryptoengine.yaml)):
- **Security level**`TEE` or `SOFTWARE`
- **Supported algorithms, block modes, padding modes, digests, EC curves, KDFs**
- **Supported key sizes** per algorithm
- **Maximum concurrent operations**
- **Hardware acceleration** availability
The `EngineCapabilities` parcelable returned by `getCapabilities()` reflects these settings at runtime.
Platform vendors customise the engine via the HAL Feature Profile ([hfp-cryptoengine.yaml](./hfp-cryptoengine.yaml)):
- **Security level**`TEE` or `SOFTWARE`
- **Supported algorithms, block modes, padding modes, digests, EC curves, KDFs**
- **Supported key sizes** (potentially per algorithm in the HFP)
- **Maximum concurrent operations**
- **Hardware acceleration** availability
The `EngineCapabilities` parcelable returned by `getCapabilities()` reflects a subset of these settings at runtime, specifically the supported algorithms, block modes, digests, and a flat set of key sizes. More detailed configuration (such as padding modes, EC curves, KDFs, and per-algorithm key size policies) is defined in the HAL Feature Profile and enforced by the implementation but is not currently exposed as separate fields on `EngineCapabilities`.

Copilot uses AI. Check for mistakes.
Comment on lines +38 to +46
/** Supported algorithms. */
Algorithm[] algorithms = {};
/** Supported block modes. */
BlockMode[] blockModes = {};
/** Supported digests. */
Digest[] digests = {};
/** Supported key sizes in bits. */
int[] keySizes = {};
/** Maximum concurrent operations. */
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EngineCapabilities is missing several capability dimensions that are declared in the CryptoEngine HFP and referenced in docs (e.g., padding modes, EC curves, key derivations, and per-algorithm key sizes). As-is, callers can’t reliably introspect what the engine supports. Consider adding explicit fields for these, or clarifying that they are not discoverable at runtime.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +9
# KeyVault HAL

The KeyVault HAL provides secure key storage and lifecycle management. It abstracts platform-specific secure storage (TEE, HSM) behind a uniform AIDL interface, offering named vault instances with independent key material, access rules, and persistence policies.

A KeyVault is purely a key store — it holds key material and manages key metadata. To perform cryptographic operations on vault-managed keys, callers attach an `ICryptoEngineController` to the vault. The engine then uses the vault's keys for its operations.

Excluded: cryptographic operations themselves — these are the responsibility of the CryptoEngine HAL.

## References
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MkDocs is configured with docs_dir: docs, so markdown files under key_vault/current/ won’t be published unless there’s an external copy/sync step. If this is intended to be part of the public HAL documentation, consider moving it under docs/halif/key_vault/current/ and adding it to mkdocs.yml nav (or document the generation path).

Copilot uses AI. Check for mistakes.
The engine operates on caller-provided key material and configuration. It has no concept of key storage or ownership — it receives keys, performs operations, and returns results.

Excluded: key storage, key lifecycle, and access policy.

Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MkDocs is configured with docs_dir: docs, so markdown files under crypto_engine/current/ won’t be published unless there’s an external copy/sync step. If this is intended to be part of the public HAL documentation, consider moving it under docs/halif/crypto_engine/current/ and adding it to mkdocs.yml nav (or document the generation path).

Suggested change
!!! note "Documentation source"
This file is the source for the public CryptoEngine HAL documentation and is copied into `docs/halif/crypto_engine/current/crypto_engine.md` as part of the documentation generation/publish workflow.

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +26
set(CRYPTOENGINE_VERSION "current")
set(SRC_DIR com/rdk/hal/keyvault)
set(CRYPTOENGINE_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../crypto_engine/${CRYPTOENGINE_VERSION}/com/rdk/hal/cryptoengine)

set(SRC
${SRC_DIR}/IKeyVault.aidl
${SRC_DIR}/IKeyVaultController.aidl
${SRC_DIR}/IKeyVaultEventListener.aidl
${SRC_DIR}/DerivedKeySpec.aidl
${SRC_DIR}/KeyDescriptor.aidl
${SRC_DIR}/VaultCapabilities.aidl
${SRC_DIR}/VaultState.aidl
${CRYPTOENGINE_SRC_DIR}/Algorithm.aidl
${CRYPTOENGINE_SRC_DIR}/CryptoConfig.aidl
${CRYPTOENGINE_SRC_DIR}/Digest.aidl
${CRYPTOENGINE_SRC_DIR}/ICryptoEngineController.aidl
${CRYPTOENGINE_SRC_DIR}/KeyType.aidl
${CRYPTOENGINE_SRC_DIR}/SecurityLevel.aidl
)
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This CMakeLists pulls CryptoEngine AIDL files into SRC (Algorithm.aidl, Digest.aidl, etc.). Other modules with cross-module imports (e.g. avbuffer/current/CMakeLists.txt:39-52) rely on INCLUDE_DIRECTORY to resolve imports without recompiling dependency AIDL sources. Consider removing the external AIDL files from SRC and keeping only the include path to crypto_engine/current to avoid duplicate generated outputs and reduce coupling.

Copilot uses AI. Check for mistakes.
Comment on lines +32 to +38
* A KeyVault is a configured crypto engine instance with its own key
* material, crypto policy, and access rules. Multiple vaults can coexist
* for different requirements (e.g. app secure storage, platform identity,
* Netflix MSL, DRM provisioning).
*
* Each vault has its own attached crypto engine and keystore, with
* key material encrypted by OTP-derived root keys.
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interface description states “A KeyVault is a configured crypto engine instance” and that each vault has its own attached crypto engine. This conflicts with the design described in key_vault.md/PR description where the vault is a keystore and callers attach an ICryptoEngineController per session. Please update this overview text to match the intended separation of concerns.

Suggested change
* A KeyVault is a configured crypto engine instance with its own key
* material, crypto policy, and access rules. Multiple vaults can coexist
* for different requirements (e.g. app secure storage, platform identity,
* Netflix MSL, DRM provisioning).
*
* Each vault has its own attached crypto engine and keystore, with
* key material encrypted by OTP-derived root keys.
* A KeyVault is a logical keystore (key namespace) with its own key
* material, crypto policy, and access rules. Multiple vaults can coexist
* for different requirements (e.g. app secure storage, platform identity,
* Netflix MSL, DRM provisioning).
*
* Crypto operations are performed by a crypto engine that is attached
* to a vault session via an ICryptoEngineController, rather than being
* embedded in the vault itself. The vault is responsible for managing
* key metadata and encrypted key blobs, which may be bound to platform
* root secrets according to the implementation.

Copilot uses AI. Check for mistakes.
* @brief Generate an asymmetric keypair within this vault.
*
* Both the public and private key are stored in the vault under
* separate aliases. The public key bytes are also returned directly
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generateKeyPair() documentation says “The public key bytes are also returned directly”, but the method signature returns only KeyDescriptor[]. If callers must export the public key via exportKey(publicAlias) (as shown in the markdown doc), please update this comment to avoid implying that raw public key bytes are returned here.

Suggested change
* separate aliases. The public key bytes are also returned directly
* separate aliases. Only key descriptors are returned from this call;
* callers must use exportKey(publicAlias) to obtain raw public key bytes

Copilot uses AI. Check for mistakes.
- Fix KeyPurpose enum values to power-of-two flags for bitmask usage
  (ENCRYPT=1, DECRYPT=2, SIGN=4, etc.) — was sequential 0,1,2,3
- Fix ICryptoOperation doc: remove reference to IKeyVaultController.begin()
- Fix deriveIntoVault doc: remove reference to non-existent config.keyAlias
- Fix registerEventListener doc: list actual callback methods
- Fix IKeyVaultEventListener doc: remove "power state transitions" reference
- Fix IKeyVault overview: vault is a logical keystore, not a crypto engine
- Fix generateKeyPair doc: clarify only descriptors returned, use exportKey
  for raw public key bytes
- Fix computeDigest doc: remove SHA-1 reference (dropped from Digest enum)
- Fix crypto_engine metadata.yaml: dependency is None, not KeyVault
- Fix crypto_engine.md: remove SHA-1 from digest list, fix Digest.aidl desc

Relates to #385
@Ulrond Ulrond added component:crypto SOC/OEM component: crypto component:key_vault SOC/OEM component: key_vault breaking-change Breaking change — requires sprint cycle even for GREEN components labels Apr 7, 2026
@Ulrond Ulrond self-assigned this Apr 7, 2026
@Ulrond Ulrond added the Post-re-structure This PR has lot of modules involved, hence good to merge before any major rework. label Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change Breaking change — requires sprint cycle even for GREEN components component:crypto SOC/OEM component: crypto component:key_vault SOC/OEM component: key_vault Post-re-structure This PR has lot of modules involved, hence good to merge before any major rework.

Projects

Status: Architecture Review Required

Development

Successfully merging this pull request may close these issues.

Task: Add CryptoEngine and KeyVault HAL interfaces

2 participants