<?xml version="1.0" encoding="UTF-8"?>
  <?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
  <!-- generated by https://github.com/cabo/kramdown-rfc version 1.7.17 (Ruby 3.0.2) -->


<!DOCTYPE rfc  [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">

]>


<rfc ipr="trust200902" docName="draft-tschofenig-cose-cek-hkdf-sha256-01" category="std" consensus="true" submissionType="IETF" tocInclude="true" sortRefs="true" symRefs="true">
  <front>
    <title abbrev="Encryption Key Derivation in COSE">Encryption Key Derivation in the COSE using HKDF with SHA-256</title>

    <author initials="H." surname="Tschofenig" fullname="Hannes Tschofenig">
      <organization abbrev="H-BRS">University of Applied Sciences Bonn-Rhein-Sieg</organization>
      <address>
        <email>Hannes.Tschofenig@gmx.net</email>
      </address>
    </author>
    <author initials="R." surname="Housley" fullname="Russ Housley">
      <organization abbrev="Vigil Security">Vigil Security, LLC</organization>
      <address>
        <email>housley@vigilsec.com</email>
      </address>
    </author>
    <author initials="K." surname="Takayama" fullname="Ken Takayama">
      <organization>SECOM CO., LTD.</organization>
      <address>
        <email>ken.takayama.ietf@gmail.com</email>
      </address>
    </author>

    <date year="2024" month="September" day="16"/>

    <area>Security</area>
    <workgroup>COSE</workgroup>
    <keyword>COSE</keyword> <keyword>AEAD Downgrade Attack</keyword>

    <abstract>


<?line 66?>

<t>This document specifies the derivation of the content-encryption key in
CBOR Object Signing and Encryption (COSE). This mechanism protects against
attacks where an attacker manipulates the content-encryption algorithm
identifier.</t>



    </abstract>

    <note title="About This Document" removeInRFC="true">
      <t>
        Status information for this document may be found at <eref target="https://datatracker.ietf.org/doc/draft-tschofenig-cose-cek-hkdf-sha256/"/>.
      </t>
      <t>
        Discussion of this document takes place on the
        COSE Working Group mailing list (<eref target="mailto:cose@ietf.org"/>),
        which is archived at <eref target="https://datatracker.ietf.org/wg/cose/about/"/>.
        Subscribe at <eref target="https://www.ietf.org/mailman/listinfo/cose/"/>.
      </t>
    </note>


  </front>

  <middle>


<?line 73?>

<section anchor="introduction"><name>Introduction</name>

<t>This document specifies the derivation of the content-encryption key
for COSE. The use of this mechanism provides protection against
where the
attacker manipulates the content-encryption algorithm identifier. This
attack has been demonstrated against CMS and the mitigation can be
found in <xref target="I-D.ietf-lamps-cms-cek-hkdf-sha256"/>.  This attack is generic
and can apply to other protocols with similar characteristics, such as
COSE. However, the attack requires several preconditions:</t>

<t><list style="numbers" type="1">
  <t>The attacker intercepts a COSE Encrypt payload an changes the
algorithm identifier to use the same underlying cipher with a different
encryption mode, such as AES-GCM to AES-CBC.</t>
  <t>The attacker converts the intercepted content into a "garbage" COSE
Encrypt payload composed of AES-CBC guess blocks.</t>
  <t>The attacker sends the "garbage" message to the victim, who then
reveals the result of the decryption to the attacker.</t>
  <t>If any of the transformed plaintext blocks match the guess for
that block, then the attacker learns the plaintext for that
block.</t>
</list></t>

<t>With highly structured messages, one block can reveal the only
sensitive part of the original message.</t>

<t>This attack is thwarted if the encryption key depends upon the
delivery of the unmodified algorithm identifier.</t>

<t>The mitigation for this attack has two parts:</t>

<t><list style="symbols">
  <t>Potential recipients include a new parameter, cek-hkdf, in the
outermost protected header of the COSE_Encrypt payload to indicate
support for this mitigation. This parameter <bcp14>MUST</bcp14> use the value true.</t>
  <t>Perform encryption with a derived content-encryption key or
content-authenticated-encryption key. The new CEK' is the result
of deriving a CEK. This key derivation uses the alg parameter
found in the outermost COSE_Encrypt header.</t>
</list></t>

<figure><artwork><![CDATA[
CEK' = HKDF(CEK, COSE_Encrypt.alg)
]]></artwork></figure>

</section>
<section anchor="conventions-and-definitions"><name>Conventions and Definitions</name>

<t>The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>", "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL
NOT</bcp14>", "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>", "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>",
"<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" in this document are to be interpreted as
described in BCP 14 <xref target="RFC2119"/> <xref target="RFC8174"/> when, and only when, they
appear in all capitals, as shown here.</t>

<?line -18?>

