61static const char*
s_tag =
"RSIP";
160 for (uint32_t b = 0U; (i + b) < len; ++b) {
174 const uint32_t index = lane_base + b;
175 if (index < iv_len) {
189 for (uint32_t w = 0U; w < handle->
body_words; ++w) {
196 if (handle ==
nullptr) {
235#if defined(RA8_INSECURE_STUB_CRYPTO) || defined(RA8_OFF_TARGET)
239static void internal_push_data(
const uint8_t* in, uint32_t len)
255 for (uint32_t b = 0U; (i + b) < len; ++b) {
267static void internal_pull_data(uint8_t* out, uint32_t len)
285 for (uint32_t b = 0U; (i + b) < len; ++b) {
293static void internal_push_iv(
const uint8_t* iv, uint32_t iv_len)
324 if (src !=
nullptr) {
325 internal_push_data(src, src_len);
336 out->
alg = (uint32_t)cmd;
339 for (uint32_t w = 0U; w < words; ++w) {
419 return internal_oem_install(alg,
nullptr, key, key_len, out);
424 const uint8_t* oem_blob,
434 if (blob_len == 0U) {
437 return internal_oem_install(cmd, iv, oem_blob, blob_len, out);
464 internal_push_data(in, len);
471 internal_pull_data(out, len);
495 if (alg_byte == 0U) {
498 return internal_sym_run(key, alg_byte, mode, dir, iv, in, out, len);
503static void internal_aead_push_tag(
const uint8_t* tag)
513static void internal_aead_pull_tag(uint8_t* tag)
541 if ((aad !=
nullptr) && (aad_len > 0U)) {
548 internal_aead_push_tag(tag);
554 internal_push_data(in, in_len);
561 internal_pull_data(out, in_len);
564 internal_aead_pull_tag(tag);
585 if (alg_byte == 0U) {
588 return internal_aead_run(key,
617 if (alg_byte == 0U) {
620 return internal_aead_run(key,
640static void internal_chacha20_push_iv(uint32_t counter,
const uint8_t* nonce)
653 const uint8_t* nonce,
667 internal_chacha20_push_iv(counter, nonce);
673 internal_push_data(in, len);
680 internal_pull_data(out, len);
686 const uint8_t* nonce,
702 return internal_aead_run(key,
716ra8_rsip_poly1305(
const uint8_t* one_time_key,
const uint8_t* msg, uint32_t msg_len, uint8_t* tag)
720 if ((msg ==
nullptr) && (msg_len != 0U)) {
735 internal_push_data(msg, msg_len);
804 const uint8_t* oem_blob,
880 const uint8_t* nonce,
898 const uint8_t* nonce,
919ra8_rsip_poly1305(
const uint8_t* one_time_key,
const uint8_t* msg, uint32_t msg_len, uint8_t* tag)
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#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_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_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_hw_error
Generic hardware fault detected (error flag set, fault interrupt).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Lightweight Logging Interface for ra8-firmware.
ra8_err_t priv_wait_bit(ra8_rsip_off_t offset, uint32_t mask)
Implementation of priv_wait_bit() – bounded MMIO mask spin.
Renesas Secure IP (RSIP-E50D) HAL driver – public API.
ra8_err_t ra8_rsip_oem_install(ra8_rsip_oem_cmd_t cmd, const uint8_t *iv, const uint8_t *oem_blob, uint32_t blob_len, ra8_rsip_key_handle_t *out)
Install an OEM-encrypted key blob into the wrapped vault.
ra8_err_t ra8_rsip_chacha20_poly1305(const ra8_rsip_key_handle_t *key, ra8_rsip_aes_dir_t dir, const uint8_t *nonce, const uint8_t *aad, uint32_t aad_len, const uint8_t *in, uint8_t *out, uint32_t in_len, uint8_t *tag)
ChaCha20-Poly1305 AEAD encrypt or decrypt (RFC 7539).
ra8_err_t ra8_rsip_aes256_install_plain(const uint8_t *key, ra8_rsip_key_handle_t *out)
Wrap a 32-byte AES-256 key (see ra8_rsip_aes128_install_plain).
ra8_err_t ra8_rsip_aes_cipher(const ra8_rsip_key_handle_t *key, ra8_rsip_aes_mode_t mode, ra8_rsip_aes_dir_t dir, const uint8_t *iv, const uint8_t *in, uint8_t *out, uint32_t len)
Encrypt or decrypt a buffer with AES in a non-AEAD mode.
uint8_t priv_aes_alg_byte(uint32_t alg)
Pick the AES algorithm byte that matches the wrapped key.
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.
ra8_err_t ra8_rsip_poly1305(const uint8_t *one_time_key, const uint8_t *msg, uint32_t msg_len, uint8_t *tag)
Poly1305 MAC over a buffer using a 32-byte one-time key.
ra8_err_t ra8_rsip_hmac_install_plain(ra8_rsip_oem_cmd_t alg, const uint8_t *key, uint32_t key_len, ra8_rsip_key_handle_t *out)
Wrap an HMAC key for use by the HMAC engine.
ra8_err_t ra8_rsip_chacha20(const ra8_rsip_key_handle_t *key, ra8_rsip_aes_dir_t dir, const uint8_t *nonce, uint32_t counter, const uint8_t *in, uint8_t *out, uint32_t len)
ChaCha20 stream encrypt or decrypt (RFC 7539, no AEAD).
ra8_err_t ra8_rsip_aes128_install_plain(const uint8_t *key, ra8_rsip_key_handle_t *out)
Wrap a 16-byte AES-128 key for use by the engine.
uint32_t priv_handle_words_for(ra8_rsip_oem_cmd_t cmd)
Map an OEM opcode to the wrapped-key body word count.
ra8_err_t ra8_rsip_chacha20_install_plain(const uint8_t *key, ra8_rsip_key_handle_t *out)
Wrap a 32-byte ChaCha20 key.
void priv_load_handle(const ra8_rsip_key_handle_t *handle)
Stream a wrapped-key body into the engine input FIFO.
void priv_push_handle_body(const ra8_rsip_key_handle_t *handle)
Implementation of priv_push_handle_body() – KEY_STAGE body word stream.
uint32_t priv_pack_le(const uint8_t *p)
Pack 4 little-endian bytes into a uint32_t.
void priv_push_iv_lanes(ra8_rsip_off_t base, const uint8_t *iv, uint32_t iv_len)
Implementation of priv_push_iv_lanes() – bounded 4-lane LE IV window writer.
ra8_err_t ra8_rsip_aes_gcm(const ra8_rsip_key_handle_t *key, ra8_rsip_aes_dir_t dir, const uint8_t *iv, const uint8_t *aad, uint32_t aad_len, const uint8_t *in, uint8_t *out, uint32_t in_len, uint8_t *tag)
AES-GCM encrypt or decrypt with associated data.
ra8_err_t ra8_rsip_aes192_install_plain(const uint8_t *key, ra8_rsip_key_handle_t *out)
Wrap a 24-byte AES-192 key (see ra8_rsip_aes128_install_plain).
ra8_err_t priv_complete(uint32_t done_mask)
Drive a single mailbox completion (DONE poll + ack).
ra8_err_t ra8_rsip_aes_ccm(const ra8_rsip_key_handle_t *key, ra8_rsip_aes_dir_t dir, const uint8_t *iv, const uint8_t *aad, uint32_t aad_len, const uint8_t *in, uint8_t *out, uint32_t in_len, uint8_t *tag)
AES-CCM encrypt or decrypt with associated data.
Cross-TU surface for the ra8_rsip driver split.
@ k_ra8_rsip_iv_words
IV / nonce register lanes.
@ k_ra8_rsip_aes_block_w
16-byte block = 4 * uint32_t.
@ k_ra8_rsip_aead_iv_bytes
Fixed GCM / CCM nonce length.
@ 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_byte_shift_2
Shift to high half of low word.
Renesas Secure IP (RSIP-E50D) register layout for the RA8D2.
@ k_ra8_rsip_sym_alg_chacha20
ChaCha20 stream cipher.
@ k_ra8_rsip_sym_alg_aes128
AES with a 128-bit key.
@ k_ra8_rsip_sym_alg_aes256
AES with a 256-bit key.
@ k_ra8_rsip_sym_alg_aes192
AES with a 192-bit key.
@ k_ra8_rsip_handle_words_hmac_sha384
HMAC-SHA-384 wrapped key.
@ k_ra8_rsip_handle_words_rsa4096_priv
RSA-4096 wrapped private.
@ k_ra8_rsip_handle_words_ecc521_priv
ECC P-521 wrapped private.
@ k_ra8_rsip_handle_words_hmac_sha224
HMAC-SHA-224 wrapped key.
@ k_ra8_rsip_handle_words_chacha20
ChaCha20 wrapped key body.
@ k_ra8_rsip_handle_words_rsa2048_priv
RSA-2048 wrapped private.
@ k_ra8_rsip_handle_words_rsa3072_priv
RSA-3072 wrapped private.
@ k_ra8_rsip_handle_words_aes128
AES-128 wrapped-key body.
@ k_ra8_rsip_handle_words_aes192
AES-192 wrapped-key body.
@ k_ra8_rsip_handle_words_hmac_sha512
HMAC-SHA-512 wrapped key.
@ k_ra8_rsip_handle_words_ecc384_priv
ECC P-384 wrapped private.
@ k_ra8_rsip_handle_words_aes256
AES-256 wrapped-key body.
@ k_ra8_rsip_handle_words_hmac_sha256
HMAC-SHA-256 wrapped key.
@ k_ra8_rsip_handle_words_ecc256_priv
ECC P-256 wrapped private.
ra8_rsip_aes_dir_t
Direction selector for symmetric ciphers.
@ k_ra8_rsip_dir_decrypt
Ciphertext -> Plaintext.
@ k_ra8_rsip_dir_encrypt
Plaintext -> Ciphertext.
@ k_ra8_rsip_chacha_op_poly1305_mac
Poly1305 MAC only.
@ k_ra8_rsip_chacha_op_encrypt
ChaCha20 stream encrypt.
ra8_rsip_oem_cmd_t
OEM-key install opcode written to OEM_CTRL.
@ k_ra8_rsip_oem_cmd_rsa3072_priv
RSA-3072 private.
@ k_ra8_rsip_oem_cmd_ecc_secp521r1_priv
ECC NIST P-521 private.
@ k_ra8_rsip_oem_cmd_rsa4096_priv
RSA-4096 private.
@ k_ra8_rsip_oem_cmd_ecc_secp256r1_priv
ECC NIST P-256 private.
@ k_ra8_rsip_oem_cmd_ecc_brain512r1_priv
ECC Brainpool P-512.
@ k_ra8_rsip_oem_cmd_ecc_secp256k1_priv
ECC secp256k1 private.
@ k_ra8_rsip_oem_cmd_ecc_secp384r1_priv
ECC NIST P-384 private.
@ k_ra8_rsip_oem_cmd_hmac_sha384
HMAC-SHA-384.
@ k_ra8_rsip_oem_cmd_chacha20
ChaCha20.
@ k_ra8_rsip_oem_cmd_aes256
AES-256.
@ k_ra8_rsip_oem_cmd_ecc_brain256r1_priv
ECC Brainpool P-256.
@ k_ra8_rsip_oem_cmd_aes128_xts
AES-128 XTS.
@ k_ra8_rsip_oem_cmd_hmac_sha512_224
HMAC-SHA-512/224.
@ k_ra8_rsip_oem_cmd_aes256_xts
AES-256 XTS.
@ k_ra8_rsip_oem_cmd_aes192
AES-192.
@ k_ra8_rsip_oem_cmd_hmac_sha224
HMAC-SHA-224.
@ k_ra8_rsip_oem_cmd_ecc_brain384r1_priv
ECC Brainpool P-384.
@ k_ra8_rsip_oem_cmd_rsa2048_priv
RSA-2048 private.
@ k_ra8_rsip_oem_cmd_hmac_sha512
HMAC-SHA-512.
@ k_ra8_rsip_oem_cmd_invalid
Sentinel / unused.
@ k_ra8_rsip_oem_cmd_hmac_sha256
HMAC-SHA-256.
@ k_ra8_rsip_oem_cmd_ecc_ed25519_priv
Ed25519 private.
@ k_ra8_rsip_oem_cmd_aes128
AES-128.
@ k_ra8_rsip_oem_cmd_hmac_sha512_256
HMAC-SHA-512/256.
static volatile uint32_t * ra8_rsip_reg32(ra8_rsip_off_t offset)
Volatile pointer to a 32-bit RSIP register at offset.
ra8_rsip_aes_mode_t
Block-cipher mode selector for the AES engine.
@ k_ra8_rsip_aes_mode_ecb
ECB.
@ k_ra8_rsip_aes_mode_cbc
CBC.
@ k_ra8_rsip_aes_mode_cmac
CMAC.
@ k_ra8_rsip_aes_mode_gcm
GCM (AEAD).
@ k_ra8_rsip_aes_mode_ccm
CCM (AEAD).
@ k_ra8_rsip_trng_word_bytes
Bytes per TRNG read.
@ k_ra8_rsip_aes_block_bytes
AES block = 128 bits.
@ k_ra8_rsip_aes192_key_bytes
AES-192 key length.
@ k_ra8_rsip_chacha_key_bytes
ChaCha20 256-bit key.
@ k_ra8_rsip_aes256_key_bytes
AES-256 key length.
@ k_ra8_rsip_aes128_key_bytes
AES-128 key length.
@ k_ra8_rsip_mask_isr_done
ISR.DONE bit.
ra8_rsip_off_t
Byte offsets of every register the HAL touches.
@ k_ra8_rsip_off_mbox_ret
Completion code from engine.
@ k_ra8_rsip_off_data_out0
Data output lane 0.
@ k_ra8_rsip_off_sym_ctrl
Cipher command (mode|dir|alg).
@ k_ra8_rsip_off_oem_iv
OEM install IV.
@ k_ra8_rsip_off_isr
Interrupt status (W1C).
@ k_ra8_rsip_off_data_in0
Data input lane 0.
@ k_ra8_rsip_off_sym_iv3
IV / nonce lane 3.
@ k_ra8_rsip_off_sym_keyh
Cipher key-handle slot.
@ k_ra8_rsip_off_sym_iv1
IV / nonce lane 1.
@ k_ra8_rsip_off_sym_tag
AEAD authentication tag.
@ k_ra8_rsip_off_mbox_op
Opcode written by host.
@ k_ra8_rsip_off_sym_aad_len
AEAD AAD length (bytes).
@ k_ra8_rsip_off_oem_arg
OEM install argument descriptor.
@ k_ra8_rsip_off_oem_ctrl
OEM install command word.
@ k_ra8_rsip_off_key_stage
Wrapped-key load port.
@ k_ra8_rsip_off_sym_iv0
IV / nonce lane 0.
@ k_ra8_rsip_off_sym_aad_in
AEAD additional-data input.
@ k_ra8_rsip_off_sym_pt_len
AEAD plaintext length (bytes).
@ k_ra8_rsip_off_sym_iv2
IV / nonce lane 2.
Opaque wrapped-key handle.
uint32_t body_words
Number of body words (1..261).
uint32_t body[k_ra8_rsip_handle_words_rsa4096_priv]
Wrapped body.
uint32_t alg
OEM-cmd algorithm selector.