50 0x428a2f98U, 0x71374491U, 0xb5c0fbcfU, 0xe9b5dba5U, 0x3956c25bU, 0x59f111f1U, 0x923f82a4U,
51 0xab1c5ed5U, 0xd807aa98U, 0x12835b01U, 0x243185beU, 0x550c7dc3U, 0x72be5d74U, 0x80deb1feU,
52 0x9bdc06a7U, 0xc19bf174U, 0xe49b69c1U, 0xefbe4786U, 0x0fc19dc6U, 0x240ca1ccU, 0x2de92c6fU,
53 0x4a7484aaU, 0x5cb0a9dcU, 0x76f988daU, 0x983e5152U, 0xa831c66dU, 0xb00327c8U, 0xbf597fc7U,
54 0xc6e00bf3U, 0xd5a79147U, 0x06ca6351U, 0x14292967U, 0x27b70a85U, 0x2e1b2138U, 0x4d2c6dfcU,
55 0x53380d13U, 0x650a7354U, 0x766a0abbU, 0x81c2c92eU, 0x92722c85U, 0xa2bfe8a1U, 0xa81a664bU,
56 0xc24b8b70U, 0xc76c51a3U, 0xd192e819U, 0xd6990624U, 0xf40e3585U, 0x106aa070U, 0x19a4c116U,
57 0x1e376c08U, 0x2748774cU, 0x34b0bcb5U, 0x391c0cb3U, 0x4ed8aa4aU, 0x5b9cca4fU, 0x682e6ff3U,
58 0x748f82eeU, 0x78a5636fU, 0x84c87814U, 0x8cc70208U, 0x90befffaU, 0xa4506cebU, 0xbef9a3f7U,
63static inline uint32_t internal_sha256_rotr(uint32_t x, uint32_t n)
109 const uint32_t ch = (e & f) ^ ((~e) & g);
110 const uint32_t temp1 = h + big_sigma1 + ch + k_sha256_round_const[i] + schedule[i];
114 const uint32_t maj = (a & b) ^ (a & c) ^ (b & c);
115 const uint32_t temp2 = big_sigma0 + maj;
140 internal_sha256_schedule(schedule, block);
141 internal_sha256_rounds(state, schedule);
144void ra8_psa_fake_sha256_oneshot(
const uint8_t* in,
162 const uint8_t* p = in;
163 for (
size_t b = 0U; b < complete_blocks; ++b) {
164 internal_sha256_block(state, p);
177 if (tail_copy_len > 0U) {
178 (void)
memcpy(tail, p, tail_copy_len);
187 for (
size_t b = 0U; b < tail_blocks; ++b) {
225static void internal_fake_aead_tag(
const uint8_t* key,
227 const uint8_t* nonce,
231 const uint8_t* cipher,
237 for (
size_t i = 0U; (i < key_len) && (off <
sizeof(buf)); ++i) {
240 for (
size_t i = 0U; (i < nonce_len) && (off <
sizeof(buf)); ++i) {
241 buf[off++] = nonce[i];
243 for (
size_t i = 0U; (i < aad_len) && (off <
sizeof(buf)); ++i) {
246 for (
size_t i = 0U; (i < cipher_len) && (off <
sizeof(buf)); ++i) {
247 buf[off++] = cipher[i];
250 ra8_psa_fake_sha256_oneshot(buf, off, digest);
252 out_tag[i] = digest[i];
276static void internal_fake_keystream(
const uint8_t* key,
278 const uint8_t* nonce,
285 for (
size_t i = 0U; (i < key_len) && (off <
sizeof(seed)); ++i) {
286 seed[off++] = key[i];
288 for (
size_t i = 0U; (i < nonce_len) && (off <
sizeof(seed)); ++i) {
289 seed[off++] = nonce[i];
292 uint32_t counter = 0U;
293 size_t produced = 0U;
294 while (produced < len) {
298 seed[off + 3U] = (uint8_t)counter;
303 for (
size_t i = 0U; i < take; ++i) {
304 dst[produced + i] = block[i];
312 const uint8_t* nonce,
316 const uint8_t* plain,
321 if (plain_len > 0U) {
323 if (plain_len >
sizeof(ks)) {
326 internal_fake_keystream(slot->
key, slot->
key_len, nonce, nonce_len, ks, plain_len);
327 for (
size_t i = 0U; i < plain_len; ++i) {
328 out[i] = (uint8_t)(plain[i] ^ ks[i]);
331 internal_fake_aead_tag(slot->
key,
345 const uint8_t* nonce,
349 const uint8_t* cipher,
355 internal_fake_aead_tag(slot->
key,
366 diff |= (uint8_t)(expected_tag[i] ^ cipher[plain_len + i]);
371 if (plain_len > 0U) {
373 if (plain_len >
sizeof(ks)) {
376 internal_fake_keystream(slot->
key, slot->
key_len, nonce, nonce_len, ks, plain_len);
377 for (
size_t i = 0U; i < plain_len; ++i) {
378 out[i] = (uint8_t)(cipher[i] ^ ks[i]);
381 *out_len = plain_len;
Error Code Definitions for ra8-firmware.
@ k_ra8_err_crc_mismatch
CRC mismatch detected on received data.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
Application-level PSA Crypto facade over tf-psa-crypto.
@ k_ra8_psa_gcm_tag_len
AES-GCM authentication tag length (16 octets).
@ k_ra8_psa_sha256_len
SHA-256 digest length (RFC 6234, Section 4.1).
Module-private definitions shared across the ra8_psa_crypto TUs.
@ 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.
@ 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.
Forward declaration of the static-pool slot type.
uint8_t key[k_ra8_psa_max_key_bytes]
Raw key material (fake).
size_t key_len
Bytes valid in key.