RFC 2409

The Internet Key Exchange (IKE)

๐Ÿ“… published November 1998, from ietf

RFC 2409: The Internet Key Exchange (IKE) ๐ŸŽ€

Network Working Group ๐Ÿ’Œ this one's from the Network Working Group, and it's giving serious standards energy โœจ

  • Authors: D. Harkins and D. Carrel, from cisco Systems ๐Ÿ‘‘
  • Category: Standards Track ๐Ÿฆ‹
  • Date: November 1998 ๐ŸŒธ
  • Obsoletes / Updates: the title block doesn't list anything this RFC obsoletes or updates, so I'm not making that up ๐Ÿ™ˆ

Status of This Memo โœจ

okay so this section is the official "what is this doc even" bit ๐Ÿ’… It says this document specifies an Internet standards track protocol for the Internet community, and it's literally asking for discussion and suggestions for improvements ๐Ÿซถ If you want the current standardization state and status of this protocol, check the current edition of the "Internet Official Protocol Standards" (STD 1). Distribution of this memo is unlimited ๐ŸŒˆ

Copyright (C) The Internet Society (1998). All Rights Reserved.

Table Of Contents ๐Ÿ“š

1 Abstract........................................................  2
2 Discussion......................................................  2
3 Terms and Definitions...........................................  3
3.1 Requirements Terminology......................................  3
3.2 Notation......................................................  3
3.3 Perfect Forward Secrecty......................................  5
3.4 Security Association..........................................  5
4 Introduction....................................................  5
5 Exchanges.......................................................  8
5.1 Authentication with Digital Signatures........................ 10
5.2 Authentication with Public Key Encryption..................... 12
5.3 A Revised method of Authentication with Public Key Encryption. 13
5.4 Authentication with a Pre-Shared Key.......................... 16
5.5 Quick Mode.................................................... 16
5.6 New Group Mode................................................ 20
5.7 ISAKMP Informational Exchanges................................ 20
6 Oakley Groups................................................... 21
6.1 First Oakley Group............................................ 21
6.2 Second Oakley Group........................................... 22
6.3 Third Oakley Group............................................ 22
6.4 Fourth Oakley Group........................................... 23
7 Payload Explosion of Complete Exchange.......................... 23
7.1 Phase 1 with Main Mode........................................ 23
7.2 Phase 2 with Quick Mode....................................... 25
8 Perfect Forward Secrecy Example................................. 27
9 Implementation Hints............................................ 27
10 Security Considerations........................................ 28
11 IANA Considerations............................................ 30
12 Acknowledgments................................................ 31
13 References..................................................... 31
Appendix A........................................................ 33
Appendix B........................................................ 37
Authors' Addresses................................................ 40
Authors' Note..................................................... 40
Full Copyright Statement.......................................... 41

1. Abstract โœจ

okay so ISAKMP ([MSST98]) gives you a framework for authentication and key exchange, but it doesn't actually define them ๐Ÿ™ƒ It's designed to be key exchange independent, which means it's built to support lots of different key exchanges. Iconic behaviour, honestly ๐Ÿ‘‘

Oakley ([Orm96]) describes a series of key exchanges (called "modes") and details the services each one provides, like perfect forward secrecy for keys, identity protection, and authentication ๐Ÿ”

SKEME ([SKEME]) describes a versatile key exchange technique that provides anonymity, repudiability, and quick key refreshment ๐Ÿ’–

This document describes a protocol that uses part of Oakley and part of SKEME, together with ISAKMP, to get authenticated keying material. That keying material is for use with ISAKMP itself, and for other security associations such as AH and ESP for the IETF IPsec DOI. Main character energy ๐ŸŽ€

2. Discussion ๐Ÿ’ฌ

This memo describes a hybrid protocol ๐Ÿฆ‹ The whole point is to negotiate security associations, and to provide authenticated keying material for them, in a protected way.