</section>
<section anchor="use-of-of-hkdf-with-sha-256-to-derive-encryption-keys"><name>Use of of HKDF with SHA-256 to Derive Encryption Keys</name>

<t>The mitigation uses the HMAC-based Extract-and-Expand Key Derivation
Function (HKDF) <xref target="RFC5869"/> to derive output keying material (OKM) from
input key material (IKM). HKDF is used with the SHA-256 hash
function <xref target="FIPS180"/>.</t>

<t>If an attacker were to change the originator-provided COSE_Encrypt
algorithm identifier then the recipient will derive a different
content-encryption key.</t>

<t>The CEK_HKDF function uses the HKDF-Extract and HKDF-
Expand functions to derive the OKM from the IKM:</t>

<figure><artwork><![CDATA[
Inputs:
  IKM        Input keying material
  alg        COSE_Key algorithm identifier

Output:
  OKM      output keying material (same size as IKM)
]]></artwork></figure>

<t>The output OKM is calculated as follows:</t>

<figure><artwork><![CDATA[
  OKM_SIZE = len(IKM)
  IF OKM_SIZE > 8160 THEN raise error

  salt = "CBOR Object Signing and Encryption"
  PRK = HKDF-Extract(salt, IKM)

  OKM = HKDF-Expand(PRK, alg, OKM_SIZE)
]]></artwork></figure>

</section>
<section anchor="security-considerations"><name>Security Considerations</name>

<t>This mitigation always uses HKDF with SHA-256. One KDF algorithm was selected to avoid the need for negotiation. In the future, if a weakness is found in the KDF algorithm, a new attribute will need to be assigned for use with an alternative KDF algorithm.</t>

<t>If the attacker removes the cek-hkdf header parameter from the COSE_Encrypt header prior to delivery to the recipient, then the recipient will not attempt to derive CEK', which will deny the recipient access to the content, but will not assist the attacker in recovering the plaintext content.</t>

<t>If the attacker changes the value of the COSE_Encrypt alg parameter prior to delivery to the recipient, then the recipient will derive a different CEK', which will not assist the attacker in recovering the plaintext content. Providing the algorithm identifer as an input to the key derivation function is sufficient to mitigate the attack described in <xref target="RS2023"/>, but this mitigation includes both the object identifier and the parameters to protect against some yet-to-be-discovered attack that only manipulates the parameters.</t>

<t>Implementations <bcp14>MUST</bcp14> protect the content-encryption keys, this includes the CEK and CEK'. Compromise of a content-encryption key may result in disclosure of the associated encrypted content. Compromise of a content-authenticated-encryption key may result in disclosure of the associated encrypted content or allow modification of the authenticated content and the additional authenticated data (AAD).</t>

<t>Implementations <bcp14>MUST</bcp14> randomly generate content-encryption keys and content-authenticated-encryption keys. Content key distribution methods are described in Section 8.5 of <xref target="RFC9052"/> and in Section 6 of <xref target="RFC9053"/>. These algorithms define derivation and protection of content-encryption keys.</t>

</section>
<section anchor="iana-considerations"><name>IANA Considerations</name>

<t>IANA is requested to add a new header parameter to the "COSE Common
Header Parameters" established with <xref target="RFC9052"/>.</t>

<figure><artwork><![CDATA[
+-----------+-------+--------------+-------------+------------------+
| Name      | Label | Value Type   | Value       | Description      |
|           |       |              | Registry    |                  |
+-----------+-------+--------------+-------------+------------------+
| cek-hkdf  | TBD   | bool         | N/A         | CEK-HKDF-SHA256  |
+-----------+-------+--------------+-------------+------------------+
]]></artwork></figure>

</section>


  </middle>

  <back>


    <references title='Normative References' anchor="sec-normative-references">



<reference anchor="RFC9052">
  <front>
    <title>CBOR Object Signing and Encryption (COSE): Structures and Process</title>
    <author fullname="J. Schaad" initials="J." surname="Schaad"/>
    <date month="August" year="2022"/>
    <abstract>
      <t>Concise Binary Object Representation (CBOR) is a data format designed for small code size and small message size. There is a need to be able to define basic security services for this data format. This document defines the CBOR Object Signing and Encryption (COSE) protocol. This specification describes how to create and process signatures, message authentication codes, and encryption using CBOR for serialization. This specification additionally describes how to represent cryptographic keys using CBOR.</t>
      <t>This document, along with RFC 9053, obsoletes RFC 8152.</t>
    </abstract>
  </front>
  <seriesInfo name="STD" value="96"/>
  <seriesInfo name="RFC" value="9052"/>
  <seriesInfo name="DOI" value="10.17487/RFC9052"/>
</reference>

