RFC 4106

The Use of Galois/Counter Mode (GCM) in IPsec Encapsulating Security Payload (ESP)

๐Ÿ“… published June 2005, from ietf

The Use of Galois/Counter Mode (GCM) in IPsec Encapsulating Security Payload (ESP) ๐ŸŽ€

Okay bestie, here's the deal ๐Ÿ’–. This is RFC 4106, a Standards Track doc dated June 2005 ๐Ÿฆ‹. It was written by J. Viega (Secure Software, Inc.) and D. McGrew (Cisco Systems, Inc.) for the Network Working Group. The title block doesn't list anything it obsoletes or updates, so no drama there โœจ.

Status of This Memo ๐Ÿ“œ

This is an Internet standards track protocol for the Internet community, and the authors are asking for discussion and suggestions for improvements ๐Ÿ’…. To check where it stands in standardization, look at the current edition of "Internet Official Protocol Standards" (STD 1). Distribution of this memo is unlimited ๐ŸŒˆ.

Copyright (C) The Internet Society (2005).

Abstract ๐Ÿฆ‹

This memo is about using the Advanced Encryption Standard (AES) in Galois/Counter Mode (GCM) as an IPsec Encapsulating Security Payload (ESP) mechanism. The goal is confidentiality and data origin authentication, and it's giving efficiency ๐Ÿ”ฅ. It can be implemented efficiently in hardware for speeds of 10 gigabits per second and above, and it's also a great fit for software implementations ๐Ÿ’œ.

Table of Contents ๐Ÿ—‚๏ธ

   1. Introduction ....................................................2
      1.1. Conventions Used in This Document ..........................2
   2. AES-GCM .........................................................3
   3. ESP Payload Data ................................................3
      3.1. Initialization Vector (IV) .................................3
      3.2. Ciphertext .................................................4
   4. Nonce Format ....................................................4
   5. AAD Construction ................................................5
   6. Integrity Check Value (ICV) .....................................5
   7. Packet Expansion ................................................6
   8. IKE Conventions .................................................6
      8.1. Keying Material and Salt Values ............................6
      8.2. Phase 1 Identifier .........................................6
      8.3. Phase 2 Identifier .........................................7
      8.4. Key Length Attribute .......................................7

   9. Test Vectors ....................................................7
   10. Security Considerations ........................................7
   11. Design Rationale ...............................................8
   12. IANA Considerations ............................................8
   13. Acknowledgements ...............................................9
   14. Normative References ...........................................9
   15. Informative References .........................................9

1. Introduction โœจ

Okay so this doc is all about using AES in GCM mode (AES-GCM) as an IPsec ESP mechanism for confidentiality and data origin authentication. We're calling this method AES-GCM-ESP ๐Ÿ’…. It's efficient and secure, and it's built for high-speed hardware too. That means AES-GCM-ESP lets IPsec connections really make use of emerging 10-gigabit and 40-gigabit network devices ๐Ÿš€.

Counter mode (CTR) has basically become the fave encryption method for high-speed implementations ๐Ÿ‘‘. Compared to conventional modes like Cipher Block Chaining (CBC) and Cipher Block Chaining Message Authentication Code (CBC-MAC), CTR can run efficiently at high data rates because it can be pipelined ๐Ÿงš. The ESP CTR protocol explains how to use this mode with IPsec ESP [RFC3686].

Here's the tea ๐Ÿซ–. CTR gives you no data origin authentication ๐Ÿ˜ญ, so the ESP CTR standard needs a data origin authentication algorithm alongside it. That's a problem, because none of the standard data origin authentication algorithms can be implemented efficiently at high data rates. GCM fixes this, because under the hood it combines CTR mode with a secure, parallelizable, and efficient authentication mechanism ๐ŸŽ€.

This document doesn't dig into the implementation details of GCM. Those live in [GCM], along with test vectors ๐ŸŒธ.

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 [RFC2119].

2. AES-GCM ๐Ÿ”

GCM is a block cipher mode of operation that provides both confidentiality and data origin authentication ๐Ÿ’–. The GCM authenticated encryption operation takes four inputs: a secret key, an initialization vector (IV), a plaintext, and an input for additional authenticated data (AAD). It gives back two outputs: a ciphertext whose length matches the plaintext, and an authentication tag. Below, we walk through how the IV, plaintext, and AAD get formed from the ESP fields, and how the ESP packet is built from the ciphertext and authentication tag โœจ.

ESP also defines an IV, but to keep things clear we call the AES-GCM IV a nonce in the context of AES-GCM-ESP ๐Ÿง . The same nonce and key combination MUST NOT be used more than once.