Processes that implement this memo can be used for negotiating virtual private networks (VPNs). They can also let a remote user at a remote site (whose IP address doesn't need to be known beforehand) access a secure host or network. Lowkey so useful ๐ŸŒธ

Client negotiation is supported ๐Ÿซถ Client mode is where the negotiating parties aren't the endpoints the security association negotiation is actually for. When you use client mode, the identities of the end parties stay hidden ๐Ÿ™ˆ

This does not implement the entire Oakley protocol, just the subset needed to satisfy its goals. It doesn't claim conformance or compliance with the entire Oakley protocol, and it isn't dependent in any way on the Oakley protocol ๐Ÿ’…

Likewise, this does not implement the entire SKEME protocol. It only takes the public key encryption method for authentication, plus its idea of fast re-keying using an exchange of nonces. This protocol isn't dependent in any way on the SKEME protocol either โœจ

3. Terms and Definitions ๐Ÿ“–

3.1. Requirements Terminology

The keywords "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT" and "MAY" that appear in this document are to be interpreted as described in [Bra97]. Those words are the keyword list, so they're flagged on purpose ๐ŸŽ€

3.2. Notation

Here's the notation used throughout this memo. Bookmark this part, bestie ๐Ÿ”–

  • HDR is an ISAKMP header whose exchange type is the mode. When written as HDR*, it indicates payload encryption ๐Ÿ”’
  • SA is an SA negotiation payload with one or more proposals. An initiator MAY provide multiple proposals for negotiation, but a responder MUST reply with only one ๐Ÿ’…
  • <P>_b indicates the body of payload <P>. The ISAKMP generic header is left out ๐ŸŒท
  • SAi_b is the entire body of the SA payload (minus the ISAKMP generic header). That means the DOI, situation, all proposals, and all transforms offered by the Initiator ๐Ÿงš
  • CKY-I and CKY-R are the Initiator's cookie and the Responder's cookie, respectively, from the ISAKMP header ๐Ÿ“
  • g^xi and g^xr are the Diffie-Hellman ([DH]) public values of the initiator and responder, respectively ๐Ÿ’œ
  • g^xy is the Diffie-Hellman shared secret ๐Ÿ”ฅ
  • KE is the key exchange payload, which contains the public information exchanged in a Diffie-Hellman exchange. No particular encoding (e.g. a TLV) is used for the data of a KE payload ๐ŸŒˆ
  • Nx is the nonce payload. x can be i or r for the ISAKMP initiator and responder, respectively โญ
  • IDx is the identification payload for "x". x can be "ii" or "ir" for the ISAKMP initiator and responder, respectively, during phase one negotiation. Or x can be "ui" or "ur" for the user initiator and responder, respectively, during phase two. The ID payload format for the Internet DOI is defined in [Pip97] ๐Ÿชช
  • SIG is the signature payload. The data to sign is exchange-specific โœ๏ธ
  • CERT is the certificate payload ๐Ÿ“œ
  • HASH (and any derivative such as HASH(2) or HASH_I) is the hash payload. The contents of the hash are specific to the authentication method ๐Ÿง
  • prf(key, msg) is the keyed pseudo-random function, often a keyed hash function, used to generate a deterministic output that appears pseudo-random. prfs are used both for key derivations and for authentication (i.e. as a keyed MAC). (See [KBC96]) ๐ŸŽฒ
  • SKEYID is a string derived from secret material known only to the active players in the exchange ๐Ÿคซ
  • SKEYID_e is the keying material used by the ISAKMP SA to protect the confidentiality of its messages ๐Ÿ”
  • SKEYID_a is the keying material used by the ISAKMP SA to authenticate its messages โœ…
  • SKEYID_d is the keying material used to derive keys for non-ISAKMP security associations ๐Ÿ—๏ธ
  • <x>y indicates that "x" is encrypted with the key "y" ๐Ÿซง
  • --> signifies "initiator to responder" communication (requests) โžก๏ธ
  • <-- signifies "responder to initiator" communication (replies) โฌ…๏ธ
  • | signifies concatenation of information. For example, X | Y is the concatenation of X with Y ๐Ÿงต
  • [x] indicates that x is optional ๐ŸŽ€

Message encryption (when noted by a '*' after the ISAKMP header) MUST begin immediately after the ISAKMP header. When communication is protected, all payloads following the ISAKMP header MUST be encrypted. Encryption keys are generated from SKEYID_e in a manner that is defined for each algorithm ๐Ÿ”’โœจ

3.3. Perfect Forward Secrecy

When used in this memo, Perfect Forward Secrecy (PFS) refers to the idea that compromising a single key will only let someone access data protected by that single key. For PFS to exist, the key used to protect transmission of data MUST NOT be used to derive any additional keys. And if that key was derived from some other keying material, that material MUST NOT be used to derive any more keys. Honestly the most important rule in this whole section ๐Ÿ›ก๏ธ

Perfect Forward Secrecy for both keys and identities is provided in this protocol (Sections 5.5 and 8) ๐Ÿ‘‘

3.4. Security Association

A security association (SA) is a set of policy and key(s) used to protect information. The ISAKMP SA is the shared policy and key(s) that the negotiating peers in this protocol use to protect their communication ๐Ÿ’–


more parts are coming, so stay tuned ๐Ÿฆ‹

4. Introduction โœจ

okay so Oakley and SKEME each define a method to set up an authenticated key exchange ๐Ÿ” that covers how the payloads get built, what info they carry, the order they get processed in, and how they're used. literally the whole recipe ๐Ÿ’…

While Oakley defines "modes", ISAKMP defines "phases" ๐ŸŽ€. The relationship between the two is super straightforward. IKE presents its different exchanges as modes, and each mode runs in one of two phases ๐Ÿฆ‹

Phase 1 is where the two ISAKMP peers set up a secure, authenticated channel to talk over ๐Ÿซถ. This is called the ISAKMP Security Association (SA). "Main Mode" and "Aggressive Mode" each accomplish a phase 1 exchange. "Main Mode" and "Aggressive Mode" MUST ONLY be used in phase 1 ๐Ÿ™ˆ

Phase 2 is where Security Associations get negotiated on behalf of services like IPsec, or any other service that needs key material and/or parameter negotiation ๐ŸŒธ "Quick Mode" accomplishes a phase 2 exchange. "Quick Mode" MUST ONLY be used in phase 2 โœจ

"New Group Mode" is not really a phase 1 or a phase 2 thing ๐Ÿคทโ€โ™€๏ธ It follows phase 1, but its whole job is to establish a new group that can be used in future negotiations ๐Ÿงš. "New Group Mode" MUST ONLY be used after phase 1 ๐Ÿ’œ

The ISAKMP SA is bi-directional ๐Ÿ”„ Once it's established, either party may initiate Quick Mode, Informational, and New Group Mode Exchanges. Per the base ISAKMP document, the ISAKMP SA is identified by the Initiator's cookie followed by the Responder's cookie. The role each party plays in the phase 1 exchange decides which cookie is the Initiator's ๐Ÿ“ The cookie order set up by the phase 1 exchange keeps identifying the ISAKMP SA no matter which direction a Quick Mode, Informational, or New Group exchange goes. So basically, the cookies MUST NOT swap places when the direction of the ISAKMP SA changes ๐Ÿšซ periodt

With ISAKMP phases, an implementation can do very fast keying when it needs to โšก A single phase 1 negotiation may be used for more than one phase 2 negotiation. A single phase 2 negotiation can also request multiple Security Associations. Thanks to these optimizations, an implementation can see less than one round trip per SA, plus less than one DH exponentiation per SA ๐Ÿคฏ "Main Mode" for phase 1 provides identity protection. When identity protection isn't needed, "Aggressive Mode" can be used to cut down round trips even more ๐Ÿƒโ€โ™€๏ธ Developer hints for doing these optimizations are included below. It should also be noted that using public key encryption to authenticate an Aggressive Mode exchange will still provide identity protection ๐Ÿ”’

This protocol doesn't define its own DOI per se ๐Ÿ™…โ€โ™€๏ธ The ISAKMP SA, established in phase 1, MAY use the DOI and situation from a non-ISAKMP service (such as the IETF IPSec DOI [Pip97]). In this case, an implementation MAY choose to restrict use of the ISAKMP SA to establishing SAs for services of the same DOI. Alternatively, an ISAKMP SA MAY be established with the value zero in both the DOI and situation (see [MSST98] for a description of these fields). In this case, implementations will be free to establish security services for any defined DOI using this ISAKMP SA ๐ŸŒˆ If a DOI of zero is used to establish a phase 1 SA, the syntax of the identity payloads used in phase 1 is the one defined in [MSST98] and not from any DOI, e.g. [Pip97], which may further expand the syntax and semantics of identities ๐Ÿง 

The following attributes are used by IKE and are negotiated as part of the ISAKMP Security Association. (These attributes pertain only to the ISAKMP Security Association, and not to any Security Associations that ISAKMP may be negotiating on behalf of other services.) ๐Ÿ“‹

  • encryption algorithm
  • hash algorithm
  • authentication method
  • information about a group over which to do Diffie-Hellman

All of these attributes are mandatory and MUST be negotiated ๐Ÿ’– It's also possible to optionally negotiate a pseudo-random function ("prf"). (There are currently no negotiable pseudo-random functions defined in this document. Private use attribute values can be used for prf negotiation between consenting parties.) If a "prf" isn't negotiated, the HMAC (see [KBC96]) version of the negotiated hash algorithm is used as the pseudo-random function. Other non-mandatory attributes are described in Appendix A. The selected hash algorithm MUST support both native and HMAC modes ๐Ÿซง

The Diffie-Hellman group MUST be specified either by using a defined group description (section 6) or by defining all attributes of a group (section 5.6). Group attributes (such as group type or prime, see Appendix A) MUST NOT be offered in conjunction with a previously defined group. That covers both a reserved group description and a private use description that's established after a New Group Mode exchange wraps up ๐Ÿ™…โ€โ™€๏ธ

IKE implementations MUST support the following attribute values:

  • DES [DES] in CBC mode with a weak, and semi-weak, key check (weak and semi-weak keys are referenced in [Sch96] and listed in Appendix A). The key is derived according to Appendix B.
  • MD5 [MD5] and SHA [SHA}.
  • Authentication via pre-shared keys.
  • MODP over default group number one (see below).

In addition, IKE implementations SHOULD support 3DES for encryption, Tiger ([TIGER]) for hash, the Digital Signature Standard, RSA [RSA] signatures, and authentication with RSA public key encryption, plus MODP group number 2 ๐ŸŽ€ IKE implementations MAY support any additional encryption algorithms defined in Appendix A, and MAY support ECP and EC2N groups ๐Ÿฆ‹

The IKE modes described here MUST be implemented whenever the IETF IPSec DOI [Pip97] is implemented. Other DOIs MAY use the modes described here ๐Ÿ’œ

5. Exchanges โœจ

okay so there are two basic ways to set up an authenticated key exchange: Main Mode and Aggressive Mode ๐Ÿฆ‹. Both make authenticated keying material out of an ephemeral Diffie-Hellman exchange ๐Ÿ’–. Main Mode MUST be implemented, and Aggressive Mode SHOULD be implemented ๐ŸŒธ. Quick Mode MUST be implemented too, since it's how you make fresh keying material and negotiate non-ISAKMP security services โœจ. New Group Mode SHOULD be implemented as well, for defining private groups for Diffie-Hellman exchanges ๐ŸŽ€. Implementations MUST NOT switch exchange types in the middle of an exchange ๐Ÿ™ˆ no switching mid-exchange, bestie!

Exchanges follow the standard ISAKMP payload syntax, attribute encoding, and timeouts and retransmits of messages. They also use informational messages. For example, a notify response gets sent when a proposal is unacceptable, or when a signature verification or decryption fails ๐Ÿ’Œ

The SA payload MUST precede all other payloads in a phase 1 exchange ๐Ÿ‘‘. Unless noted otherwise, there are no required orders for ISAKMP payloads in any message ๐Ÿ’….

The Diffie-Hellman public value in a KE payload, whether it's phase 1 or phase 2, MUST be the length of the negotiated Diffie-Hellman group. If it's too short, pad it with zeros at the front ๐Ÿงš. The nonce payload MUST be between 8 and 256 bytes inclusive ๐Ÿ“.

Main Mode is an instance of the ISAKMP Identity Protect Exchange. The first two messages negotiate policy. The next two exchange Diffie-Hellman public values and the extra data (like nonces) needed for the exchange. The last two messages authenticate the Diffie-Hellman exchange ๐Ÿ”. The authentication method negotiated in the initial ISAKMP exchange changes what goes into the payloads, but not what they're for. The XCHG for Main Mode is ISAKMP Identity Protect โœจ.

Aggressive Mode is similar, an instance of the ISAKMP Aggressive Exchange ๐Ÿƒโ€โ™€๏ธ. The first two messages negotiate policy, exchange Diffie-Hellman public values and the extra data needed for the exchange, and exchange identities. The second message also authenticates the responder. The third message authenticates the initiator and proves they took part in the exchange. The XCHG for Aggressive Mode is ISAKMP Aggressive. The final message MAY NOT be sent under protection of the ISAKMP SA, which lets each party hold off on exponentiation, if they want, until the negotiation is finished ๐Ÿ•ฐ๏ธ. The graphic depictions of Aggressive Mode show the final payload in the clear, but it doesn't have to be in the clear ๐Ÿซถ.

IKE exchanges aren't open-ended. They have a fixed number of messages ๐Ÿ”’. Receiving a Certificate Request payload MUST NOT extend the number of messages transmitted or expected ๐Ÿ’€.

Aggressive Mode has real limits on SA negotiation. Because of how the messages are built, the group the Diffie-Hellman exchange happens in can't be negotiated. Different authentication methods can also restrict attribute negotiation even more. For example, authentication with public key encryption can't be negotiated, and when you use the revised method of public key encryption for authentication, the cipher and hash can't be negotiated either. If you need IKE's full attribute negotiation, Main Mode may be required ๐Ÿ˜ค.

Quick Mode and New Group Mode don't have an ISAKMP analog. Their XCHG values are defined in Appendix A ๐Ÿ“–.

Main Mode, Aggressive Mode, and Quick Mode all do security association negotiation ๐Ÿค. SA offers take the form of Transform Payload(s) inside Proposal Payload(s) inside Security Association (SA) payload(s). If you're making multiple offers for phase 1 exchanges (Main Mode and Aggressive Mode), they MUST take the form of multiple Transform Payloads for a single Proposal Payload, all in a single SA payload. Put another way, for phase 1 exchanges there MUST NOT be multiple Proposal Payloads for a single SA payload, and there MUST NOT be multiple SA payloads ๐Ÿšซ. This document doesn't restrict what offers look like in phase 2 exchanges ๐Ÿฆ‹.

There's no limit on how many offers the initiator can send to the responder ๐Ÿ’Œ. Conformant implementations MAY choose to limit how many offers they inspect, for performance reasons โšก.

During security association negotiation, initiators present offers for potential security associations to responders. Responders MUST NOT modify attributes of any offer, attribute encoding excepted (see Appendix A) ๐Ÿ™…โ€โ™€๏ธ. If the initiator of an exchange notices that attribute values have changed, or that attributes were added or deleted from an offer, that response MUST be rejected ๐Ÿšจ.

With Main Mode or Aggressive Mode, four authentication methods are allowed: digital signature, two forms of authentication with public key encryption, or pre-shared key ๐Ÿ”‘. SKEYID is computed separately for each authentication method:

For signatures:            SKEYID = prf(Ni_b | Nr_b, g^xy)
For public key encryption: SKEYID = prf(hash(Ni_b | Nr_b), CKY-I |
CKY-R)
For pre-shared keys:       SKEYID = prf(pre-shared-key, Ni_b |
Nr_b)

The result of either Main Mode or Aggressive Mode is three groups of authenticated keying material ๐Ÿ’œ:

SKEYID_d = prf(SKEYID, g^xy | CKY-I | CKY-R | 0)
SKEYID_a = prf(SKEYID, SKEYID_d | g^xy | CKY-I | CKY-R | 1)
SKEYID_e = prf(SKEYID, SKEYID_a | g^xy | CKY-I | CKY-R | 2)

Those keys plus the agreed policy protect any further communication ๐Ÿ›ก๏ธ. The values 0, 1, and 2 above are each represented by a single octet. The key used for encryption is derived from SKEYID_e in an algorithm-specific way (see Appendix B) ๐Ÿง.

To authenticate either exchange, the initiator generates HASH_I and the responder generates HASH_R, where:

HASH_I = prf(SKEYID, g^xi | g^xr | CKY-I | CKY-R | SAi_b | IDii_b )
HASH_R = prf(SKEYID, g^xr | g^xi | CKY-R | CKY-I | SAi_b | IDir_b )

With digital signature authentication, HASH_I and HASH_R get signed and verified ๐Ÿ–‹๏ธ. With public key encryption or pre-shared keys, HASH_I and HASH_R directly authenticate the exchange ๐Ÿ”. The entire ID payload (including ID type, port, and protocol, but excluding the generic header) is hashed into both HASH_I and HASH_R ๐ŸŒˆ.

As mentioned above, the negotiated authentication method changes the content and use of messages in Phase 1 Modes, but not their intent ๐ŸŽ€. When public keys are used for authentication, the Phase 1 exchange can be done with either signatures or public key encryption (if the algorithm supports it). Here are the Phase 1 exchanges with each authentication option ๐Ÿ‘€.

5.1 IKE Phase 1 Authenticated With Signatures ๐Ÿ–‹๏ธโœจ

With signatures, the extra information exchanged in the second roundtrip is nonces. The exchange is authenticated by signing a mutually obtainable hash ๐Ÿ’–. Main Mode with signature authentication goes like this:

     Initiator                          Responder
    -----------                        -----------
     HDR, SA                     -->
                                 <--    HDR, SA
     HDR, KE, Ni                 -->
                                 <--    HDR, KE, Nr
     HDR*, IDii, [ CERT, ] SIG_I -->
                                 <--    HDR*, IDir, [ CERT, ] SIG_R

Aggressive Mode with signatures, in conjunction with ISAKMP, goes like this:

     Initiator                          Responder
    -----------                        -----------
     HDR, SA, KE, Ni, IDii       -->
                                 <--    HDR, SA, KE, Nr, IDir,
                                             [ CERT, ] SIG_R
     HDR, [ CERT, ] SIG_I        -->

In both modes, the signed data, SIG_I or SIG_R, is the result of the negotiated digital signature algorithm applied to HASH_I or HASH_R, respectively ๐Ÿ”ฅ.

In general, the signature is over HASH_I and HASH_R as above, using the negotiated prf, or the HMAC version of the negotiated hash function (if no prf was negotiated). But this can be overridden when building the signature, if the signature algorithm is tied to a particular hash algorithm. For example, DSS is only defined with SHA's 160-bit output ๐Ÿง. In that case, the signature is over HASH_I and HASH_R as above, except it uses the HMAC version of the hash algorithm associated with the signature method. The negotiated prf and hash function keep being used for all the other prescribed pseudo-random functions ๐ŸŒธ.

Since the hash algorithm in use is already known, there's no need to encode its OID into the signature ๐Ÿ™Œ. There's also no binding between the OIDs used for RSA signatures in PKCS #1 and the ones used in this document. So RSA signatures MUST be encoded as a private key encryption in PKCS #1 format, and NOT as a signature in PKCS #1 format (which includes the OID of the hash algorithm) ๐Ÿšซ. DSS signatures MUST be encoded as r followed by s ๐Ÿ’….

One or more certificate payloads MAY be optionally passed ๐Ÿ“œ๐ŸŽ€

5.2 Phase 1 Authenticated With Public Key Encryption โœจ

okay so this one authenticates the exchange using public key encryption ๐Ÿ”, and the extra info being swapped is encrypted nonces ๐Ÿฆ‹. Each side can rebuild a hash, and that hash proves the other party actually decrypted the nonce. That's the authentication part, and it's giving clean ๐Ÿ’…

The initiator has to already have the responder's public key before any of this can happen ๐Ÿ™ˆ Now, if the responder has multiple public keys, the initiator passes a hash of the certificate it used to encrypt the ancillary info as part of the third message. That way the responder knows which private key to use for decryption, and identity protection is still retained ๐Ÿซถ

The identities (IDii and IDir) are encrypted with the other party's public key too, alongside the nonce. If the authentication method is public key encryption, the nonce and identity payloads MUST be encrypted with the public key of the other party. Only the body of each payload gets encrypted. The payload headers stay in the clear ๐ŸŽ€

When you're using encryption for authentication, Main Mode looks like this ๐ŸŒธ

     Initiator                        Responder
    -----------                      -----------
     HDR, SA                   -->
                               <--    HDR, SA
     HDR, KE, [ HASH(1), ]
       <IDii_b>PubKey_r,
         <Ni_b>PubKey_r        -->
                                      HDR, KE, <IDir_b>PubKey_i,
                               <--            <Nr_b>PubKey_i
     HDR*, HASH_I              -->
                               <--    HDR*, HASH_R

And Aggressive Mode with encryption looks like this ๐Ÿงš

     Initiator                        Responder
    -----------                      -----------
     HDR, SA, [ HASH(1),] KE,
       <IDii_b>Pubkey_r,
        <Ni_b>Pubkey_r         -->
                                      HDR, SA, KE, <IDir_b>PubKey_i,
                               <--         <Nr_b>PubKey_i, HASH_R
     HDR, HASH_I               -->

HASH(1) is a hash (using the negotiated hash function) of the certificate the initiator uses to encrypt the nonce and identity. Lowkey the most important detail in this whole section ๐Ÿ‘‘

RSA encryption MUST be encoded in PKCS #1 format ๐Ÿ’… Even though only the body of the ID and nonce payloads gets encrypted, the encrypted data still has to be preceded by a valid ISAKMP generic header. The payload length covers the entire encrypted payload plus the header. The PKCS #1 encoding lets you figure out the real length of the cleartext payload once it's decrypted โœจ

Now the vibe check: using encryption for authentication gives you a plausible deniability exchange ๐Ÿ™ˆ There's no proof (unlike a digital signature) that the conversation ever happened, because each party can fully rebuild both sides of it. Security for secret generation also gets a boost, since an attacker would have to break the Diffie-Hellman exchange AND both RSA encryptions ๐Ÿ’€ This exchange was motivated by [SKEME].

Also, unlike the other authentication methods, authentication with public key encryption lets you have identity protection with Aggressive Mode ๐Ÿฆ‹ that's the flex ๐Ÿ’–


5.3 Phase 1 Authenticated With a Revised Mode of Public Key Encryption ๐ŸŒˆ

so public key encryption auth has really big perks compared to signatures (see section 5.2 above), but the catch is it costs 4 public key operations: two public key encryptions and two private key decryptions ๐Ÿ˜ญ This revised mode keeps those same perks but only needs half the public key operations ๐Ÿ™Œ

Here's the glow-up: the nonce is still encrypted with the peer's public key, but the peer's identity (and the certificate, if it gets sent) is encrypted with the negotiated symmetric encryption algorithm from the SA payload, using a key derived from the nonce ๐ŸŽ€ It adds minimal complexity and state, and saves two costly public key operations on each side. The Key Exchange payload is encrypted with that same derived key too, which gives extra protection against cryptanalysis of the Diffie-Hellman exchange ๐Ÿ”ฅ

Just like the public key encryption method (section 5.2), a HASH payload may be sent to identify a certificate if the responder has multiple certificates that contain usable public keys. This happens, for example, if the certificate isn't for signatures only, whether because of certificate restrictions or algorithmic restrictions ๐Ÿ“ If the HASH payload is sent, it MUST be the first payload of the second message exchange, and it MUST be followed by the encrypted nonce. If the HASH payload is not sent, the first payload of the second message exchange MUST be the encrypted nonce. The initiator may optionally send a certificate payload too, so the responder has a public key to respond with โœจ

When you're using the revised encryption mode for authentication, Main Mode looks like this ๐Ÿงš

     Initiator                        Responder
    -----------                      -----------
     HDR, SA                   -->
                               <--    HDR, SA
     HDR, [ HASH(1), ]
       <Ni_b>Pubkey_r,
       <KE_b>Ke_i,
       <IDii_b>Ke_i,
       [<<Cert-I_b>Ke_i]       -->
                                      HDR, <Nr_b>PubKey_i,
                                           <KE_b>Ke_r,
                               <--         <IDir_b>Ke_r,
     HDR*, HASH_I              -->
                               <--    HDR*, HASH_R

And Aggressive Mode with the revised encryption method goes like this ๐Ÿ’œ

     Initiator                        Responder
    -----------                      -----------
     HDR, SA, [ HASH(1),]
       <Ni_b>Pubkey_r,
       <KE_b>Ke_i, <IDii_b>Ke_i
       [, <Cert-I_b>Ke_i ]     -->
                                      HDR, SA, <Nr_b>PubKey_i,
                                           <KE_b>Ke_r, <IDir_b>Ke_r,
                               <--         HASH_R
     HDR, HASH_I               -->

HASH(1) is identical to the one in section 5.2. Ke_i and Ke_r are keys for the symmetric encryption algorithm negotiated in the SA payload exchange. Only the body of the payloads gets encrypted (in both the public key and symmetric operations). The generic payload headers stay in the clear, and the payload length includes whatever was added to do the encryption ๐Ÿซถ

The symmetric cipher keys are derived from the decrypted nonces. First, Ne_i and Ne_r get computed:

   Ne_i = prf(Ni_b, CKY-I)
   Ne_r = prf(Nr_b, CKY-R)

Then Ke_i and Ke_r are taken from Ne_i and Ne_r respectively, following the method in Appendix B for deriving symmetric keys for the negotiated encryption algorithm. If the output length of the negotiated prf is greater than or equal to the key length the cipher needs, Ke_i and Ke_r come from the most significant bits of Ne_i and Ne_r respectively. If the key length you want for Ke_i and Ke_r is longer than the prf output, you get the bits you need by feeding the prf's result back into itself over and over and concatenating the results until you have enough. For example, if the negotiated encryption algorithm needs a 320-bit key and the prf only outputs 128 bits, Ke_i is the most significant 320 bits of K, where:

   K = K1 | K2 | K3 and
   K1 = prf(Ne_i, 0)
   K2 = prf(Ne_i, K1)
   K3 = prf(Ne_i, K2)

To keep things short, only the derivation of Ke_i is shown, since Ke_r works exactly the same way. The length of the value 0 in the computation of K1 is a single octet. Ne_i, Ne_r, Ke_i, and Ke_r are all ephemeral and MUST be discarded after use ๐Ÿ’€ no hoarding these keys, bestie

Aside from the rules about where the optional HASH payload goes and the mandatory nonce payload, there are no further payload requirements. Any payloads (in whatever order) that come after the encrypted nonce MUST be encrypted with Ke_i or Ke_r, depending on the direction ๐ŸŒธ

If CBC mode is used for the symmetric encryption, the initialization vectors (IVs) get set like this. The IV for encrypting the first payload after the nonce is set to 0 (zero). The IV for each following payload encrypted with the ephemeral symmetric cipher key Ke_i is the last ciphertext block of the previous payload. Encrypted payloads are padded up to the nearest block size. Every padding byte except the last one contains 0x00, and the last byte of the padding holds the number of padding bytes used, not counting that last one. Note that this means there will always be padding ๐Ÿ™ˆ


5.4 Phase 1 Authenticated With a Pre-Shared Key ๐Ÿ”‘

a key that was derived through some out-of-band mechanism can also be used to authenticate the exchange ๐Ÿฆ‹ How that key gets established is outside the scope of this document, so we're not going there today ๐Ÿ’…

When you do pre-shared key authentication, Main Mode is defined as follows:

          Initiator                        Responder
         ----------                       -----------
          HDR, SA             -->
                              <--    HDR, SA
          HDR, KE, Ni         -->
                              <--    HDR, KE, Nr
          HDR*, IDii, HASH_I  -->
                              <--    HDR*, IDir, HASH_R

Aggressive mode with a pre-shared key looks like this:

        Initiator                        Responder
       -----------                      -----------
        HDR, SA, KE, Ni, IDii -->
                              <--    HDR, SA, KE, Nr, IDir, HASH_R
        HDR, HASH_I           -->

When you're using pre-shared key authentication with Main Mode, the key can only be identified by the IP addresses of the peers, because HASH_I has to be computed before the initiator has processed IDir ๐Ÿ˜ญ Aggressive Mode works with a wider range of identifiers for the pre-shared secret. It also lets two parties keep multiple, different pre-shared keys and figure out which one to use for a given exchange ๐Ÿ‘‘

5.5 Phase 2 - Quick Mode

okay so Quick Mode isn't a complete exchange by itself ๐Ÿ’… it's bound to a phase 1 exchange, but it's the star of the SA negotiation (phase 2) โœจ. Its whole job is to derive keying material and negotiate shared policy for non-ISAKMP SAs ๐Ÿ”ฅ. Everything exchanged along with Quick Mode MUST be protected by the ISAKMP SA, so all payloads except the ISAKMP header are encrypted ๐Ÿ”’. In Quick Mode, a HASH payload MUST immediately follow the ISAKMP header, and a SA payload MUST immediately follow the HASH ๐ŸŽ€. That HASH authenticates the message and also gives you liveliness proofs ๐Ÿ’œ.

The message ID in the ISAKMP header is how you tell which Quick Mode is in progress for a particular ISAKMP SA, and that SA is identified by the cookies in the ISAKMP header ๐Ÿฆ‹. Every instance of Quick Mode uses a unique initialization vector (see Appendix B), so you can have multiple simultaneous Quick Modes going on off a single ISAKMP SA at the same time ๐ŸŒธ. literally so efficient ๐Ÿ˜ญ

Quick Mode is basically an SA negotiation plus an exchange of nonces, and the nonces give you replay protection ๐Ÿ›ก๏ธ. They're used to generate fresh key material and to stop replay attacks from creating bogus security associations ๐Ÿ™ˆ. An optional Key Exchange payload can be included too, so you get an extra Diffie-Hellman exchange and exponentiation per Quick Mode ๐Ÿงš. Using the key exchange payload with Quick Mode is optional, but it MUST be supported โœจ.

Base Quick Mode (without the KE payload) refreshes the keying material that was derived from the exponentiation in phase 1. This does NOT provide PFS ๐Ÿ’€. If you use the optional KE payload, an additional exponentiation happens and PFS is provided for the keying material ๐Ÿ‘‘.

The identities of the SAs negotiated in Quick Mode are implicitly assumed to be the IP addresses of the ISAKMP peers, with no implied constraints on the protocol or port numbers allowed, unless client identifiers are specified in Quick Mode ๐Ÿฆ‹. If ISAKMP is acting as a client negotiator on behalf of another party, the identities of the parties MUST be passed as IDci and then IDcr ๐Ÿซถ. Local policy decides whether the proposals are acceptable for the identities specified ๐ŸŽ€. If the client identities aren't acceptable to the Quick Mode responder (because of policy or other reasons), a Notify payload with Notify Message Type INVALID-ID-INFORMATION (18) SHOULD be sent ๐Ÿ™…โ€โ™€๏ธ.

The client identities are used to identify and direct traffic to the right tunnel when there are multiple tunnels between two peers ๐Ÿš‡. They also let you have unique and shared SAs with different granularities ๐Ÿ“.

All offers made during a Quick Mode are logically related and must be consistent ๐Ÿ’…. For example, if a KE payload is sent, the attribute describing the Diffie-Hellman group (see section 6.1 and [Pip97]) MUST be included in every transform of every proposal of every SA being negotiated ๐Ÿ‘‘. Same vibe for client identities: if they're used, they MUST apply to every SA in the negotiation ๐Ÿ’–.

Quick Mode is defined as follows:

     Initiator                        Responder
    -----------                      -----------
     HDR*, HASH(1), SA, Ni
       [, KE ] [, IDci, IDcr ] -->
                               <--    HDR*, HASH(2), SA, Nr
                                            [, KE ] [, IDci, IDcr ]
     HDR*, HASH(3)             -->

Where:

HASH(1) is the prf over the message id (M-ID) from the ISAKMP header, concatenated with the entire message that follows the hash, including all payload headers but excluding any padding added for encryption ๐Ÿง.

HASH(2) is identical to HASH(1), except the initiator's nonce (Ni, minus the payload header) is added after M-ID but before the complete message ๐ŸŒˆ. Adding the nonce to HASH(2) is for a liveliness proof ๐Ÿ’ซ.

HASH(3) is for liveliness too ๐Ÿซถ. It's the prf over the value zero represented as a single octet, followed by a concatenation of the message id and the two nonces (the initiator's first, then the responder's), minus the payload header ๐ŸŒธ.

So the hashes for the above exchange are:

HASH(1) = prf(SKEYID_a, M-ID | SA | Ni [ | KE ] [ | IDci | IDcr )
HASH(2) = prf(SKEYID_a, M-ID | Ni_b | SA | Nr [ | KE ] [ | IDci |
IDcr )
HASH(3) = prf(SKEYID_a, 0 | M-ID | Ni_b | Nr_b)

Apart from the HASH, SA, and the optional ID payloads, there are NO payload ordering restrictions in Quick Mode ๐Ÿ™ƒ. HASH(1) and HASH(2) may look different from the illustration above if the payloads are ordered differently, or if any optional payloads (like a notify payload) get chained onto the message ๐Ÿงฉ.

If PFS isn't needed and no KE payloads are exchanged, the new keying material is defined as:

KEYMAT = prf(SKEYID_d, protocol | SPI | Ni_b | Nr_b).

If PFS is desired and KE payloads were exchanged, the new keying material is defined as:

KEYMAT = prf(SKEYID_d, g(qm)^xy | protocol | SPI | Ni_b | Nr_b)

where g(qm)^xy is the shared secret from the ephemeral Diffie-Hellman exchange of this Quick Mode ๐Ÿ”.

In either case, "protocol" and "SPI" come from the ISAKMP Proposal Payload that contained the negotiated Transform ๐ŸŽ€.

A single SA negotiation results in two security associations, one inbound and one outbound ๐Ÿ”. Different SPIs for each SA (one chosen by the initiator, the other by the responder) guarantee a different key for each direction ๐Ÿ—๏ธ. The SPI chosen by the destination of the SA is used to derive KEYMAT for that SA ๐Ÿ’….

When you need more keying material than the prf can supply, KEYMAT gets expanded by feeding the results of the prf back into itself and concatenating the results until you've got enough ๐Ÿฐ. So:

KEYMAT = K1 | K2 | K3 | ...
where
  K1 = prf(SKEYID_d, [ g(qm)^xy | ] protocol | SPI | Ni_b | Nr_b)
  K2 = prf(SKEYID_d, K1 | [ g(qm)^xy | ] protocol | SPI | Ni_b |
  Nr_b)
  K3 = prf(SKEYID_d, K2 | [ g(qm)^xy | ] protocol | SPI | Ni_b |
  Nr_b)
  etc.

This keying material (with PFS or without, and whether it's derived directly or through concatenation) MUST be used with the negotiated SA ๐Ÿ”‘. It's up to the service to define how keys are derived from the keying material ๐Ÿง.

With an ephemeral Diffie-Hellman exchange in Quick Mode, the exponential (g(qm)^xy) is irretrievably removed from the current state ๐Ÿซ . SKEYID_e and SKEYID_a (derived from the phase 1 negotiation) keep protecting and authenticating the ISAKMP SA, and SKEYID_d keeps being used to derive keys ๐ŸŒท.

You can negotiate multiple SAs and keys in one exchange like this:

     Initiator                        Responder
    -----------                      -----------
     HDR*, HASH(1), SA0, SA1, Ni,
       [, KE ] [, IDci, IDcr ] -->
                               <--    HDR*, HASH(2), SA0, SA1, Nr,
                                         [, KE ] [, IDci, IDcr ]
     HDR*, HASH(3)             -->

The keying material is derived exactly the same way as in the single SA case. When two SA payloads are negotiated, the result is four security associations, two in each direction for both SAs ๐ŸŽ‰.


5.6 New Group Mode

okay so New Group Mode MUST NOT be used before the ISAKMP SA is established ๐Ÿ™…โ€โ™€๏ธ. The description of a new group MUST only follow phase 1 negotiation ๐Ÿซถ. (It's not a phase 2 exchange, though, just so we're clear ๐Ÿ’….)

     Initiator                        Responder
    -----------                      -----------
     HDR*, HASH(1), SA        -->
                              <--     HDR*, HASH(2), SA

HASH(1) is the prf output, using SKEYID_a as the key, with the message-ID from the ISAKMP header concatenated with the entire SA proposal (body and header) as the data ๐Ÿงฉ. HASH(2) is the prf output, using SKEYID_a as the key, with the message-ID from the ISAKMP header concatenated with the reply as the data ๐Ÿฆ‹. So the hashes for the above exchange are:

HASH(1) = prf(SKEYID_a, M-ID | SA)
HASH(2) = prf(SKEYID_a, M-ID | SA)

The proposal specifies the characteristics of the group (see Appendix A, "Attribute Assigned Numbers") ๐ŸŽ€. Group descriptions for private Groups MUST be greater than or equal to 2^15 ๐Ÿ’œ. If the group isn't acceptable, the responder MUST reply with a Notify payload with the message type set to ATTRIBUTES-NOT-SUPPORTED (13) ๐Ÿ™ˆ.

ISAKMP implementations MAY require private groups to expire along with the SA they were established under โฐ.

Groups can be negotiated directly in the SA proposal with Main Mode ๐ŸŒธ. To do this, the component parts get passed as SA attributes (see Appendix A). For a MODP group, that's the type, prime, and generator. For an EC2N group, it's the type, the Irreducible Polynomial, Group Generator One, Group Generator Two, Group Curve A, Group Curve B, and Group Order ๐Ÿง. Alternatively, you can hide the nature of the group by using New Group Mode, so only the group identifier gets passed in the clear during phase 1 negotiation ๐Ÿ•ต๏ธโ€โ™€๏ธ.


5.7 ISAKMP Informational Exchanges

this protocol protects ISAKMP Informational Exchanges when possible ๐Ÿ›ก๏ธ. Once the ISAKMP security association has been established (and SKEYID_e and SKEYID_a have been generated), ISAKMP Informational Exchanges used with this protocol look like this ๐Ÿ‘€:

     Initiator                        Responder
    -----------                      -----------
     HDR*, HASH(1), N/D      -->

N/D is either an ISAKMP Notify Payload or an ISAKMP Delete Payload ๐Ÿ“ฎ. HASH(1) is the prf output, using SKEYID_a as the key, with a M-ID unique to this exchange concatenated with the entire informational payload (either a Notify or Delete) as the data ๐Ÿซถ. So the hash for the above exchange is:

HASH(1) = prf(SKEYID_a, M-ID | N/D)

As noted, the message ID in the ISAKMP header (the one used in the prf computation) is unique to this exchange, and it MUST NOT be the same as the message ID of another phase 2 exchange that generated this informational exchange ๐Ÿ™…โ€โ™€๏ธ. The derivation of the initialization vector, used with SKEYID_e to encrypt this message, is described in Appendix B ๐ŸŽ€.

If the ISAKMP security association hasn't been established yet when the Informational Exchange happens, the exchange is done in the clear, without an accompanying HASH payload ๐Ÿซฃ.


6 Oakley Groups

With IKE, the group used for the Diffie-Hellman exchange gets negotiated ๐Ÿค. Four groups (values 1 through 4) are defined below ๐ŸŒˆ. These groups came from the Oakley protocol, which is why they're called "Oakley Groups" ๐Ÿ’ซ. The attribute class for "Group" is defined in Appendix A, and all values 2^15 and higher are used for private group identifiers ๐Ÿ”. For a discussion of how strong the default Oakley groups are, see the Security Considerations section below ๐Ÿ‘€.

These groups were all generated by Richard Schroeppel at the University of Arizona ๐Ÿงš. Their properties are described in [Orm96] โœจ.

6.1 First Oakley Default Group

Oakley implementations MUST support a MODP group with the following prime and generator ๐Ÿ‘‘. This group is assigned id 1 (one) ๐Ÿฆ‹.

The prime is: 2^768 - 2 ^704 - 1 + 2^64 * { [2^638 pi] + 149686 }
Its hexadecimal value is

   FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1
   29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD
   EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245
   E485B576 625E7EC6 F44C42E9 A63A3620 FFFFFFFF FFFFFFFF

The generator is: 2.

6.2 Second Oakley Group

okay so this one is a MODP group bestie ๐ŸŒธ IKE implementations SHOULD support it, and it gets id 2 (two) ๐ŸŽ€

the prime is 2^1024 - 2^960 - 1 + 2^64 * { [2^894 pi] + 129093 } and here's its hex value ๐Ÿงš

      FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1
      29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD
      EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245
      E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED
      EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE65381
      FFFFFFFF FFFFFFFF

and the generator is 2 (decimal) โœจ

6.3 Third Oakley Group

this one is an EC2N group and it's giving elliptic curve realness ๐Ÿฆ‹ IKE implementations SHOULD support it, and it's assigned id 3 (three) ๐Ÿ’œ

the curve lives over the Galois Field GF[2^155], so the field size is 155. the irreducible polynomial for the field is:

u^155 + u^62 + 1.

and the equation for the elliptic curve is:

y^2 + xy = x^3 + ax^2 + b.

here are the group details, all in one neat little table ๐Ÿ’…

Field Size:                         155
Group Prime/Irreducible Polynomial:
                 0x0800000000000000000000004000000000000001
Group Generator One:                0x7b
Group Curve A:                      0x0
Group Curve B:                      0x07338f

Group Order: 0X0800000000000000000057db5698537193aef944

the KE payload data for this group is the value x from the solution (x,y). that point on the curve is picked by taking the randomly chosen secret Ka and computing Ka*P, where * is the repetition of the group addition and double operations. P is the curve point whose x coordinate equals generator 1, and its y coordinate comes from the defining equation ๐Ÿ”ฅ the equation of the curve is implicitly known by the Group Type and the A and B coefficients. there are two possible values for the y coordinate, and either one can be used successfully. the two parties don't need to agree on which one to pick ๐Ÿซถ

6.4 Fourth Oakley Group

another EC2N group, and it's giving sibling energy ๐ŸŒˆ IKE implementations SHOULD support it, and it's assigned id 4 (four) โœจ the curve is based on the Galois Field GF[2^185], so the field size is 185. the irreducible polynomial for the field is:

u^185 + u^69 + 1.

the equation for the elliptic curve is:

y^2 + xy = x^3 + ax^2 + b.

the group details look like this ๐Ÿ“

Field Size:                         185
Group Prime/Irreducible Polynomial:
                 0x020000000000000000000000000000200000000000000001
Group Generator One:                0x18
Group Curve A:                      0x0
Group Curve B:                      0x1ee9

Group Order: 0X01ffffffffffffffffffffffdbf2f889b73e484175f94ebc

when you use this group, the data in the KE payload is identical to what you get with Oakley Group 3 (three) ๐Ÿ‘‘

other groups can be defined using New Group Mode ๐ŸŽ€ these default groups were generated by Richard Schroeppel at the University of Arizona, and properties of these primes are described in [Orm96] ๐Ÿ’…


7. Payload Explosion for a Complete IKE Exchange

this section shows how IKE gets used to do two big jobs ๐Ÿงš it's the full cute walkthrough:

  • establish a secure and authenticated channel between ISAKMP processes (phase 1); and
  • generate key material for, and negotiate, an IPsec SA (phase 2).

7.1 Phase 1 using Main Mode

okay so this diagram shows the payloads the two parties swap in the first round trip exchange ๐Ÿฆ‹ the initiator MAY propose several proposals, and the responder MUST reply with one ๐Ÿ”ฅ

    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
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ~             ISAKMP Header with XCHG of Main Mode,             ~
   ~                  and Next Payload of ISA_SA                   ~
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !       0       !    RESERVED   !        Payload Length         !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !                  Domain of Interpretation                     !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !                          Situation                            !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !       0       !    RESERVED   !        Payload Length         !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !  Proposal #1  ! PROTO_ISAKMP  ! SPI size = 0  | # Transforms  !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !    ISA_TRANS  !    RESERVED   !        Payload Length         !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !  Transform #1 !  KEY_OAKLEY   |          RESERVED2            !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ~                   prefered SA attributes                      ~
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !       0       !    RESERVED   !        Payload Length         !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !  Transform #2 !  KEY_OAKLEY   |          RESERVED2            !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ~                   alternate SA attributes                     ~
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

the responder replies in kind, but it picks one transform proposal (the ISAKMP SA attributes) and sends that one back ๐Ÿ’–

the second exchange has these payloads ๐ŸŒธ

    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
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ~             ISAKMP Header with XCHG of Main Mode,             ~
   ~                  and Next Payload of ISA_KE                   ~
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !    ISA_NONCE  !    RESERVED   !        Payload Length         !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ~   D-H Public Value  (g^xi from initiator g^xr from responder) ~
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !       0       !    RESERVED   !        Payload Length         !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ~         Ni (from initiator) or  Nr (from responder)           ~
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

now the shared keys, SKEYID_e and SKEYID_a, protect and authenticate everything after this ๐Ÿ” but heads up, bestie: both SKEYID_e and SKEYID_a are unauthenticated at this point ๐Ÿ‘€

the keys are not authenticated yet, so don't treat them as trusted until the next step is done

here's the third exchange ๐Ÿฆ‹

    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
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ~            ISAKMP Header with XCHG of Main Mode,              ~
   ~     and Next Payload of ISA_ID and the encryption bit set     ~
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !    ISA_SIG    !    RESERVED   !        Payload Length         !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ~        Identification Data of the ISAKMP negotiator           ~
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !       0       !    RESERVED   !        Payload Length         !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ~       signature verified by the public key of the ID above    ~
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

so the key exchange gets authenticated over a signed hash, the way section 5.1 describes ๐Ÿซถ once the signature checks out with the authentication algorithm negotiated as part of the ISAKMP SA, the shared keys SKEYID_e and SKEYID_a can finally be marked as authenticated ๐ŸŽ‰ (for brevity, certificate payloads weren't exchanged ๐Ÿ™ˆ)

7.2. Phase 2 using Quick Mode ๐Ÿ’…

okay bestie, this is the hypothetical Quick Mode exchange ๐ŸŽ€ The first round happens with ISAKMP SA negotiation, and the ISAKMP negotiators here are just proxies standing in for other parties who asked for authentication ๐Ÿซถ

    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
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ~            ISAKMP Header with XCHG of Quick Mode,             ~
   ~   Next Payload of ISA_HASH and the encryption bit set         ~
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !     ISA_SA    !    RESERVED   !        Payload Length         !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ~                 keyed hash of message                         ~
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !   ISA_NONCE   !    RESERVED   !         Payload Length        !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !                 Domain Of Interpretation                      !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !                          Situation                            !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !       0       !    RESERVED   !        Payload Length         !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !  Proposal #1  ! PROTO_IPSEC_AH! SPI size = 4  | # Transforms  !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ~                        SPI (4 octets)                         ~
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !    ISA_TRANS  !    RESERVED   !        Payload Length         !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !  Transform #1 !     AH_SHA    |          RESERVED2            !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !                       other SA attributes                     !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !       0       !    RESERVED   !        Payload Length         !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !  Transform #2 !     AH_MD5    |          RESERVED2            !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !                       other SA attributes                     !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !    ISA_ID     !    RESERVED   !        Payload Length         !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ~                            nonce                              ~
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !    ISA_ID     !    RESERVED   !        Payload Length         !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ~              ID of source for which ISAKMP is a client        ~
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !      0        !    RESERVED   !        Payload Length         !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ~           ID of destination for which ISAKMP is a client      ~
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

the contents of the hash are described in 5.5 above ๐Ÿง  The responder replies with a similar message that only contains one transform, which is the selected AH transform ๐Ÿฆ‹ Once the initiator gets that, it can hand the negotiated security association and the keying material over to the key engine โœจ As a check against replay attacks, the responder waits until it receives the next message ๐Ÿ™ˆ

    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
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ~          ISAKMP Header with XCHG of Quick Mode,               ~
   ~   Next Payload of ISA_HASH and the encryption bit set         ~
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !       0       !    RESERVED   !        Payload Length         !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ~                         hash data                             ~
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

the contents of the hash are described in 5.5 above ๐Ÿ’œ


8. Perfect Forward Secrecy Example ๐Ÿฆ‹

this protocol can provide PFS of both keys and identities ๐Ÿ‘‘ The identities of both the ISAKMP negotiating peers and, if it applies, the identities for whom the peers are negotiating can be protected with PFS ๐Ÿ”

To get Perfect Forward Secrecy of both keys and all identities, two parties would do the following:

  • A Main Mode Exchange to protect the identities of the ISAKMP peers. This establishes an ISAKMP SA. ๐ŸŒธ
  • A Quick Mode Exchange to negotiate other security protocol protection. This establishes an SA on each end for this protocol. ๐Ÿงš
  • Delete the ISAKMP SA and its associated state. ๐Ÿ—‘๏ธ

Since the key for use in the non-ISAKMP SA was derived from the single ephemeral Diffie-Hellman exchange, PFS is preserved โœจ literally iconic ๐Ÿ˜ญ

To get Perfect Forward Secrecy of merely the keys of a non-ISAKMP security association, it is not necessary to do a phase 1 exchange if an ISAKMP SA already exists between the two peers ๐Ÿ™Œ A single Quick Mode, where the optional KE payload is passed and an additional Diffie-Hellman exchange is performed, is all that is required ๐Ÿ’… At this point the state derived from this Quick Mode must be deleted from the ISAKMP SA, as described in section 5.5 ๐Ÿซง


9. Implementation Hints ๐Ÿ“

okay this part is full of tips, and the big one is that using a single ISAKMP Phase 1 negotiation makes the later Phase 2 negotiations extremely quick ๐Ÿƒโ€โ™€๏ธ๐Ÿ’จ As long as the Phase 1 state stays cached and PFS isn't needed, Phase 2 can go ahead without any exponentiation ๐Ÿงฎ How many Phase 2 negotiations you can run off one Phase 1 is a local policy issue ๐ŸŽ€ It depends on how strong the algorithms are and how much you trust the peer system ๐Ÿค

An implementation may want to negotiate a range of SAs when it performs Quick Mode ๐ŸŒˆ That speeds up the "re-keying" ๐Ÿ”„ Quick Mode defines how KEYMAT is defined for a range of SAs. When one peer decides it's time to change SAs, it simply uses the next one in the stated range ๐Ÿ’– A range of SAs can be set up by negotiating multiple SAs (identical attributes, different SPIs) with one Quick Mode ๐Ÿฆ‹

An optimization that's often useful is setting up Security Associations with peers before they're needed, so that when they are needed they're already in place โœจ That way there are no delays from key management before the initial data transmission ๐Ÿš€ It's easy to implement: set up more than one Security Association with a peer for each requested Security Association, and cache the ones that aren't used right away ๐Ÿงบ

Also, if an ISAKMP implementation is alerted that an SA will soon be needed (for example, to replace an existing SA that will expire in the near future), it can establish the new SA before that new SA is actually needed โฐ

The base ISAKMP specification describes conditions where one party to the protocol may tell the other party about some activity, either the deletion of a security association or an error in the protocol, such as a signature verification failing or a payload failing to decrypt ๐Ÿ™ˆ It is strongly suggested that these Informational exchanges not be responded to under any circumstances ๐Ÿšซ Otherwise you can end up in a "notify war" ๐Ÿ’€ where failing to understand a message triggers a notify to the peer, who can't understand it either and sends its own notify back, which isn't understood either ๐Ÿ˜ญ๐Ÿซ 

10. Security Considerations ๐Ÿ”โœจ

okay bestie, this whole memo is a hybrid protocol ๐Ÿฆ‹. It mixes bits of Oakley and bits of SKEME with ISAKMP so peers can negotiate security associations and derive keying material in a secure and authenticated way ๐Ÿ’–.

Confidentiality comes from a negotiated encryption algorithm ๐Ÿ”’. Authentication comes from a negotiated method: a digital signature algorithm, a public key algorithm that supports encryption, or a pre-shared key ๐Ÿ—๏ธ. Honestly, the confidentiality and authentication of this exchange are only as good as the attributes negotiated as part of the ISAKMP security association ๐Ÿ’….

Repeated re-keying with Quick Mode can use up the entropy of the Diffie-Hellman shared secret ๐Ÿ˜ญ. Implementors should take note of this and set a limit on Quick Mode Exchanges between exponentiations. This memo does not prescribe such a limit ๐Ÿ™ˆ.

Perfect Forward Secrecy (PFS) of both keying material and identities is possible with this protocol ๐ŸŒˆ. By specifying a Diffie-Hellman group and passing public values in KE payloads, ISAKMP peers can establish PFS of keys -- but the identities would be protected by SKEYID_e from the ISAKMP SA, so they would not be protected by PFS. If PFS of both keying material and identities is desired, an ISAKMP peer MUST establish only one non-ISAKMP security association (e.g. IPsec Security Association) per ISAKMP SA. PFS for keys and identities is accomplished by deleting the ISAKMP SA (and optionally issuing a DELETE message) upon establishment of the single non-ISAKMP SA. In this way a phase one negotiation is uniquely tied to a single phase two negotiation, and the ISAKMP SA established during phase one negotiation is never used again ๐Ÿฆ‹.

The strength of a key derived from a Diffie-Hellman exchange using any of the groups defined here depends on the inherent strength of the group, the size of the exponent used, and the entropy provided by the random number generator used. Because of these inputs it is difficult to determine the strength of a key for any of the defined groups ๐Ÿค”. The default Diffie-Hellman group (number one) is sufficient to use for DES when used with a strong random number generator and an exponent no less than 160 bits. Groups two through four provide greater security โœจ. Implementations should make note of these conservative estimates when establishing policy and negotiating security parameters.

Note that these limitations apply to the Diffie-Hellman groups themselves. Nothing in IKE prohibits using stronger groups, and nothing will dilute the strength obtained from stronger groups ๐Ÿ’ช. In fact, the extensible framework of IKE encourages the definition of more groups, and use of elliptical curve groups will greatly increase strength using much smaller numbers ๐Ÿงš.

For situations where the defined groups provide insufficient strength, New Group Mode can be used to exchange a Diffie-Hellman group that provides the necessary strength ๐Ÿ”ฅ. It is incumbent upon implementations to check the primality of the groups being offered and to independently arrive at strength estimates ๐Ÿง.

It is assumed that the Diffie-Hellman exponents in this exchange are erased from memory after use ๐Ÿงน. In particular, these exponents must not be derived from long-lived secrets like the seed to a pseudo-random generator. No exceptions, bestie ๐Ÿšซ.

IKE exchanges maintain running initialization vectors (IV), where the last ciphertext block of the last message is the IV for the next message ๐ŸŒธ. To stop retransmissions (or forged messages with valid cookies) from knocking exchanges out of sync, IKE implementations SHOULD NOT update their running IV until the decrypted message has passed a basic sanity check and has been determined to actually advance the IKE state machine -- i.e. it is not a retransmission ๐ŸŽ€.

๐Ÿ˜ญ Heads up! While the last roundtrip of Main Mode (and optionally the last message of Aggressive Mode) is encrypted, it is not, strictly speaking, authenticated. An active substitution attack on the ciphertext could result in payload corruption. If such an attack corrupts mandatory payloads, it would be detected by an authentication failure. But if it corrupts any optional payloads (e.g. notify payloads chained onto the last message of a Main Mode exchange), it might not be detectable ๐Ÿ’€.

11. IANA Considerations ๐Ÿ“‹

This document contains many "magic numbers" that are maintained by the IANA ๐Ÿ”ข. This section explains the criteria the IANA should use to assign additional numbers in each of these lists ๐Ÿ’….

11.1 Attribute Classes ๐Ÿท๏ธ

Attributes negotiated in this protocol are identified by their class. Requests for assignment of new classes must be accompanied by a standards-track RFC which describes the use of this attribute.

11.2 Encryption Algorithm Class ๐Ÿ”

Values of the Encryption Algorithm Class define an encryption algorithm to use when called for in this document. Requests for assignment of new encryption algorithm values must be accompanied by a reference to a standards-track or Informational RFC, or a reference to published cryptographic literature which describes this algorithm.

11.3 Hash Algorithm ๐Ÿง‚

Values of the Hash Algorithm Class define a hash algorithm to use when called for in this document. Requests for assignment of new hash algorithm values must be accompanied by a reference to a standards-track or Informational RFC, or a reference to published cryptographic literature which describes this algorithm. Due to the key derivation and key expansion uses of HMAC forms of hash algorithms in IKE, requests for assignment of new hash algorithm values must take into account the cryptographic properties -- e.g it's resistance to collision -- of the hash algorithm itself ๐Ÿง .

11.4 Group Description and Group Type ๐Ÿ‘ฅ

Values of the Group Description Class identify a group to use in a Diffie-Hellman exchange. Values of the Group Type Class define the type of group. Requests for assignment of new groups must be accompanied by a reference to a standards-track or Informational RFC which describes this group. Requests for assignment of new group types must be accompanied by a reference to a standards-track or Informational RFC, or by a reference to published cryptographic or mathmatical literature which describes the new type ๐ŸŒˆ.

11.5 Life Type โณ

Values of the Life Type Class define a type of lifetime to which the ISAKMP Security Association applies. Requests for assignment of new life types must be accompanied by a detailed description of the units of this type and its expiry ๐Ÿ•ฐ๏ธ.


12. Acknowledgements ๐ŸŒท

This document is the result of close consultation with Hugo Krawczyk, Douglas Maughan, Hilarie Orman, Mark Schertler, Mark Schneider, and Jeff Turner. It relies on protocols which were written by them. Without their interest and dedication, this would not have been written ๐Ÿซถ.

Special thanks to Rob Adams, Cheryl Madson, Derrell Piper, Harry Varnis, and Elfed Weaver for technical input, encouragement, and various sanity checks along the way ๐Ÿ’–.

We would also like to thank the many members of the IPSec working group who contributed to the development of this protocol over the past year ๐Ÿฆ‹.


13. References ๐Ÿ“š

[CAST] Adams, C., "The CAST-128 Encryption Algorithm", RFC 2144, May 1997.

[BLOW] Schneier, B., "The Blowfish Encryption Algorithm", Dr. Dobb's Journal, v. 19, n. 4, April 1994.

[Bra97] Bradner, S., "Key Words for use in RFCs to indicate Requirement Levels", BCP 14, RFC 2119, March 1997.

[DES] ANSI X3.106, "American National Standard for Information Systems-Data Link Encryption", American National Standards Institute, 1983.

[DH] Diffie, W., and Hellman M., "New Directions in Cryptography", IEEE Transactions on Information Theory, V. IT-22, n. 6, June 1977.

[DSS] NIST, "Digital Signature Standard", FIPS 186, National Institute of Standards and Technology, U.S. Department of Commerce, May, 1994.

[IDEA] Lai, X., "On the Design and Security of Block Ciphers," ETH Series in Information Processing, v. 1, Konstanz: Hartung-Gorre Verlag, 1992

[KBC96] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed-Hashing for Message Authentication", RFC 2104, February 1997.

[SKEME] Krawczyk, H., "SKEME: A Versatile Secure Key Exchange Mechanism for Internet", from IEEE Proceedings of the 1996 Symposium on Network and Distributed Systems Security.

[MD5] Rivest, R., "The MD5 Message Digest Algorithm", RFC 1321, April 1992.

[MSST98] Maughhan, D., Schertler, M., Schneider, M., and J. Turner, "Internet Security Association and Key Management Protocol (ISAKMP)", RFC 2408, November 1998.

[Orm96] Orman, H., "The Oakley Key Determination Protocol", RFC 2412, November 1998.

[PKCS1] RSA Laboratories, "PKCS #1: RSA Encryption Standard", November 1993.

[Pip98] Piper, D., "The Internet IP Security Domain Of Interpretation for ISAKMP", RFC 2407, November 1998.

[RC5] Rivest, R., "The RC5 Encryption Algorithm", Dr. Dobb's Journal, v. 20, n. 1, January 1995.

[RSA] Rivest, R., Shamir, A., and Adleman, L., "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems", Communications of the ACM, v. 21, n. 2, February 1978.

[Sch96] Schneier, B., "Applied Cryptography, Protocols, Algorithms, and Source Code in C", 2nd edition.

[SHA] NIST, "Secure Hash Standard", FIPS 180-1, National Institue of Standards and Technology, U.S. Department of Commerce, May 1994.

[TIGER] Anderson, R., and Biham, E., "Fast Software Encryption", Springer LNCS v. 1039, 1996.

Appendix A โœจ

okay so this is the list of DES weak and semi-weak keys, bestie ๐Ÿงš they come from [Sch96], and everything is written in hexidecimal ๐Ÿ’œ

DES Weak Keys
0101 0101 0101 0101
1F1F 1F1F E0E0 E0E0
E0E0 E0E0 1F1F 1F1F
FEFE FEFE FEFE FEFE

DES Semi-Weak Keys
01FE 01FE 01FE 01FE
1FE0 1FE0 0EF1 0EF1
01E0 01E0 01F1 01F1
1FFE 1FFE 0EFE 0EFE
011F 011F 010E 010E
E0FE E0FE F1FE F1FE

FE01 FE01 FE01 FE01
E01F E01F F10E F10E
E001 E001 F101 F101
FE1F FE1F FE0E FE0E
1F01 1F01 0E01 0E01
FEE0 FEE0 FEF1 FEF1

Attribute Assigned Numbers ๐ŸŽ€

attributes negotiated during phase one use the definitions below ๐Ÿ’… phase two attributes live in the applicable DOI spec instead (like IPsec attributes live in the IPsec DOI), with one exception: a group description when Quick Mode includes an ephemeral Diffie-Hellman exchange. attribute types are either Basic (B) or Variable-length (V). the base ISAKMP spec encodes them as Type/Value for Basic and Type/Length/Value for Variable ๐ŸŒธ

the encoding rules are where it gets spicy ๐ŸŒถ๏ธ Attributes described as basic MUST NOT be encoded as variable. Variable length attributes MAY be encoded as basic attributes if their value can fit into two octets. If this is the case, an attribute offered as variable (or basic) by the initiator of this protocol MAY be returned to the initiator as a basic (or variable). no cap, this is the stuff you have to get right ๐Ÿ™ˆ

Attribute Classes

       class                         value              type
  -------------------------------------------------------------------
   Encryption Algorithm                1                 B
   Hash Algorithm                      2                 B
   Authentication Method               3                 B
   Group Description                   4                 B
   Group Type                          5                 B
   Group Prime/Irreducible Polynomial  6                 V
   Group Generator One                 7                 V
   Group Generator Two                 8                 V
   Group Curve A                       9                 V
   Group Curve B                      10                 V
   Life Type                          11                 B
   Life Duration                      12                 V
   PRF                                13                 B
   Key Length                         14                 B
   Field Size                         15                 B
   Group Order                        16                 V

values 17-16383 are reserved to IANA, and values 16384-32767 are for private use among mutually consenting parties ๐Ÿฆ‹

Class Values

the registries for each class are next, and they're giving organized ๐Ÿ“‹

- Encryption Algorithm                       Defined In
   DES-CBC                             1     RFC 2405
   IDEA-CBC                            2
   Blowfish-CBC                        3
   RC5-R16-B64-CBC                     4
   3DES-CBC                            5
   CAST-CBC                            6

  values 7-65000 are reserved to IANA. Values 65001-65535 are for
  private use among mutually consenting parties.
- Hash Algorithm                             Defined In
   MD5                                 1     RFC 1321
   SHA                                 2     FIPS 180-1
   Tiger                               3     See Reference [TIGER]

  values 4-65000 are reserved to IANA. Values 65001-65535 are for
  private use among mutually consenting parties.
- Authentication Method
   pre-shared key                      1
   DSS signatures                      2
   RSA signatures                      3
   Encryption with RSA                 4
   Revised encryption with RSA         5

  values 6-65000 are reserved to IANA. Values 65001-65535 are for
  private use among mutually consenting parties.
- Group Description
   default 768-bit MODP group (section 6.1)      1

   alternate 1024-bit MODP group (section 6.2)   2

   EC2N group on GP[2^155] (section 6.3)         3

   EC2N group on GP[2^185] (section 6.4)         4

  values 5-32767 are reserved to IANA. Values 32768-65535 are for
  private use among mutually consenting parties.
- Group Type
   MODP (modular exponentiation group)            1
   ECP  (elliptic curve group over GF[P])         2
   EC2N (elliptic curve group over GF[2^N])       3

  values 4-65000 are reserved to IANA. Values 65001-65535 are for
  private use among mutually consenting parties.
- Life Type
   seconds                             1
   kilobytes                           2

  values 3-65000 are reserved to IANA. Values 65001-65535 are for
  private use among mutually consenting parties. For a given "Life
  Type" the value of the "Life Duration" attribute defines the actual
  length of the SA life-- either a number of seconds, or a number of
  kbytes protected.
- PRF
  There are currently no pseudo-random functions defined.

  values 1-65000 are reserved to IANA. Values 65001-65535 are for
  private use among mutually consenting parties.

the Key Length rules are a big deal, so read these carefully ๐Ÿ‘‘ When using an Encryption Algorithm that has a variable length key, this attribute specifies the key length in bits. (MUST use network byte order). This attribute MUST NOT be used when the specified Encryption Algorithm uses a fixed length key.

Field Size is just the field size, in bits, of a Diffie-Hellman group ๐Ÿ’–

Group Order is the group order of an elliptical curve group. the length of this attribute depends on the field size, so keep that in mind ๐ŸŒˆ

Additional Exchanges Defined-- XCHG values
  Quick Mode                         32
  New Group Mode                     33

Appendix B โœจ

okay bestie, this appendix is all about the encryption details, and it is ONLY for encrypting ISAKMP messages ๐Ÿ”. When a service (like an IPsec transform) uses ISAKMP to make keying material, every encryption-algorithm-specific detail (key and IV generation, padding, etc...) MUST be defined by that service. ISAKMP does not claim to make keys that fit any encryption algorithm ๐Ÿ’…. It just hands over the requested amount of keying material, and the service MUST generate a suitable key from it. Weak key checks and stuff like that? Totally the service's job ๐Ÿ™ˆ.

Using negotiated PRFs might mean the PRF output has to be expanded, because this document uses a PRF feedback mechanism ๐Ÿ”. Say the fictional DOORAK-MAC needs 24 bytes of key but only spits out 8 bytes of output. Then the output must be expanded three times before it can be used as the key for another instance of itself. Expanding just means feeding the PRF's results back into itself to make successive blocks, then concatenating those blocks until you've got the number of bytes you need ๐Ÿงฉ. Here's how that looks with DOORAK-MAC as the negotiated PRF for pre-shared key authentication:

  BLOCK1-8 = prf(pre-shared-key, Ni_b | Nr_b)
  BLOCK9-16 = prf(pre-shared-key, BLOCK1-8 | Ni_b | Nr_b)
  BLOCK17-24 = prf(pre-shared-key, BLOCK9-16 | Ni_b | Nr_b)
and
  SKEYID = BLOCK1-8 | BLOCK9-16 | BLOCK17-24

So, to derive SKEYID_d, it goes like this:

  BLOCK1-8 = prf(SKEYID, g^xy | CKY-I | CKY-R | 0)
  BLOCK9-16 = prf(SKEYID, BLOCK1-8 | g^xy | CKY-I | CKY-R | 0)
  BLOCK17-24 = prf(SKEYID, BLOCK9-16 | g^xy | CKY-I | CKY-R | 0)
and
  SKEYID_d = BLOCK1-8 | BLOCK9-16 | BLOCK17-24

Subsequent PRF derivations are done similarly ๐ŸŒธ.

Keys that protect the ISAKMP SA come from SKEYID_e, and how they're derived depends on the algorithm ๐Ÿฆ‹. If SKEYID_e isn't long enough to supply all the keying material an algorithm needs, the key is built by feeding the results of a pseudo-random function back into itself, concatenating the results, and taking the highest necessary bits. Think of it as a fill-the-bucket trick ๐Ÿชฃ.

Let's say the fictional algorithm AKULA needs 320 bits of key (and has no weak key check), but the prf used to make SKEYID_e only generates 120 bits of material. The key for AKULA would be the first 320 bits of Ka, where:

   Ka = K1 | K2 | K3
and
   K1 = prf(SKEYID_e, 0)
   K2 = prf(SKEYID_e, K1)
   K3 = prf(SKEYID_e, K2)

Here, prf is the negotiated prf, or the HMAC version of the negotiated hash function if no prf was negotiated. The 0 is represented by a single octet ๐Ÿ”ข. Each prf result gives 120 bits of material, so that's 360 bits total, and AKULA uses the first 320 bits of that 360-bit string โœจ.

In phase 1, the IV material for CBC mode encryption algorithms comes from a hash of the initiator's public Diffie-Hellman value concatenated with the responder's public Diffie-Hellman value, using the negotiated hash algorithm ๐Ÿง. This is only used for the first message. Each message should be padded up to the nearest block size using bytes containing 0x00. The message length in the header MUST include the length of the pad, since that's what reflects the size of the ciphertext ๐Ÿ“. Subsequent messages MUST use the last CBC encryption block from the previous message as their initialization vector ๐Ÿ”—.

In phase 2, the IV material for CBC mode encryption of the first message of a Quick Mode exchange comes from a hash of the last phase 1 CBC output block concatenated with the phase 2 message id, using the negotiated hash algorithm ๐ŸŽ€. The IV for subsequent messages inside a Quick Mode exchange is the CBC output block from the previous message. Padding and IVs for subsequent messages work just like they do in phase 1 ๐Ÿ’….

Once the ISAKMP SA has been authenticated, all Informational Exchanges get encrypted using SKEYID_e ๐Ÿ”. Their IV is derived in exactly the same way as a Quick Mode's, so it's a hash of the last phase 1 CBC output block concatenated with the message id from the ISAKMP header of the Informational Exchange. That's the Informational Exchange's own message id, not the one from whatever message may have prompted the exchange ๐Ÿ™ƒ.

The final phase 1 CBC output block (the result of encrypting or decrypting the last phase 1 message) must be retained in the ISAKMP SA state, so you can generate unique IVs for each Quick Mode ๐Ÿง . Every post-phase 1 exchange (Quick Modes and Informational Exchanges) generates its IVs independently, so the IVs don't get out of sync when two different exchanges start at the same time ๐Ÿซถ.

In all cases, there is a single bidirectional cipher/IV context. Giving each Quick Mode and Informational Exchange its own unique context keeps the IVs from getting out of sync ๐Ÿ’œ.

The key for DES-CBC comes from the first eight (8) non-weak and non-semi-weak bytes of SKEYID_e (see Appendix A) ๐ŸŒท. The IV is the first 8 bytes of the IV material derived above.

The key for IDEA-CBC comes from the first sixteen (16) bytes of SKEYID_e. The IV is the first eight (8) bytes of the IV material derived above ๐Ÿ“.

The key for Blowfish-CBC is either the negotiated key size, or the first fifty-six (56) bytes of a key (if no key size was negotiated), derived with the pseudo-random function feedback method we talked about. The IV is the first eight (8) bytes of the IV material derived above ๐Ÿ .

The key for RC5-R16-B64-CBC is the negotiated key size, or the first sixteen (16) bytes of a key (if no key size was negotiated), derived from the same PRF feedback method if it's needed. The IV is the first eight (8) bytes of the IV material derived above. The number of rounds MUST be 16 and the block size MUST be 64 ๐ŸŒˆ.

The key for 3DES-CBC is the first twenty-four (24) bytes of a key derived with the PRF feedback method. 3DES-CBC is an encrypt-decrypt-encrypt operation that uses the first, middle, and last eight (8) bytes of the entire 3DES-CBC key ๐Ÿงš. The IV is the first eight (8) bytes of the IV material derived above.

The key for CAST-CBC is either the negotiated key size, or the first sixteen (16) bytes of a key derived with the PRF feedback method. The IV is the first eight (8) bytes of the IV material derived above โญ.

Support for algorithms other than DES-CBC is purely optional ๐ŸŒŸ. Some optional algorithms may be subject to intellectual property claims โš–๏ธ.


Authors' Addresses

Dan Harkins cisco Systems 170 W. Tasman Dr. San Jose, California, 95134-1706 United States of America

Phone: +1 408 526 4000 EMail: dharkins@cisco.com

Dave Carrel 76 Lippard Ave. San Francisco, CA 94131-2947 United States of America

Phone: +1 415 337 8469 EMail: carrel@ipsec.org

Authors' Note

The authors really want people to build their own independent implementations and do interoperability testing of this hybrid protocol ๐Ÿคโœจ. Go get it, bestie ๐Ÿ’–.

Copyright (C) The Internet Society (1998). All Rights Reserved. ๐ŸŽ€

This document and translations of it may be copied and shared with others, and derivative works that comment on or otherwise explain it, or help with implementing it, may be prepared, copied, published, and distributed, in whole or in part, without restriction of any kind ๐Ÿ“š. The one catch is that the above copyright notice and this paragraph have to be included on all such copies and derivative works. However, this document itself may not be modified in any way, such as by removing the copyright notice or references to the Internet Society or other Internet organizations. The exceptions are when it's needed for developing Internet standards (then the copyright procedures in the Internet Standards process must be followed), or when it's translated into languages other than English ๐ŸŒ.

The limited permissions granted above are perpetual and will not be revoked by the Internet Society or its successors or assigns ๐Ÿ’œ.

This document and the information contained herein is provided on an "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIMS 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. ๐Ÿ’€
๐Ÿ“ฆ where this page comes from