<reference anchor="RFC9053">
  <front>
    <title>CBOR Object Signing and Encryption (COSE): Initial Algorithms</title>
    <author fullname="J. Schaad" initials="J." surname="Schaad"/>
    <date month="August" year="2022"/>
    <abstract>
      <t>Concise Binary Object Representation (CBOR) is a data format designed for small code size and small message size. There is a need to be able to define basic security services for this data format. This document defines a set of algorithms that can be used with the CBOR Object Signing and Encryption (COSE) protocol (RFC 9052).</t>
      <t>This document, along with RFC 9052, obsoletes RFC 8152.</t>
    </abstract>
  </front>
  <seriesInfo name="RFC" value="9053"/>
  <seriesInfo name="DOI" value="10.17487/RFC9053"/>
</reference>

<reference anchor="RFC5869">
  <front>
    <title>HMAC-based Extract-and-Expand Key Derivation Function (HKDF)</title>
    <author fullname="H. Krawczyk" initials="H." surname="Krawczyk"/>
    <author fullname="P. Eronen" initials="P." surname="Eronen"/>
    <date month="May" year="2010"/>
    <abstract>
      <t>This document specifies a simple Hashed Message Authentication Code (HMAC)-based key derivation function (HKDF), which can be used as a building block in various protocols and applications. The key derivation function (KDF) is intended to support a wide range of applications and requirements, and is conservative in its use of cryptographic hash functions. This document is not an Internet Standards Track specification; it is published for informational purposes.</t>
    </abstract>
  </front>
  <seriesInfo name="RFC" value="5869"/>
  <seriesInfo name="DOI" value="10.17487/RFC5869"/>
</reference>


<reference anchor="FIPS180" target="https://csrc.nist.gov/pubs/fips/180-4/upd1/final">
  <front>
    <title>Secure Hash Standard (SHS), FIPS PUB 180-4</title>
    <author >
      <organization>National Institute of Standards and Technology (NIST)</organization>
    </author>
    <date year="2015" month="August"/>
  </front>
</reference>


<reference anchor="RFC2119">
  <front>
    <title>Key words for use in RFCs to Indicate Requirement Levels</title>
    <author fullname="S. Bradner" initials="S." surname="Bradner"/>
    <date month="March" year="1997"/>
    <abstract>
      <t>In many standards track documents several words are used to signify the requirements in the specification. These words are often capitalized. This document defines these words as they should be interpreted in IETF documents. This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.</t>
    </abstract>
  </front>
  <seriesInfo name="BCP" value="14"/>
  <seriesInfo name="RFC" value="2119"/>
  <seriesInfo name="DOI" value="10.17487/RFC2119"/>
</reference>

<reference anchor="RFC8174">
  <front>
    <title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title>
    <author fullname="B. Leiba" initials="B." surname="Leiba"/>
    <date month="May" year="2017"/>
    <abstract>
      <t>RFC 2119 specifies common key words that may be used in protocol specifications. This document aims to reduce the ambiguity by clarifying that only UPPERCASE usage of the key words have the defined special meanings.</t>
    </abstract>
  </front>
  <seriesInfo name="BCP" value="14"/>
  <seriesInfo name="RFC" value="8174"/>
  <seriesInfo name="DOI" value="10.17487/RFC8174"/>
</reference>




    </references>

    <references title='Informative References' anchor="sec-informative-references">




<reference anchor="I-D.ietf-lamps-cms-cek-hkdf-sha256">
   <front>
      <title>Encryption Key Derivation in the Cryptographic Message Syntax (CMS) using HKDF with SHA-256</title>
      <author fullname="Russ Housley" initials="R." surname="Housley">
         <organization>Vigil Security, LLC</organization>
      </author>
      <date day="10" month="September" year="2024"/>
      <abstract>
	 <t>   This document specifies the derivation of the content-encryption key
   or the content-authenticated-encryption key in the Cryptographic
   Message Syntax (CMS).  The use of this mechanism provides protection
   against where the attacker manipulates the content-encryption
   algorithm identifier or the content-authenticated-encryption
   algorithm identifier.

	 </t>
      </abstract>
   </front>
   <seriesInfo name="Internet-Draft" value="draft-ietf-lamps-cms-cek-hkdf-sha256-04"/>
   
</reference>


<reference anchor="RS2023" target="https://datatracker.ietf.org/meeting/118/materials/slides-118-lamps-attack-against-aead-in-cms">
  <front>
    <title>AEAD-to-CBC Downgrade Attacks on CMS</title>
    <author initials="F." surname="Strenzke" fullname="Falko Strenzke">
      <organization>MTG AG</organization>
    </author>
    <author initials="J." surname="Roth" fullname="Johannes Roth">
      <organization>MTG AG</organization>
    </author>
    <date year="2023" month="November"/>
  </front>
</reference>


    </references>


<?line 204?>

<section anchor="acknowledgments"><name>Acknowledgments</name>

<t>Add your name here.</t>

</section>


  </back>

<!-- ##markdown-source:
H4sIAAAAAAA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