Reusing a nonce/key combination wrecks the security guarantees of AES-GCM mode ๐Ÿ’€, so it can be tricky to use this mode safely with statically configured keys. For safety's sake, implementations MUST use an automated key management system, such as the Internet Key Exchange (IKE) [RFC2409], to make sure this requirement is met ๐Ÿซถ.

3. ESP Payload Data ๐Ÿ“

The ESP Payload Data is made up of an eight-octet initialization vector (IV), followed by the ciphertext. The payload field, as defined in [RFC2406], is laid out as shown in Figure 1, along with the ICV associated with the payload ๐Ÿ’œ.

    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)                         |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                                                               |
   ~                       Ciphertext (variable)                   ~
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

               Figure 1: ESP Payload Encrypted with AES-GCM.

3.1. Initialization Vector (IV) ๐ŸŽฒ

The AES-GCM-ESP IV field MUST be eight octets. For a given key, the IV MUST NOT repeat. The most natural way to do this is with a counter, but anything that guarantees uniqueness works too, such as a linear feedback shift register (LFSR) ๐Ÿ”. Note that the encrypter can use any IV generation method that meets the uniqueness requirement, and it doesn't need to coordinate with the decrypter ๐Ÿ™Œ.

3.2. Ciphertext ๐Ÿ”’

The plaintext input to AES-GCM is formed by concatenating the plaintext data described by the Next Header field with the Padding, the Pad Length, and the Next Header field. The Ciphertext field holds the ciphertext output from the AES-GCM algorithm. The length of the ciphertext is identical to that of the plaintext ๐ŸŒท.

Implementations that don't try to hide the length of the plaintext SHOULD use the minimum amount of padding required, which will be less than four octets ๐Ÿช„.

4. Nonce Format ๐Ÿงฉ

The nonce passed to the GCM-AES encryption algorithm has the following layout ๐Ÿ’…:

    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
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                             Salt                              |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                     Initialization Vector                     |
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                          Figure 2: Nonce Format

The components of the nonce are as follows ๐Ÿ‘‡:

  • Salt: The salt is a four-octet value that gets assigned at the beginning of the security association, and then stays constant for the life of that security association ๐Ÿง‚. The salt SHOULD be unpredictable (i.e., chosen at random) before it is selected, but it doesn't need to be secret. We describe how to set the salt for a Security Association established via the Internet Key Exchange in Section 8.1.
  • Initialization Vector: The IV field is described in Section 3.1.

5. AAD Construction ๐Ÿ›ก๏ธ

The authentication of data integrity and data origin for the SPI and (Extended) Sequence Number fields is provided without encryption โœจ. This is done by including those fields in the AES-GCM Additional Authenticated Data (AAD) field. Two formats of the AAD are defined: one for 32-bit sequence numbers, and one for 64-bit extended sequence numbers. The format with 32-bit sequence numbers is shown in Figure 3, and the format with 64-bit extended sequence numbers is shown in Figure 4 ๐Ÿฆ‹.

    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
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                               SPI                             |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                     32-bit Sequence Number                    |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

             Figure 3: AAD Format with 32-bit Sequence Number
    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
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                               SPI                             |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                 64-bit Extended Sequence Number               |
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

         Figure 4: AAD Format with 64-bit Extended Sequence Number

6. Integrity Check Value (ICV) ๐Ÿ”‘

The ICV consists solely of the AES-GCM Authentication Tag ๐Ÿท๏ธ. Implementations MUST support a full-length 16-octet ICV, and MAY support 8 or 12 octet ICVs, and MUST NOT support other ICV lengths. Although ESP doesn't require an ICV to be present, AES-GCM-ESP intentionally doesn't allow a zero-length ICV ๐Ÿ™…โ€โ™€๏ธ. That's because GCM provides no integrity protection whatsoever when used with a zero-length Authentication Tag ๐Ÿ˜ฑ.

Zero-length ICVs are a no-go here. Without a tag, GCM gives you no integrity protection at all.

7. Packet Expansion ๐Ÿ“ฆ

The IV adds an additional eight octets to the packet, and the ICV adds an additional 8, 12, or 16 octets ๐ŸŽˆ. These are the only sources of packet expansion, other than the 10-13 octets taken up by the ESP SPI, Sequence Number, Padding, Pad Length, and Next Header fields (if the minimal amount of padding is used) ๐Ÿงฎ.

8. IKE Conventions ๐Ÿค

