ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_rsip_devsec.c
Go to the documentation of this file.
1
60
61#include <stdint.h>
62
63#include "ra8_check.h"
64#include "ra8_err.h"
65#include "ra8_log.h"
66#include "ra8_rsip.h"
67#include "ra8_rsip_regs.h"
68
80/* The fail-closed rebuild (test_ra8_rsip_devsec_failclosed) compiles this TU
81 * with RA8_LOG_LEVEL=0, where the check macros discard their tag operand. */
82[[maybe_unused]] static const char* s_tag = "RSIP";
83
84/*
85 * The device-security registers modelled below (lifecycle state, debug level,
86 * tamper control / status, DPA arm) are NOT documented RA8D2 registers: HUM
87 * Ch 51 "Security Features" (p 3263-3301) is a prose feature index and HUM
88 * Ch 52 "Renesas Secure IP (RSIP-E50D)" (p 3302-3307) is a conceptual overview
89 * with no register map -- the real state lives in the DLM / option-setting
90 * memory / SAU, not an RSIP MMIO word. The command-path bodies here only
91 * round-trip the host register fake; they compute no real security state.
92 * They compile only under the insecure-stub / off-target guard so a production
93 * image gets the fail-closed #else and can never mistake these bytes for a
94 * genuine lifecycle / debug / tamper reading. The register pokes below
95 * therefore carry NO HUM citation -- there is no real register map to cite; the
96 * former "HUM Ch 51.1 / 51.5 / 51.6" citations were fabricated and are removed.
97 */
98#if defined(RA8_INSECURE_STUB_CRYPTO) || defined(RA8_OFF_TARGET)
99
101{
102 RA8_CHECK_NULL_PTR(out, s_tag, "out must not be nullptr");
104 return k_ra8_ok;
105}
106
108{
109 if ((uint32_t)state > k_ra8_rsip_life_rma) {
111 }
112 const uint32_t cur = *ra8_rsip_reg32(k_ra8_rsip_off_life_state);
113 if ((uint32_t)state < cur) {
115 }
116 *ra8_rsip_reg32(k_ra8_rsip_off_life_state) = (uint32_t)state;
117 return k_ra8_ok;
118}
119
121{
122 RA8_CHECK_NULL_PTR(out, s_tag, "out must not be nullptr");
124 return k_ra8_ok;
125}
126
128{
129 if ((uint32_t)level > (uint32_t)k_ra8_rsip_debug_al2) {
131 }
132 *ra8_rsip_reg32(k_ra8_rsip_off_debug_level) = (uint32_t)level;
133 return k_ra8_ok;
134}
135
136ra8_err_t ra8_rsip_tamper_enable(uint32_t sources)
137{
138 if ((sources & ~k_ra8_rsip_tamper_src_all) != 0U) {
140 }
142 return k_ra8_ok;
143}
144
146{
147 RA8_CHECK_NULL_PTR(out, s_tag, "out must not be nullptr");
149 return k_ra8_ok;
150}
151
152ra8_err_t ra8_rsip_tamper_ack(uint32_t mask)
153{
154 if (mask == 0U) {
156 }
157 if ((mask & ~k_ra8_rsip_tamper_src_all) != 0U) {
159 }
161 return k_ra8_ok;
162}
163
164ra8_err_t ra8_rsip_dpa_arm(bool enable)
165{
166 volatile uint32_t* ctrl = ra8_rsip_reg32(k_ra8_rsip_off_ctrl);
167 if (enable) {
169 } else {
171 }
172 *ra8_rsip_reg32(k_ra8_rsip_off_dpa_ctrl) = (uint32_t)enable;
173 return k_ra8_ok;
174}
175
176#else /* production build: neither RA8_INSECURE_STUB_CRYPTO nor RA8_OFF_TARGET */
177
178/*
179 * Fail-closed production variant. With no documented RA8D2 device-security
180 * register interface (the real lifecycle / debug / tamper state lives in the
181 * DLM / option-setting memory / SAU, not an RSIP MMIO word), every entry point
182 * returns a hard error (never k_ra8_ok) and writes no fabricated state, so a
183 * production image cannot mistake the fake command-path for a real
184 * lifecycle, debug-authorisation, tamper, or side-channel reading.
185 */
186
188{
189 RA8_CHECK_NULL_PTR(out, s_tag, "life_get: out must not be nullptr");
191}
192
198
200{
201 RA8_CHECK_NULL_PTR(out, s_tag, "debug_level_get: out must not be nullptr");
203}
204
210
212{
213 (void)sources;
215}
216
218{
219 RA8_CHECK_NULL_PTR(out, s_tag, "tamper_status: out must not be nullptr");
221}
222
224{
225 (void)mask;
227}
228
230{
231 (void)enable;
233}
234
235#endif /* RA8_INSECURE_STUB_CRYPTO || RA8_OFF_TARGET */
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
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.
Definition ra8_check.h:243
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.
Definition ra8_err.h:180
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
Definition ra8_err.h:161
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Lightweight Logging Interface for ra8-firmware.
Renesas Secure IP (RSIP-E50D) HAL driver – public API.
ra8_err_t ra8_rsip_debug_level_get(ra8_rsip_debug_level_t *out)
Read the current debug authorisation level.
ra8_err_t ra8_rsip_tamper_ack(uint32_t mask)
Acknowledge tamper-source flags (write-1-to-clear).
ra8_err_t ra8_rsip_life_advance(ra8_rsip_life_state_t state)
Advance the device lifecycle to a new state.
ra8_err_t ra8_rsip_tamper_enable(uint32_t sources)
Enable or disable a set of tamper sources.
ra8_err_t ra8_rsip_tamper_status(uint32_t *out)
Read latched tamper-source flags.
ra8_err_t ra8_rsip_debug_level_set(ra8_rsip_debug_level_t level)
Set the debug authorisation level.
ra8_err_t ra8_rsip_dpa_arm(bool enable)
Arm or disarm SPA / DPA countermeasures.
ra8_err_t ra8_rsip_life_get(ra8_rsip_life_state_t *out)
Read the device-lifecycle state.
Renesas Secure IP (RSIP-E50D) register layout for the RA8D2.
ra8_rsip_debug_level_t
Debug authorisation levels AL0/AL1/AL2 (off-target-only model – no documented RA8D2 register; real st...
@ k_ra8_rsip_debug_al2
AL2 – secure + non-secure debug.
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_mask_ctrl_dpa_arm
CTRL.DPA_ARM bit.
@ k_ra8_rsip_tamper_src_all
Union of all sources.
ra8_rsip_life_state_t
Device-lifecycle state values (off-target-only model – no documented RA8D2 register; real state is in...
@ k_ra8_rsip_life_rma
Return-merchandise-auth.
@ k_ra8_rsip_off_ctrl
Engine control word.
@ k_ra8_rsip_off_life_state
Current lifecycle state.
@ k_ra8_rsip_off_tamper_status
Latched tamper-event flags.
@ k_ra8_rsip_off_tamper_ctrl
Tamper-source enable mask.
@ k_ra8_rsip_off_dpa_ctrl
SPA/DPA countermeasure arm.
@ k_ra8_rsip_off_debug_level
AL0/AL1/AL2 debug level.