ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
aesccm.h File Reference

AEAD AES-CCM (NIST SP 800-38C / RFC 3610), 128- and 256-bit keys, detached tag. More...

#include "protocore_config.h"

Go to the source code of this file.

Classes

struct  AesCcmNs
 Dispatch table. Addressed by offset, so the layout is asserted below. More...
 

Macros

#define PROTOCORE_AESCCM_TAG_LEN   16
 AES-CCM authentication tag length used by SMB 3.x (bytes).
 

Functions

 PROTOCORE_NS_LAYOUT (AesCcmNs, seal, open)
 
proto_bool protocore_aes_ccm_seal (uint8_t *work, const uint8_t *key, size_t key_len, const uint8_t *nonce, size_t nonce_len, const uint8_t *aad, size_t aad_len, const uint8_t *pt, size_t pt_len, uint8_t *ct_out, uint8_t *tag_out)
 CBC-MAC the record, encrypt the payload from A1, write the detached tag.
 
proto_bool protocore_aes_ccm_open (uint8_t *work, const uint8_t *key, size_t key_len, const uint8_t *nonce, size_t nonce_len, const uint8_t *aad, size_t aad_len, const uint8_t *ct, size_t ct_len, const uint8_t *tag, uint8_t *out)
 Decrypt from A1, recompute the tag over the recovered plaintext, compare it in.
 

Variables

PROTOCORE_NS AesCcmNs AesCcm PROTOCORE_UNUSED = {.seal = protocore_aes_ccm_seal, .open = protocore_aes_ccm_open}
 Module namespace.
 

Detailed Description

AEAD AES-CCM (NIST SP 800-38C / RFC 3610), 128- and 256-bit keys, detached tag.

CCM = CTR encryption + CBC-MAC authentication under one key. SMB 3.x offers it as SMB2_ENCRYPTION_AES128_CCM (0x0001) and SMB2_ENCRYPTION_AES256_CCM (0x0003); the transport uses an 11-byte nonce and a 16-byte tag (MS-SMB2 ยง3.1.4.3). The entries below are one surface over both arms: the SP 800-38C construction is the same on either, and the AES block under it is the part's accelerator where it carries one and the shared software block (crypto/cipher/aes_block.h) where it does not, so the whole AEAD is unit-testable off-target.

The key rides with the record: a seal or an open expands it into the borrow and runs that one record under it. The tag is detached: a seal writes the ciphertext and the 16 tag bytes to separate destinations, which is where the SMB2 TRANSFORM_HEADER carries them - the Signature field holds the tag.

Host-tested against reference AES-CCM vectors (nonce 11, tag 16, AES-128 and AES-256).

AesCcmNs::open fails closed: on a tag mismatch it zeroes out and AesCcmNs::ok comes back false, so no unauthenticated plaintext reaches the caller.

work is PROTOCORE_AESCCM_BORROW secure bytes the CALLER took, at an address it knows. It is not held past the call, so nothing here aliases it. The caller releases it, and the pool wipes on release; this module neither takes it, holds it, releases it, nor wipes it. The borrow IS the record context, so two records are two borrows and never collide, and the expanded key schedule dies with the release.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file aesccm.h.

Macro Definition Documentation

◆ PROTOCORE_AESCCM_TAG_LEN

#define PROTOCORE_AESCCM_TAG_LEN   16

AES-CCM authentication tag length used by SMB 3.x (bytes).

Definition at line 41 of file aesccm.h.

Function Documentation

◆ PROTOCORE_NS_LAYOUT()

PROTOCORE_NS_LAYOUT ( AesCcmNs  ,
seal  ,
open   
)

◆ protocore_aes_ccm_seal()

proto_bool protocore_aes_ccm_seal ( uint8_t *  work,
const uint8_t *  key,
size_t  key_len,
const uint8_t *  nonce,
size_t  nonce_len,
const uint8_t *  aad,
size_t  aad_len,
const uint8_t *  pt,
size_t  pt_len,
uint8_t *  ct_out,
uint8_t *  tag_out 
)

CBC-MAC the record, encrypt the payload from A1, write the detached tag.

Parameters
workPROTOCORE_AES_CCM_BORROW bytes the caller took. Not held past the call.
key16 bytes (AES-128) or 32 bytes (AES-256)
key_len16 or 32
nonce7..13 bytes; SMB uses 11
nonce_lenits length
aadadditional authenticated data, NULL when aad_len is 0
aad_lenits length, below 0xFF00
ptthe plaintext
pt_lenits length
ct_outpt_len ciphertext bytes; may alias pt
tag_outPROTOCORE_AESCCM_TAG_LEN bytes
Returns
PROTO_TRUE on success.

◆ protocore_aes_ccm_open()

proto_bool protocore_aes_ccm_open ( uint8_t *  work,
const uint8_t *  key,
size_t  key_len,
const uint8_t *  nonce,
size_t  nonce_len,
const uint8_t *  aad,
size_t  aad_len,
const uint8_t *  ct,
size_t  ct_len,
const uint8_t *  tag,
uint8_t *  out 
)

Decrypt from A1, recompute the tag over the recovered plaintext, compare it in.

Parameters
workPROTOCORE_AES_CCM_BORROW bytes the caller took. Not held past the call.
key16 bytes (AES-128) or 32 bytes (AES-256)
key_len16 or 32
nonce7..13 bytes; SMB uses 11
nonce_lenits length
aadadditional authenticated data, NULL when aad_len is 0
aad_lenits length, below 0xFF00
ctthe ciphertext
ct_lenits length
tagPROTOCORE_AESCCM_TAG_LEN bytes to verify against
outct_len plaintext bytes; may alias ct
Returns
PROTO_TRUE on success.

Variable Documentation

◆ PROTOCORE_UNUSED

PROTOCORE_NS AesCcmNs AesCcm PROTOCORE_UNUSED = {.seal = protocore_aes_ccm_seal, .open = protocore_aes_ccm_open}

Module namespace.

Definition at line 91 of file aesccm.h.