This section describes the conventions used to generate keying material and salt values for use with AES-GCM-ESP, using the Internet Key Exchange (IKE) [RFC2409] protocol ๐Ÿ”‘. It also defines the identifiers and attributes needed to negotiate a security association using AES-GCM-ESP โœจ.

8.1. Keying Material and Salt Values โœจ

okay so IKE needs a pseudo-random function (PRF) to make keying material ๐Ÿ”‘ and it just keeps calling that PRF over and over until it has enough, called KEYMAT ๐Ÿซถ the KEYMAT is pulled out of the output string without caring about where the boundaries are, which is very on-brand for it ๐Ÿ’…

the KEYMAT for AES-GCM-ESP MUST be four octets longer than the AES key needs ๐Ÿ’– here's how it gets split up:

AES-GCM-ESP with a 128 bit key the KEYMAT requested for each AES-GCM key is 20 octets ๐ŸŽ€ the first 16 octets are the 128-bit AES key, and the last four are the salt value used in the nonce โœจ

AES-GCM-ESP with a 192 bit key the KEYMAT requested for each AES-GCM key is 28 octets ๐ŸŒธ the first 24 octets are the 192-bit AES key, and the last four are the salt value in the nonce ๐Ÿฆ‹

AES-GCM-ESP with a 256 bit key the KEYMAT requested for each AES GCM key is 36 octets ๐Ÿ‘‘ the first 32 octets are the 256-bit AES key, and the last four are the salt value in the nonce ๐Ÿ’œ

8.2. Phase 1 Identifier ๐Ÿงš

ok real talk, this doc does NOT spell out how to use AES-GCM for IKE Phase 1 ๐Ÿ™ˆ if you want AES-GCM there, you'd need a separate spec and a new Encryption Algorithm Identifier to be assigned ๐Ÿ“ in the meantime, implementations SHOULD use a Phase 1 cipher that's at least as strong as AES-GCM ๐Ÿ’ช and using AES CBC [RFC3602] with the same key size AES-GCM-ESP uses is RECOMMENDED ๐Ÿ“

8.3. Phase 2 Identifier ๐Ÿ’…

for IKE Phase 2 negotiations, IANA gave out three ESP Transform Identifiers for AES-GCM with an eight-byte explicit IV ๐Ÿซถ

18 for AES-GCM with an 8 octet ICV;
19 for AES-GCM with a 12 octet ICV; and
20 for AES-GCM with a 16 octet ICV.

8.4. Key Length Attribute ๐ŸŒˆ

since AES has three key lengths, the Key Length attribute MUST be specified in the IKE Phase 2 exchange [RFC2407] ๐Ÿ˜ญ and it MUST have a value of 128, 192, or 256 โœจ

9. Test Vectors ๐Ÿงช

Appendix B of [GCM] has test vectors that will help implementers get AES-GCM mode working ๐Ÿซถ๐Ÿ”ฅ

10. Security Considerations ๐Ÿ”

this section is SERIOUS bestie, read it all ๐Ÿ˜ญ๐Ÿšจ

GCM is provably secure against adversaries that can adaptively choose plaintexts, ciphertexts, ICVs, and the AAD field ๐Ÿ›ก๏ธ this holds under standard cryptographic assumptions (roughly, that the output of the underlying cipher, under a randomly chosen key, is indistinguishable from a randomly selected output) ๐Ÿง  basically, if you use GCM within its intended parameters, breaking GCM would mean breaking the underlying block cipher ๐Ÿ’€ the proof of security is in [GCM] if you want to nerd out ๐Ÿค“

the most important security consideration is that the IV never repeats for a given key ๐Ÿšจ part of how that's handled is by NOT allowing AES-GCM with statically configured keys, which is covered in Section 2 ๐Ÿ™…โ€โ™€๏ธ

when IKE is used to establish fresh keys between two peer entities, separate keys get established for the two traffic flows ๐Ÿฆ‹ but if a different mechanism is used to establish fresh keys (one that only establishes a single key to encrypt packets), then there's a high probability the peers will pick the same IV values for some packets ๐Ÿ˜ฑ so to avoid counter block collisions, ESP implementations that let the same key be used for encrypting and decrypting packets with the same peer MUST make sure the two peers assign different salt values to the security association (SA) ๐Ÿ’–

another thing: like with any encryption mode, the security of all data protected under a given security association goes down a tiny bit with each message ๐Ÿ“‰

to protect against this, implementations MUST generate a fresh key before encrypting 2^64 blocks of data with a given key ๐Ÿ”‘ and it's worth noting that it's impossible to hit this limit when using 32-bit Sequence Numbers ๐Ÿ™Œ

