Skip to content

File syn_aes_cmac.c

FileList > crypto > syn_aes_cmac.c

Go to the source code of this file

AES-CMAC (Cipher-based Message Authentication Code, RFC 4493 / NIST SP 800-38B).

  • #include "syn_aes.h"
  • #include "syn_aes_cmac.h"
  • #include <string.h>

Public Functions

Type Name
SYN_Status syn_aes_cmac (const uint8_t key, const uint8_t * msg, size_t msg_len, uint8_t mac)
Generate a 128-bit AES-CMAC authentication tag (RFC 4493).
bool syn_aes_cmac_verify (const uint8_t key, const uint8_t * msg, size_t msg_len, const uint8_t mac)
Verify an AES-CMAC authentication tag in constant time (RFC 4493).

Public Static Functions

Type Name
void generate_subkeys (const SYN_AES_Context * ctx, uint8_t k1, uint8_t k2)
Subkey generation algorithm per RFC 4493 section 2.3.
void shl_128 (const uint8_t in, uint8_t out)
Left shift a 128-bit block by 1 bit (Big-Endian).

Public Functions Documentation

function syn_aes_cmac

Generate a 128-bit AES-CMAC authentication tag (RFC 4493).

SYN_Status syn_aes_cmac (
    const uint8_t key,
    const uint8_t * msg,
    size_t msg_len,
    uint8_t mac
) 

Parameters:

  • key 16-byte AES-128 secret key.
  • msg Pointer to message to authenticate (may be NULL if msg_len is 0).
  • msg_len Length of the message in bytes.
  • mac 16-byte buffer to receive the computed MAC tag.

Returns:

SYN_OK on success, or SYN_INVALID_PARAM on invalid/NULL parameters.


function syn_aes_cmac_verify

Verify an AES-CMAC authentication tag in constant time (RFC 4493).

bool syn_aes_cmac_verify (
    const uint8_t key,
    const uint8_t * msg,
    size_t msg_len,
    const uint8_t mac
) 

Parameters:

  • key 16-byte AES-128 secret key.
  • msg Pointer to message to verify (may be NULL if msg_len is 0).
  • msg_len Length of the message in bytes.
  • mac 16-byte expected MAC tag to verify against.

Returns:

true if valid and authentic, false on mismatch or invalid parameters.


Public Static Functions Documentation

function generate_subkeys

Subkey generation algorithm per RFC 4493 section 2.3.

static void generate_subkeys (
    const SYN_AES_Context * ctx,
    uint8_t k1,
    uint8_t k2
) 

Parameters:

  • ctx Initialized AES context.
  • k1 First 128-bit subkey.
  • k2 Second 128-bit subkey.

function shl_128

Left shift a 128-bit block by 1 bit (Big-Endian).

static void shl_128 (
    const uint8_t in,
    uint8_t out
) 

Parameters:

  • in 16-byte source block.
  • out 16-byte shifted output block.


The documentation for this class was generated from the following file src/syntropic/crypto/syn_aes_cmac.c