Movatterモバイル変換


[0]ホーム

URL:


RFC 9459AES-CTR and AES-CBC with COSESeptember 2023
Housley & TschofenigStandards Track[Page]
Stream:
Internet Engineering Task Force (IETF)
RFC:
9459
Category:
Standards Track
Published:
ISSN:
2070-1721
Authors:
R. Housley
Vigil Security
H. Tschofenig

RFC 9459

CBOR Object Signing and Encryption (COSE): AES-CTR and AES-CBC

Abstract

The Concise Binary Object Representation (CBOR) data format is designedfor small code size and small message size. CBOR Object Signing andEncryption (COSE) is specified in RFC 9052 to provide basicsecurity services using the CBOR data format. This document specifies theconventions for using AES-CTR and AES-CBC as content encryptionalgorithms 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 athttps://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

This document specifies the conventions for using AES-CTR and AES-CBC as content encryption algorithms with the CBOR Object Signing and Encryption(COSE)[RFC9052] syntax. Today, encryption with COSE uses AuthenticatedEncryption with Associated Data (AEAD) algorithms[RFC5116], which provideboth confidentiality and integrity protection. However, there are situationswhere another mechanism, such as a digital signature, is used to provideintegrity. In these cases, an AEAD algorithm is not needed. The softwaremanifest being defined by the IETF SUIT WG[SUIT-MANIFEST] is oneexample where a digital signature is always present.

2.Conventions and Terminology

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 EncryptionStandard[AES][MODES]. AES supports three key sizes: 128 bits,192 bits, and 256 bits. AES has a block size of 128 bits (16 octets).Each of these modes has different characteristics. 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) arediscussed in this document.

4.AES Counter Mode

When AES-CTR is used as a COSE content encryption algorithm, theencryptor generates a unique value that is communicated to thedecryptor. This value is called an "Initialization Vector" (or "IV") in thisdocument. The same IV and AES key combinationMUST NOT be used morethan once. The encryptor can generate the IV in any manner that ensuresthe same IV value is not used more than once with the same AES key.

When using AES-CTR, each AES encrypt operation generates 128 bits of keystream. AES-CTR encryption is the XOR of the key stream with theplaintext. AES-CTR decryption is the XOR of the key stream with theciphertext. If the generated key stream is longer than the plaintext orciphertext, the extra key stream bits are simply discarded. For this reason,AES-CTR does not require the plaintext to be padded to a multiple of the block size.

AES-CTR has many properties that make it an attractive COSE content encryptionalgorithm. AES-CTR uses the AES block cipher to create a stream cipher. Datais encrypted and decrypted by XORing with the key stream produced by AES encrypting sequential IV block values, called "counter blocks", where:

AES-CTRis easy to implement, can be pipelined and parallelized, and supports key stream precomputation. Sending of the IV is the onlysource of expansion because the plaintext and ciphertext are the same size.

When used correctly, AES-CTR provides a high level of confidentiality.Unfortunately, AES-CTR is easy to use incorrectly. Being a streamcipher, reuse of the IV with the same key is catastrophic. An IVcollision immediately leaks information about the plaintext. Forthis reason, it is inappropriate to use AES-CTR with statickeys. Extraordinary measures would be needed to prevent reuse of anIV value with the static key across power cycles. To be safe,implementationsMUST use fresh keys with AES-CTR.

AES-CTR keys may be obtained either from a key structure or from a recipientstructure. Implementations encrypting and decryptingMUST validate that thekey type, key length, and algorithm are correct and appropriate for theentities involved.

With AES-CTR, it is trivial to use a valid ciphertext to forge other(valid to the decryptor) ciphertexts. Thus, it is equally catastrophic touse AES-CTR without a companion authentication and integritymechanism. ImplementationsMUST use AES-CTR in conjunction with anauthentication and integrity mechanism, such as a digital signature.

The instructions inSection 5.4 of [RFC9052] are followed for AES-CTR.Since AES-CTR cannot provide integrity protection for external additionalauthenticated data, the decryptorMUST ensure that no external additional authenticated data was supplied. SeeSection 6.

The 'protected' headerMUST be a zero-length byte string.

4.1.AES-CTR COSE Key

When using a COSE key for the AES-CTR algorithm, the following checks are made:

  • The 'kty' fieldMUST be present, and itMUST be 'Symmetric'.
  • If the 'alg' field is present, itMUST match the AES-CTR algorithm being used.
  • If the 'key_ops' field is present, itMUST include 'encrypt' when encrypting.
  • If the 'key_ops' field is present, itMUST include 'decrypt' when decrypting.

4.2.AES-CTR COSE Algorithm Identifiers

The following table defines the COSE AES-CTR algorithm values. Note thatthese algorithms are being registered as "Deprecated" to avoid accidentaluse without a companion integrity protection mechanism.

