|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Secure-side sealed key import + opaque handle vending. More...
Go to the source code of this file.
Enumerations | |
| enum | ra8_key_import_limits_t : uint16_t { k_ra8_key_import_blob_bytes = 48U , k_ra8_key_import_mac_bytes = 16U , k_ra8_key_import_key_bytes = 32U , k_ra8_key_import_handle_zero = 0U } |
| Sizing constants exposed to NS callers via the veneer. More... | |
Functions | |
| ra8_err_t | priv_ra8_key_import_reset (void) |
| Reset the import table (drops every handle) and re-seed the salt. | |
| ra8_err_t | priv_ra8_key_import_seal (const uint8_t *blob, uint32_t blob_len, uint32_t *out_handle) |
| Validate a sealed blob and import the key into a free slot. | |
| ra8_err_t | priv_ra8_key_import_resolve (uint32_t handle, uint16_t *out_slot) |
| Resolve a handle to the underlying slot index. | |
| ra8_err_t | priv_ra8_key_import_build_blob (const uint8_t *material, uint8_t *out_blob) |
| Build a sealed blob from a raw key (provisioning + test helper). | |
Secure-side sealed key import + opaque handle vending.
Layered on top of key_vault.h. Where ra8_key_vault_store is a privileged secure-only API for one-time provisioning of a 32-byte symmetric key into an in-memory slot, the ra8_key_import_* API is the bridge that lets Non-Secure code request a sealed import and then refer to the key only by an opaque handle whose value has no relation to the slot index or the key bytes.
The model:
The sealing MAC is AES-CMAC (NIST SP 800-38B) over the 32 key bytes, keyed by the key-authentication key (KAK) the vault holds (ra8_key_vault_load_mac_key) – a secret the Non-Secure world can never reach. The CMAC itself is computed through the ra8_sec_cmac_* seam. That seam resolves to the KAT-pinned in-tree AES-CMAC reference in EVERY build, firmware and host alike; its TF-PSA-Crypto psa_mac_* backend is compiled by nothing (#619). A forged blob therefore requires recovering the KAK, not merely replaying a trivial fold.
Definition in file key_import_internal.h.
| enum ra8_key_import_limits_t : uint16_t |
Sizing constants exposed to NS callers via the veneer.
Definition at line 57 of file key_import_internal.h.
|
nodiscard |
Build a sealed blob from a raw key (provisioning + test helper).
Computes the AES-CMAC over material using the vault KAK and writes [key | cmac] to out_blob. Secure-side provisioning code uses this to package a key just before passing it through the import API. Tests use it to drive the happy path.
| [in] | material | 32-byte key material to seal. |
| [out] | out_blob | Destination of k_ra8_key_import_blob_bytes. |
| k_ra8_ok | Blob built. |
| k_ra8_err_null_ptr | material or out_blob was NULL. |
| k_ra8_err_not_found | No KAK provisioned in the vault. |
Build a sealed blob from a raw key (provisioning + test helper).
Copies the key bytes verbatim, computes the AES-CMAC over them with the vault KAK via priv_ra8_sec_cmac_compute, and writes the trailing k_ra8_key_import_mac_bytes of the blob. Provided so provisioning and unit tests can package a key the import path will accept.
| [in] | material | Raw 32-byte key material. |
| [out] | out_blob | Receives k_ra8_key_import_blob_bytes of output. |
| k_ra8_ok | Blob written. |
| k_ra8_err_null_ptr | material or out_blob was NULL. |
| k_ra8_err_not_found | No KAK provisioned in the vault. |
Definition at line 369 of file key_import.c.
References k_ra8_key_import_key_bytes, k_ra8_key_vault_mac_key_bytes, k_ra8_ok, priv_ra8_sec_cmac_compute(), RA8_CHECK_NULL_PTR, ra8_key_vault_load_mac_key(), ra8_secure_memzero(), and s_tag.
|
nodiscard |
Reset the import table (drops every handle) and re-seed the salt.
Reset the import table (drops every handle) and re-seed the salt.
Clears every s_slot_used bit and rotates the salt with a fixed mixing constant so successive resets vend different handles for the same slot index. Falls back to the boot seed if the rerolled salt happens to be zero.
| k_ra8_ok | Always; the operation cannot fail. |
Definition at line 224 of file key_import.c.
References internal_rotate_left_32(), k_initial_salt, k_ra8_ok, k_salt_reroll_rot, k_salt_reroll_xor, s_salt, and s_slot_used.
|
nodiscard |
Resolve a handle to the underlying slot index.
| [in] | handle | Handle previously returned from priv_ra8_key_import_seal. |
| [out] | out_slot | Slot index 0..k_ra8_key_vault_slots-1 on success. |
| k_ra8_ok | Slot returned. |
| k_ra8_err_null_ptr | out_slot was NULL. |
| k_ra8_err_not_found | Handle does not refer to a live import. |
Resolve a handle to the underlying slot index.
Walks the live slot bitmap and recomputes the per-slot handle until a match is found. The slot index never leaves the secure world via the handle itself; this function is the only place that performs the inverse mapping.
| [in] | handle | Opaque handle previously returned by priv_ra8_key_import_seal. |
| [out] | out_slot | Receives the resolved slot index on success. |
| k_ra8_ok | Handle matched a live slot. |
| k_ra8_err_null_ptr | out_slot was NULL. |
| k_ra8_err_not_found | Handle does not match any live slot. |
Definition at line 329 of file key_import.c.
References internal_handle_for_slot(), k_ra8_err_not_found, k_ra8_key_vault_slots, k_ra8_ok, RA8_CHECK_NULL_PTR, s_slot_used, and s_tag.
|
nodiscard |
Validate a sealed blob and import the key into a free slot.
Walks the sealed blob [key (32B) | cmac (16B)], verifies the AES-CMAC keyed by the vault KAK, and copies the key bytes into the next free slot via ra8_key_vault_store. The returned handle is an obfuscated form of the slot index that NS callers can use as the slot argument to subsequent veneer calls.
| [in] | blob | Sealed blob (caller-owned secure copy). |
| [in] | blob_len | Must equal k_ra8_key_import_blob_bytes. |
| [out] | out_handle | Opaque handle (non-zero on success). |
| k_ra8_ok | Key imported, handle written. |
| k_ra8_err_null_ptr | blob or out_handle was NULL. |
| k_ra8_err_invalid_size | blob_len mismatched. |
| k_ra8_err_invalid_arg | CMAC verification failed. |
| k_ra8_err_not_found | No KAK provisioned in the vault. |
| k_ra8_err_no_mem | Every slot already occupied. |
Validate a sealed blob and import the key into a free slot.
Validates the blob length, checks the AES-CMAC, allocates the lowest free vault slot, copies the key into the vault, and returns an opaque handle that the NS world can later present to the SHA-256 challenge primitive without ever learning the slot index.
| [in] | blob | Sealed key blob. |
| [in] | blob_len | Length of blob; must equal k_ra8_key_import_blob_bytes. |
| [out] | out_handle | Receives the opaque handle on success. |
| k_ra8_ok | Key sealed and handle issued. |
| k_ra8_err_null_ptr | blob or out_handle was NULL. |
| k_ra8_err_invalid_size | blob_len did not match expected size. |
| k_ra8_err_invalid_arg | CMAC verification failed. |
| k_ra8_err_not_found | No KAK provisioned in the vault. |
| k_ra8_err_no_mem | All vault slots are in use. |
Definition at line 268 of file key_import.c.
References internal_handle_for_slot(), internal_verify_cmac(), k_ra8_err_invalid_size, k_ra8_err_no_mem, k_ra8_key_import_blob_bytes, k_ra8_key_vault_slots, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_key_vault_store(), s_slot_used, and s_tag.