ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
32
33#include <stdint.h>
34#include <string.h>
35
36#include "ra8_attributes.h"
37#include "ra8_board_ek_ra8d2.h"
38#include "ra8_boot_entry.h"
39#include "ra8_cgc.h"
40#include "ra8_err.h"
41#include "ra8_isr.h"
42#include "ra8_rsip_core.h"
43#include "ra8_time.h"
44
46typedef enum : uint32_t {
47 k_kat_baud = 115200U,
50
52typedef enum : uint8_t {
55
57static const uint8_t s_msg_abc[] = {'a', 'b', 'c'};
58
60static const uint8_t s_msg_two_block[] = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
61
64 0xE3U, 0xB0U, 0xC4U, 0x42U, 0x98U, 0xFCU, 0x1CU, 0x14U, 0x9AU, 0xFBU, 0xF4U,
65 0xC8U, 0x99U, 0x6FU, 0xB9U, 0x24U, 0x27U, 0xAEU, 0x41U, 0xE4U, 0x64U, 0x9BU,
66 0x93U, 0x4CU, 0xA4U, 0x95U, 0x99U, 0x1BU, 0x78U, 0x52U, 0xB8U, 0x55U,
67};
68
71 0xBAU, 0x78U, 0x16U, 0xBFU, 0x8FU, 0x01U, 0xCFU, 0xEAU, 0x41U, 0x41U, 0x40U,
72 0xDEU, 0x5DU, 0xAEU, 0x22U, 0x23U, 0xB0U, 0x03U, 0x61U, 0xA3U, 0x96U, 0x17U,
73 0x7AU, 0x9CU, 0xB4U, 0x10U, 0xFFU, 0x61U, 0xF2U, 0x00U, 0x15U, 0xADU,
74};
75
78 0x24U, 0x8DU, 0x6AU, 0x61U, 0xD2U, 0x06U, 0x38U, 0xB8U, 0xE5U, 0xC0U, 0x26U,
79 0x93U, 0x0CU, 0x3EU, 0x60U, 0x39U, 0xA3U, 0x3CU, 0xE4U, 0x59U, 0x64U, 0xFFU,
80 0x21U, 0x67U, 0xF6U, 0xECU, 0xEDU, 0xD4U, 0x19U, 0xDBU, 0x06U, 0xC1U,
81};
82
84static const uint8_t s_kat_msg_ok[] = "rsip sha256: KAT OK\r\n";
85
87static const uint8_t s_kat_msg_fail[] = "rsip sha256: KAT FAIL\r\n";
88
103{
104 while (1) {
105 __asm__ volatile("wfi");
106 }
107}
108
123{
124 uint32_t cpuclk0_hz = 0U;
125 if (ra8_cgc_init() != k_ra8_ok) {
127 }
130 }
131 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
133 }
136 }
139 }
142 }
143 /* ra8_rsip_sha256 uses the software SHA-256 backend (the RSIP HASH hardware has
144 * no usable register interface -- see libs/ra8_hal/src/ra8_rsip.c), so no RSIP
145 * engine bring-up is required. */
146}
147
169[[nodiscard]] RA8_INTERNAL static bool
170internal_kat_one(const uint8_t* msg, uint32_t len, const uint8_t* expect)
171{
172 uint8_t digest[k_ra8_rsip_sha256_digest_bytes] = {};
173 if (ra8_rsip_sha256(msg, len, digest) != k_ra8_ok) {
174 return false;
175 }
176 return memcmp(digest, expect, (size_t)k_ra8_rsip_sha256_digest_bytes) == 0;
177}
178
179void main(void)
180{
183
184 while (1) {
185 bool ok = true;
186 if (!internal_kat_one(s_msg_abc, (uint32_t)sizeof(s_msg_abc), s_exp_abc)) {
187 ok = false;
188 }
190 ok = false;
191 }
192 if (!internal_kat_one(s_msg_abc, 0U, s_exp_empty)) { /* zero-length: msg ignored */
193 ok = false;
194 }
195
196 if (ok) {
197 (void)ra8_board_uart_console_write(s_kat_msg_ok, (size_t)(sizeof(s_kat_msg_ok) - 1U));
199 } else {
200 (void)ra8_board_uart_console_write(s_kat_msg_fail, (size_t)(sizeof(s_kat_msg_fail) - 1U));
202 }
204 }
206}
void main(void)
Secure fallback main entry point.
Definition main.c:37
kat_const_t
Demo tunables.
Definition main.c:39
@ k_kat_period_ms
Kat period ms.
Definition main.c:41
@ k_kat_baud
Kat baud.
Definition main.c:40
static const uint8_t s_exp_two_block[k_ra8_rsip_sha256_digest_bytes]
Expected SHA-256(56-byte two-block message) – FIPS 180-4.
Definition main.c:77
static bool internal_kat_one(const uint8_t *msg, uint32_t len, const uint8_t *expect)
Hash one message on the RSIP engine and compare to a known answer.
Definition main.c:170
kat_msg_len_t
Length of the 56-byte NIST two-block message (excludes the NUL).
Definition main.c:52
@ k_kat_msg2_len
Kat msg2 length.
Definition main.c:53
static void internal_kat_panic_halt(void)
Park the processor after fatal setup or KAT control-flow failure.
Definition main.c:102
static const uint8_t s_exp_abc[k_ra8_rsip_sha256_digest_bytes]
Expected SHA-256("abc") – FIPS 180-4.
Definition main.c:70
static const uint8_t s_kat_msg_fail[]
HIL verdict emitted after one or more SHA-256 vectors fail.
Definition main.c:87
static const uint8_t s_msg_two_block[]
NIST vector 3 input: the 448-bit two-block message.
Definition main.c:60
static const uint8_t s_msg_abc[]
NIST vector 2 input: "abc".
Definition main.c:57
static const uint8_t s_kat_msg_ok[]
HIL verdict emitted after all SHA-256 vectors pass.
Definition main.c:84
static const uint8_t s_exp_empty[k_ra8_rsip_sha256_digest_bytes]
Expected SHA-256("") – FIPS 180-4.
Definition main.c:63
static void internal_kat_setup_or_halt(void)
Initialize clocks, timing, console, and status LEDs for the KAT.
Definition main.c:122
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_err_t ra8_board_led_toggle(ra8_board_led_id_t led)
Toggle led's output state.
ra8_err_t ra8_board_led_init(ra8_board_led_id_t led)
Configure led as a digital output, initial level low (off).
@ k_ra8_board_led2
LED2, GREEN, P303 (jumper E26).
@ k_ra8_board_led1
LED1, BLUE, P600 (jumper E27).
ra8_err_t ra8_board_uart_console_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
ra8_err_t ra8_board_uart_console_init(uint32_t baud)
Configure SCI8 + PD02/PD03 as the debug-console UART.
Boot entry points shared between a vector table and its startup code.
High-level Clock Generation Circuit driver.
ra8_err_t ra8_cgc_get_clock_hz(ra8_clock_id_t id, uint32_t *out_hz)
Query the current frequency of a clock-tree domain.
Definition ra8_cgc.c:132
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
Definition ra8_cgc.h:70
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Definition ra8_cgc.c:727
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Definition ra8_isr.c:439
Renesas Secure IP (RSIP-E50D) HAL – core lifecycle / TRNG / hash API.
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.
Definition ra8_rsip.c:397
@ k_ra8_rsip_sha256_digest_bytes
SHA-256 digest length.
SysTick-based tick counter, delay and timestamp helpers.
ra8_err_t ra8_time_init(uint32_t cpu_hz)
Initialise SysTick for a 1 kHz tick interrupt.
Definition ra8_time.c:59
void ra8_delay_ms(uint32_t ms)
Busy-wait for at least ms milliseconds.
Definition ra8_time.c:129