XU XUv0.13.1
中文

#embedded/wifi/ccmp

import: #embedded/wifi/ccmp

counts: 3 functions, 0 methods, 1 types, 1 constants, 0 method sets

CCMP-128 for ordinary three-address Data/QoS Data MPDUs without FCS. AES is variable-time. PN values are six LITTLE-endian bytes, never int the physical ESP32 backend uses 32-bit native integer registers.

const MAX_FRAME

XuAPI
pub const MAX_FRAME = 1600

Purpose

CCMP-128 for ordinary three-address Data/QoS Data MPDUs without FCS. AES is variable-time. PN values are six LITTLE-endian bytes, never int the physical ESP32 backend uses 32-bit native integer registers.

struct CcmpPacket

XuAPI
pub struct CcmpPacket {
    pub valid bool
    pub payload string
    pub pn string
    pub key_index int
}

Purpose

Structure encapsulating valid, payload, pn, key_index.

Public fields

valid bool
field (bool)
payload string
field (string)
pn string
field (string)
key_index int
field (int)

next_pn

XuAPI
pub fn next_pn(pn &string) string

Purpose

Start with six zero bytes, consume next_pn BEFORE submitting a new frame, and retain the consumed value even when transmission fails. Empty means invalid input or exhaustion: install a fresh key; NEVER wrap or reset the counter while using the same key. Retransmit an already protected MPDU unchanged rather than encrypting different contents with its old PN.

Parameters

pn &string
pn (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

protect

XuAPI
pub fn protect(key &string, header &string, payload &string, pn &string, key_index int) string

Purpose

Protect one MPDU using an explicitly consumed PN. Returns empty on invalid input or AES failure; sets Protected and inserts CCMP header plus 8-byte MIC. This stateless function cannot detect caller PN reuse; follow next_pn's per-key lifetime rules. key_index must select the actual installed key.

Parameters

key &string
key (read-only borrow; caller keeps the original; type &string)
header &string
header (read-only borrow; caller keeps the original; type &string)
payload &string
payload (read-only borrow; caller keeps the original; type &string)
pn &string
pn (read-only borrow; caller keeps the original; type &string)
key_index int
key_index (int)

Returns

string — result string

unprotect

XuAPI
pub fn unprotect(key &string, frame &string, last_pn &string) CcmpPacket

Purpose

last_pn is exactly six LE bytes, scoped to installed key + transmitter + TID (a separate non-QoS replay domain). Reject PN <= floor before AES. Commit the returned PN after valid=true, before dispatching the payload. Caller selects the receive key from the CCMP Key ID and checks key_index the Key ID itself is not included in CCMP's authenticated data.

Parameters

key &string
key (read-only borrow; caller keeps the original; type &string)
frame &string
frame (read-only borrow; caller keeps the original; type &string)
last_pn &string
last_pn (read-only borrow; caller keeps the original; type &string)

Returns

CcmpPacket — a value of this type