also, for each message, GCM calls the block cipher once for each full 16-octet block in the payload, once for any remaining octets in the payload, and one more time for computing the ICV ๐Ÿงฎ

last one: smaller ICV values are more likely to be subject to forgery attacks ๐Ÿšฉ so implementations SHOULD use as large a size as reasonable ๐Ÿ’ช

11. Design Rationale ๐ŸŽ€

this spec was designed to be as similar as reasonable to the AES-CCM ESP [CCM-ESP] and AES-CTR ESP [RFC3686] mechanisms ๐Ÿ‘ฏโ€โ™€๏ธ while still promoting simple, efficient implementations in both hardware and software โšก the design and implementation experience from those standards got reused, which is iconic of them ๐Ÿ™Œ

the major difference with CCM is that the CCM ESP mechanism requires an 11-octet nonce, whereas the GCM ESP mechanism requires using a 12-octet nonce ๐Ÿง GCM is specially optimized for the 12-octet nonce case, so it's fast ๐ŸŽ๏ธ nonces of other lengths would add unnecessary complexity and delays, especially in hardware ๐Ÿ˜ค the extra octet of nonce is used to make the salt bigger ๐Ÿง‚

12. IANA Considerations ๐Ÿ“‹

IANA has assigned three ESP Transform Identifiers for AES-GCM with an eight-byte explicit IV ๐Ÿฆ‹

18 for AES-GCM with an 8 octet ICV;
19 for AES-GCM with a 12 octet ICV; and
20 for AES-GCM with a 16 octet ICV.

13. Acknowledgements ๐Ÿซถ

this work is closely modeled after Russ Housley's AES-CCM transform [CCM-ESP] ๐Ÿ’œ portions of this document are directly copied from that work in progress, and the authors thank Russ for his support ๐Ÿฅน

also, the GCM mode of operation was originally conceived as an improvement to Carter-Wegman Counter (CWC) mode [CWC] ๐Ÿง  CWC was the first unencumbered block cipher mode able to support high-speed authenticated encryption ๐Ÿš€

14. Normative References ๐Ÿ“š

15. Informative References ๐ŸŒธ

  • [CCM-ESP] Housley, R., "Using AES CCM Mode With IPsec ESP", Work In Progress.
  • [CWC] Kohno, T., Viega, J. and D. Whiting, "CWC: A high-performance conventional authenticated encryption mode", Fast Software Encryption. http://eprint.iacr.org/2003/106.pdf, February 2004.
  • [RFC2409] Harkins, D. and D. Carrel, "The Internet Key Exchange (IKE)", RFC 2409, November 1998.
  • [RFC3686] Housley, R., "Using Advanced Encryption Standard (AES) Counter Mode With IPsec Encapsulating Security Payload (ESP)", RFC 3686, January 2004.

Authors' Addresses ๐Ÿ’Œ

John Viega
Secure Software, Inc.
4100 Lafayette Center Dr., Suite 100
Chantilly, VA  20151
US

Phone: (703) 814 4402
EMail: viega@securesoftware.com
David A. McGrew
Cisco Systems, Inc.
510 McCarthy Blvd.
Milpitas, CA  95035
US

Phone: (408) 525 8651
EMail: mcgrew@cisco.com
URI:   http://www.mindspring.com/~dmcgrew/dam.htm

Copyright (C) The Internet Society (2005).

This document is subject to the rights, licenses and restrictions contained in BCP 78, and except as set forth therein, the authors retain all their rights.

This document and the information contained herein are provided on an "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.

Intellectual Property ๐Ÿงพ

The IETF takes no position regarding the validity or scope of any Intellectual Property Rights or other rights that might be claimed to pertain to the implementation or use of the technology described in this document or the extent to which any license under such rights might or might not be available; nor does it represent that it has made any independent effort to identify any such rights. Information on the procedures with respect to rights in RFC documents can be found in BCP 78 and BCP 79.

Copies of IPR disclosures made to the IETF Secretariat and any assurances of licenses to be made available, or the result of an attempt made to obtain a general license or permission for the use of such proprietary rights by implementers or users of this specification can be obtained from the IETF on-line IPR repository at http://www.ietf.org/ipr.

The IETF invites any interested party to bring to its attention any copyrights, patents or patent applications, or other proprietary rights that may cover technology that may be required to implement this standard. Please address the information to the IETF at ietf-ipr@ietf.org.

Acknowledgement ๐Ÿ’–

Funding for the RFC Editor function is currently provided by the Internet Society. ๐Ÿซถโœจ

๐Ÿ“ฆ where this page comes from