Full name: Advanced Encryption Standard in Counter with Cipher Block Chaining-Message Authentication Code mode.
Definition
AES-CCM is an authenticated encryption §5.16 mode: a method that uses one secret key both to encrypt a message and to compute a tag, a short value with which the receiver detects any change. AES (Advanced Encryption Standard) is the block cipher §15.3 used, a keyed function that maps one 16-byte block to another. CCM stands for Counter with CBC-MAC (cipher block chaining message authentication code): CBC-MAC computes the tag, and counter mode §15.5 encrypts. Every message needs a nonce §5.18, a value never used twice with the same key. RFC 3610 defines CCM.
The idea
A sensor sends readings by radio. Each packet has an 8-byte header that relays must read and a 23-byte reading that must stay private. Encryption alone does not stop changes. In counter mode, the encryption method inside CCM, the encrypted message (the ciphertext) is the original message combined bit by bit with a stream of secret pseudorandom bytes, so flipping one ciphertext bit flips exactly the same message bit, and decryption cannot notice. A message authentication code §5.7 alone detects changes but hides nothing. Combining the two by hand leaves open which key does which job, which bytes the tag covers, and whether to check before decrypting.
CCM settles those questions once. One AES key does both jobs, which RFC 3610 says simplifies implementation. The tag covers an unambiguous encoding of the nonce, both lengths, the header and the message, and the tag is then encrypted. The header goes in as associated data: bytes that the tag covers but that travel unencrypted.
The picture is a chain and a mask. CBC-MAC is the chain: each 16-byte block of input is mixed into a running 16-byte value, which passes through AES again, so the final value depends on every input byte. Counter mode supplies the mask: AES applied to successive counter blocks, each of which contains the nonce, gives a stream of bytes that only a key holder can compute. A new nonce gives a new mask. Reusing a nonce reuses the mask.
How it works
RFC 3610 and NIST Special Publication (SP) 800-38C both define CCM [169, 318]. RFC 3610 names the inputs as follows.
: the AES key, 16, 24 or 32 bytes long.
: the length of the tag in bytes, one of 4, 6, 8, 10, 12, 14 or 16.
: the size in bytes of the field that stores the message length, from 2 to 8.
: the nonce, bytes long.
: the message, bytes long, where denotes the length of in bytes.
: the associated data, bytes long, possibly empty.
The nonce and the message length share one 16-byte block with a flags byte: . That is why a longer nonce means a shorter maximum message.
Encryption runs in eight steps.
First block. Build the 16-byte block : one flags byte, then the nonce, then written in bytes, most significant byte first. The flags byte is , where is 1 if there is associated data and 0 otherwise, and .
Associated data blocks. If is not empty, write its length first: in 2 bytes when ; otherwise, when , as the bytes
0xFF 0xFEfollowed by 4 length bytes; and otherwise as0xFF 0xFFfollowed by 8 length bytes. Append , pad with zero bytes to a multiple of 16 bytes, and cut the result into 16-byte blocks.Message blocks. Cut into 16-byte blocks, padding the last one with zero bytes.
Tag. Run CBC-MAC over all blocks in order. Encrypt with AES. For each following block, combine it with the previous result by bitwise XOR (exclusive or, which sets each bit where the two inputs differ) and encrypt the combination. The first bytes of the last result are the tag .
Keystream. Build counter blocks , each made of a flags byte equal to , the nonce, and the block number in bytes. Encrypting with AES gives the keystream block .
Encryption. XOR the message with the first bytes of joined end to end. is kept for the tag.
Tag encryption. Compute , the XOR of with the first bytes of .
Output. Send the encrypted message followed by . The associated data is not part of the output; the receiver must already have it, for example as the packet header.
Decryption. The receiver rebuilds the keystream from the key and the nonce, recovers the message and , recomputes CBC-MAC over its own copy of the associated data and the recovered message, and compares the result with . RFC 3610 requires that on a mismatch the receiver release nothing except the fact that the check failed: no decrypted bytes and no tag.
Two details of the format have consequences that are easy to miss. First, bits 3 to 5 of the flags byte, counting from bit 0, the least significant bit, hold , which is never zero, in , and are zero in every counter block, so never equals a counter block; RFC 3610 relies on this when it uses one key for both jobs. Second, because holds the message length and every step of the chain depends on the step before, the sender must know before the first AES call, and before any associated data enters the chain. SP 800-38C states that CCM is meant for data that is fully available before processing starts and is not designed for stream processing.
Worked example
This is packet vector 1 of RFC 3610, recomputed here both from the steps above and with a cryptographic library.
Key: the 16 bytes
C0,C1, and so on up toCF, written in hexadecimal, so the cipher is AES with a 128-bit key.Nonce: the 13 bytes
00 00 00 03 02 01 00 A0 A1 A2 A3 A4 A5.Tag length: bytes.
Input packet: the 31 bytes
00to1E. The first 8 bytes are the header, used as associated data. The other bytes are the message.
The nonce has 13 bytes, so , and the longest allowed message is bytes; 23 bytes fits. There is associated data, and , so the flags byte is , which is 0x59. The message length 23 is 00 17 in two bytes. So
=
59 00 00 00 03 02 01 00 A0 A1 A2 A3 A4 A5 00 17
The associated data becomes the 2-byte length 00 08 followed by the 8 header bytes, bytes, padded to one block. The 23-byte message fills one block and 7 bytes of a second one, which gets zero bytes of padding. CBC-MAC therefore chains blocks with 4 AES calls, and the first 8 bytes of its result are the tag:
=
2D C6 97 E4 11 CA 83 A8
The counter blocks begin with the flags byte , so
=
01 00 00 00 03 02 01 00 A0 A1 A2 A3 A4 A5 00 01
The message needs and , and the tag needs : 3 more AES calls, in all. begins with the byte 50, so the first message byte 08 becomes 08 XOR 50 = 58. The first 8 bytes of are 3A 2E 46 C8 EC 33 A5 48. The encrypted tag therefore begins with 2D XOR 3A = 17, and in full it is 17 E8 D1 2C FD F9 26 E0.
The packet sent is the 8 header bytes in the clear, the 23 encrypted message bytes and the 8-byte encrypted tag, bytes:
00 01 02 03 04 05 06 07(header)
58 8C 97 9A 61 C6 63 D2 F0 66 D0 C2 C0 F9 89 80
6D 5F 6B 61 DA C3 84(encrypted message, 23 bytes)
17 E8 D1 2C FD F9 26 E0(encrypted tag)
This is the output printed in RFC 3610. CCM added 8 bytes, the tag. A protocol that also sends the 13-byte nonce with each packet adds 13 more, bytes.
Stated precisely
Let be the nonce length in bytes, the size of the length field in bytes, the tag length in bytes, and and the lengths in bytes of the message and the associated data. RFC 3610 (section 2) and SP 800-38C (appendix A) allow exactly the parameters that satisfy So lies between 7 and 13. SP 800-38C writes the tag length in bits, , and requires it to stay the same for every use of one key.
For each key the following rules hold.
Nonce uniqueness. Every encryption under uses a nonce that no other encryption under has used. RFC 3610 says that the set of nonce values used with a key must not contain duplicates; SP 800-38C says that distinct pairs of message and associated data protected during the lifetime of the key must get distinct nonces.
Volume. The total number of AES calls under , counting CBC-MAC and encryption together, must not exceed . Each 16-byte message block costs two AES calls, one in the chain and one for its keystream, so this allows about bytes.
One mode per key. SP 800-38C requires that the key be used only for CCM.
Check before release. No decrypted byte leaves the receiver before the tag has been checked.
RFC 3610 cites a security proof of confidentiality §1.8 and authenticity by Jakob Jonsson, “On the Security of CTR + CBC-MAC” (2002) [320]; CTR is the usual short name for counter mode. The design rationale in RFC 3610 rests on one assumption about AES: that it behaves as a pseudorandom permutation §15.2, meaning that nobody without the key can tell it apart from a permutation of 16-byte blocks chosen at random. For forgeries, SP 800-38C states that the probability that a single inauthentic ciphertext passes the check, for a given nonce and associated data, is no greater than , and that many attempts raise the total chance. Its sizing rule: if at most failed checks are allowed before the key is retired, and is the highest acceptable probability of accepting a forgery, choose . In its example, and give , so a 32-bit tag is enough.
Limits and common mistakes
A repeated nonce under one key repeats the keystream. The XOR of the two ciphertexts then equals the XOR of the two messages, so an attacker who knows or guesses one message learns the other. RFC 5116, which defines a common interface for authenticated encryption, records this loss of confidentiality for CCM, and RFC 3610 says that reuse destroys the security properties of the mode. The nonce entry explains how to keep nonces unique across restarts.
A short tag is easy to guess. With , one random guess passes with probability 1 in . RFC 3610 recommends of at least 8 for most applications, and SP 800-38C allows tags shorter than 64 bits only after a careful risk analysis and where the protocol limits how often the check may fail.
CCM does not detect a replay attack §1.26, in which an attacker records a valid packet and sends it again: the copy passes the check. The receiver must reject old nonces itself, for example by remembering the highest packet counter it has accepted.
The CBC-MAC inside CCM depends on the CCM formatting. SP 800-38C does not approve CBC-MAC outside CCM, and SP 800-38B says that the basic CBC-MAC has security deficiencies. One of them: without a length block, if is the tag of a one-block message , then is also the tag of the two-block message followed by XOR , because the second chain step encrypts XOR XOR , which is again. CCM’s length field in and its encrypted tag prevent this.
With 128-bit keys, using the same nonce value with many different keys invites precomputation. RFC 3610 describes an attacker who tabulates the keystream block , which encrypts the first 16 message bytes, for one chosen nonce under random keys, then compares it with messages sent under that nonce whose first 16 bytes it knows; after about such messages it can expect a match, which reveals that message’s key for a total of about steps instead of . It suggests a 256-bit key, or a few random bytes in the nonce.
Only the AES block size is the same in every use of CCM: 16 bytes. The key is 16, 24 or 32 bytes, the nonce 7 to 13 bytes and the tag 4 to 16 bytes, and a protocol usually fixes each of them; RFC 5116, for example, defines AEAD_AES_128_CCM with a 16-byte key, a 12-byte nonce, a 16-byte tag and .
Questions answered
What nonce-uniqueness and message-length constraints must an implementation obey?
An AES-CCM implementation must never use the same nonce twice with the same key, and every message must be shorter than bytes, where , from 2 to 8, is the size in bytes of the length field and the nonce is bytes long. AES-CCM is the Advanced Encryption Standard block cipher used in Counter with CBC-MAC (cipher block chaining message authentication code) mode, which encrypts a message and computes a tag that detects changes; a nonce is a value that may be used only once per key. In detail:
Nonce uniqueness. The scope is the key, not one program run. Every device that holds the key, both directions of a connection and every run after a restart draw from one set of nonces, so a counter used as the nonce must never restart or go backward while the key is in use. A repeated nonce reveals the XOR (bitwise exclusive or) of the two messages.
Length against nonce size. A 13-byte nonce leaves and a maximum message of bytes; a 12-byte nonce leaves and a maximum of bytes.
Associated data, the bytes that are authenticated but not encrypted, must be shorter than bytes.
Lengths known first. Both lengths enter the first blocks of the tag computation, so both must be known before the data is processed; CCM cannot encrypt a stream of unknown length.
Volume per key. At most AES calls per key, about bytes of message.
Tag length is one of 4, 6, 8, 10, 12, 14 or 16 bytes, the same for every use of the key.
A protocol that uses CCM usually fixes these values, and its own limits apply on top.
Related entries: Authenticated encryption (AEAD) (§5.16), Nonce (§5.18), Tag truncation (§5.12), Message authentication code (MAC) (§5.7), Forgery probability (§5.13), Block cipher (§15.3), Counter mode (CTR) (§15.5), Cipher block chaining (CBC) (§15.6), Replay attack (§1.26). Further reading: [47, 67, 74, 318, 320].