Table 1
NameValueKey SizeDescriptionRecommended
A128CTR-65534128AES-CTR w/ 128-bit keyDeprecated
A192CTR-65533192AES-CTR w/ 192-bit keyDeprecated
A256CTR-65532256AES-CTR w/ 256-bit keyDeprecated

5.AES Cipher Block Chaining Mode

AES-CBC mode requires a 16-octet IV. Use of arandomly or pseudorandomly generated IV ensures that the encryption of thesame plaintext will yield different ciphertext.

AES-CBC performs an XOR of the IV with the first plaintext block before itis encrypted. For successive blocks, AES-CBC performs an XOR of the previousciphertext block with the current plaintext before it is encrypted.

AES-CBC requires padding of the plaintext; the padding algorithm specifiedinSection 6.3 of [RFC5652]MUST be used prior to encrypting theplaintext. This padding algorithm allows the decryptor to unambiguouslyremove the padding.

The simplicity of AES-CBC makes it an attractive COSE content encryptionalgorithm. The need to carry an IV and the need for padding lead to anincrease in the overhead (when compared to AES-CTR). AES-CBC is much saferfor use with static keys than AES-CTR. That said, as described in[RFC4107],the use of automated key management to generate fresh keys is greatlypreferred.

AES-CBC does not provide integrity protection. Thus, an attackercan introduce undetectable errors if AES-CBC is used without a companionauthentication and integrity mechanism. ImplementationsMUST use AES-CBCin conjunction with an authentication and integrity mechanism, such as adigital signature.

The instructions inSection 5.4 of [RFC9052] are followed for AES-CBC.Since AES-CBC cannot provide integrity protection for external additionalauthenticated data, the decryptorMUST ensure that no external additional authenticated data was supplied. SeeSection 6.

The 'protected' headerMUST be a zero-length byte string.

5.1.AES-CBC COSE Key

When using a COSE key for the AES-CBC algorithm, the following checks are made:

  • The 'kty' fieldMUST be present, and itMUST be 'Symmetric'.
  • If the 'alg' field is present, itMUST match the AES-CBC algorithm being used.
  • If the 'key_ops' field is present, itMUST include 'encrypt' when encrypting.
  • If the 'key_ops' field is present, itMUST include 'decrypt' when decrypting.

5.2.AES-CBC COSE Algorithm Identifiers

The following table defines the COSE AES-CBC algorithm values. Note thatthese algorithms are being registered as "Deprecated" to avoid accidentaluse without a companion integrity protection mechanism.

Table 2
NameValueKey SizeDescriptionRecommended
A128CBC-65531128AES-CBC w/ 128-bit keyDeprecated
A192CBC-65530192AES-CBC w/ 192-bit keyDeprecated
A256CBC-65529256AES-CBC w/ 256-bit keyDeprecated

6.Implementation Considerations

COSE libraries that support either AES-CTR or AES-CBC and acceptAdditional Authenticated Data (AAD) as inputMUST return anerror if one of these non-AEAD content encryption algorithms isselected. This ensures that a caller does not expect the AADto be protected when the cryptographic algorithm is unable to do so.

7.IANA Considerations

IANA has registered six COSE algorithm identifiers for AES-CTR andAES-CBC in the "COSE Algorithms" registry[IANA-COSE].

The information for the six COSE algorithm identifiers is provided inSections4.2 and5.2. Also, for all six entries, the"Capabilities" column contains "[kty]", the "Change Controller"column contains "IETF", and the "Reference" column containsa reference to this document.

8.Security Considerations

This document specifies AES-CTR and AES-CBC for COSE, which are notAEAD ciphers. The use of the ciphers is limited to special use cases, such as firmware encryption, where integrity and authentication is provided by another mechanism.

Since AES has a 128-bit block size, regardless of the modeemployed, the ciphertext generated by AES encryption becomesdistinguishable from random values after 264 blocks are encryptedwith a single key. Implementations should change the key beforereaching this limit.

To avoid cross-protocol concerns, implementationsMUST NOT use the samekeying material with more than one mode. For example, the same keyingmaterial must not be used with AES-CTR and AES-CBC.

There are fairly generic precomputation attacks against all block ciphermodes that allow a meet-in-the-middle attack against the key. These attacksrequire the creation and searching of huge tables of ciphertext associatedwith known plaintext and known keys. Assuming that the memory and processorresources are available for a precomputation attack, then the theoreticalstrength of AES-CTR and AES-CBC is limited to 2(n/2) bits, where n is thenumber of bits in the key. The use of long keys is the best countermeasureto precomputation attacks.

When used properly, AES-CTR mode provides strong confidentiality. Unfortunately,it is very easy to misuse this counter mode. If counter block values are everused for more than one plaintext with the same key, then the same key streamwill be used to encrypt both plaintexts, and the confidentiality guarantees arevoided.

