ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
sec_cmac.c
Go to the documentation of this file.
1
37
38#include <stddef.h>
39#include <stdint.h>
40
41#include "ra8_attributes.h"
42#include "ra8_check.h"
43#include "ra8_err.h"
44#include "ra8_secure.h"
45#include "sec_cmac_internal.h"
46
48static const char* s_tag = "SECMAC";
49
80internal_cmac_check_args(const uint8_t* key, uint16_t key_len, const uint8_t* msg, uint32_t msg_len)
81{
82 RA8_CHECK_NULL_PTR(key, s_tag, "cmac: key");
83 if ((key_len != (uint16_t)k_ra8_sec_cmac_key_128) &&
84 (key_len != (uint16_t)k_ra8_sec_cmac_key_256)) {
86 }
87 if ((msg == nullptr) && (msg_len != 0U)) {
88 return k_ra8_err_null_ptr;
89 }
90 if (msg_len > (uint32_t)k_ra8_sec_cmac_max_msg_bytes) {
92 }
93 return k_ra8_ok;
94}
95
96#ifdef RA8_KEY_IMPORT_PSA_CMAC
97
98/* =============================================================================
99 * PSA backend -- production / HIL image (TF-PSA-Crypto)
100 * =============================================================================
101 */
102
103#include "psa/crypto.h"
104
130internal_psa_import_cmac_key(const uint8_t* key, uint16_t key_len, psa_key_id_t* out_id)
131{
132 psa_key_attributes_t attr = psa_key_attributes_init();
133 psa_set_key_type(&attr, PSA_KEY_TYPE_AES);
134 psa_set_key_algorithm(&attr, PSA_ALG_CMAC);
135 psa_set_key_usage_flags(&attr, PSA_KEY_USAGE_SIGN_MESSAGE | PSA_KEY_USAGE_VERIFY_MESSAGE);
136 psa_key_id_t kid = 0;
137 const psa_status_t st = psa_import_key(&attr, key, (size_t)key_len, &kid);
138 psa_reset_key_attributes(&attr);
139 if (st != PSA_SUCCESS) {
140 return k_ra8_err_hw_error;
141 }
142 *out_id = kid;
143 return k_ra8_ok;
144}
145
146ra8_err_t priv_ra8_sec_cmac_compute(const uint8_t* key,
147 uint16_t key_len,
148 const uint8_t* msg,
149 uint32_t msg_len,
150 uint8_t* out_mac)
151{
152 RA8_CHECK_NULL_PTR(out_mac, s_tag, "compute: out_mac");
153 const ra8_err_t ck = internal_cmac_check_args(key, key_len, msg, msg_len);
154 if (ck != k_ra8_ok) {
155 return ck;
156 }
157 psa_key_id_t kid = 0;
158 const ra8_err_t ierr = internal_psa_import_cmac_key(key, key_len, &kid);
159 if (ierr != k_ra8_ok) {
160 return ierr;
161 }
162 size_t produced = 0U;
163 const psa_status_t st = psa_mac_compute(kid,
164 PSA_ALG_CMAC,
165 msg,
166 (size_t)msg_len,
167 out_mac,
169 &produced);
170 (void)psa_destroy_key(kid);
171 if ((st != PSA_SUCCESS) || (produced != (size_t)k_ra8_sec_cmac_tag_bytes)) {
172 return k_ra8_err_hw_error;
173 }
174 return k_ra8_ok;
175}
176
177ra8_err_t priv_ra8_sec_cmac_verify(const uint8_t* key,
178 uint16_t key_len,
179 const uint8_t* msg,
180 uint32_t msg_len,
181 const uint8_t* mac,
182 uint16_t mac_len)
183{
184 RA8_CHECK_NULL_PTR(mac, s_tag, "verify: mac");
185 const ra8_err_t ck = internal_cmac_check_args(key, key_len, msg, msg_len);
186 if (ck != k_ra8_ok) {
187 return ck;
188 }
189 psa_key_id_t kid = 0;
190 const ra8_err_t ierr = internal_psa_import_cmac_key(key, key_len, &kid);
191 if (ierr != k_ra8_ok) {
192 return ierr;
193 }
194 /* psa_mac_verify performs the length check and a constant-time compare
195 * internally, returning PSA_ERROR_INVALID_SIGNATURE on any mismatch. */
196 const psa_status_t st =
197 psa_mac_verify(kid, PSA_ALG_CMAC, msg, (size_t)msg_len, mac, (size_t)mac_len);
198 (void)psa_destroy_key(kid);
199 if (st == PSA_SUCCESS) {
200 return k_ra8_ok;
201 }
202 if (st == PSA_ERROR_INVALID_SIGNATURE) {
204 }
205 return k_ra8_err_hw_error;
206}
207
208#else /* !RA8_KEY_IMPORT_PSA_CMAC -- in-tree AES-CMAC reference (host + portable) */
209
210/* =============================================================================
211 * Reference backend -- self-contained AES-128/256 + CMAC (FIPS 197 / SP 800-38B)
212 * =============================================================================
213 *
214 * The AES round transform and CMAC subkey/GF(2^128) doubling below are direct
215 * transcriptions of FIPS 197 and NIST SP 800-38B. The S-box and the field
216 * constants are standard values, not tunable parameters; the loops all have
217 * compile-time-fixed bounds. The host suite pins the output to the published
218 * SP 800-38B AES-128 and AES-256 known-answer vectors.
219 */
220
222typedef enum : uint16_t {
227} aes_dim_t;
228
239
241typedef enum : uint8_t {
243 k_cmac_rb = 0x87U,
245} aes_gf_t;
246
248static const uint8_t s_aes_sbox[256] = {
249 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
250 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
251 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
252 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
253 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
254 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
255 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
256 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
257 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
258 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
259 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
260 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
261 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
262 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
263 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
264 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16,
265};
266
285RA8_INTERNAL static uint8_t internal_aes_xtime(uint8_t value)
286{
287 const uint8_t hi = (uint8_t)(value >> k_aes_msb_shift);
288 return (uint8_t)(((uint8_t)(value << 1U)) ^ (uint8_t)(hi * (uint8_t)k_aes_field_poly));
289}
290
310RA8_INTERNAL static void
311internal_aes_key_expand(const uint8_t* key, uint8_t nk, uint8_t nr, uint8_t* rk)
312{
313 const uint16_t total_words = (uint16_t)((uint16_t)k_aes_state_cols * (uint16_t)(nr + 1U));
314 for (uint16_t i = 0U; i < ((uint16_t)nk * (uint16_t)k_aes_word_bytes); ++i) {
315 rk[i] = key[i];
316 }
317 uint8_t rcon = (uint8_t)k_aes_rcon_seed;
318 for (uint16_t i = nk; i < total_words; ++i) {
319 uint8_t t[k_aes_word_bytes];
320 for (uint8_t j = 0U; j < (uint8_t)k_aes_word_bytes; ++j) {
321 t[j] = rk[((uint16_t)(i - 1U) * (uint16_t)k_aes_word_bytes) + j];
322 }
323 if ((i % nk) == 0U) {
324 const uint8_t tmp = t[0];
325 t[0] = (uint8_t)(s_aes_sbox[t[1]] ^ rcon);
326 t[1] = s_aes_sbox[t[2]];
327 t[2] = s_aes_sbox[t[3]];
328 t[3] = s_aes_sbox[tmp];
329 rcon = internal_aes_xtime(rcon);
330 } else if ((nk > 6U) && ((i % nk) == (uint8_t)k_aes_ext_sub_i)) {
331 for (uint8_t j = 0U; j < (uint8_t)k_aes_word_bytes; ++j) {
332 t[j] = s_aes_sbox[t[j]];
333 }
334 } else {
335 /* No transform: straight copy from t[] below. */
336 }
337 for (uint8_t j = 0U; j < (uint8_t)k_aes_word_bytes; ++j) {
338 rk[((uint16_t)i * (uint16_t)k_aes_word_bytes) + j] =
339 (uint8_t)(rk[((uint16_t)(i - nk) * (uint16_t)k_aes_word_bytes) + j] ^ t[j]);
340 }
341 }
342}
343
362{
363 for (uint8_t i = 0U; i < (uint8_t)k_aes_block_bytes; ++i) {
364 s[i] = s_aes_sbox[s[i]];
365 }
366 uint8_t shifted[k_aes_block_bytes];
367 for (uint8_t r = 0U; r < (uint8_t)k_aes_state_cols; ++r) {
368 for (uint8_t c = 0U; c < (uint8_t)k_aes_state_cols; ++c) {
369 shifted[((uint8_t)(c * (uint8_t)k_aes_state_cols)) + r] =
370 s[((uint8_t)(((c + r) & (uint8_t)k_aes_col_mask) * (uint8_t)k_aes_state_cols)) + r];
371 }
372 }
373 for (uint8_t i = 0U; i < (uint8_t)k_aes_block_bytes; ++i) {
374 s[i] = shifted[i];
375 }
376}
377
396{
397 for (uint8_t c = 0U; c < (uint8_t)k_aes_state_cols; ++c) {
398 uint8_t* col = &s[(uint8_t)(c * (uint8_t)k_aes_state_cols)];
399 const uint8_t a0 = col[0];
400 const uint8_t a1 = col[1];
401 const uint8_t a2 = col[2];
402 const uint8_t a3 = col[3];
403 col[0] = (uint8_t)(internal_aes_xtime(a0) ^ internal_aes_xtime(a1) ^ a1 ^ a2 ^ a3);
404 col[1] = (uint8_t)(a0 ^ internal_aes_xtime(a1) ^ internal_aes_xtime(a2) ^ a2 ^ a3);
405 col[2] = (uint8_t)(a0 ^ a1 ^ internal_aes_xtime(a2) ^ internal_aes_xtime(a3) ^ a3);
406 col[3] = (uint8_t)(internal_aes_xtime(a0) ^ a0 ^ a1 ^ a2 ^ internal_aes_xtime(a3));
407 }
408}
409
432RA8_INTERNAL static void
433internal_aes_encrypt(const uint8_t* rk, uint8_t nr, const uint8_t* in, uint8_t* out)
434{
435 uint8_t s[k_aes_block_bytes];
436 for (uint8_t i = 0U; i < (uint8_t)k_aes_block_bytes; ++i) {
437 s[i] = (uint8_t)(in[i] ^ rk[i]);
438 }
439 for (uint8_t round = 1U; round <= nr; ++round) {
441 if (round != nr) {
443 }
444 const uint8_t* round_key = &rk[(size_t)round * (size_t)k_aes_block_bytes];
445 for (uint8_t i = 0U; i < (uint8_t)k_aes_block_bytes; ++i) {
446 s[i] = (uint8_t)(s[i] ^ round_key[i]);
447 }
448 }
449 for (uint8_t i = 0U; i < (uint8_t)k_aes_block_bytes; ++i) {
450 out[i] = s[i];
451 }
452}
453
472RA8_INTERNAL static void internal_cmac_double(const uint8_t* in, uint8_t* out)
473{
474 const uint8_t msb = (uint8_t)(in[0] >> k_aes_msb_shift);
475 for (uint8_t i = 0U; i < (uint8_t)k_aes_last_byte; ++i) {
476 out[i] = (uint8_t)((uint8_t)(in[i] << 1U) | (uint8_t)(in[i + 1U] >> k_aes_msb_shift));
477 }
478 out[k_aes_last_byte] = (uint8_t)(in[k_aes_last_byte] << 1U);
479 if (msb != 0U) {
480 out[k_aes_last_byte] = (uint8_t)(out[k_aes_last_byte] ^ (uint8_t)k_cmac_rb);
481 }
482}
483
504RA8_INTERNAL static void
505internal_cmac_subkeys(const uint8_t* rk, uint8_t nr, uint8_t* k1, uint8_t* k2)
506{
507 const uint8_t zero[k_aes_block_bytes] = {};
508 uint8_t l_val[k_aes_block_bytes];
509 internal_aes_encrypt(rk, nr, zero, l_val);
510 internal_cmac_double(l_val, k1);
511 internal_cmac_double(k1, k2);
512 ra8_secure_memzero(l_val, sizeof(l_val));
513}
514
538RA8_INTERNAL static void internal_cmac_build_last(const uint8_t* msg,
539 uint32_t msg_len,
540 uint32_t last_off,
541 bool complete,
542 const uint8_t* k1,
543 const uint8_t* k2,
544 uint8_t* last)
545{
546 if (complete) {
547 for (uint8_t i = 0U; i < (uint8_t)k_aes_block_bytes; ++i) {
548 last[i] = (uint8_t)(msg[last_off + i] ^ k1[i]);
549 }
550 return;
551 }
552 const uint32_t rem = msg_len - last_off;
553 for (uint8_t i = 0U; i < (uint8_t)k_aes_block_bytes; ++i) {
554 uint8_t byte = 0U;
555 if ((uint32_t)i < rem) {
556 byte = msg[last_off + (uint32_t)i];
557 } else if ((uint32_t)i == rem) {
558 byte = (uint8_t)k_cmac_pad_marker;
559 } else {
560 byte = 0U;
561 }
562 last[i] = (uint8_t)(byte ^ k2[i]);
563 }
564}
565
589RA8_INTERNAL static void internal_cmac_tag(const uint8_t* key,
590 uint16_t key_len,
591 const uint8_t* msg,
592 uint32_t msg_len,
593 uint8_t* out_mac)
594{
595 const uint8_t nk = (uint8_t)(key_len / (uint16_t)k_aes_word_bytes);
596 const uint8_t nr =
597 (key_len == (uint16_t)k_ra8_sec_cmac_key_128) ? (uint8_t)k_aes_nr_128 : (uint8_t)k_aes_nr_256;
598 uint8_t rk[k_aes_max_rk_bytes];
599 internal_aes_key_expand(key, nk, nr, rk);
600
601 uint8_t k1[k_aes_block_bytes];
602 uint8_t k2[k_aes_block_bytes];
603 internal_cmac_subkeys(rk, nr, k1, k2);
604
605 /* Block count and whether the last block is a whole 16 bytes. */
606 const uint32_t n_blocks =
607 (msg_len == 0U) ? 1U : ((msg_len + (uint32_t)k_aes_last_byte) / (uint32_t)k_aes_block_bytes);
608 const bool complete = (msg_len != 0U) && ((msg_len % (uint32_t)k_aes_block_bytes) == 0U);
609 const uint32_t last_off = (n_blocks - 1U) * (uint32_t)k_aes_block_bytes;
610
611 uint8_t last[k_aes_block_bytes];
612 internal_cmac_build_last(msg, msg_len, last_off, complete, k1, k2, last);
613
614 uint8_t x[k_aes_block_bytes] = {};
615 uint8_t y[k_aes_block_bytes];
616 for (uint32_t b = 0U; (b + 1U) < n_blocks; ++b) {
617 for (uint8_t i = 0U; i < (uint8_t)k_aes_block_bytes; ++i) {
618 y[i] = (uint8_t)(x[i] ^ msg[((uint32_t)b * (uint32_t)k_aes_block_bytes) + (uint32_t)i]);
619 }
620 internal_aes_encrypt(rk, nr, y, x);
621 }
622 for (uint8_t i = 0U; i < (uint8_t)k_aes_block_bytes; ++i) {
623 y[i] = (uint8_t)(x[i] ^ last[i]);
624 }
625 internal_aes_encrypt(rk, nr, y, out_mac);
626
627 ra8_secure_memzero(rk, sizeof(rk));
628 ra8_secure_memzero(k1, sizeof(k1));
629 ra8_secure_memzero(k2, sizeof(k2));
630}
631
633 uint16_t key_len,
634 const uint8_t* msg,
635 uint32_t msg_len,
636 uint8_t* out_mac)
637{
638 RA8_CHECK_NULL_PTR(out_mac, s_tag, "compute: out_mac");
639 const ra8_err_t ck = internal_cmac_check_args(key, key_len, msg, msg_len);
640 if (ck != k_ra8_ok) {
641 return ck;
642 }
643 internal_cmac_tag(key, key_len, msg, msg_len, out_mac);
644 return k_ra8_ok;
645}
646
648 uint16_t key_len,
649 const uint8_t* msg,
650 uint32_t msg_len,
651 const uint8_t* mac,
652 uint16_t mac_len)
653{
654 RA8_CHECK_NULL_PTR(mac, s_tag, "verify: mac");
655 const ra8_err_t ck = internal_cmac_check_args(key, key_len, msg, msg_len);
656 if (ck != k_ra8_ok) {
657 return ck;
658 }
659 uint8_t computed[k_ra8_sec_cmac_tag_bytes];
660 internal_cmac_tag(key, key_len, msg, msg_len, computed);
661 /* Security verdict: reject a wrong-length tag OR a tag that does not match
662 * in constant time. ra8_ct_equal has no data-dependent early-out, so the
663 * timing does not leak how many leading bytes matched (ra8_secure.h). */
664 const bool len_bad = (mac_len != (uint16_t)k_ra8_sec_cmac_tag_bytes);
665 const bool tag_bad = !ra8_ct_equal(computed, mac, (size_t)k_ra8_sec_cmac_tag_bytes);
666 ra8_secure_memzero(computed, sizeof(computed));
667 if (len_bad || tag_bad) {
669 }
670 return k_ra8_ok;
671}
672
673#endif /* RA8_KEY_IMPORT_PSA_CMAC */
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
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.
#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_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
Definition ra8_err.h:478
@ 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
Secure-comparison primitives for the crypto / secure-boot paths.
bool ra8_ct_equal(const void *a, const void *b, size_t len)
Constant-time equality of two byte buffers.
Definition ra8_secure.c:20
void ra8_secure_memzero(void *ptr, size_t len)
Securely zero a buffer such that the write cannot be optimised away.
Definition ra8_secure.c:37
static void internal_cmac_double(const uint8_t *in, uint8_t *out)
Double a 128-bit value in GF(2^128) (CMAC subkey step).
Definition sec_cmac.c:472
static uint8_t internal_aes_xtime(uint8_t value)
Multiply a byte by x in GF(2^8) with the AES reduction poly.
Definition sec_cmac.c:285
static void internal_aes_encrypt(const uint8_t *rk, uint8_t nr, const uint8_t *in, uint8_t *out)
Encrypt one 16-byte block with AES-nr.
Definition sec_cmac.c:433
static ra8_err_t internal_cmac_check_args(const uint8_t *key, uint16_t key_len, const uint8_t *msg, uint32_t msg_len)
Shared precondition check for both CMAC entry points.
Definition sec_cmac.c:80
static void internal_aes_mix_columns(uint8_t *s)
Apply MixColumns to the AES state in place.
Definition sec_cmac.c:395
static void internal_cmac_build_last(const uint8_t *msg, uint32_t msg_len, uint32_t last_off, bool complete, const uint8_t *k1, const uint8_t *k2, uint8_t *last)
Fold the (possibly padded) final CMAC block with its subkey.
Definition sec_cmac.c:538
static void internal_aes_sub_shift(uint8_t *s)
Apply SubBytes + ShiftRows to the AES state in place.
Definition sec_cmac.c:361
static void internal_cmac_tag(const uint8_t *key, uint16_t key_len, const uint8_t *msg, uint32_t msg_len, uint8_t *out_mac)
Compute the AES-CMAC tag of a message (SP 800-38B).
Definition sec_cmac.c:589
aes_off_t
AES round counts and small byte offsets (FIPS 197).
Definition sec_cmac.c:230
@ k_aes_rcon_seed
Rcon seed value (round 1).
Definition sec_cmac.c:237
@ k_aes_nr_128
AES-128 rounds.
Definition sec_cmac.c:231
@ k_aes_col_mask
Column index wrap mask (mod 4).
Definition sec_cmac.c:234
@ k_aes_last_byte
Index of the final byte in a block.
Definition sec_cmac.c:236
@ k_aes_nr_256
AES-256 rounds.
Definition sec_cmac.c:232
@ k_aes_msb_shift
Byte MSB shift.
Definition sec_cmac.c:235
@ k_aes_ext_sub_i
AES-256 extra SubWord at iNk==4.
Definition sec_cmac.c:233
static void internal_aes_key_expand(const uint8_t *key, uint8_t nk, uint8_t nr, uint8_t *rk)
Expand an AES key into the full round-key schedule.
Definition sec_cmac.c:311
static const uint8_t s_aes_sbox[256]
AES S-box (FIPS 197 Fig.
Definition sec_cmac.c:248
aes_gf_t
GF field constants used by AES / CMAC.
Definition sec_cmac.c:241
@ k_cmac_pad_marker
CMAC final-block pad bit (SP 800-38B 5.5).
Definition sec_cmac.c:244
@ k_cmac_rb
GF(2^128) constant (SP 800-38B 5.3).
Definition sec_cmac.c:243
@ k_aes_field_poly
GF(2^8) reduction poly (FIPS 197 4.2).
Definition sec_cmac.c:242
static void internal_cmac_subkeys(const uint8_t *rk, uint8_t nr, uint8_t *k1, uint8_t *k2)
Derive the CMAC subkeys K1 / K2 from the expanded key.
Definition sec_cmac.c:505
ra8_err_t priv_ra8_sec_cmac_compute(const uint8_t *key, uint16_t key_len, const uint8_t *msg, uint32_t msg_len, uint8_t *out_mac)
Compute the AES-CMAC tag of a message under a symmetric key.
Definition sec_cmac.c:632
ra8_err_t priv_ra8_sec_cmac_verify(const uint8_t *key, uint16_t key_len, const uint8_t *msg, uint32_t msg_len, const uint8_t *mac, uint16_t mac_len)
Verify an AES-CMAC tag against a message under a symmetric key.
Definition sec_cmac.c:647
aes_dim_t
AES dimensions in bytes (FIPS 197).
Definition sec_cmac.c:222
@ k_aes_state_cols
Columns in the AES state.
Definition sec_cmac.c:225
@ k_aes_word_bytes
Bytes per key-schedule word.
Definition sec_cmac.c:224
@ k_aes_max_rk_bytes
Round-key bytes for AES-256 (16*(14+1)).
Definition sec_cmac.c:226
@ k_aes_block_bytes
AES block / CMAC tag size.
Definition sec_cmac.c:223
Secure-side AES-CMAC seam (real PSA backend / in-tree reference).
@ k_ra8_sec_cmac_key_256
AES-256 key length in bytes.
@ k_ra8_sec_cmac_tag_bytes
CMAC tag length (one AES block).
@ k_ra8_sec_cmac_key_128
AES-128 key length in bytes.
@ k_ra8_sec_cmac_max_msg_bytes
Largest authenticated message.