In modern network security, we often rely on high-level primitives like the cryptography library's AESCCM to handle our encryption and integrity checks. While efficient, these abstractions hide the intricate dance of the IEEE 802.11i standard.
I built this project to peel back those layers. By comparing a library-based implementation with a manual, step-by-step simulation of AES-CTR and AES-CBC-MAC, I’ve documented exactly how CCMP manages temporal keys, nonces, and the critical formatting of
The repository contains two distinct Python implementations for the Counter Mode with Cipher Block Chaining Message Authentication Code Protocol (CCMP):
- High-Level (
AESCCM): Utilizes standard primitives that abstract MIC calculation and encryption into a singleencrypt()call. - Manual Simulation: A "bare-metal" approach using
AES-CTRfor confidentiality andAES-CBC-MACfor integrity, simulating the XOR chains and manual padding required by the standard.
| Step | Library Implementation (AESCCM) | Manual Implementation |
|---|---|---|
| Nonce Construction | Implicitly handled. | Explicitly built using Source MAC, QoS, and PN. |
| Integrity (MIC) | Part of the encrypt() call |
Calculates via a manual XOR chain in calculate_mic() |
| Encryption (CTR) | High-level encrypt() over AAD/Payload |
Explicit encrypt_ctr() over concatenated (Plaintext + MIC) |
| Output | Returns Ciphertext + 64-bit MIC. | Returns Encrypted Payload + Encrypted MIC. |
The manual implementation simulates the following critical CCMP functions:
-
generate_ccmp_nonce: Constructs the 13-byte nonce (Source MAC + QoS + 48-bit PN). -
construct_be_block: Formats the$B_0$ block, the IV used for the CBC-MAC chain. -
calculate_mic: Manually XORs blocks ($T_i = AES(T_{i-1} \oplus P_i)$) to generate the 64-bit MIC. -
encrypt_ctr: Simulates the key-stream generation and XORing for data confidentiality.
Interestingly, while both implementations are functionally correct and secure, the final ciphertexts often differ slightly despite identical inputs.
Small variations in the construction of the
The simulation includes robust mechanisms for:
- Integrity Failures: Raises
IntegrityCompromisedError(mapped fromInvalidTag) if the MIC check fails. - Replay Protection: Explicit PN (Packet Number) tracking prevents the reuse of older, intercepted frames.
- IEEE 802.11i Standard
- K. Benton, "The Evolution of 802.11 Wireless Security," 2010.
Note: This project was developed as a deep-dive into cryptographic protocol simulation for the CyberMACS Master's program.