ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_psa_crypto.c
Go to the documentation of this file.
1
37
38#include "ra8_psa_crypto.h"
39
40#include <stddef.h>
41#include <stdint.h>
42#include <string.h>
43
44#include "ra8_attributes.h"
45#include "ra8_check.h"
46#include "ra8_err.h"
47#include "ra8_log.h"
49
50#ifndef RA8_OFF_TARGET
51#include "psa/crypto.h"
52#endif
53
54/* =============================================================================
55 * Logging tag
56 * =============================================================================
57 */
58
60[[maybe_unused]] static const char* const s_ra8_psa_tag = "ra8_psa_crypto";
61
62/* =============================================================================
63 * Pool state
64 * =============================================================================
65 *
66 * The internal typed-constant enums and the concrete
67 * ``struct ra8_psa_key_handle`` definition live in
68 * ``ra8_psa_crypto_internal.h`` so the fake TU can share them.
69 */
70
73
75static bool s_initialized;
76
77/* =============================================================================
78 * Internal helpers
79 * =============================================================================
80 */
81
82/* Validate that a typed handle points into the static pool -- see implementation for details. */
84{
85 if (handle == nullptr) {
86 return false;
87 }
88 const struct ra8_psa_key_handle* base = &s_key_pool[0];
90 if ((handle < base) || (handle >= end)) {
91 return false;
92 }
93 return handle->in_use;
94}
95
102{
103 for (uint8_t i = 0U; i < (uint8_t)k_ra8_psa_max_keys; ++i) {
104 if (!s_key_pool[i].in_use) {
105 return &s_key_pool[i];
106 }
107 }
108 return nullptr;
109}
110
111/* =============================================================================
112 * Public API
113 * =============================================================================
114 */
115
117{
118 if (s_initialized) {
119 return k_ra8_err_exists;
120 }
121
122#ifndef RA8_OFF_TARGET
123 const psa_status_t st = psa_crypto_init();
124 if (st != PSA_SUCCESS) {
125 ra8_log_error(s_ra8_psa_tag, "psa_crypto_init failed");
126 return k_ra8_err_hw_error;
127 }
128#endif
129
130 for (uint8_t i = 0U; i < (uint8_t)k_ra8_psa_max_keys; ++i) {
131 s_key_pool[i].in_use = false;
132 s_key_pool[i].key_len = 0U;
133 }
134
135 s_initialized = true;
136 return k_ra8_ok;
137}
138
140{
141 if (!s_initialized) {
143 }
144
145 for (uint8_t i = 0U; i < (uint8_t)k_ra8_psa_max_keys; ++i) {
146 if (s_key_pool[i].in_use) {
147#ifndef RA8_OFF_TARGET
148 (void)psa_destroy_key(s_key_pool[i].psa_id);
149#endif
150 (void)memset(s_key_pool[i].key, 0, sizeof(s_key_pool[i].key));
151 s_key_pool[i].in_use = false;
152 s_key_pool[i].key_len = 0U;
153 }
154 }
155
156#ifndef RA8_OFF_TARGET
157 mbedtls_psa_crypto_free();
158#endif
159
160 s_initialized = false;
161 return k_ra8_ok;
162}
163
164#ifndef RA8_OFF_TARGET
165
166/* Translate ``ra8_psa_key_type_t`` to its ``PSA_KEY_TYPE_*`` peer -- see implementation for details. */
168{
169 switch (type) {
171 return PSA_KEY_TYPE_AES;
173 return PSA_KEY_TYPE_HMAC;
175 return PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1);
177 return PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_FAMILY_SECP_R1);
179 default:
180 return PSA_KEY_TYPE_RAW_DATA;
181 }
182}
183
184/* Translate ``ra8_psa_alg_t`` to its ``PSA_ALG_*`` peer -- see implementation for details. */
185RA8_INTERNAL static psa_algorithm_t internal_map_alg(ra8_psa_alg_t alg)
186{
187 switch (alg) {
189 return PSA_ALG_GCM;
191 return PSA_ALG_ECDSA(PSA_ALG_SHA_256);
193 return PSA_ALG_SHA_256;
195 default:
196 return 0;
197 }
198}
199
200/* Translate ``ra8_psa_key_usage_t`` bitmask to ``PSA_KEY_USAGE_*`` flags -- see implementation for details. */
202{
203 psa_key_usage_t out = 0;
204 if ((usage & k_ra8_psa_usage_sign) != 0U) {
205 out |= PSA_KEY_USAGE_SIGN_HASH;
206 }
207 if ((usage & k_ra8_psa_usage_verify) != 0U) {
208 out |= PSA_KEY_USAGE_VERIFY_HASH;
209 }
210 if ((usage & k_ra8_psa_usage_encrypt) != 0U) {
211 out |= PSA_KEY_USAGE_ENCRYPT;
212 }
213 if ((usage & k_ra8_psa_usage_decrypt) != 0U) {
214 out |= PSA_KEY_USAGE_DECRYPT;
215 }
216 if ((usage & k_ra8_psa_usage_derive) != 0U) {
217 out |= PSA_KEY_USAGE_DERIVE;
218 }
219 return out;
220}
221
222/* Run the PSA-side import + slot wire-up for ``ra8_psa_key_import`` -- see implementation for details. */
225 const uint8_t* data,
226 size_t data_len)
227{
228 psa_key_attributes_t pa = psa_key_attributes_init();
229 psa_set_key_type(&pa, internal_map_key_type(attr->type));
230 psa_set_key_algorithm(&pa, internal_map_alg(attr->alg));
231 psa_set_key_usage_flags(&pa, internal_map_usage(attr->usage));
232
233 psa_key_id_t kid = 0;
234 const psa_status_t st = psa_import_key(&pa, data, data_len, &kid);
235 if (st != PSA_SUCCESS) {
236 return k_ra8_err_hw_error;
237 }
238 slot->psa_id = kid;
239 return k_ra8_ok;
240}
241
242#endif /* !RA8_OFF_TARGET */
243
246 const uint8_t* data,
247 size_t data_len)
248{
249 if (out_handle != nullptr) {
250 *out_handle = nullptr;
251 }
252 if ((out_handle == nullptr) || (attr == nullptr) || (data == nullptr) || (data_len == 0U)) {
254 }
255 if (!s_initialized) {
257 }
258 if (data_len > (size_t)k_ra8_psa_max_key_bytes) {
260 }
261 if (attr->usage == k_ra8_psa_usage_none) {
263 }
264
266 if (slot == nullptr) {
267 return k_ra8_err_no_mem;
268 }
269
270#ifndef RA8_OFF_TARGET
271 const ra8_err_t pst = internal_psa_import_into_slot(slot, attr, data, data_len);
272 if (pst != k_ra8_ok) {
273 return pst;
274 }
275#endif
276
277 slot->in_use = true;
278 slot->attr = *attr;
279 (void)memcpy(slot->key, data, data_len);
280 slot->key_len = data_len;
281
282 *out_handle = slot;
283 return k_ra8_ok;
284}
285
287{
288 if (!s_initialized) {
290 }
291 if (!internal_handle_valid(handle)) {
293 }
294
295#ifndef RA8_OFF_TARGET
296 (void)psa_destroy_key(handle->psa_id);
297#endif
298 (void)memset(handle->key, 0, sizeof(handle->key));
299 handle->key_len = 0U;
300 handle->in_use = false;
301 return k_ra8_ok;
302}
303
305 const uint8_t* input,
306 size_t input_len,
307 uint8_t* out,
308 size_t out_cap,
309 size_t* out_len)
310{
311 if (out_len != nullptr) {
312 *out_len = 0U;
313 }
314 if ((out == nullptr) || (out_len == nullptr)) {
316 }
317 if ((input == nullptr) && (input_len != 0U)) {
319 }
320 if (alg != k_ra8_psa_alg_sha_256) {
322 }
323 if (!s_initialized) {
325 }
326 if (out_cap < (size_t)k_ra8_psa_sha256_len) {
328 }
329
330#ifdef RA8_OFF_TARGET
331 ra8_psa_fake_sha256_oneshot(input, input_len, out);
332#else
333 size_t produced = 0U;
334 const psa_status_t st =
335 psa_hash_compute(PSA_ALG_SHA_256, input, input_len, out, out_cap, &produced);
336 if (st != PSA_SUCCESS) {
337 return k_ra8_err_hw_error;
338 }
339 (void)produced;
340#endif
341
342 *out_len = (size_t)k_ra8_psa_sha256_len;
343 return k_ra8_ok;
344}
345
347 ra8_psa_alg_t alg,
348 const uint8_t* hash,
349 size_t hash_len,
350 uint8_t* sig,
351 size_t sig_cap,
352 size_t* sig_len)
353{
354 if (sig_len != nullptr) {
355 *sig_len = 0U;
356 }
357 if ((hash == nullptr) || (sig == nullptr) || (sig_len == nullptr)) {
359 }
360 if (!s_initialized) {
362 }
363 if (!internal_handle_valid(handle)) {
365 }
366 if (alg != k_ra8_psa_alg_ecdsa_sha_256) {
368 }
369 if ((handle->attr.usage & k_ra8_psa_usage_sign) == 0U) {
371 }
372 if (hash_len != (size_t)k_ra8_psa_sha256_len) {
374 }
375 if (sig_cap < (size_t)k_ra8_psa_sha256_len) {
377 }
378
379#ifdef RA8_OFF_TARGET
380 /* Fake "signature" = SHA-256(key || hash). 32 bytes. */
382 (void)memcpy(buf, handle->key, handle->key_len);
383 (void)memcpy(&buf[handle->key_len], hash, hash_len);
384 uint8_t digest[32];
385 ra8_psa_fake_sha256_oneshot(buf, handle->key_len + hash_len, digest);
386 (void)memcpy(sig, digest, sizeof(digest));
387 *sig_len = sizeof(digest);
388#else
389 size_t produced = 0U;
390 const psa_status_t st = psa_sign_hash(handle->psa_id,
391 PSA_ALG_ECDSA(PSA_ALG_SHA_256),
392 hash,
393 hash_len,
394 sig,
395 sig_cap,
396 &produced);
397 if (st != PSA_SUCCESS) {
398 return k_ra8_err_hw_error;
399 }
400 *sig_len = produced;
401#endif
402
403 return k_ra8_ok;
404}
405
407 ra8_psa_alg_t alg,
408 const uint8_t* hash,
409 size_t hash_len,
410 const uint8_t* sig,
411 size_t sig_len)
412{
413 if ((hash == nullptr) || (sig == nullptr)) {
415 }
416 if (!s_initialized) {
418 }
419 if (!internal_handle_valid(handle)) {
421 }
422 if (alg != k_ra8_psa_alg_ecdsa_sha_256) {
424 }
425 if ((handle->attr.usage & k_ra8_psa_usage_verify) == 0U) {
427 }
428 if (hash_len != (size_t)k_ra8_psa_sha256_len) {
430 }
431
432#ifdef RA8_OFF_TARGET
433 if (sig_len != (size_t)k_ra8_psa_sha256_len) {
435 }
437 (void)memcpy(buf, handle->key, handle->key_len);
438 (void)memcpy(&buf[handle->key_len], hash, hash_len);
439 uint8_t digest[32];
440 ra8_psa_fake_sha256_oneshot(buf, handle->key_len + hash_len, digest);
441 /* Constant-time compare. */
442 uint8_t diff = 0U;
443 for (uint32_t i = 0U; i < (uint32_t)k_ra8_psa_sha256_len; ++i) {
444 diff |= (uint8_t)(digest[i] ^ sig[i]);
445 }
446 return (diff == 0U) ? k_ra8_ok : k_ra8_err_crc_mismatch;
447#else
448 const psa_status_t st =
449 psa_verify_hash(handle->psa_id, PSA_ALG_ECDSA(PSA_ALG_SHA_256), hash, hash_len, sig, sig_len);
450 if (st == PSA_SUCCESS) {
451 return k_ra8_ok;
452 }
453 if (st == PSA_ERROR_INVALID_SIGNATURE) {
455 }
456 return k_ra8_err_hw_error;
457#endif
458}
459
460/* Shared precondition checks for ``ra8_psa_aead_encrypt`` -- see implementation for details. */
462 ra8_psa_alg_t alg,
463 const uint8_t* nonce,
464 size_t nonce_len,
465 const uint8_t* aad,
466 size_t aad_len,
467 const uint8_t* plain,
468 size_t plain_len,
469 const uint8_t* out,
470 size_t out_cap,
471 const size_t* out_len)
472{
473 if ((nonce == nullptr) || (out == nullptr) || (out_len == nullptr)) {
475 }
476 if (((plain == nullptr) && (plain_len != 0U)) || ((aad == nullptr) && (aad_len != 0U))) {
478 }
479 if (!s_initialized) {
481 }
482 if (!internal_handle_valid(handle) || (alg != k_ra8_psa_alg_aes_gcm) ||
483 ((handle->attr.usage & k_ra8_psa_usage_encrypt) == 0U)) {
485 }
486 if ((nonce_len != (size_t)k_ra8_psa_gcm_nonce_len) ||
487 (out_cap < (plain_len + (size_t)k_ra8_psa_gcm_tag_len))) {
489 }
490 return k_ra8_ok;
491}
492
494 ra8_psa_alg_t alg,
495 const uint8_t* nonce,
496 size_t nonce_len,
497 const uint8_t* aad,
498 size_t aad_len,
499 const uint8_t* plain,
500 size_t plain_len,
501 uint8_t* out,
502 size_t out_cap,
503 size_t* out_len)
504{
505 if (out_len != nullptr) {
506 *out_len = 0U;
507 }
508 const ra8_err_t ck = internal_aead_encrypt_check(handle,
509 alg,
510 nonce,
511 nonce_len,
512 aad,
513 aad_len,
514 plain,
515 plain_len,
516 out,
517 out_cap,
518 out_len);
519 if (ck != k_ra8_ok) {
520 return ck;
521 }
522
523#ifdef RA8_OFF_TARGET
524 /* Encrypt = plaintext XOR keystream(key, nonce). Tag = SHA-256-trunc16. */
525 const ra8_err_t ser = ra8_psa_fake_aead_encrypt(handle,
526 nonce,
527 nonce_len,
528 aad,
529 aad_len,
530 plain,
531 plain_len,
532 out,
533 out_len);
534 if (ser != k_ra8_ok) {
535 return ser;
536 }
537#else
538 size_t produced = 0U;
539 const psa_status_t st = psa_aead_encrypt(handle->psa_id,
540 PSA_ALG_GCM,
541 nonce,
542 nonce_len,
543 aad,
544 aad_len,
545 plain,
546 plain_len,
547 out,
548 out_cap,
549 &produced);
550 if (st != PSA_SUCCESS) {
551 return k_ra8_err_hw_error;
552 }
553 *out_len = produced;
554#endif
555
556 return k_ra8_ok;
557}
558
559/* Shared precondition checks for ``ra8_psa_aead_decrypt`` -- see implementation for details. */
561 ra8_psa_alg_t alg,
562 const uint8_t* nonce,
563 size_t nonce_len,
564 const uint8_t* aad,
565 size_t aad_len,
566 const uint8_t* cipher,
567 size_t cipher_len,
568 const uint8_t* out,
569 size_t out_cap,
570 const size_t* out_len,
571 size_t* out_plain_len)
572{
573 if ((nonce == nullptr) || (cipher == nullptr) || (out_len == nullptr)) {
575 }
576 if ((aad == nullptr) && (aad_len != 0U)) {
578 }
579 if (!s_initialized) {
581 }
582 if (!internal_handle_valid(handle) || (alg != k_ra8_psa_alg_aes_gcm) ||
583 ((handle->attr.usage & k_ra8_psa_usage_decrypt) == 0U)) {
585 }
586 if ((nonce_len != (size_t)k_ra8_psa_gcm_nonce_len) ||
587 (cipher_len < (size_t)k_ra8_psa_gcm_tag_len)) {
589 }
590 const size_t plain_len = cipher_len - (size_t)k_ra8_psa_gcm_tag_len;
591 if ((out == nullptr) && (plain_len != 0U)) {
593 }
594 if (out_cap < plain_len) {
596 }
597 *out_plain_len = plain_len;
598 return k_ra8_ok;
599}
600
602 ra8_psa_alg_t alg,
603 const uint8_t* nonce,
604 size_t nonce_len,
605 const uint8_t* aad,
606 size_t aad_len,
607 const uint8_t* cipher,
608 size_t cipher_len,
609 uint8_t* out,
610 size_t out_cap,
611 size_t* out_len)
612{
613 if (out_len != nullptr) {
614 *out_len = 0U;
615 }
616 size_t plain_len = 0U;
617 const ra8_err_t ck = internal_aead_decrypt_check(handle,
618 alg,
619 nonce,
620 nonce_len,
621 aad,
622 aad_len,
623 cipher,
624 cipher_len,
625 out,
626 out_cap,
627 out_len,
628 &plain_len);
629 if (ck != k_ra8_ok) {
630 return ck;
631 }
632
633#ifdef RA8_OFF_TARGET
634 const ra8_err_t sdr = ra8_psa_fake_aead_decrypt(handle,
635 nonce,
636 nonce_len,
637 aad,
638 aad_len,
639 cipher,
640 plain_len,
641 out,
642 out_len);
643 if (sdr != k_ra8_ok) {
644 return sdr;
645 }
646#else
647 size_t produced = 0U;
648 const psa_status_t st = psa_aead_decrypt(handle->psa_id,
649 PSA_ALG_GCM,
650 nonce,
651 nonce_len,
652 aad,
653 aad_len,
654 cipher,
655 cipher_len,
656 out,
657 out_cap,
658 &produced);
659 if (st == PSA_ERROR_INVALID_SIGNATURE) {
661 }
662 if (st != PSA_SUCCESS) {
663 return k_ra8_err_hw_error;
664 }
665 *out_len = produced;
666#endif
667
668 return k_ra8_ok;
669}
670
696ra8_err_t ra8_psa_crypto_random(uint8_t* out, size_t out_len)
697{
698 if (out == nullptr) {
700 }
701 if (out_len == 0U) {
703 }
704 if (!s_initialized) {
706 }
707
708#ifdef RA8_OFF_TARGET
709 /* Deterministic xorshift32 -- reproducible host-test entropy.
710 * Constants from Marsaglia 2003 "Xorshift RNGs" J. Stat. Soft. 8(14). */
711 static uint32_t s_state = (uint32_t)k_xs32_seed;
712 for (size_t i = 0U; i < out_len; ++i) {
713 uint32_t x = s_state;
714 x ^= x << (uint32_t)k_xs32_shl_a;
715 x ^= x >> (uint32_t)k_xs32_shr_b;
716 x ^= x << (uint32_t)k_xs32_shl_c;
717 s_state = x;
718 out[i] = (uint8_t)(x & (uint32_t)k_xs32_byte_m);
719 }
720 return k_ra8_ok;
721#else
722 const psa_status_t st = psa_generate_random(out, out_len);
723 if (st != PSA_SUCCESS) {
724 ra8_log_error(s_ra8_psa_tag, "psa_generate_random failed");
725 return k_ra8_err_hw_error;
726 }
727 return k_ra8_ok;
728#endif
729}
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
static bool s_initialized
True once display_init has succeeded.
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_crc_mismatch
CRC mismatch detected on received data.
Definition ra8_err.h:423
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
Definition ra8_err.h:142
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_err_exists
Item already exists – cannot create again.
Definition ra8_err.h:216
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
Definition ra8_err.h:235
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_hw_error
Generic hardware fault detected (error flag set, fault interrupt).
Definition ra8_err.h:310
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
Definition ra8_err.h:167
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_error(tag, message)
RA8 log error.
Definition ra8_log.h:335
static ra8_err_t internal_aead_decrypt_check(ra8_psa_key_t handle, ra8_psa_alg_t alg, const uint8_t *nonce, size_t nonce_len, const uint8_t *aad, size_t aad_len, const uint8_t *cipher, size_t cipher_len, const uint8_t *out, size_t out_cap, const size_t *out_len, size_t *out_plain_len)
ra8_err_t ra8_psa_hash_compute(ra8_psa_alg_t alg, const uint8_t *input, size_t input_len, uint8_t *out, size_t out_cap, size_t *out_len)
Compute a one-shot SHA-256 digest.
static ra8_err_t internal_aead_encrypt_check(ra8_psa_key_t handle, ra8_psa_alg_t alg, const uint8_t *nonce, size_t nonce_len, const uint8_t *aad, size_t aad_len, const uint8_t *plain, size_t plain_len, const uint8_t *out, size_t out_cap, const size_t *out_len)
static struct ra8_psa_key_handle s_key_pool[k_ra8_psa_max_keys]
Per-handle state pool sized at compile time.
static psa_algorithm_t internal_map_alg(ra8_psa_alg_t alg)
ra8_err_t ra8_psa_key_destroy(ra8_psa_key_t handle)
Destroy a previously-imported key.
ra8_err_t ra8_psa_aead_decrypt(ra8_psa_key_t handle, ra8_psa_alg_t alg, const uint8_t *nonce, size_t nonce_len, const uint8_t *aad, size_t aad_len, const uint8_t *cipher, size_t cipher_len, uint8_t *out, size_t out_cap, size_t *out_len)
Decrypt + verify-tag an AES-GCM buffer.
ra8_err_t ra8_psa_crypto_init(void)
One-shot facade initialisation.
ra8_err_t ra8_psa_key_import(ra8_psa_key_t *out_handle, const ra8_psa_key_attr_t *attr, const uint8_t *data, size_t data_len)
Import a raw-byte key into the static pool.
ra8_err_t ra8_psa_verify_hash(ra8_psa_key_t handle, ra8_psa_alg_t alg, const uint8_t *hash, size_t hash_len, const uint8_t *sig, size_t sig_len)
Verify an ECDSA signature over a pre-computed hash.
ra8_err_t ra8_psa_sign_hash(ra8_psa_key_t handle, ra8_psa_alg_t alg, const uint8_t *hash, size_t hash_len, uint8_t *sig, size_t sig_cap, size_t *sig_len)
Sign a pre-computed hash with a private ECDSA key.
ra8_err_t ra8_psa_crypto_random(uint8_t *out, size_t out_len)
Fill out with cryptographically secure bytes.
static psa_key_type_t internal_map_key_type(ra8_psa_key_type_t type)
ra8_err_t ra8_psa_crypto_deinit(void)
Symmetric tear-down for ra8_psa_crypto_init.
static psa_key_usage_t internal_map_usage(ra8_psa_key_usage_t usage)
static bool internal_handle_valid(ra8_psa_key_t handle)
static ra8_err_t internal_psa_import_into_slot(struct ra8_psa_key_handle *slot, const ra8_psa_key_attr_t *attr, const uint8_t *data, size_t data_len)
static const char *const s_ra8_psa_tag
Logging tag prefix used by every ra8_psa_crypto log line.
static struct ra8_psa_key_handle * internal_alloc_slot(void)
Locate the first free slot in the pool.
ra8_err_t ra8_psa_aead_encrypt(ra8_psa_key_t handle, ra8_psa_alg_t alg, const uint8_t *nonce, size_t nonce_len, const uint8_t *aad, size_t aad_len, const uint8_t *plain, size_t plain_len, uint8_t *out, size_t out_cap, size_t *out_len)
Encrypt + authenticate a buffer with AES-GCM.
Application-level PSA Crypto facade over tf-psa-crypto.
ra8_psa_key_usage_t
Bitmask of allowed operations on an imported key.
@ k_ra8_psa_usage_encrypt
Allow ra8_psa_aead_encrypt.
@ k_ra8_psa_usage_derive
Allow KDF-style derivation (future).
@ k_ra8_psa_usage_verify
Allow ra8_psa_verify_hash.
@ k_ra8_psa_usage_none
No usage allowed (placeholder).
@ k_ra8_psa_usage_decrypt
Allow ra8_psa_aead_decrypt.
@ k_ra8_psa_usage_sign
Allow ra8_psa_sign_hash.
struct ra8_psa_key_handle * ra8_psa_key_t
Opaque PSA key handle (typed pointer into the static pool).
ra8_psa_key_type_t
Project-local enum mirroring the PSA key-type families we care about.
@ k_ra8_psa_key_type_ecc_p256_pub
ECDSA P-256 public key (uncompressed).
@ k_ra8_psa_key_type_raw
Raw octet string (HKDF input).
@ k_ra8_psa_key_type_aes
Symmetric AES key.
@ k_ra8_psa_key_type_hmac
HMAC key (any hash).
@ k_ra8_psa_key_type_ecc_p256_priv
ECDSA P-256 private key.
ra8_psa_alg_t
Algorithm selector passed to sign / verify / AEAD operations.
@ k_ra8_psa_alg_none
Sentinel for "unset".
@ k_ra8_psa_alg_ecdsa_sha_256
ECDSA over SHA-256 (FIPS 186-4).
@ k_ra8_psa_alg_aes_gcm
AES-GCM AEAD (NIST SP 800-38D).
@ k_ra8_psa_alg_sha_256
SHA-256 hash (FIPS 180-4).
@ k_ra8_psa_max_keys
Maximum simultaneous key handles handed out by the pool.
@ k_ra8_psa_gcm_tag_len
AES-GCM authentication tag length (16 octets).
@ 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).
@ k_ra8_psa_gcm_nonce_len
AES-GCM nonce length used by ra8_psa_aead_* (NIST SP 800-38D).
Module-private definitions shared across the ra8_psa_crypto TUs.
@ k_xs32_seed
Default seed.
@ k_xs32_byte_m
Mask isolating the low byte of state.
@ k_xs32_shr_b
Right shift.
@ k_xs32_shl_c
Second left shift.
@ k_xs32_shl_a
First left shift.
static uint32_t s_state
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.