RFC 9459
CBOR Object Signing and Encryption (COSE): AES-CTR and AES-CBC
RFC 9459: CBOR Object Signing and Encryption (COSE): AES-CTR and AES-CBC π
Okay bestie, here's the title block tea β RFC 9459 is titled "CBOR Object Signing and Encryption (COSE): AES-CTR and AES-CBC." It came out of the Internet Engineering Task Force (IETF), it's a Standards Track document, and it's dated September 2023. The ISSN is 2070-1721. The authors are R. Housley (Vigil Security) and H. Tschofenig π¦ The title block doesn't list anything this RFC obsoletes or updates, so no drama there πΈ
Abstract π«Ά
The Concise Binary Object Representation (CBOR) data format is built for small code size and small message size, which is so iconic π§ COSE (CBOR Object Signing and Encryption) is specified in RFC 9052 and gives you basic security services using CBOR. This doc is all about the rules for using AES-CTR and AES-CBC as content encryption algorithms with COSE π
Status of This Memo π
This is an Internet Standards Track document.
This document is a product of the Internet Engineering Task Force (IETF). It represents the consensus of the IETF community. It has received public review and has been approved for publication by the Internet Engineering Steering Group (IESG). Further information on Internet Standards is available in Section 2 of RFC 7841.
Information about the current status of this document, any errata, and how to provide feedback on it may be obtained at https://www.rfc-editor.org/info/rfc9459.
Copyright Notice Β©οΈ
Copyright (c) 2023 IETF Trust and the persons identified as the document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Revised BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Revised BSD License.
Table of Contents πΊοΈ
1. Introduction
2. Conventions and Terminology
3. AES Modes of Operation
4. AES Counter Mode
4.1. AES-CTR COSE Key
4.2. AES-CTR COSE Algorithm Identifiers
5. AES Cipher Block Chaining Mode
5.1. AES-CBC COSE Key
5.2. AES-CBC COSE Algorithm Identifiers
6. Implementation Considerations
7. IANA Considerations
8. Security Considerations
9. References
9.1. Normative References
9.2. Informative References
Acknowledgements
Authors' Addresses
1. Introduction π
Okay so this doc sets the conventions for using AES-CTR and AES-CBC as content encryption algorithms with the CBOR Object Signing and Encryption (COSE) [RFC9052] syntax. Right now, COSE encryption uses Authenticated Encryption with Associated Data (AEAD) algorithms [RFC5116], which give you both confidentiality and integrity protection π But there are situations where something else, like a digital signature, handles integrity. In those cases you don't need an AEAD algorithm. The software manifest being defined by the IETF SUIT WG [SUIT-MANIFEST] is one example where a digital signature is always present π₯
2. Conventions and Terminology π
Here's the boilerplate that decides which key words count as requirements. Read it closely, it matters:
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.
3. AES Modes of Operation π§©
NIST has defined several modes of operation for the Advanced Encryption Standard [AES] [MODES]. AES comes in three key sizes: 128 bits, 192 bits, and 256 bits. AES has a block size of 128 bits (16 octets). Each mode has its own characteristics, and the modes include CBC (Cipher Block Chaining), CFB (Cipher FeedBack), OFB (Output FeedBack), and CTR (Counter) π
Only AES Counter (AES-CTR) mode and AES Cipher Block Chaining (AES-CBC) are discussed in this document β¨
4. AES Counter Mode π«
When AES-CTR is used as a COSE content encryption algorithm, the encryptor makes a unique value that gets communicated to the decryptor. This value is called an "Initialization Vector" (or "IV") in this document. The same IV and AES key combination MUST NOT be used more than once π The encryptor can generate the IV in any manner that makes sure the same IV value is never used more than once with the same AES key.
Here's how the encryption works. Each AES encrypt operation generates 128 bits of key stream. AES-CTR encryption is the XOR of the key stream with the plaintext, and AES-CTR decryption is the XOR of the key stream with the ciphertext. If the generated key stream is longer than the plaintext or ciphertext, the extra key stream bits are just thrown away. That's why AES-CTR doesn't need the plaintext padded to a multiple of the block size π
AES-CTR has a lot going for it as a COSE content encryption algorithm. It uses the AES block cipher to make a stream cipher. Data gets encrypted and decrypted by XORing with the key stream, which is made by AES encrypting sequential IV block values called "counter blocks":
- The first block of the key stream is the AES encryption of the IV.
- The second block of the key stream is the AES encryption of
(IV + 1) mod 2^128. - The third block of the key stream is the AES encryption of
(IV + 2) mod 2^128, and so on.
AES-CTR is easy to implement, can be pipelined and parallelized, and supports key stream precomputation. Sending the IV is the only source of expansion, because the plaintext and ciphertext are the same size π¦
When it's used correctly, AES-CTR gives a high level of confidentiality. BUT it's super easy to use incorrectly, so pay attention bestie π Because it's a stream cipher, reusing an IV with the same key is catastrophic. An IV collision immediately leaks information about the plaintext. For this reason, it is inappropriate to use AES-CTR with static keys. You'd need extraordinary measures to stop an IV value from being reused with the static key across power cycles. To be safe, implementations MUST use fresh keys with AES-CTR π
AES-CTR keys can be obtained either from a key structure or from a recipient structure. Implementations encrypting and decrypting MUST validate that the key type, key length, and algorithm are correct and appropriate for the entities involved π§
With AES-CTR, it's trivial to take a valid ciphertext and use it to forge other ciphertexts that are still valid to the decryptor. So it's just as catastrophic to use AES-CTR without a companion authentication and integrity mechanism. Implementations MUST use AES-CTR in conjunction with an authentication and integrity mechanism, such as a digital signature π‘οΈ
The instructions in Section 5.4 of [RFC9052] are followed for AES-CTR. Since AES-CTR cannot provide integrity protection for external additional authenticated data, the decryptor MUST ensure that no external additional authenticated data was supplied. See Section 6 π
The 'protected' header MUST be a zero-length byte string.
4.1. AES-CTR COSE Key ποΈ
When you use a COSE key for the AES-CTR algorithm, these checks happen:
- The 'kty' field MUST be present, and it MUST be 'Symmetric'.
- If the 'alg' field is present, it MUST match the AES-CTR algorithm being used.
- If the 'key_ops' field is present, it MUST include 'encrypt' when encrypting.
- If the 'key_ops' field is present, it MUST include 'decrypt' when decrypting.
4.2. AES-CTR COSE Algorithm Identifiers π·οΈ
The table below defines the COSE AES-CTR algorithm values. These algorithms are being registered as "Deprecated" so nobody uses them by accident without a companion integrity protection mechanism. Not gonna lie, that's a big deal π
+=========+========+==========+=============+=============+
| Name | Value | Key Size | Description | Recommended |
+=========+========+==========+=============+=============+
| A128CTR | -65534 | 128 | AES-CTR w/ | Deprecated |
| | | | 128-bit key | |
+---------+--------+----------+-------------+-------------+
| A192CTR | -65533 | 192 | AES-CTR w/ | Deprecated |
| | | | 192-bit key | |
+---------+--------+----------+-------------+-------------+
| A256CTR | -65532 | 256 | AES-CTR w/ | Deprecated |
| | | | 256-bit key | |
+---------+--------+----------+-------------+-------------+
Table 1
5. AES Cipher Block Chaining Mode πΈ
AES-CBC mode requires a 16-octet IV. Using a randomly or pseudorandomly generated IV makes sure that encrypting the same plaintext gives you different ciphertext, which is the vibe π
AES-CBC XORs the IV with the first plaintext block before it's encrypted. For each block after that, AES-CBC XORs the previous ciphertext block with the current plaintext before encrypting it β¨
AES-CBC requires padding of the plaintext. The padding algorithm specified in Section 6.3 of [RFC5652] MUST be used prior to encrypting the plaintext. This padding algorithm lets the decryptor remove the padding without any ambiguity π―
The simplicity of AES-CBC makes it an attractive COSE content encryption algorithm. Carrying an IV and adding padding does add overhead compared to AES-CTR. AES-CBC is much safer for use with static keys than AES-CTR. That said, as described in [RFC4107], using automated key management to generate fresh keys is greatly preferred π
AES-CBC does not provide integrity protection. So an attacker can slip in undetectable errors if AES-CBC is used without a companion authentication and integrity mechanism. Implementations MUST use AES-CBC in conjunction with an authentication and integrity mechanism, such as a digital signature π‘οΈ
The instructions in Section 5.4 of [RFC9052] are followed for AES-CBC. Since AES-CBC cannot provide integrity protection for external additional authenticated data, the decryptor MUST ensure that no external additional authenticated data was supplied. See Section 6 π
The 'protected' header MUST be a zero-length byte string.
5.1. AES-CBC COSE Key ποΈ
When you use a COSE key for the AES-CBC algorithm, these checks happen:
- The 'kty' field MUST be present, and it MUST be 'Symmetric'.
- If the 'alg' field is present, it MUST match the AES-CBC algorithm being used.
- If the 'key_ops' field is present, it MUST include 'encrypt' when encrypting.
- If the 'key_ops' field is present, it MUST include 'decrypt' when decrypting.
Part 1 of 2 done π Next up: the algorithm identifiers for AES-CBC and everything after them β¨
5.2. AES-CBC COSE Algorithm Identifiers
Here's the lineup of COSE AES-CBC algorithm values π. Heads up: these are registered as "Deprecated" so nobody uses them by accident without a companion integrity protection mechanism π.
+=========+========+==========+=============+=============+
| Name | Value | Key Size | Description | Recommended |
+=========+========+==========+=============+=============+
| A128CBC | -65531 | 128 | AES-CBC w/ | Deprecated |
| | | | 128-bit key | |
+---------+--------+----------+-------------+-------------+
| A192CBC | -65530 | 192 | AES-CBC w/ | Deprecated |
| | | | 192-bit key | |
+---------+--------+----------+-------------+-------------+
| A256CBC | -65529 | 256 | AES-CBC w/ | Deprecated |
| | | | 256-bit key | |
+---------+--------+----------+-------------+-------------+
Table 2
6. Implementation Considerations π§
Okay, this one is a big deal π₯. COSE libraries that support either AES-CTR or AES-CBC, and that accept Additional Authenticated Data (AAD) as input, MUST return an error if one of these non-AEAD content encryption algorithms gets selected. The reason is that it stops a caller from thinking the AAD is protected when the algorithm can't actually protect it π.
7. IANA Considerations πΈ
IANA has registered six COSE algorithm identifiers for AES-CTR and AES-CBC in the "COSE Algorithms" registry [IANA-COSE] π.
The details for those six identifiers live in Sections 4.2 and 5.2. For all six entries, the "Capabilities" column has "[kty]", the "Change Controller" column has "IETF", and the "Reference" column points back to this document β¨.
8. Security Considerations π
Okay, the security section is where things get seriously juicy, so buckle up ππ₯.
This document specifies AES-CTR and AES-CBC for COSE, and neither one is an AEAD cipher. These ciphers are only meant for special use cases, like firmware encryption, where something else provides integrity and authentication π«Ά.
AES has a 128-bit block size no matter which mode you use. That means the ciphertext starts looking distinguishable from random values once 2^64 blocks have been encrypted under a single key. Implementations should change the key before hitting that limit π§ .
Now the main event π. To avoid cross-protocol concerns, implementations MUST NOT use the same keying material with more than one mode. For example, the same keying material must not be used with AES-CTR and AES-CBC π.
There are pretty generic precomputation attacks against every block cipher mode that allow a meet-in-the-middle attack against the key π΅. These attacks need huge tables of ciphertext tied to known plaintext and known keys to be created and searched. If the memory and processor resources exist for a precomputation attack, the theoretical strength of AES-CTR and AES-CBC is limited to 2^(n/2) bits, where n is the number of bits in the key. Long keys are the best countermeasure to precomputation attacks π¦.
When it's used properly, AES-CTR mode gives strong confidentiality β¨. The problem is that it's super easy to misuse this counter mode π. If counter block values ever get used for more than one plaintext with the same key, then the same key stream encrypts both plaintexts, and the confidentiality guarantees are gone π.
So what happens if the encryptor XORs the same key stream with two different plaintexts? Say two plaintext octet sequences P1, P2, P3 and Q1, Q2, Q3 both get encrypted with key stream K1, K2, K3. The two ciphertexts look like this:
(P1 XOR K1), (P2 XOR K2), (P3 XOR K3)
(Q1 XOR K1), (Q2 XOR K2), (Q3 XOR K3)
If an attacker gets to see both of those ciphertext streams, confidentiality fails completely, because:
(P1 XOR K1) XOR (Q1 XOR K1) = P1 XOR Q1
(P2 XOR K2) XOR (Q2 XOR K2) = P2 XOR Q2
(P3 XOR K3) XOR (Q3 XOR K3) = P3 XOR Q3
Once the attacker has the two plaintexts XORed together, it's pretty straightforward to pull them apart π΅οΈββοΈ. So using any stream cipher, AES-CTR included, to encrypt two plaintexts under the same key stream leaks the plaintext π¨.
Data forgery is trivial with AES-CTR mode π±. The attack works like the key stream reuse one above. If a known plaintext octet sequence P1, P2, P3 gets encrypted with key stream K1, K2, K3, the attacker can swap the plaintext for one of their own choosing. The ciphertext is:
(P1 XOR K1), (P2 XOR K2), (P3 XOR K3)
The attacker just XORs a chosen sequence Q1, Q2, Q3 into the ciphertext, which gives:
(Q1 XOR (P1 XOR K1)), (Q2 XOR (P2 XOR K2)), (Q3 XOR (P3 XOR K3))
That's the same as:
((Q1 XOR P1) XOR K1), ((Q2 XOR P2) XOR K2), ((Q3 XOR P3) XOR K3)
When decrypted, the attacker's ciphertext gives back exactly what they wanted:
(Q1 XOR P1), (Q2 XOR P2), (Q3 XOR P3)
AES-CBC does not provide integrity protection π©. So if AES-CBC gets used without a companion authentication mechanism, an attacker can slip in undetectable errors.
If an attacker can strip the authentication and integrity mechanism, they can replace it with one of their own making, even without knowing the plaintext π. The usual defense against that sort of attack is an Authenticated Encryption with Associated Data (AEAD) algorithm [RFC5116]. Of course, neither AES-CTR nor AES-CBC is an AEAD π. So an implementation should provide integrity protection for the 'kid' field, which prevents undetected stripping of the authentication and integrity mechanism. That also stops an attacker from changing the 'kid' to trick the recipient into using a different key π.
With AES-CBC mode, implementers should perform integrity checks before decryption to avoid padding oracle vulnerabilities [Vaudenay] π§.
Once the COSE algorithm identifiers for AES-CTR and AES-CBC are in the COSE Algorithms Registry, an attacker can swap the COSE algorithm identifiers for one of these values. From there, the attacker might be able to manipulate the ciphertext to learn some of the plaintext, or extract the keying material used for authentication and integrity π.
AES-CCM [RFC3610] and AES-GCM [GCMMODE] both use AES-CTR for encryption. So an attacker can switch the algorithm identifier to AES-CTR, strip the authentication tag to get around authentication and integrity, and then manipulate the ciphertext π« .
An attacker can also switch the algorithm identifier from AES-GCM to AES-CBC. They guess 16 bytes of plaintext at a time and check whether the recipient accepts the padding π. Padding oracle vulnerabilities are discussed further in [Vaudenay] π.
9. References π
9.1. Normative References
[AES]National Institute of Standards and Technology (NIST), "Advanced Encryption Standard (AES)", NIST FIPS 197, DOI 10.6028/NIST.FIPS.197-upd1, May 2023,<https://doi.org/10.6028/NIST.FIPS.197-upd1>.[MODES]Dworkin, M., "Recommendation for Block Cipher Modes of Operation: Methods and Techniques", NIST Special Publication 800-38A, DOI 10.6028/NIST.SP.800-38A, December 2001,<https://doi.org/10.6028/NIST.SP.800-38A>.[RFC2119]Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997,<https://www.rfc-editor.org/info/rfc2119>.[RFC4107]Bellovin, S. and R. Housley, "Guidelines for Cryptographic Key Management", BCP 107, RFC 4107, DOI 10.17487/RFC4107, June 2005,<https://www.rfc-editor.org/info/rfc4107>.[RFC5652]Housley, R., "Cryptographic Message Syntax (CMS)", STD 70, RFC 5652, DOI 10.17487/RFC5652, September 2009,<https://www.rfc-editor.org/info/rfc5652>.[RFC8174]Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, May 2017,<https://www.rfc-editor.org/info/rfc8174>.[RFC9052]Schaad, J., "CBOR Object Signing and Encryption (COSE): Structures and Process", STD 96, RFC 9052, DOI 10.17487/RFC9052, August 2022,<https://www.rfc-editor.org/info/rfc9052>.
9.2. Informative References
[GCMMODE]Dworkin, M., "Recommendation for Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC", NIST Special Publication 800-38D, DOI 10.6028/NIST.SP.800-38D, November 2007,<https://doi.org/10.6028/NIST.SP.800-38D>.[IANA-COSE]IANA, "CBOR Object Signing and Encryption (COSE)",<https://www.iana.org/assignments/cose>.[RFC3610]Whiting, D., Housley, R., and N. Ferguson, "Counter with CBC-MAC (CCM)", RFC 3610, DOI 10.17487/RFC3610, September 2003,<https://www.rfc-editor.org/info/rfc3610>.[RFC5116]McGrew, D., "An Interface and Algorithms for Authenticated Encryption", RFC 5116, DOI 10.17487/RFC5116, January 2008,<https://www.rfc-editor.org/info/rfc5116>.[SUIT-MANIFEST]Moran, B., Tschofenig, H., Birkholz, H., Zandberg, K., and Γ. RΓΈnningstad, "A Concise Binary Object Representation (CBOR)-based Serialization Format for the Software Updates for Internet of Things (SUIT) Manifest", Work in Progress, Internet-Draft, draft-ietf-suit-manifest-22, 27 February 2023,<https://datatracker.ietf.org/doc/html/draft-ietf-suit-manifest-22>.[Vaudenay]Vaudenay, S., "Security Flaws Induced by CBC Padding -- Applications to SSL, IPSEC, WTLS...", EUROCRYPT 2002, 2002,<https://www.iacr.org/cryptodb/archive/2002/EUROCRYPT/2850/2850.pdf>.
Acknowledgements π«Ά
Huge thanks to David Brown for raising the need for non-AEAD algorithms to support encryption within the SUIT manifest π. Thanks also to Ilari Liusvaara, Scott Arciszewski, John PreuΓ Mattsson, Laurence Lundblade, Paul Wouters, Roman Danyliw, Sophie Schmieg, Stephen Farrell, Carsten Bormann, Scott Fluhrer, Brendan Moran, and John Scudder for the review and thoughtful comments π.
Authors' Addresses π
Russ Housley Vigil Security, LLC Email: housley@vigilsec.com
Hannes Tschofenig Email: hannes.tschofenig@gmx.net
π¦ where this page comes from
- ietf: rfc9459 2023-09
- π girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms