|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Renesas Secure IP (RSIP-E50D) HAL – core lifecycle / TRNG / hash API. More...
Go to the source code of this file.
Data Structures | |
| struct | ra8_rsip_config_t |
| Initial configuration for ra8_rsip_init. More... | |
| struct | ra8_rsip_sha256_ctx_t |
| Streaming state for incremental SHA-256. More... | |
| struct | ra8_rsip_hmac_sha256_ctx_t |
| Streaming state for incremental HMAC-SHA-256. More... | |
Typedefs | |
| typedef void(* | ra8_rsip_event_fn_t) (void *ctx, uint32_t isr) |
| RSIP interrupt callback. | |
Enumerations | |
| enum | ra8_rsip_sha_buf_t : uint16_t { k_ra8_rsip_sha256_state_words = 8U , k_ra8_rsip_sha256_block = 64U , k_ra8_rsip_hmac_inner_pad = 0x36U , k_ra8_rsip_hmac_outer_pad = 0x5CU } |
| Fixed geometry for the incremental SHA / HMAC state. More... | |
Functions | |
| ra8_err_t | ra8_rsip_init (const ra8_rsip_config_t *cfg) |
| Power on the RSIP engine and (optionally) run BIST. | |
| ra8_err_t | ra8_rsip_deinit (void) |
| Power off the RSIP engine. | |
| ra8_err_t | ra8_rsip_get_status (uint32_t *out) |
| Snapshot the STATUS mailbox word. | |
| ra8_err_t | ra8_rsip_clear_status (uint32_t mask) |
| Acknowledge ISR bits via write-1-to-clear. | |
| ra8_err_t | ra8_rsip_attach_handler (ra8_rsip_event_fn_t fn, void *ctx) |
| Attach a single shared interrupt callback. | |
| void | ra8_rsip_dispatch (void) |
| Run the attached callback with the current ISR snapshot. | |
| ra8_err_t | ra8_rsip_trng_read (uint8_t *buf, uint32_t len) |
| Drain len bytes from the RSIP true RNG – fail-closed, no backend. | |
| ra8_err_t | ra8_rsip_sha256 (const uint8_t *msg, uint32_t msg_len, uint8_t *digest) |
| Compute SHA-256 of an in-memory buffer. | |
| ra8_err_t | ra8_rsip_sha256_init (ra8_rsip_sha256_ctx_t *ctx) |
| Initialise a streaming SHA-256 context. | |
| ra8_err_t | ra8_rsip_sha256_update (ra8_rsip_sha256_ctx_t *ctx, const uint8_t *data, uint32_t len) |
| Absorb additional bytes into a streaming SHA-256 context. | |
| ra8_err_t | ra8_rsip_sha256_final (ra8_rsip_sha256_ctx_t *ctx, uint8_t *digest_out) |
| Emit the digest of a streaming SHA-256 context. | |
| ra8_err_t | ra8_rsip_hmac_sha256_init (ra8_rsip_hmac_sha256_ctx_t *ctx, const uint8_t *key, uint32_t key_len) |
| Initialise a streaming HMAC-SHA-256 context. | |
| ra8_err_t | ra8_rsip_hmac_sha256_update (ra8_rsip_hmac_sha256_ctx_t *ctx, const uint8_t *data, uint32_t len) |
| Absorb additional bytes into a streaming HMAC-SHA-256 context. | |
| ra8_err_t | ra8_rsip_hmac_sha256_final (ra8_rsip_hmac_sha256_ctx_t *ctx, uint8_t *mac_out) |
| Emit the MAC of a streaming HMAC-SHA-256 context. | |
| ra8_err_t | ra8_rsip_enter_stop (void) |
| Park the engine for software-standby entry. | |
| ra8_err_t | ra8_rsip_exit_stop (void) |
| Re-enable the engine after software-standby exit. | |
Renesas Secure IP (RSIP-E50D) HAL – core lifecycle / TRNG / hash API.
Core surface of the RA8D2 RSIP-E50D HAL split out of the ra8_rsip.h umbrella. This sub-header owns the engine lifecycle (init / deinit / power transition), the status / IRQ mailbox plumbing, the 128-bit TRNG drain, the one-shot SHA-256 primitive, and the incremental SHA-256 / HMAC-SHA-256 streaming contexts.
The mailbox-driven peripheral is documented in HUM Ch 52 "Renesas Secure IP (RSIP-E50D)" p 3302-3307; cross-references to the broader security feature set live in HUM Ch 51 "Security Features" p 3263-3301.
Definition in file ra8_rsip_core.h.
| typedef void(* ra8_rsip_event_fn_t) (void *ctx, uint32_t isr) |
RSIP interrupt callback.
| [in] | ctx | Caller-provided context pointer. |
| [in] | isr | Snapshot of the k_ra8_rsip_off_isr word at the moment the interrupt fired (see k_ra8_rsip_mask_isr_*). |
Definition at line 64 of file ra8_rsip_core.h.
| enum ra8_rsip_sha_buf_t : uint16_t |
Fixed geometry for the incremental SHA / HMAC state.
The software backend compresses complete SHA-256 blocks as they arrive and retains only one partial block. Input length is therefore independent of context size; the 64-bit byte count enforces the FIPS 180-4 bit-length encoding bound at update time.
Definition at line 367 of file ra8_rsip_core.h.
|
nodiscard |
Attach a single shared interrupt callback.
The RSIP routes a small number of edge-triggered events (DONE / RND / HASH / TAMPER) into one peripheral IRQ line. The driver fans them out by passing the live ISR snapshot to a single callback.
| [in] | fn | Callback fired by ra8_rsip_dispatch; may be NULL to detach. |
| [in] | ctx | Opaque context forwarded to fn. |
| k_ra8_ok | Callback installed. |
Definition at line 307 of file ra8_rsip.c.
References k_ra8_ok, s_rsip_ctx, and s_rsip_fn.
|
nodiscard |
Acknowledge ISR bits via write-1-to-clear.
Writes mask to the ISR register; only the bits listed in k_ra8_rsip_mask_isr_* are valid. The write masks unrelated bits before issuing.
| [in] | mask | OR of k_ra8_rsip_mask_isr_* values. |
| k_ra8_ok | Bits cleared. |
| k_ra8_err_invalid_arg | mask had bits outside the ISR field. |
Definition at line 293 of file ra8_rsip.c.
References k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_rsip_mask_isr_all, k_ra8_rsip_off_isr, and ra8_rsip_reg32().
|
nodiscard |
Power off the RSIP engine.
Clears CTRL.ENABLE, scrubs any pending ISR bits, releases the shared callback slot, and asks ra8_mstp to gate MSTPC31.
| k_ra8_ok | Engine gated. |
| k_ra8_err_invalid_state | ra8_mstp had no matching enable. |
| k_ra8_err_hw_timeout | MSTP read-back loop expired. |
Definition at line 267 of file ra8_rsip.c.
References k_ra8_mstp_rsip, k_ra8_rsip_mask_isr_all, k_ra8_rsip_off_ctrl, k_ra8_rsip_off_isr, ra8_mstp_disable(), ra8_rsip_reg32(), s_rsip_ctx, and s_rsip_fn.
| void ra8_rsip_dispatch | ( | void | ) |
Run the attached callback with the current ISR snapshot.
Called from the secure-world ICU dispatch when the RSIP IRQ fires. Reads the live ISR word, fires the registered callback (if any), and acks the bits the callback observed via ra8_rsip_clear_status.
Definition at line 315 of file ra8_rsip.c.
References k_ra8_rsip_off_isr, ra8_rsip_reg32(), s_rsip_ctx, and s_rsip_fn.
|
nodiscard |
Park the engine for software-standby entry.
HUM Ch 52.3.1 p 3307 ("Software Standby Mode") requires the engine to be idle before software-standby; this helper clears CTRL.ENABLE then gates MSTPC31.
| k_ra8_ok | Engine parked. |
| k_ra8_err_invalid_state | ra8_mstp had no matching enable. |
| k_ra8_err_hw_timeout | MSTP read-back loop expired. |
Definition at line 947 of file ra8_rsip.c.
References k_ra8_mstp_rsip, k_ra8_rsip_off_ctrl, ra8_mstp_disable(), and ra8_rsip_reg32().
|
nodiscard |
Re-enable the engine after software-standby exit.
Calls ra8_mstp_enable to clock the block, sets CTRL.ENABLE, and re-runs BIST so a side-channel injection during standby does not silently leak.
| k_ra8_ok | Engine ready, BIST passed. |
| k_ra8_err_hw_init_failed | BIST did not pass. |
| k_ra8_err_hw_timeout | MSTP read-back loop expired. |
Definition at line 955 of file ra8_rsip.c.
References internal_run_bist(), k_ra8_mstp_rsip, k_ra8_ok, k_ra8_rsip_mask_ctrl_enable, k_ra8_rsip_off_ctrl, ra8_mstp_disable(), ra8_mstp_enable(), RA8_RETURN_ON_ERROR, ra8_rsip_reg32(), and s_tag.
|
nodiscard |
Snapshot the STATUS mailbox word.
| [out] | out | Receives the raw STATUS word; never NULL. |
| k_ra8_ok | Snapshot returned. |
| k_ra8_err_null_ptr | out was nullptr. |
Definition at line 284 of file ra8_rsip.c.
References k_ra8_ok, k_ra8_rsip_off_status, RA8_CHECK_NULL_PTR, ra8_rsip_reg32(), and s_tag.
|
nodiscard |
Emit the MAC of a streaming HMAC-SHA-256 context.
| [in,out] | ctx | Context populated by prior update() calls. |
| [out] | mac_out | 32-byte MAC output buffer; never NULL. |
| k_ra8_ok | MAC written. |
| k_ra8_err_null_ptr | ctx or mac_out was nullptr. |
| k_ra8_err_invalid_state | ctx was not initialized. |
| k_ra8_err_hw_timeout | Either SHA pass timed out. |
Definition at line 927 of file ra8_rsip.c.
References ra8_rsip_hmac_sha256_ctx_t::initialized, ra8_rsip_hmac_sha256_ctx_t::inner, internal_hmac_outer(), k_ra8_err_invalid_state, k_ra8_ok, k_ra8_rsip_sha256_block, k_ra8_rsip_sha256_digest_bytes, ra8_rsip_hmac_sha256_ctx_t::key_block, RA8_CHECK_NULL_PTR, ra8_rsip_sha256_final(), and s_tag.
|
nodiscard |
Initialise a streaming HMAC-SHA-256 context.
| [out] | ctx | Streaming HMAC state; never NULL. |
| [in] | key | HMAC key bytes; never NULL when key_len > 0. |
| [in] | key_len | Length of key in bytes (may be 0). |
| k_ra8_ok | Context ready. |
| k_ra8_err_null_ptr | ctx was nullptr or key was NULL with non-zero key_len. |
| k_ra8_err_hw_timeout | Internal SHA collapse of an oversized key timed out. |
Definition at line 846 of file ra8_rsip.c.
References ra8_rsip_hmac_sha256_ctx_t::initialized, ra8_rsip_sha256_ctx_t::initialized, ra8_rsip_hmac_sha256_ctx_t::inner, internal_hmac_prep_key(), k_ra8_err_null_ptr, k_ra8_ok, k_ra8_rsip_hmac_inner_pad, k_ra8_rsip_sha256_block, ra8_rsip_hmac_sha256_ctx_t::key_block, RA8_CHECK_NULL_PTR, ra8_rsip_sha256_init(), ra8_rsip_sha256_update(), and s_tag.
|
nodiscard |
Absorb additional bytes into a streaming HMAC-SHA-256 context.
| [in,out] | ctx | Context primed by ra8_rsip_hmac_sha256_init. |
| [in] | data | Bytes to absorb; may be NULL only if len is 0. |
| [in] | len | Number of bytes in data. |
| k_ra8_ok | Bytes accumulated. |
| k_ra8_err_null_ptr | ctx was nullptr or data NULL with non-zero len. |
| k_ra8_err_invalid_state | ctx was not initialized. |
| k_ra8_err_invalid_size | Cumulative input exceeds SHA-256's encoded length range. |
Definition at line 874 of file ra8_rsip.c.
References ra8_rsip_hmac_sha256_ctx_t::initialized, ra8_rsip_hmac_sha256_ctx_t::inner, k_ra8_err_invalid_state, RA8_CHECK_NULL_PTR, ra8_rsip_sha256_update(), and s_tag.
|
nodiscard |
Power on the RSIP engine and (optionally) run BIST.
Sequence:
| [in] | cfg | Non-NULL configuration descriptor. |
| k_ra8_ok | Engine ready, BIST passed. |
| k_ra8_err_null_ptr | cfg was nullptr. |
| k_ra8_err_hw_init_failed | BIST did not pass within budget. |
Definition at line 234 of file ra8_rsip.c.
References internal_run_bist(), k_ra8_mstp_rsip, k_ra8_ok, k_ra8_rsip_mask_ctrl_enable, k_ra8_rsip_mask_ctrl_reset, k_ra8_rsip_mask_isr_all, k_ra8_rsip_off_ctrl, k_ra8_rsip_off_isr, RA8_CHECK_NULL_PTR, ra8_log_info, ra8_mstp_disable(), ra8_mstp_enable(), RA8_RETURN_ON_ERROR, ra8_rsip_reg32(), ra8_rsip_config_t::run_bist, and s_tag.
Referenced by demo_setup_or_halt(), internal_demo_setup_or_halt(), and internal_run().
|
nodiscard |
Compute SHA-256 of an in-memory buffer.
Streams msg through the HASH engine 32 bits at a time, then reads back the 8-word (32-byte) digest from HASH_DIGEST. Algorithm select is hard-wired to k_ra8_rsip_hash_sha256. Suitable for short messages; incremental update / final API is deferred to a future revision.
| [in] | msg | Pointer to the input buffer; never NULL. |
| [in] | msg_len | Length of msg in bytes; may be 0. |
| [out] | digest | 32-byte output buffer; never NULL. |
| k_ra8_ok | Digest written. |
| k_ra8_err_null_ptr | msg or digest was nullptr. |
| k_ra8_err_hw_timeout | HASH engine did not signal done. |
Definition at line 397 of file ra8_rsip.c.
References internal_sw_sha256(), k_ra8_ok, k_ra8_rsip_hash_sha256, k_ra8_rsip_mask_status_ready, k_ra8_rsip_off_hash_ctrl, k_ra8_rsip_off_hash_status, priv_hash_wait_done(), priv_wait_bit(), RA8_CHECK_NULL_PTR, RA8_RETURN_ON_ERROR, ra8_rsip_reg32(), and s_tag.
Referenced by app_stage_images(), internal_demo_verify_cert_pin(), internal_kat_one(), and internal_sha256_dispatch().
|
nodiscard |
Emit the digest of a streaming SHA-256 context.
| [in,out] | ctx | Context populated by prior update() calls. |
| [out] | digest_out | 32-byte digest output buffer; never NULL. |
| k_ra8_ok | Digest written. |
| k_ra8_err_null_ptr | ctx or digest_out was nullptr. |
| k_ra8_err_invalid_state | ctx was not initialized. |
Definition at line 794 of file ra8_rsip.c.
References ra8_rsip_sha256_ctx_t::block, ra8_rsip_sha256_ctx_t::initialized, internal_sw_sha256_emit(), internal_sw_sha256_finalize(), k_ra8_err_invalid_state, k_ra8_ok, k_ra8_rsip_sha256_block, k_ra8_rsip_sha256_state_words, RA8_CHECK_NULL_PTR, s_tag, ra8_rsip_sha256_ctx_t::state, ra8_rsip_sha256_ctx_t::total_bytes, and ra8_rsip_sha256_ctx_t::used.
Referenced by app_sha_final(), internal_sha_final(), internal_sw_sha256(), and ra8_rsip_hmac_sha256_final().
|
nodiscard |
Initialise a streaming SHA-256 context.
| [out] | ctx | Streaming state; never NULL. |
| k_ra8_ok | Context ready for update(). |
| k_ra8_err_null_ptr | ctx was nullptr. |
Definition at line 747 of file ra8_rsip.c.
References ra8_rsip_sha256_ctx_t::initialized, k_ra8_ok, k_ra8_rsip_sha256_state_words, RA8_CHECK_NULL_PTR, s_sw_sha256_h0, s_tag, ra8_rsip_sha256_ctx_t::state, ra8_rsip_sha256_ctx_t::total_bytes, and ra8_rsip_sha256_ctx_t::used.
Referenced by app_sha_init(), internal_sha_init(), internal_sw_sha256(), and ra8_rsip_hmac_sha256_init().
|
nodiscard |
Absorb additional bytes into a streaming SHA-256 context.
| [in,out] | ctx | Context primed by ra8_rsip_sha256_init. |
| [in] | data | Bytes to absorb; may be NULL only if len is 0. |
| [in] | len | Number of bytes in data. |
| k_ra8_ok | Bytes compressed or retained. |
| k_ra8_err_null_ptr | ctx was nullptr or data was NULL with non-zero len. |
| k_ra8_err_invalid_state | ctx was not initialized. |
| k_ra8_err_invalid_size | Cumulative input cannot be represented by SHA-256's 64-bit bit-length field. |
Definition at line 759 of file ra8_rsip.c.
References ra8_rsip_sha256_ctx_t::block, ra8_rsip_sha256_ctx_t::initialized, internal_sw_sha256_compress(), k_ra8_err_invalid_size, k_ra8_err_invalid_state, k_ra8_err_null_ptr, k_ra8_ok, k_ra8_rsip_byte_bits, k_ra8_rsip_sha256_block, RA8_CHECK_NULL_PTR, s_tag, ra8_rsip_sha256_ctx_t::state, ra8_rsip_sha256_ctx_t::total_bytes, and ra8_rsip_sha256_ctx_t::used.
Referenced by app_sha_update(), internal_sha_update(), internal_sw_sha256(), ra8_rsip_hmac_sha256_init(), and ra8_rsip_hmac_sha256_update().
|
nodiscard |
Drain len bytes from the RSIP true RNG – fail-closed, no backend.
The RSIP-E50D TRNG has no documented register interface (HUM Ch 52 is a 6-page feature overview with no register map), so the hand-written RND_* access is invented and non-functional on silicon: RND_STATUS.READY never asserts. This routine therefore fails closed with k_ra8_err_not_supported rather than spin to a timeout or hand back a deterministic / all-zero value – predictable "entropy" is far more dangerous than an honest error. A working TRNG needs an FSP-derived RSIP primitive sequence; the register path is retained behind RA8_RSIP_TRNG_HARDWARE (never defined) for a future port. A software PRNG is NOT a substitute here.
| [out] | buf | Destination buffer (>= len bytes); never NULL. |
| [in] | len | Bytes to fetch; must be a non-zero multiple of 4. |
| k_ra8_err_not_supported | No working RSIP TRNG register interface exists (the shipped, fail-closed path). |
| k_ra8_err_null_ptr | buf was nullptr. |
| k_ra8_err_invalid_arg | len is zero or not a multiple of k_ra8_rsip_trng_word_bytes. |
Definition at line 338 of file ra8_rsip.c.
References k_ra8_err_invalid_arg, k_ra8_err_not_supported, k_ra8_ok, k_ra8_rsip_byte_bits, k_ra8_rsip_byte_mask, k_ra8_rsip_byte_shift_2, k_ra8_rsip_byte_shift_3, k_ra8_rsip_mask_ctrl_enable, k_ra8_rsip_mask_status_ready, k_ra8_rsip_off_rnd_ctrl, k_ra8_rsip_off_rnd_data, k_ra8_rsip_off_rnd_status, k_ra8_rsip_trng_word_bytes, k_ra8_rsip_word_shift, priv_wait_bit(), RA8_CHECK_NULL_PTR, ra8_rsip_reg32(), and s_tag.
Referenced by internal_demo_entropy_source(), and mbedtls_psa_external_get_random().