Request for Comments: 3686 Vigil Security
Category: Standards Track January 2004
Using Advanced Encryption Standard (AES) Counter Mode
With IPsec Encapsulating Security Payload (ESP)
Status of this Memo
This document specifies an Internet standards track protocol for the
Internet community, and requests discussion and suggestions for
improvements. Please refer to the current edition of the "Internet
Official Protocol Standards" (STD 1) for the standardization state
and status of this protocol. Distribution of this memo is unlimited.
Copyright Notice
Copyright (C) The Internet Society (2004). All Rights Reserved.
Abstract
This document describes the use of Advanced Encryption Standard (AES)
Counter Mode, with an explicit initialization vector, as an IPsec
Encapsulating Security Payload (ESP) confidentiality mechanism.
Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1. Conventions Used In This Document. . . . . . . . . . . . 2
2. AES Block Cipher . . . . . . . . . . . . . . . . . . . . . . . 2
2.1. Counter Mode . . . . . . . . . . . . . . . . . . . . . . 2
2.2. Key Size and Rounds. . . . . . . . . . . . . . . . . . . 5
2.3. Block Size . . . . . . . . . . . . . . . . . . . . . . . 5
3. ESP Payload. . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.1. Initialization Vector. . . . . . . . . . . . . . . . . . 6
3.2. Encrypted Payload. . . . . . . . . . . . . . . . . . . . 6
3.3. Authentication Data. . . . . . . . . . . . . . . . . . . 6
4. Counter Block Format . . . . . . . . . . . . . . . . . . . . . 7
5. IKE Conventions. . . . . . . . . . . . . . . . . . . . . . . . 8
5.1. Keying Material and Nonces . . . . . . . . . . . . . . . 8
5.2. Phase 1 Identifier . . . . . . . . . . . . . . . . . . . 9
5.3. Phase 2 Identifier . . . . . . . . . . . . . . . . . . . 9
5.4. Key Length Attribute . . . . . . . . . . . . . . . . . . 9
6. Test Vectors . . . . . . . . . . . . . . . . . . . . . . . . . 9
7. Security Considerations. . . . . . . . . . . . . . . . . . . . 12
8. Design Rationale . . . . . . . . . . . . . . . . . . . . . . . 14
9. IANA Considerations. . . . . . . . . . . . . . . . . . . . . . 16
10. Intellectual Property Statement. . . . . . . . . . . . . . . . 16
11. Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . 16
12. References . . . . . . . . . . . . . . . . . . . . . . . . . . 17
12.1. Normative References . . . . . . . . . . . . . . . . . . 17
12.2. Informative References . . . . . . . . . . . . . . . . . 17
13. Author’s Address . . . . . . . . . . . . . . . . . . . . . . . 18
14. Full Copyright Statement . . . . . . . . . . . . . . . . . . . 19
1. Introduction
The National Institute of Standards and Technology (NIST) recently
selected the Advanced Encryption Standard (AES) [AES], also known as
Rijndael. The AES is a block cipher, and it can be used in many
different modes. This document describes the use of AES Counter Mode
(AES-CTR), with an explicit initialization vector (IV), as an IPsec
Encapsulating Security Payload (ESP) [ESP] confidentiality mechanism.
This document does not provide an overview of IPsec. However,
information about how the various components of IPsec and the way in
which they collectively provide security services is available in
[ARCH] and [ROADMAP].
1.1. Conventions Used In This Document
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
document are to be interpreted as described in [STDWORDS].
2. AES Block Cipher
This section contains a brief description of the relevant
characteristics of the AES block cipher. Implementation requirements
are also discussed.
2.1. Counter Mode
NIST has defined five modes of operation for AES and other FIPS-
approved block ciphers [MODES]. Each of these modes has different
characteristics. The five modes are: ECB (Electronic Code Book), CBC
(Cipher Block Chaining), CFB (Cipher FeedBack), OFB (Output
FeedBack), and CTR (Counter).
Only AES Counter mode (AES-CTR) is discussed in this specification.
AES-CTR requires the encryptor to generate a unique per-packet value,
and communicate this value to the decryptor. This specification
calls this per-packet value an initialization vector (IV). The same
IV and key combination MUST NOT be used more than once. The
encryptor can generate the IV in any manner that ensures uniqueness.
Common approaches to IV generation include incrementing a counter for
each packet and linear feedback shift registers (LFSRs).
This specification calls for the use of a nonce for additional
protection against precomputation attacks. The nonce value need not
be secret. However, the nonce MUST be unpredictable prior to the
establishment of the IPsec security association that is making use of
AES-CTR.
AES-CTR has many properties that make it an attractive encryption
algorithm for in high-speed networking. AES-CTR uses the AES block
cipher to create a stream cipher. Data is encrypted and decrypted by
XORing with the key stream produced by AES encrypting sequential
counter block values. AES-CTR is easy to implement, and AES-CTR can
be pipelined and parallelized. AES-CTR also supports key stream
precomputation.
Pipelining is possible because AES has multiple rounds (see section
2.2). A hardware implementation (and some software implementations)
can create a pipeline by unwinding the loop implied by this round
structure. For example, after a 16-octet block has been input, one
round later another 16-octet block can be input, and so on. In AES-
CTR, these inputs are the sequential counter block values used to
generate the key stream.
Multiple independent AES encrypt implementations can also be used to
improve performance. For example, one could use two AES encrypt
implementations in parallel, to process a sequence of counter block
values, doubling the effective throughput.
The sender can precompute the key stream. Since the key stream does
not depend on any data in the packet, the key stream can be
precomputed once the nonce and IV are assigned. This precomputation
can reduce packet latency. The receiver cannot perform similar
precomputation because the IV will not be known before the packet
arrives.
AES-CTR uses the only AES encrypt operation (for both encryption and
decryption), making AES-CTR implementations smaller than
implementations of many other AES modes.
When used correctly, AES-CTR provides a high level of
confidentiality. Unfortunately, AES-CTR is easy to use incorrectly.
Being a stream cipher, any reuse of the per-packet value, called the
IV, with the same nonce and key is catastrophic. An IV collision
immediately leaks information about the plaintext in both packets.
For this reason, it is inappropriate to use this mode of operation
with static keys. Extraordinary measures would be needed to prevent
reuse of an IV value with the static key across power cycles. To be
safe, implementations MUST use fresh keys with AES-CTR. The Internet
Key Exchange (IKE) [IKE] protocol can be used to establish fresh
keys. IKE can also provide the nonce value.
With AES-CTR, it is trivial to use a valid ciphertext to forge other
(valid to the decryptor) ciphertexts. Thus, it is equally
catastrophic to use AES-CTR without a companion authentication
function. Implementations MUST use AES-CTR in conjunction with an
authentication function, such as HMAC-SHA-1-96 [HMAC-SHA].
To encrypt a payload with AES-CTR, the encryptor partitions the
plaintext, PT, into 128-bit blocks. The final block need not be 128
bits; it can be less.
PT = PT[1] PT[2] ... PT[n]
Each PT block is XORed with a block of the key stream to generate the
ciphertext, CT. The AES encryption of each counter block results in
128 bits of key stream. The most significant 96 bits of the counter
block are set to the nonce value, which is 32 bits, followed by the
per-packet IV value, which is 64 bits. The least significant 32 bits
of the counter block are initially set to one. This counter value is
incremented by one to generate subsequent counter blocks, each
resulting in another 128 bits of key stream. The encryption of n
plaintext blocks can be summarized as:
CTRBLK := NONCE || IV || ONE
FOR i := 1 to n-1 DO
CT[i] := PT[i] XOR AES(CTRBLK)
CTRBLK := CTRBLK + 1
END
CT[n] := PT[n] XOR TRUNC(AES(CTRBLK))
The AES() function performs AES encryption with the fresh key.
The TRUNC() function truncates the output of the AES encrypt
operation to the same length as the final plaintext block, returning
the most significant bits.
Decryption is similar. The decryption of n ciphertext blocks can be
summarized as:
CTRBLK := NONCE || IV || ONE
FOR i := 1 to n-1 DO
PT[i] := CT[i] XOR AES(CTRBLK)
CTRBLK := CTRBLK + 1
END
PT[n] := CT[n] XOR TRUNC(AES(CTRBLK))
2.2. Key Size and Rounds
AES supports three key sizes: 128 bits, 192 bits, and 256 bits. The
default key size is 128 bits, and all implementations MUST support
this key size. Implementations MAY also support key sizes of 192
bits and 256 bits.
AES uses a different number of rounds for each of the defined key
sizes. When a 128-bit key is used, implementations MUST use 10
rounds. When a 192-bit key is used, implementations MUST use 12
rounds. When a 256-bit key is used, implementations MUST use 14
rounds.
2.3. Block Size
The AES has a block size of 128 bits (16 octets). As such, when
using AES-CTR, each AES encrypt operation generates 128 bits of key
stream. AES-CTR encryption is the XOR of the key stream with the
plaintext. AES-CTR decryption is the XOR of the key stream with the
ciphertext. If the generated key stream is longer than the plaintext
or ciphertext, the extra key stream bits are simply discarded. For
this reason, AES-CTR does not require the plaintext to be padded to a
multiple of the block size. However, to provide limited traffic flow
confidentiality, padding MAY be included, as specified in [ESP].
3. ESP Payload
The ESP payload is comprised of the IV followed by the ciphertext.
The payload field, as defined in [ESP], is structured as shown in
Figure 1.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Initialization Vector |
| (8 octets) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ Encrypted Payload (variable) ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ Authentication Data (variable) ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 1. ESP Payload Encrypted with AES-CTR
3.1. Initialization Vector
The AES-CTR IV field MUST be eight octets. The IV MUST be chosen by
the encryptor in a manner that ensures that the same IV value is used
only once for a given key. The encryptor can generate the IV in any
manner that ensures uniqueness. Common approaches to IV generation
include incrementing a counter for each packet and linear feedback
shift registers (LFSRs).
Including the IV in each packet ensures that the decryptor can
generate the key stream needed for decryption, even when some packets
are lost or reordered.
3.2. Encrypted Payload
The encrypted payload contains the ciphertext.
AES-CTR mode does not require plaintext padding. However, ESP does
require padding to 32-bit word-align the authentication data. The
padding, Pad Length, and the Next Header MUST be concatenated with
the plaintext before performing encryption, as described in [ESP].
3.3. Authentication Data
Since it is trivial to construct a forgery AES-CTR ciphertext from a
valid AES-CTR ciphertext, AES-CTR implementations MUST employ a non-
NULL ESP authentication method. HMAC-SHA-1-96 [HMAC-SHA] is a likely
choice.
4. Counter Block Format
Each packet conveys the IV that is necessary to construct the
sequence of counter blocks used to generate the key stream necessary
to decrypt the payload. The AES counter block cipher block is 128
bits. Figure 2 shows the format of the counter block.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Nonce |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Initialization Vector (IV) |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Block Counter |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 2. Counter Block Format
The components of the counter block are as follows:
Nonce
The Nonce field is 32 bits. As the name implies, the nonce is a
single use value. That is, a fresh nonce value MUST be assigned
for each security association. It MUST be assigned at the
beginning of the security association. The nonce value need not
be secret, but it MUST be unpredictable prior to the beginning of
the security association.
Initialization Vector
The IV field is 64 bits. As described in section 3.1, the IV MUST
be chosen by the encryptor in a manner that ensures that the same
IV value is used only once for a given key.
Block Counter
The block counter field is the least significant 32 bits of the
counter block. The block counter begins with the value of one,
and it is incremented to generate subsequent portions of the key
stream. The block counter is a 32-bit big-endian integer value.
Using the encryption process described in section 2.1, this
construction permits each packet to consist of up to:
(2^32)-1 blocks = 4,294,967,295 blocks
= 68,719,476,720 octets
This construction can produce enough key stream for each packet
sufficient to handle any IPv6 jumbogram [JUMBO].
5. IKE Conventions
This section describes the conventions used to generate keying
material and nonces for use with AES-CTR using the Internet Key
Exchange (IKE) [IKE] protocol. The identifiers and attributes needed
to negotiate a security association which uses AES-CTR are also
defined.
5.1. Keying Material and Nonces
As described in section 2.1, implementations MUST use fresh keys with
AES-CTR. IKE can be used to establish fresh keys. This section
describes the conventions for obtaining the unpredictable nonce value
from IKE. Note that this convention provides a nonce value that is
secret as well as unpredictable.
IKE makes use of a pseudo-random function (PRF) to derive keying
material. The PRF is used iteratively to derive keying material of
arbitrary size, called KEYMAT. Keying material is extracted from the
output string without regard to boundaries.
The size of the requested KEYMAT MUST be four octets longer than is
needed for the associated AES key. The keying material is used as
follows:
AES-CTR with a 128 bit key
The KEYMAT requested for each AES-CTR key is 20 octets. The first
16 octets are the 128-bit AES key, and the remaining four octets
are used as the nonce value in the counter block.
AES-CTR with a 192 bit key
The KEYMAT requested for each AES-CTR key is 28 octets. The first
24 octets are the 192-bit AES key, and the remaining four octets
are used as the nonce value in the counter block.
AES-CTR with a 256 bit key
The KEYMAT requested for each AES-CTR key is 36 octets. The first
32 octets are the 256-bit AES key, and the remaining four octets
are used as the nonce value in the counter block.
5.2. Phase 1 Identifier
This document does not specify the conventions for using AES-CTR for
IKE Phase 1 negotiations. For AES-CTR to be used in this manner, a
separate specification is needed, and an Encryption Algorithm
Identifier needs to be assigned.
5.3. Phase 2 Identifier
For IKE Phase 2 negotiations, IANA has assigned an ESP Transform
Identifier of 13 for AES-CTR with an explicit IV.
5.4. Key Length Attribute
Since the AES supports three key lengths, the Key Length attribute
MUST be specified in the IKE Phase 2 exchange [DOI]. The Key Length
attribute MUST have a value of 128, 192, or 256.
6. Test Vectors
This section contains nine test vectors, which can be used to confirm
that an implementation has correctly implemented AES-CTR. The first
three test vectors use AES with a 128 bit key; the next three test
vectors use AES with a 192 bit key; and the last three test vectors
use AES with a 256 bit key.
Test Vector #1: Encrypting 16 octets using AES-CTR with 128-bit key
AES Key : AE 68 52 F8 12 10 67 CC 4B F7 A5 76 55 77 F3 9E
AES-CTR IV : 00 00 00 00 00 00 00 00
Nonce : 00 00 00 30
Plaintext String : ’Single block msg’
Plaintext : 53 69 6E 67 6C 65 20 62 6C 6F 63 6B 20 6D 73 67
Counter Block (1): 00 00 00 30 00 00 00 00 00 00 00 00 00 00 00 01
Key Stream (1): B7 60 33 28 DB C2 93 1B 41 0E 16 C8 06 7E 62 DF
Ciphertext : E4 09 5D 4F B7 A7 B3 79 2D 61 75 A3 26 13 11 B8
Test Vector #2: Encrypting 32 octets using AES-CTR with 128-bit key
AES Key : 7E 24 06 78 17 FA E0 D7 43 D6 CE 1F 32 53 91 63
AES-CTR IV : C0 54 3B 59 DA 48 D9 0B
Nonce : 00 6C B6 DB
Plaintext : 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
: 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
Counter Block (1): 00 6C B6 DB C0 54 3B 59 DA 48 D9 0B 00 00 00 01
Key Stream (1): 51 05 A3 05 12 8F 74 DE 71 04 4B E5 82 D7 DD 87
Counter Block (2): 00 6C B6 DB C0 54 3B 59 DA 48 D9 0B 00 00 00 02
Key Stream (2): FB 3F 0C EF 52 CF 41 DF E4 FF 2A C4 8D 5C A0 37
Ciphertext : 51 04 A1 06 16 8A 72 D9 79 0D 41 EE 8E DA D3 88
: EB 2E 1E FC 46 DA 57 C8 FC E6 30 DF 91 41 BE 28
Test Vector #3: Encrypting 36 octets using AES-CTR with 128-bit key
AES Key : 76 91 BE 03 5E 50 20 A8 AC 6E 61 85 29 F9 A0 DC
AES-CTR IV : 27 77 7F 3F 4A 17 86 F0
Nonce : 00 E0 01 7B
Plaintext : 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
: 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
: 20 21 22 23
Counter Block (1): 00 E0 01 7B 27 77 7F 3F 4A 17 86 F0 00 00 00 01
Key Stream (1): C1 CE 4A AB 9B 2A FB DE C7 4F 58 E2 E3 D6 7C D8
Counter Block (2): 00 E0 01 7B 27 77 7F 3F 4A 17 86 F0 00 00 00 02
Key Stream (2): 55 51 B6 38 CA 78 6E 21 CD 83 46 F1 B2 EE 0E 4C
Counter Block (3): 00 E0 01 7B 27 77 7F 3F 4A 17 86 F0 00 00 00 03
Key Stream (3): 05 93 25 0C 17 55 36 00 A6 3D FE CF 56 23 87 E9
Ciphertext : C1 CF 48 A8 9F 2F FD D9 CF 46 52 E9 EF DB 72 D7
: 45 40 A4 2B DE 6D 78 36 D5 9A 5C EA AE F3 10 53
: 25 B2 07 2F
Test Vector #4: Encrypting 16 octets using AES-CTR with 192-bit key
AES Key : 16 AF 5B 14 5F C9 F5 79 C1 75 F9 3E 3B FB 0E ED
: 86 3D 06 CC FD B7 85 15
AES-CTR IV : 36 73 3C 14 7D 6D 93 CB
Nonce : 00 00 00 48
Plaintext String : ’Single block msg’
Plaintext : 53 69 6E 67 6C 65 20 62 6C 6F 63 6B 20 6D 73 67
Counter Block (1): 00 00 00 48 36 73 3C 14 7D 6D 93 CB 00 00 00 01