ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_dotf.h
Go to the documentation of this file.
1
101
102#pragma once
103
104#ifdef __cplusplus
105extern "C" {
106#endif
107
108#include <stdint.h>
109
110#include "ra8_dotf_regs.h"
111#include "ra8_err.h"
112
113/* =============================================================================
114 * Configuration enums
115 * =============================================================================
116 */
117
133
153
154/* =============================================================================
155 * Region descriptor
156 * =============================================================================
157 */
158
172typedef struct {
173 uint32_t start_addr;
174 uint32_t end_addr;
175 uint8_t key_index;
176 uint8_t region_id;
178
179/* =============================================================================
180 * Key handle (opaque to ra8_rsip)
181 * =============================================================================
182 */
183
201typedef struct {
203 uint8_t key_index;
204 uint8_t valid;
205 uint32_t words[8];
207
214typedef void (*ra8_dotf_event_fn_t)(void* ctx, uint8_t channel);
215
216/* =============================================================================
217 * Lifecycle
218 * =============================================================================
219 */
220
246[[nodiscard]] ra8_err_t ra8_dotf_init(void);
247
261[[nodiscard]] ra8_err_t ra8_dotf_deinit(void);
262
263/* =============================================================================
264 * Per-region configuration (multi-region staging)
265 * =============================================================================
266 */
267
310[[nodiscard]] ra8_err_t ra8_dotf_set_region(uint8_t channel, const ra8_dotf_region_t* region);
311
341[[nodiscard]] ra8_err_t ra8_dotf_select_region(uint8_t channel, uint8_t region_id);
342
363[[nodiscard]] ra8_err_t ra8_dotf_get_active_region(uint8_t channel, ra8_dotf_region_t* region);
364
365/* =============================================================================
366 * RSIP key + IV staging
367 * =============================================================================
368 */
369
402[[nodiscard]] ra8_err_t ra8_dotf_install_key(uint8_t channel, const ra8_dotf_key_handle_t* handle);
403
444[[nodiscard]] ra8_err_t ra8_dotf_rotate_key(uint8_t channel,
445 const ra8_dotf_key_handle_t* new_handle,
446 const uint32_t* iv_words);
447
475[[nodiscard]] ra8_err_t ra8_dotf_set_iv(uint8_t channel, const uint32_t* iv_words);
476
477/* =============================================================================
478 * Per-channel enable / disable
479 * =============================================================================
480 */
481
508[[nodiscard]] ra8_err_t ra8_dotf_enable(uint8_t channel);
509
521[[nodiscard]] ra8_err_t ra8_dotf_disable(uint8_t channel);
522
523/* =============================================================================
524 * REG00 sub-field tuning
525 * =============================================================================
526 */
527
545[[nodiscard]] ra8_err_t ra8_dotf_set_sca_level(uint8_t channel, ra8_dotf_sca_level_t level);
546
564[[nodiscard]] ra8_err_t ra8_dotf_set_key_size(uint8_t channel, ra8_dotf_key_size_t size);
565
595[[nodiscard]] ra8_err_t ra8_dotf_run_self_test(uint8_t channel, uint32_t* out_status);
596
597/* =============================================================================
598 * Status accessors
599 * =============================================================================
600 */
601
615[[nodiscard]] ra8_err_t ra8_dotf_get_status(uint8_t channel, uint32_t* out_mask);
616
628[[nodiscard]] ra8_err_t ra8_dotf_clear_status(uint8_t channel);
629
630/* =============================================================================
631 * IRQ attach / dispatch
632 * =============================================================================
633 */
634
654[[nodiscard]] ra8_err_t ra8_dotf_attach_handler(ra8_dotf_event_fn_t fn, void* ctx);
655
670void ra8_dotf_dispatch(uint8_t channel);
671
672/* =============================================================================
673 * Power transition
674 * =============================================================================
675 */
676
698
729[[nodiscard]] ra8_err_t ra8_dotf_open(const ra8_dotf_open_cfg_t* cfg);
730
749[[nodiscard]] ra8_err_t ra8_dotf_close(void);
750
780[[nodiscard]] ra8_err_t ra8_dotf_set_region_window(uint8_t channel, uint32_t start, uint32_t len);
781
792[[nodiscard]] ra8_err_t ra8_dotf_enter_stop(void);
793
804[[nodiscard]] ra8_err_t ra8_dotf_exit_stop(void);
805
806#ifdef __cplusplus
807}
808#endif
ra8_err_t ra8_dotf_deinit(void)
Disable DOTF and gate the OSPI clock.
Definition ra8_dotf.c:545
ra8_err_t ra8_dotf_exit_stop(void)
Bring the DOTF block back from low-power mode.
ra8_err_t ra8_dotf_close(void)
Tear down DOTF and release all hardware state.
ra8_err_t ra8_dotf_clear_status(uint8_t channel)
Clear REG00 (force the channel into bypass).
Definition ra8_dotf.c:928
void ra8_dotf_dispatch(uint8_t channel)
Dispatch a DOTF event from the IRQ glue.
Definition ra8_dotf.c:956
ra8_err_t ra8_dotf_enter_stop(void)
Park the DOTF block prior to entering a low-power mode.
ra8_err_t ra8_dotf_open(const ra8_dotf_open_cfg_t *cfg)
One-shot DOTF bring-up: init + install_key + set_iv + set_region (+ enable).
ra8_err_t ra8_dotf_set_sca_level(uint8_t channel, ra8_dotf_sca_level_t level)
Update the side-channel countermeasure level for a channel.
Definition ra8_dotf.c:843
ra8_err_t ra8_dotf_enable(uint8_t channel)
Enable AES decryption for one channel.
Definition ra8_dotf.c:804
ra8_dotf_key_size_t
AES key sizes supported by the DOTF AES core.
Definition ra8_dotf.h:128
@ k_ra8_dotf_key_size_128
128-bit AES.
Definition ra8_dotf.h:129
@ k_ra8_dotf_key_size_192
192-bit AES.
Definition ra8_dotf.h:130
@ k_ra8_dotf_key_size_256
256-bit AES.
Definition ra8_dotf.h:131
ra8_err_t ra8_dotf_attach_handler(ra8_dotf_event_fn_t fn, void *ctx)
Register a fault / event callback (shared across both channels).
Definition ra8_dotf.c:948
ra8_err_t ra8_dotf_set_region_window(uint8_t channel, uint32_t start, uint32_t len)
Stage a region from a (start, length) pair instead of a struct.
ra8_err_t ra8_dotf_get_status(uint8_t channel, uint32_t *out_mask)
Read REG00 (raw control / status snapshot).
Definition ra8_dotf.c:913
ra8_err_t ra8_dotf_disable(uint8_t channel)
Disable AES decryption for one channel (transparent bypass).
Definition ra8_dotf.c:823
ra8_err_t ra8_dotf_install_key(uint8_t channel, const ra8_dotf_key_handle_t *handle)
Bind a wrapped AES key handle to a DOTF channel.
Definition ra8_dotf.c:637
ra8_err_t ra8_dotf_rotate_key(uint8_t channel, const ra8_dotf_key_handle_t *new_handle, const uint32_t *iv_words)
Atomically rotate the key bound to a channel.
Definition ra8_dotf.c:764
ra8_err_t ra8_dotf_select_region(uint8_t channel, uint8_t region_id)
Promote a staged region into the live CONVAREAST / CONVAREAD pair.
Definition ra8_dotf.c:591
ra8_err_t ra8_dotf_set_iv(uint8_t channel, const uint32_t *iv_words)
Stage the AES counter-mode IV for a channel via REG03.
Definition ra8_dotf.c:661
ra8_err_t ra8_dotf_set_key_size(uint8_t channel, ra8_dotf_key_size_t size)
Update the cached AES key size for a channel.
Definition ra8_dotf.c:863
ra8_err_t ra8_dotf_init(void)
Power on the DOTF block and reset both channels.
Definition ra8_dotf.c:524
void(* ra8_dotf_event_fn_t)(void *ctx, uint8_t channel)
DOTF fault / status event callback.
Definition ra8_dotf.h:214
ra8_err_t ra8_dotf_run_self_test(uint8_t channel, uint32_t *out_status)
Trigger the built-in self-test (REG00 bit 20) for a channel.
Definition ra8_dotf.c:883
ra8_err_t ra8_dotf_get_active_region(uint8_t channel, ra8_dotf_region_t *region)
Read back the active region for a channel.
Definition ra8_dotf.c:618
ra8_dotf_sca_level_t
Side-channel countermeasure tuning levels.
Definition ra8_dotf.h:148
@ k_ra8_dotf_sca_max
Maximum level, bits 16 + 17 set.
Definition ra8_dotf.h:151
@ k_ra8_dotf_sca_standard
Default level, bit 16 set.
Definition ra8_dotf.h:150
@ k_ra8_dotf_sca_off
Side-channel countermeasures disabled.
Definition ra8_dotf.h:149
ra8_err_t ra8_dotf_set_region(uint8_t channel, const ra8_dotf_region_t *region)
Stage one DOTF region in the channel's region table.
Definition ra8_dotf.c:569
Decryption On The Fly (DOTF) register layout for the Renesas RA8D2.
@ k_ra8_dotf_reg00_key_size_128
Key size = 128-bit (FSP dflt).
@ k_ra8_dotf_reg00_key_size_192
Key size = 192-bit.
@ k_ra8_dotf_reg00_key_size_256
Key size = 256-bit.
Error Code Definitions for ra8-firmware.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Wrapped-key handle handed to DOTF by ra8_rsip.
Definition ra8_dotf.h:201
ra8_dotf_key_size_t size
128 / 192 / 256 selector for REG00.
Definition ra8_dotf.h:202
uint32_t words[8]
Wrapped-key payload (up to 256 bits).
Definition ra8_dotf.h:205
uint8_t valid
Non-zero if the wrapped key is real.
Definition ra8_dotf.h:204
uint8_t key_index
RSIP key slot this handle came from.
Definition ra8_dotf.h:203
One-shot DOTF bring-up descriptor consumed by ra8_dotf_open.
Definition ra8_dotf.h:690
bool enable_after
true => arm AES after staging.
Definition ra8_dotf.h:696
uint32_t iv_words[4]
128-bit IV in word order.
Definition ra8_dotf.h:693
ra8_dotf_sca_level_t sca_level
Side-channel level.
Definition ra8_dotf.h:695
uint8_t channel
0 = DOTF0, 1 = DOTF1.
Definition ra8_dotf.h:691
ra8_dotf_key_handle_t key
RSIP-wrapped key handle.
Definition ra8_dotf.h:692
ra8_dotf_region_t region
Initial conversion region.
Definition ra8_dotf.h:694
Conversion-area descriptor for ra8_dotf_set_region.
Definition ra8_dotf.h:172
uint8_t region_id
0..k_ra8_dotf_max_regions-1 staging slot.
Definition ra8_dotf.h:176
uint32_t start_addr
First byte of the encrypted region (incl).
Definition ra8_dotf.h:173
uint8_t key_index
RSIP key index (forwarded to install_key flow).
Definition ra8_dotf.h:175
uint32_t end_addr
Last byte of the encrypted region (incl).
Definition ra8_dotf.h:174