What happens if the encryptor XORs the same key stream with two differentplaintexts? Suppose two plaintext octet sequences P1, P2, P3 and Q1, Q2, Q3are both encrypted with key stream K1, K2, K3. The two correspondingciphertexts are:

   (P1 XOR K1), (P2 XOR K2), (P3 XOR K3)   (Q1 XOR K1), (Q2 XOR K2), (Q3 XOR K3)

If both of these two ciphertext streams are exposed to an attacker, then acatastrophic failure of confidentiality results, since:

   (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 obtains the two plaintexts XORed together, it is relativelystraightforward to separate them. Thus, using any stream cipher, includingAES-CTR, to encrypt two plaintexts under the same key stream leaks theplaintext.

Data forgery is trivial with AES-CTR mode. The demonstration of this attackis similar to the key stream reuse discussion above. If a known plaintextoctet sequence P1, P2, P3 is encrypted with key stream K1, K2, K3, then theattacker can replace the plaintext with one of its own choosing. Theciphertext is:

   (P1 XOR K1), (P2 XOR K2), (P3 XOR K3)

The attacker simply XORs a selected sequence Q1, Q2, Q3 with theciphertext to obtain:

   (Q1 XOR (P1 XOR K1)), (Q2 XOR (P2 XOR K2)), (Q3 XOR (P3 XOR K3))

Which is the same as:

   ((Q1 XOR P1) XOR K1), ((Q2 XOR P2) XOR K2), ((Q3 XOR P3) XOR K3)

Decryption of the attacker-generated ciphertext will yield exactly whatthe attacker intended:

   (Q1 XOR P1), (Q2 XOR P2), (Q3 XOR P3)

AES-CBC does not provide integrity protection. Thus, an attackercan introduce undetectable errors if AES-CBC is used without a companion authentication mechanism.

If an attacker is able to strip the authentication and integrity mechanism,then the attacker can replace it with one of their own creation, evenwithout knowing the plaintext. The usual defense against such an attack isan Authenticated Encryption with Associated Data (AEAD) algorithm[RFC5116]. Of course, neither AES-CTR nor AES-CBC is an AEAD. Thus,an implementation should provide integrity protection for the 'kid' fieldto prevent undetected stripping of the authentication and integritymechanism; this prevents an attacker from altering the 'kid' to trick therecipient into using a different key.

With AES-CBC mode, implementers should perform integrity checks prior todecryption to avoid padding oracle vulnerabilities[Vaudenay].

With the assignment of COSE algorithm identifiers for AES-CTR andAES-CBC in the COSE Algorithms Registry, an attacker can replace theCOSE algorithm identifiers with one of these identifiers. Then, theattacker might be able to manipulate the ciphertext to learn some of theplaintext or extract the keying material used for authentication andintegrity.

Since AES-CCM[RFC3610] and AES-GCM[GCMMODE] use AES-CTR for encryption,an attacker can switch the algorithm identifier to AES-CTR and then strip theauthentication tag to bypass the authentication and integrity, allowing the attacker to manipulate the ciphertext.

An attacker can switch the algorithm identifier from AES-GCM to AES-CBC,guessing 16 bytes of plaintext at a time, and see if the recipientaccepts the padding. Padding oracle vulnerabilities are discussedfurther 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,,<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,,<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,,<https://www.rfc-editor.org/info/rfc2119>.
[RFC4107]
Bellovin, S. andR. Housley,"Guidelines for Cryptographic Key Management",BCP 107,RFC 4107,DOI 10.17487/RFC4107,,<https://www.rfc-editor.org/info/rfc4107>.
[RFC5652]
Housley, R.,"Cryptographic Message Syntax (CMS)",STD 70,RFC 5652,DOI 10.17487/RFC5652,,<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,,<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,,<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,,<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., andN. Ferguson,"Counter with CBC-MAC (CCM)",RFC 3610,DOI 10.17487/RFC3610,,<https://www.rfc-editor.org/info/rfc3610>.
[RFC5116]
McGrew, D.,"An Interface and Algorithms for Authenticated Encryption",RFC 5116,DOI 10.17487/RFC5116,,<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,,<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,,<https://www.iacr.org/cryptodb/archive/2002/EUROCRYPT/2850/2850.pdf>.

Acknowledgements

Many thanks toDavid Brown for raising the need for non-AEAD algorithmsto support encryption within the SUIT manifest. Many thanks toIlari Liusvaara,Scott Arciszewski,John Preuß Mattsson,Laurence Lundblade,Paul Wouters,Roman Danyliw,Sophie Schmieg,Stephen Farrell,Carsten Bormann,Scott Fluhrer,Brendan Moran, andJohn Scudderfor the review and thoughtful comments.

Authors' Addresses

Russ Housley
Vigil Security, LLC
Email:housley@vigilsec.com
Hannes Tschofenig
Email:hannes.tschofenig@gmx.net

[8]ページ先頭

©2009-2025 Movatter.jp