ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_psa_crypto_internal.h
Go to the documentation of this file.
1
31
32#pragma once
33
34#include <stddef.h>
35#include <stdint.h>
36
37#include "ra8_err.h"
38#include "ra8_psa_crypto.h"
39
40#ifndef RA8_OFF_TARGET
41/* The real backend stores a PSA key handle in each slot; pull in the type the
42 * struct below references. Skipped under RA8_OFF_TARGET, which keeps its own
43 * software key material and never links tf-psa-crypto. */
44#include "psa/crypto.h"
45#endif
46
47/* =============================================================================
48 * Internal typed constants (no magic numbers)
49 * =============================================================================
50 */
51
102
107typedef enum : uint32_t {
108 k_xs32_seed = 0xACE1ACE1U,
111
116typedef enum : uint8_t {
121
126typedef enum : uint32_t {
127 k_ra8_psa_sha256_h0 = 0x6a09e667U,
128 k_ra8_psa_sha256_h1 = 0xbb67ae85U,
129 k_ra8_psa_sha256_h2 = 0x3c6ef372U,
130 k_ra8_psa_sha256_h3 = 0xa54ff53aU,
131 k_ra8_psa_sha256_h4 = 0x510e527fU,
132 k_ra8_psa_sha256_h5 = 0x9b05688cU,
133 k_ra8_psa_sha256_h6 = 0x1f83d9abU,
134 k_ra8_psa_sha256_h7 = 0x5be0cd19U,
136
137/* =============================================================================
138 * Pool slot definition
139 * =============================================================================
140 */
141
153 bool in_use;
155 size_t key_len;
157#ifndef RA8_OFF_TARGET
158 psa_key_id_t psa_id;
159#endif
160};
161
162#ifdef RA8_OFF_TARGET
163
164/* =============================================================================
165 * Off-target crypto helpers (defined in ra8_psa_crypto_fake.c)
166 * =============================================================================
167 */
168
188void ra8_psa_fake_sha256_oneshot(const uint8_t* in,
189 size_t in_len,
190 uint8_t out[k_ra8_psa_sha256_len]);
191
220ra8_err_t ra8_psa_fake_aead_encrypt(const struct ra8_psa_key_handle* slot,
221 const uint8_t* nonce,
222 size_t nonce_len,
223 const uint8_t* aad,
224 size_t aad_len,
225 const uint8_t* plain,
226 size_t plain_len,
227 uint8_t* out,
228 size_t* out_len);
229
259ra8_err_t ra8_psa_fake_aead_decrypt(const struct ra8_psa_key_handle* slot,
260 const uint8_t* nonce,
261 size_t nonce_len,
262 const uint8_t* aad,
263 size_t aad_len,
264 const uint8_t* cipher,
265 size_t plain_len,
266 uint8_t* out,
267 size_t* out_len);
268
269#endif /* RA8_OFF_TARGET */
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
Application-level PSA Crypto facade over tf-psa-crypto.
@ k_ra8_psa_max_key_bytes
Maximum imported raw-key length in bytes (P-384 + AES-256).
@ k_ra8_psa_sha256_len
SHA-256 digest length (RFC 6234, Section 4.1).
ra8_psa_internal_const_t
Internal numeric constants used by the crypto facade.
@ k_ra8_psa_shift_b2
Shift for big-endian byte 2.
@ k_ra8_psa_state_idx_d
SHA-256 working register d slot.
@ k_ra8_psa_rot_e_a
Sigma1(e) rot a.
@ k_ra8_psa_state_idx_f
SHA-256 working register f slot.
@ k_ra8_psa_w_back_2
Schedule offset W[i-2].
@ k_ra8_psa_sha256_schedule_len
Length of message schedule W[].
@ k_ra8_psa_fake_scratch_bytes
AEAD fake scratch buffer size.
@ k_ra8_psa_state_idx_e
SHA-256 working register e slot.
@ k_ra8_psa_shift_b1
Shift for big-endian byte 1.
@ k_ra8_psa_state_idx_b
SHA-256 working register b slot.
@ k_ra8_psa_sha256_block_bytes
SHA-256 message block size.
@ k_ra8_psa_word_bits
Word width in bits.
@ k_ra8_psa_rot_s0_b
sigma0(W[i-15]) rot b.
@ k_ra8_psa_rot_e_b
Sigma1(e) rot b.
@ k_ra8_psa_length_field_bytes
64-bit big-endian length tail.
@ k_ra8_psa_state_idx_a
SHA-256 working register a slot.
@ k_ra8_psa_bytes_per_word
Bytes packed per 32-bit word.
@ k_ra8_psa_sha256_pad_buf_len
Two-block padding scratch.
@ k_ra8_psa_w_back_7
Schedule offset W[i-7].
@ k_ra8_psa_byte_bits
Bits per byte.
@ k_ra8_psa_sha256_init_words
Initial copy from block to W[].
@ k_ra8_psa_rot_e_c
Sigma1(e) rot c.
@ k_ra8_psa_state_idx_g
SHA-256 working register g slot.
@ k_ra8_psa_state_idx_h
SHA-256 working register h slot.
@ k_ra8_psa_rot_a_a
Sigma0(a) rot a.
@ k_ra8_psa_shift_b3
Shift for big-endian byte 3.
@ k_ra8_psa_w_back_16
Schedule offset W[i-16].
@ k_ra8_psa_rot_s0_a
sigma0(W[i-15]) rot a.
@ k_ra8_psa_w_back_15
Schedule offset W[i-15].
@ k_ra8_psa_sha256_state_words
SHA-256 working state words.
@ k_ra8_psa_state_idx_c
SHA-256 working register c slot.
@ k_ra8_psa_rot_s1_a
sigma1(W[i-2]) rot a.
@ k_ra8_psa_shr_s0
sigma0(W[i-15]) shr.
@ k_ra8_psa_shr_s1
sigma1(W[i-2]) shr.
@ k_ra8_psa_rot_s1_b
sigma1(W[i-2]) rot b.
@ k_ra8_psa_rot_a_b
Sigma0(a) rot b.
@ k_ra8_psa_sha256_pad_threshold
If remaining < this, one tail block.
@ k_ra8_psa_rot_a_c
Sigma0(a) rot c.
@ k_ra8_psa_pad_marker
SHA-256 padding sentinel byte.
ra8_psa_sha256_iv_t
SHA-256 initial hash values H0..H7 (FIPS 180-4 Sec 5.3.3).
@ k_ra8_psa_sha256_h0
RA8 PSA sha256 h0.
@ k_ra8_psa_sha256_h6
RA8 PSA sha256 h6.
@ k_ra8_psa_sha256_h4
RA8 PSA sha256 h4.
@ k_ra8_psa_sha256_h7
RA8 PSA sha256 h7.
@ k_ra8_psa_sha256_h5
RA8 PSA sha256 h5.
@ k_ra8_psa_sha256_h1
RA8 PSA sha256 h1.
@ k_ra8_psa_sha256_h2
RA8 PSA sha256 h2.
@ k_ra8_psa_sha256_h3
RA8 PSA sha256 h3.
ra8_psa_xs32_const_t
xorshift32 off-target RNG constants (Marsaglia 2003).
@ k_xs32_seed
Default seed.
@ k_xs32_byte_m
Mask isolating the low byte of state.
ra8_psa_xs32_shift_t
xorshift32 shift amounts (Marsaglia 2003 Table 1 row "y[13,17,5]").
@ k_xs32_shr_b
Right shift.
@ k_xs32_shl_c
Second left shift.
@ k_xs32_shl_a
First left shift.
Attributes describing a key being imported.
Forward declaration of the static-pool slot type.
psa_key_id_t psa_id
Underlying PSA key identifier.
uint8_t key[k_ra8_psa_max_key_bytes]
Raw key material (fake).
ra8_psa_key_attr_t attr
Cached caller attributes.
size_t key_len
Bytes valid in key.
bool in_use
Slot allocated.