This document defines four transforms of Type 1 (Encryption Algorithm) for use in ESP and IKEv2. All of them use MGM as the mode of operation with tree-based external rekeying. The transforms differ in underlying ciphers and in cryptographic services they provide.
-
ENCR_KUZNYECHIK_MGM_KTREE (Transform ID 32) is an AEAD transform based on the "Kuznyechik" algorithm; it provides confidentiality and message authentication and thus can be used in both ESP and IKEv2.
-
ENCR_MAGMA_MGM_KTREE (Transform ID 33) is an AEAD transform based on the "Magma" algorithm; it provides confidentiality and message authentication and thus can be used in both ESP and IKEv2.
-
ENCR_KUZNYECHIK_MGM_MAC_KTREE (Transform ID 34) is a MAC-only transform based on the "Kuznyechik" algorithm; it provides no confidentiality and thus can only be used in ESP, but not in IKEv2.
-
ENCR_MAGMA_MGM_MAC_KTREE (Transform ID 35) is a MAC-only transform based on the "Magma" algorithm; it provides no confidentiality and thus can only be used in ESP, but not in IKEv2.
Note that transforms ENCR_KUZNYECHIK_MGM_MAC_KTREE and ENCR_MAGMA_MGM_MAC_KTREE don't provide any confidentiality, but they are defined as Type 1 (Encryption Algorithm) transforms because of the need to include an Initialization Vector (IV), which is impossible for Type 3 (Integrity Algorithm) transforms.
All four transforms use the same tree-based external rekeying mechanism. The idea is that the key that is provided for the transform is not directly used to protect messages. Instead, a tree of keys is derived using this key as a root. This tree may have several levels. The leaf keys are used for message protection, while intermediate-node keys are used to derive lower-level keys, including leaf keys. See
Section 5.2.3 of
RFC 8645 for more details. This construction allows us to protect a large amount of data, at the same time providing a bound on a number of times any particular key in the tree is used, thus defending against some side-channel attacks and also increasing the key lifetime limitations based on combinatorial properties.
The transforms defined in this document use a three-level tree. The leaf key that protects a message is computed as follows:
K_msg = KDF (KDF (KDF (K, l1, 0x00 | i1), l2, i2), l3, i3)
where:
-
KDF (k, l, s)
-
Key Derivation Function KDF_GOSTR3411_2012_256 (defined in Section 4.5 of RFC 7836), which accepts three input parameters -- a key (k), a label (l), and a seed (s) -- and provides a new key as output
-
K
-
the root key for the tree (see Section 4.4)
-
l1, l2, l3
-
labels defined as 6-octet ASCII strings without null termination:
-
l1 =
-
"level1"
-
l2 =
-
"level2"
-
l3 =
-
"level3"
-
i1, i2, i3
-
parameters that determine which keys out of the tree are used on each level. Together, they determine a leaf key that is used for message protection; the length of i1 is one octet, and i2 and i3 are two-octet integers in network byte order
-
|
-
indicates concatenation
This construction allows us to generate up to 2
8 keys on level 1 and up to 2
16 keys on levels 2 and 3. So, the total number of possible leaf keys generated from a single Security Association (SA) key is 2
40.
This specification doesn't impose any requirements on how frequently external rekeying takes place. It is expected that the sending application will follow its own policy dictating how many times the keys on each level must be used.
Each message protected by the defined transforms
MUST contain an IV. The IV has a size of 64 bits and consists of four fields. The fields i1, i2, and i3 are parameters that determine the particular leaf key this message was protected with (see
Section 4.1). The fourth field is a counter, representing the message number for this key.
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| i1 | i2 | i3 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| i3 (cont) | pnum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
where:
-
i1 (1 octet), i2 (2 octets), i3 (2 octets):
-
parameters that determine the particular key used to protect this message; 2-octet parameters are integers in network byte order
-
pnum (3 octets):
-
message counter in network byte order for the leaf key protecting this message; up to 224 messages may be protected using a single leaf key
For any given SA, the IV
MUST NOT be used more than once, but there is no requirement that IV be unpredictable.
MGM requires a per-message nonce (called the Initial Counter Nonce, or ICN in [
RFC 9058]) that
MUST be unique in the context of any leaf key. The size of the ICN is n-1 bits, where n is the block size of the underlying cipher. The two ciphers used in the transforms defined in this document have different block sizes, so two different formats for the ICN are defined.
MGM specification requires that the nonce be n-1 bits in size, where n is the block size of the underlying cipher. This document defines MGM nonces having n bits (the block size of the underlying cipher) in size. Since n is always a multiple of 8 bits, this makes MGM nonces having a whole number of octets. When used inside MGM, the most significant bit of the first octet of the nonce (represented as an octet string) is dropped, making the effective size of the nonce equal to n-1 bits. Note that the dropped bit is a part of the "zero" field (see Figures [
2] and [
3]), which is always set to 0, so no information is lost when it is dropped.
For transforms based on the "Kuznyechik" cipher (ENCR_KUZNYECHIK_MGM_KTREE and ENCR_KUZNYECHIK_MGM_MAC_KTREE), the ICN consists of a "zero" octet; a 24-bit message counter; and a 96-bit secret salt, which is fixed for the SA and is not transmitted.
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| zero | pnum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| salt |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
where:
-
zero (1 octet):
-
set to 0
-
pnum (3 octets):
-
the counter for the messages protected by the given leaf key; this field MUST be equal to the pnum field in the IV
-
salt (12 octets):
-
secret salt. The salt is a string of bits that are formed when the SA is created (see Section 4.4 for details). The salt does not change during the SA's lifetime and is not transmitted on the wire. Every SA will have its own salt.
For transforms based on the "Magma" cipher (ENCR_MAGMA_MGM_KTREE and ENCR_MAGMA_MGM_MAC_KTREE), the ICN consists of a "zero" octet; a 24-bit message counter; and a 32-bit secret salt, which is fixed for the SA and is not transmitted.
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| zero | pnum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| salt |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
where:
-
zero (1 octet):
-
set to 0
-
pnum (3 octets):
-
the counter for the messages protected by the given leaf key; this field MUST be equal to the pnum field in the IV
-
salt (4 octets):
-
secret salt. The salt is a string of bits that are formed when the SA is created (see Section 4.4 for details). The salt does not change during the SA's lifetime and is not transmitted on the wire. Every SA will have its own salt.
We'll call a string of bits that is used to initialize the transforms defined in this specification a "transform key". The transform key is a composite entity consisting of the root key for the tree and the secret salt.
The transform key for the ENCR_KUZNYECHIK_MGM_KTREE and ENCR_KUZNYECHIK_MGM_MAC_KTREE transforms consists of 352 bits (44 octets), of which the first 256 bits is a root key for the tree (denoted as K in
Section 4.1) and the remaining 96 bits is a secret salt (see
Section 4.3.1).
The transform key for the ENCR_MAGMA_MGM_KTREE and ENCR_MAGMA_MGM_MAC_KTREE transforms consists of 288 bits (36 octets), of which the first 256 bits is a root key for the tree (denoted as K in
Section 4.1) and the remaining 32 bits is a secret salt (see
Section 4.3.2).
In the case of ESP, the transform keys are extracted from the KEYMAT as defined in
Section 2.17 of
RFC 7296. In the case of IKEv2, the transform keys are either SK_ei or SK_er, which are generated as defined in
Section 2.14 of
RFC 7296. Note that since these transforms provide authenticated encryption, no additional keys are needed for authentication. This means that, in the case of IKEv2, the keys SK_ai/SK_ar are not used and
MUST be treated as having zero length.
The length of the authentication tag that MGM can compute is in the range from 32 bits to the block size of the underlying cipher.
Section 4 of
RFC 9058 states that the authentication tag length
MUST be fixed for a particular protocol. For transforms based on the "Kuznyechik" cipher (ENCR_KUZNYECHIK_MGM_KTREE and ENCR_KUZNYECHIK_MGM_MAC_KTREE), the resulting Integrity Check Value (ICV) length is set to 96 bits. For transforms based on the "Magma" cipher (ENCR_MAGMA_MGM_KTREE and ENCR_MAGMA_MGM_MAC_KTREE), the full ICV length is set to the block size (64 bits).
The transforms defined in this document don't require any plaintext padding, as specified in [
RFC 9058]. This means that only those padding requirements that are imposed by the protocol are applied (4 bytes for ESP, no padding for IKEv2).
Additional Authenticated Data (AAD) in ESP is constructed differently, depending on the transform being used and whether the Extended Sequence Number (ESN) is in use or not. The ENCR_KUZNYECHIK_MGM_KTREE and ENCR_MAGMA_MGM_KTREE transforms provide confidentiality, so the content of the ESP body is encrypted and the AAD consists of the ESP Security Parameter Index (SPI) and (E)SN. The AAD is constructed similarly to the AAD in [
RFC 4106].
On the other hand, the ENCR_KUZNYECHIK_MGM_MAC_KTREE and ENCR_MAGMA_MGM_MAC_KTREE transforms don't provide confidentiality; they provide only message authentication. For this purpose, the IV and the part of the ESP packet that is normally encrypted are included in the AAD. For these transforms, the encryption capability provided by MGM is not used. The AAD is constructed similarly to the AAD in [
RFC 4543].
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 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
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 |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
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 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| IV |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ Payload Data (variable) ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Padding (0-255 bytes) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | Pad Length | Next Header |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
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 |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| IV |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ Payload Data (variable) ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Padding (0-255 bytes) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | Pad Length | Next Header |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
For IKEv2, the AAD consists of the IKEv2 Header, any unencrypted payloads following it (if present), and either the Encrypted payload header (
Section 3.14 of
RFC 7296) or the Encrypted Fragment payload (
Section 2.5 of
RFC 7383), depending on whether IKE fragmentation is used. The AAD is constructed similarly to the AAD in [
RFC 5282].
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~ IKEv2 Header ~
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~ Unencrypted IKE Payloads ~
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload |C| RESERVED | Payload Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~ IKEv2 Header ~
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~ Unencrypted IKE Payloads ~
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload |C| RESERVED | Payload Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Fragment Number | Total Fragments |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
When the SA is established, the i1, i2, and i3 parameters are set to 0 by the sender and a leaf key is calculated. The pnum parameter starts from 0 and is incremented with each message protected by the same leaf key. When the sender decides that the leaf should be changed, it increments the i3 parameter and generates a new leaf key. The pnum parameter for the new leaf key is reset to 0, and the process continues. If the sender decides that a third-level key corresponding to i3 is used enough times, it increments i2, resets i3 to 0, and calculates a new leaf key. The pnum is reset to 0 (as with every new leaf key), and the process continues. A similar procedure is used when a second-level key needs to be changed.
A combination of i1, i2, i3, and pnum
MUST NOT repeat for any particular SA. This means that the wrapping of these counters is not allowed: when i2, i3, or pnum reaches its respective maximum value, a procedure for changing a leaf key, described above, is executed, and if all four parameters reach their maximum values, the IPsec SA becomes unusable.
There may be other reasons to recalculate leaf keys besides reaching maximum values for the counters. For example, as described in
Section 5, it is
RECOMMENDED that the sender count the number of octets protected by a particular leaf key and generate a new key when some threshold is reached, and at the latest when reaching the octet limits stated in
Section 5 for each of the ciphers.
The receiver always uses i1, i2, and i3 from the received message. If they differ from the values in previously received packets, a new leaf key is calculated. The pnum parameter is always used from the received packet. To improve performance, implementations may cache recently used leaf keys. When a new leaf key is calculated (based on the values from the received message), the old key may be kept for some time to improve performance in the case of possible packet reordering (when packets protected by the old leaf key are delayed and arrive later).