74#ifndef RA8_RSIP_SOFTWARE_BACKEND
76#define RA8_RSIP_SOFTWARE_BACKEND (1)
92static const char*
s_tag =
"RSIP";
124#if defined(RA8_OFF_TARGET) && defined(UNIT_TEST)
128 if (ra8_fake_mmio_wait_eval(reg, i, ((*reg & mask) == mask))) {
132 if ((*reg & mask) == mask) {
188#ifdef RA8_RSIP_HASH_HARDWARE
192static void internal_sha256_push_msg(
const uint8_t* msg, uint32_t msg_len)
212#ifdef RA8_RSIP_HASH_HARDWARE
216static void internal_sha256_pull_digest(uint8_t* digest)
320 const uint32_t snapshot = *isr;
321 if (snapshot == 0U) {
348#ifdef RA8_RSIP_TRNG_HARDWARE
357 for (uint32_t w = 0U; w < words; ++w) {
370 const uint32_t word = *data;
402#ifdef RA8_RSIP_HASH_HARDWARE
419 internal_sha256_push_msg(msg, msg_len);
424 internal_sha256_pull_digest(digest);
440#ifdef RA8_RSIP_SOFTWARE_BACKEND
450typedef enum : uint32_t {
490 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL,
491 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL,
492 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL,
493 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL,
494 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
495 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL,
496 0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL,
497 0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL,
498 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL,
499 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
500 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL,
501 0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL,
502 0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL,
503 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL,
504 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
505 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL,
515 0x6a09e667UL, 0xbb67ae85UL, 0x3c6ef372UL, 0xa54ff53aUL,
516 0x510e527fUL, 0x9b05688cUL, 0x1f83d9abUL, 0x5be0cd19UL,
546typedef enum : uint8_t {
595 const uint32_t ch = (e & f) ^ ((~e) & g);
596 const uint32_t temp1 = h + s1 + ch +
s_sw_sha256_k[i] + w[i];
600 const uint32_t maj = (a & b) ^ (a & c) ^ (b & c);
601 const uint32_t temp2 = s0 + maj;
631 working[i] = state[i];
635 state[i] += working[i];
738#ifdef RA8_RSIP_SOFTWARE_BACKEND
742 static const uint8_t s_empty = 0U;
743 return ra8_rsip_sha256((msg ==
nullptr) ? &s_empty : msg, msg_len, digest);
762 if ((data ==
nullptr) && (len != 0U)) {
775 uint32_t consumed = 0U;
776 while ((ctx->
used != 0U) && (consumed < len)) {
777 ctx->
block[ctx->
used++] = data[consumed++];
787 while (consumed < len) {
788 ctx->
block[ctx->
used++] = data[consumed++];
835 block[i] = digest[i];
837 }
else if (key_len > 0U) {
838 for (uint32_t i = 0U; i < key_len; ++i) {
849 if ((key ==
nullptr) && (key_len != 0U)) {
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_ISR_SAFE
The function is callable from interrupt context.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_hw_init_failed
Hardware peripheral failed to initialise.
@ k_ra8_err_not_supported
Requested feature not compiled in, not wired, or not supported by this MCU variant.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Bounded wait-flag primitives for RA8D2 HAL drivers.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info(tag, message)
RA8 log info.
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_enable(ra8_mstp_t id)
Reference-counted "ungate this peripheral" request.
ra8_err_t ra8_mstp_disable(ra8_mstp_t id)
Reference-counted "gate this peripheral" request.
@ k_ra8_mstp_rsip
MSTPC31 RSIP-E50D.
static void internal_sw_sha256_emit(const uint32_t state[k_ra8_rsip_sw_sha256_state_w], uint8_t *digest)
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.
static const uint32_t s_sw_sha256_k[k_ra8_rsip_sw_sha256_round_cnt]
FIPS PUB 180-4 Section 4.1.2 SHA-256 round constants K[0..63].
ra8_err_t ra8_rsip_get_status(uint32_t *out)
Snapshot the STATUS mailbox word.
ra8_err_t ra8_rsip_enter_stop(void)
Park the engine for software-standby entry.
ra8_err_t priv_wait_bit(ra8_rsip_off_t offset, uint32_t mask)
Implementation of priv_wait_bit() – bounded MMIO mask spin.
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.
static void * s_rsip_ctx
Caller context paired with s_rsip_fn.
ra8_err_t ra8_rsip_deinit(void)
Power off the RSIP engine.
static void internal_sw_sha256_compress(uint32_t state[k_ra8_rsip_sw_sha256_state_w], const uint8_t block[k_ra8_rsip_sha256_block])
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_rsip_sw_sha256_t
File-private constants for the software SHA-256 fall-back.
@ k_ra8_rsip_sw_sha256_round_cnt
Sched + compression rounds.
@ k_ra8_rsip_sw_rotr_19
RA8 rsip sw rotr 19.
@ k_ra8_rsip_sw_sha256_pad_byte
RFC 6234 / FIPS 180-4 marker.
@ k_ra8_rsip_sw_sha256_w_back_2
W[i-2] schedule lookback.
@ k_ra8_rsip_sw_rotr_22
RA8 rsip sw rotr 22.
@ k_ra8_rsip_sw_sha256_w_back_7
W[i-7] schedule lookback.
@ k_ra8_rsip_sw_rotr_6
RA8 rsip sw rotr 6.
@ k_ra8_rsip_sw_rotr_18
RA8 rsip sw rotr 18.
@ k_ra8_rsip_sw_rotr_7
RA8 rsip sw rotr 7.
@ k_ra8_rsip_sw_sha256_w_back_16
W[i-16] schedule lookback.
@ k_ra8_rsip_sw_sha256_state_w
8 working-state words.
@ k_ra8_rsip_sw_rotr_11
RA8 rsip sw rotr 11.
@ k_ra8_rsip_sw_word_bits
Word width in bits.
@ k_ra8_rsip_sw_rotr_10
RA8 rsip sw rotr 10.
@ k_ra8_rsip_sw_rotr_13
RA8 rsip sw rotr 13.
@ k_ra8_rsip_sw_rotr_25
RA8 rsip sw rotr 25.
@ k_ra8_rsip_sw_sha256_block_w
64-byte block = 16 words.
@ k_ra8_rsip_sw_rotr_17
RA8 rsip sw rotr 17.
@ k_ra8_rsip_sw_sha256_len_bytes
64-bit length encoding tail.
@ k_ra8_rsip_sw_rotr_3
RA8 rsip sw rotr 3.
@ k_ra8_rsip_sw_sha256_w_back_15
W[i-15] schedule lookback.
@ k_ra8_rsip_sw_rotr_2
RA8 rsip sw rotr 2.
static ra8_err_t internal_sha256_dispatch(const uint8_t *msg, uint32_t msg_len, uint8_t *digest)
static uint32_t internal_sw_rotr(uint32_t x, uint32_t n)
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_clear_status(uint32_t mask)
Acknowledge ISR bits via write-1-to-clear.
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.
static void internal_sw_sha256_finalize(ra8_rsip_sha256_ctx_t *ctx)
Finalize one streaming SHA-256 chaining state.
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_exit_stop(void)
Re-enable the engine after software-standby exit.
static ra8_err_t internal_hmac_prep_key(const uint8_t *key, uint32_t key_len, uint8_t block[k_ra8_rsip_sha256_block])
static void internal_sw_sha256(const uint8_t *msg, uint32_t msg_len, uint8_t *digest)
One-shot software SHA-256 over a contiguous message buffer.
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.
void ra8_rsip_dispatch(void)
Run the attached callback with the current ISR snapshot.
static void internal_sw_sha256_rounds(uint32_t s[k_ra8_rsip_sw_sha256_state_w], const uint32_t w[k_ra8_rsip_sw_sha256_round_cnt])
Run the 64-round SHA-256 compression loop over one message schedule.
static ra8_rsip_event_fn_t s_rsip_fn
Currently attached interrupt callback, or nullptr.
static ra8_err_t internal_hmac_outer(const uint8_t key_block[k_ra8_rsip_sha256_block], const uint8_t inner[k_ra8_rsip_sha256_digest_bytes], uint8_t *mac_out)
Compute SHA256(K_opad || inner_digest) for HMAC.
ra8_err_t priv_hash_wait_done(void)
Wait for the HASH engine to raise DONE after the trailing block.
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.
sha256_lane_t
FIPS 180-4 6.2.2 SHA-256 working-state lane indices a..h.
@ k_sha256_lane_h
Sha256 lane h.
@ k_sha256_lane_f
Sha256 lane f.
@ k_sha256_lane_d
Sha256 lane d.
@ k_sha256_lane_c
Sha256 lane c.
@ k_sha256_lane_e
Sha256 lane e.
@ k_sha256_lane_g
Sha256 lane g.
@ k_sha256_lane_a
Sha256 lane a.
@ k_sha256_lane_b
Sha256 lane b.
static const uint32_t s_sw_sha256_h0[k_ra8_rsip_sw_sha256_state_w]
FIPS PUB 180-4 Section 5.3.3 initial hash value H(0).
static void internal_sw_sha256_schedule(uint32_t w[k_ra8_rsip_sw_sha256_round_cnt], const uint8_t block[k_ra8_rsip_sha256_block])
ra8_err_t ra8_rsip_sha256_init(ra8_rsip_sha256_ctx_t *ctx)
Initialise a streaming SHA-256 context.
ra8_err_t ra8_rsip_attach_handler(ra8_rsip_event_fn_t fn, void *ctx)
Attach a single shared interrupt callback.
static ra8_err_t internal_run_bist(void)
Arm the BIST and wait for STATUS.BIST_OK.
Renesas Secure IP (RSIP-E50D) HAL driver – public API.
void priv_unpack_le(uint32_t word, uint8_t *p)
Unpack a uint32_t into 4 little-endian bytes.
void priv_push_bytes_to_port(ra8_rsip_off_t off, const uint8_t *in, uint32_t len)
Implementation of priv_push_bytes_to_port() – LE word stream + zero-padded tail.
@ k_ra8_rsip_sha256_state_words
SHA-256 chaining-state words.
@ k_ra8_rsip_sha256_block
SHA-256 message-block byte length.
@ k_ra8_rsip_hmac_inner_pad
RFC 2104 inner-pad fill byte.
@ k_ra8_rsip_hmac_outer_pad
RFC 2104 outer-pad fill byte.
void(* ra8_rsip_event_fn_t)(void *ctx, uint32_t isr)
RSIP interrupt callback.
Cross-TU surface for the ra8_rsip driver split.
@ k_ra8_rsip_byte_bits
Shift one byte.
@ k_ra8_rsip_word_shift
log2(sizeof(uint32_t)).
@ k_ra8_rsip_byte_shift_3
Shift to top byte of word.
@ k_ra8_rsip_byte_mask
Mask one byte out of a word.
@ k_ra8_rsip_poll_budget
Max iterations for any spin loop.
@ k_ra8_rsip_byte_shift_2
Shift to high half of low word.
Renesas Secure IP (RSIP-E50D) register layout for the RA8D2.
@ k_ra8_rsip_hash_sha256
SHA-256.
static volatile uint32_t * ra8_rsip_reg32(ra8_rsip_off_t offset)
Volatile pointer to a 32-bit RSIP register at offset.
@ k_ra8_rsip_trng_word_bytes
Bytes per TRNG read.
@ k_ra8_rsip_sha256_digest_words
SHA-256 = 8 * uint32_t.
@ k_ra8_rsip_sha256_digest_bytes
SHA-256 digest length.
@ k_ra8_rsip_mask_isr_done
ISR.DONE bit.
@ k_ra8_rsip_mask_isr_all
Union of ISR bits.
@ k_ra8_rsip_mask_status_bistok
STATUS.BIST_OK.
@ k_ra8_rsip_mask_ctrl_bist
CTRL.BIST bit.
@ k_ra8_rsip_mask_ctrl_reset
CTRL.RESET bit.
@ k_ra8_rsip_mask_status_ready
STATUS.READY bit.
@ k_ra8_rsip_mask_ctrl_enable
CTRL.ENABLE bit.
ra8_rsip_off_t
Byte offsets of every register the HAL touches.
@ k_ra8_rsip_off_ctrl
Engine control word.
@ k_ra8_rsip_off_status
Status / state monitor.
@ k_ra8_rsip_off_hash_digest
HASH output digest base.
@ k_ra8_rsip_off_isr
Interrupt status (W1C).
@ k_ra8_rsip_off_rnd_ctrl
TRNG control word.
@ k_ra8_rsip_off_rnd_data
TRNG output (32-bit per read).
@ k_ra8_rsip_off_hash_status
HASH ready / done flags.
@ k_ra8_rsip_off_rnd_status
TRNG ready / health flags.
@ k_ra8_rsip_off_hash_ctrl
HASH control (algorithm select).
@ k_ra8_rsip_off_hash_data_in
HASH input window (32-bit each).
Initial configuration for ra8_rsip_init.
bool run_bist
true -> arm BIST after MSTP release.
Streaming state for incremental HMAC-SHA-256.
ra8_rsip_sha256_ctx_t inner
Running inner-hash state.
uint8_t key_block[k_ra8_rsip_sha256_block]
Prepared 64-byte key block.
uint8_t initialized
1 = ready, 0 = unset.
Streaming state for incremental SHA-256.
uint32_t state[k_ra8_rsip_sha256_state_words]
Chaining words H0..H7.
uint8_t block[k_ra8_rsip_sha256_block]
Partial message block.
uint32_t used
Bytes in block.
uint8_t initialized
1 = ready, 0 = unset.
uint64_t total_bytes
Bytes absorbed so far.