ProtoCore v0.0.2
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
aes_cmac.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file aes_cmac.h
6 * @brief AES-128-CMAC (RFC 4493 / NIST SP800-38B) one-shot MAC.
7 *
8 * The CMAC construction over the AES-128 block cipher: derive two subkeys K1/K2 from
9 * AES-128(key, 0^128), CBC-MAC the message, and XOR the final block with K1 (message a whole
10 * number of blocks) or the 10*-padded last block with K2. SMB 3.x uses it as the message-signing
11 * MAC when the negotiated signing algorithm is AES-CMAC (MS-SMB2 §3.1.4.1, dialects 3.0 / 3.0.2 /
12 * 3.1.1); it is a general primitive, not SMB-specific.
13 *
14 * On ESP32/Arduino the AES-128 block runs on the mbedTLS context (hardware AES accelerator); on the
15 * native host build it uses the shared table-free software AES (crypto/cipher/aes_block.h). Pure,
16 * zero heap. Verified against the RFC 4493 §4 worked examples.
17 *
18 * @author Douglas Quigg (dstroy0)
19 * @date 2026
20 */
21
22#ifndef PROTOCORE_AES_CMAC_H
23#define PROTOCORE_AES_CMAC_H
24
25#include <stddef.h>
26#include <stdint.h>
27
28/** @brief AES-128-CMAC output length (one AES block). */
29#define PC_AES_CMAC_LEN 16
30
31/**
32 * @brief Compute the AES-128-CMAC of @p msg under @p key (RFC 4493).
33 *
34 * @param key the 16-byte AES-128 key.
35 * @param msg the message (may be null iff @p msg_len is 0).
36 * @param msg_len message length in bytes (0 is valid - the empty-message CMAC).
37 * @param mac receives the 16-byte tag.
38 */
39void pc_aes_cmac(const uint8_t key[16], const uint8_t *msg, size_t msg_len, uint8_t mac[PC_AES_CMAC_LEN]);
40
41#endif // PROTOCORE_AES_CMAC_H
#define PC_AES_CMAC_LEN
AES-128-CMAC output length (one AES block).
Definition aes_cmac.h:29
void pc_aes_cmac(const uint8_t key[16], const uint8_t *msg, size_t msg_len, uint8_t mac[PC_AES_CMAC_LEN])
Compute the AES-128-CMAC of msg under key (RFC 4493).
Definition aes_cmac.cpp:110