<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE rfc SYSTEM "rfc2629-xhtml.ent">

<rfc 
xmlns:xi="http://www.w3.org/2001/XInclude" 
number="9044"
updates="" 
obsoletes=""
category="std"
consensus="true"
submissionType="IETF"
ipr="trust200902"
sortRefs="true"
symRefs="true"
tocInclude="true"
docName="draft-ietf-lamps-cms-aes-gmac-alg-05"
xml:lang="en" 
version="3">

  <front>
    <title abbrev="Using AES-GMAC with the CMS">Using the AES-GMAC Algorithm with the Cryptographic Message Syntax (CMS)</title>
   <seriesInfo name="RFC" value="9044"/>

    <author initials="R." surname="Housley" fullname="Russ Housley">
      <organization abbrev="Vigil Security">Vigil Security, LLC</organization>
      <address>
        <postal>
          <street>516 Dranesville Road</street>
          <city>Herndon</city>
<region>VA</region>
          <code>20170</code>
          <country>United States of America</country>
        </postal>
        <email>housley@vigilsec.com</email>
      </address>
    </author>

    <date year="2021" month="June"/>

    <area>Security</area>


<keyword>Authentication</keyword>
<keyword>Message Authentication Code</keyword>

    <abstract>
<t>This document specifies the conventions for using the AES-GMAC Message
Authentication Code algorithm with the Cryptographic Message Syntax
(CMS) as specified in RFC 5652.</t>
    </abstract>

  </front>
  <middle>


<section anchor="intro" title="Introduction">

<t>This document specifies the conventions for using the AES-GMAC
<xref target="AES"/> <xref target="GCM"/> Message Authentication Code (MAC) algorithm with the
Cryptographic Message Syntax (CMS) <xref target="RFC5652"/>.</t>

</section>
<section anchor="terms" title="Terminology">
        <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&nbsp;14 <xref target="RFC2119"/> <xref target="RFC8174"/> 
    when, and only when, they appear in all capitals, as shown here.
        </t>

</section>
<section anchor="message-authentication-code-algorithms" title="Message Authentication Code Algorithms">

<t>This section specifies the conventions employed by CMS <xref target="RFC5652"/>
implementations that support the AES-GMAC <xref target="AES"/> <xref target="GCM"/> Message
Authentication Code (MAC) algorithm.</t>

<t>MAC algorithm identifiers are located in the AuthenticatedData
macAlgorithm field.</t>

<t>MAC values are located in the AuthenticatedData mac field.</t>

<section anchor="aes-gmac" title="AES-GMAC">

<t>The AES-GMAC <xref target="AES"/> <xref target="GCM"/> Message Authentication Code (MAC) algorithm
uses one of the following algorithm identifiers in the AuthenticatedData
macAlgorithm field; the choice depends on the size of the AES key, which
is either 128 bits, 192 bits, or 256 bits:</t>

<sourcecode type="asn.1"><![CDATA[
   aes OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840)
           organization(1) gov(101) csor(3) nistAlgorithm(4) 1 }

   id-aes128-GMAC OBJECT IDENTIFIER ::= { aes 9 }
    
   id-aes192-GMAC OBJECT IDENTIFIER ::= { aes 29 }

   id-aes256-GMAC OBJECT IDENTIFIER ::= { aes 49 }
]]></sourcecode>

<t>For all three of these algorithm identifier values, the
AlgorithmIdentifier parameters field <bcp14>MUST</bcp14> be present, and the parameters
<bcp14>MUST</bcp14> contain GMACParameters:</t>

<sourcecode type="asn.1"><![CDATA[
   GMACParameters ::= SEQUENCE {
      nonce        OCTET STRING, -- recommended size is 12 octets
      length       MACLength DEFAULT 12 }

   MACLength ::= INTEGER (12 | 13 | 14 | 15 | 16)
]]></sourcecode>

<t>The GMACParameters nonce field is the GMAC initialization
vector. The nonce may have any number of bits between 8 and (2^64)-1,
but it <bcp14>MUST</bcp14> be a multiple of 8 bits.  Within the scope of any
content-authentication key, the nonce value <bcp14>MUST</bcp14> be unique.  A
nonce value of 12 octets can be processed more efficiently,
so that length for the nonce value is <bcp14>RECOMMENDED</bcp14>.</t>

<t>The GMACParameters length field tells the size of the message
authentication code.  It <bcp14>MUST</bcp14> match the size in octets of the value
in the AuthenticatedData mac field.  A length of 12 octets is
<bcp14>RECOMMENDED</bcp14>.</t>

</section>
</section>
<section anchor="implementation-considerations" title="Implementation Considerations">

<t>An implementation of the Advanced Encryption Standard (AES)
Galois/Counter Mode (GCM) authenticated encryption algorithm is specified
in <xref target="GCM"/>.  An implementation of AES-GCM can be used to compute the GMAC
message authentication code by providing the content-authentication key
as the AES key, the nonce as the initialization vector, a zero-length
plaintext content, and the content to be authenticated as the additional
authenticated data (AAD).  The result of the AES-GCM invocation is the
AES-GMAC authentication code, which is called the "authentication tag" in
some implementations.  In AES-GCM, the encryption step is skipped when no
input plaintext is provided; therefore, no ciphertext is produced.</t>

<t>The DEFAULT and <bcp14>RECOMMENDED</bcp14> values in GMACParameters were selected
to align with the parameters defined for AES-GCM in <xref target="RFC5084" sectionFormat="of" section="3.2"/>.</t>

</section>
<section anchor="asn1-module" title="ASN.1 Module">

<t>The following ASN.1 module uses the definition for MAC-ALGORITHM
from <xref target="RFC5912"/>.</t>

<sourcecode type="asn.1"> <![CDATA[
CryptographicMessageSyntaxGMACAlgorithms
    { iso(1) member-body(2) us(840) rsadsi(113549) 
      pkcs(1) pkcs-9(9) smime(16) modules(0)
      id-mod-aes-gmac-alg-2020(72) }

DEFINITIONS IMPLICIT TAGS ::=
BEGIN

-- EXPORTS All

IMPORTS
  AlgorithmIdentifier{}, MAC-ALGORITHM
  FROM AlgorithmInformation-2009 -- from [RFC5912]
      { iso(1) identified-organization(3) dod(6) internet(1)
        security(5) mechanisms(5) pkix(7) id-mod(0)
        id-mod-algorithmInformation-02(58)} ;

-- Object Identifiers

aes OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840)
       organization(1) gov(101) csor(3) nistAlgorithm(4) 1 }

id-aes128-GMAC OBJECT IDENTIFIER ::= { aes 9 }
    
id-aes192-GMAC OBJECT IDENTIFIER ::= { aes 29 }

id-aes256-GMAC OBJECT IDENTIFIER ::= { aes 49 }

-- GMAC Parameters

GMACParameters ::= SEQUENCE {
   nonce        OCTET STRING, -- recommended size is 12 octets
   length       MACLength DEFAULT 12 }

MACLength ::= INTEGER (12 | 13 | 14 | 15 | 16)

-- Algorithm Identifiers

maca-aes128-GMAC MAC-ALGORITHM ::= { 
   IDENTIFIER id-aes128-GMAC
   PARAMS TYPE GMACParameters ARE required
   IS-KEYED-MAC TRUE }

maca-aes192-GMAC MAC-ALGORITHM ::= {
   IDENTIFIER id-aes192-GMAC
   PARAMS TYPE GMACParameters ARE required
   IS-KEYED-MAC TRUE }

maca-aes256-GMAC MAC-ALGORITHM ::= {
   IDENTIFIER id-aes256-GMAC
   PARAMS TYPE GMACParameters ARE required
   IS-KEYED-MAC TRUE }

END -- of CryptographicMessageSyntaxGMACAlgorithms
]]></sourcecode>

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

<t>
   IANA has registered the object identifier shown in <xref target="IANA1"/> in the "SMI Security for S/MIME
   Module Identifier (1.2.840.113549.1.9.16.0)" registry.</t>

<table anchor="IANA1"> 
  <thead>
    <tr>
      <th>Decimal</th>   
      <th>Description</th>   
      <th>References</th>
    </tr>
  </thead>
  <tbody>         
    <tr>
      <td>72</td>
      <td>id-mod-aes-gmac-alg-2020</td>
      <td>RFC 9044</td>
    </tr>
  </tbody>
</table>

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

<t>The CMS provides a method for authenticating data.  This document
identifies the conventions for using the AES-GMAC algorithm with the CMS.</t>

<t>The key management technique employed to distribute message-authentication
keys must itself provide authentication; otherwise, the content is delivered
with integrity from an unknown source.</t>

<t>When more than two parties share the same message-authentication key, data
origin authentication is not provided.  Any party that knows the
message-authentication key can compute a valid MAC; therefore, the content
could originate from any one of the parties.</t>

<t>Within the scope of any content-authentication key, the AES-GMAC nonce value
<bcp14>MUST</bcp14> be unique.  Use of a nonce value more than once allows an attacker to
generate valid AES-GMAC authentication codes for arbitrary messages, resulting
in the loss of authentication as described in Appendix A of <xref target="GCM"/>.</t>

<t>Within the scope of any content-authentication key, the authentication tag
length (MACLength) <bcp14>MUST</bcp14> be fixed.</t>

<t>If AES-GMAC is used as a building block in another algorithm (e.g., as
a pseudorandom function), AES-GMAC <bcp14>MUST</bcp14> be used only one time by that
algorithm.  For instance, AES-GMAC <bcp14>MUST NOT</bcp14> be used as the pseudorandom
function for PBKDF2.</t>

<t>When initialization vector (IV) lengths other than 96 bits are used, the GHASH function is used to
process the provided IV, which introduces a potential for IV collisions.
However, IV collisions are not a concern with CMS AuthenticatedData because
a fresh content-authentication key is usually generated for each message.</t>

<t>The probability of a successful forgery is close to 2^(-t), where t is the
number of bits in the authentication tag length (MACLength*8).  This nearly
ideal authentication protection is achieved for CMS AuthenticatedData when a
fresh content-authentication key is generated for each message.  However, the
strength of GMAC degrades slightly as a function of the length of the message
being authenticated <xref target="F2005"/> <xref target="MV2005"/>.  Implementations <bcp14>SHOULD</bcp14> use 16-octet
authentication tags for messages over 2^64 octets.</t>

<t>Implementations must randomly generate message-authentication keys.  The use
of inadequate pseudorandom number generators (PRNGs) to generate keys can
result in little or no security.  An attacker may find it much easier to
reproduce the PRNG environment that produced the keys, searching the resulting
small set of possibilities, rather than brute-force searching the whole key
space.  The generation of quality random numbers is difficult.  <xref target="RFC4086"/>
offers important guidance in this area.</t>

<t>Implementers should be aware that cryptographic algorithms become weaker
with time.  As new cryptanalysis techniques are developed and computing
performance improves, the work factor to break a particular cryptographic
algorithm will reduce.  Therefore, cryptographic algorithm implementations
should be modular, allowing new algorithms to be readily inserted.  That is,
implementers should be prepared to regularly update the set of algorithms
in their implementations.  More information is available in BCP 201 <xref target="RFC7696"/>.</t>

</section>
  </middle>

  <back>
    <references>
      <name>References</name>
      <references>
        <name>Normative References</name>
<xi:include                                                                    
href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
<xi:include                                                                    
href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5652.xml"/>
<xi:include                                                                    
href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5912.xml"/>
<xi:include                                                                    
href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>

<reference anchor="AES">
  <front>
    <title>Advanced Encryption Standard (AES)</title>
    <author >
      <organization>National Institute of Standards and Technology</organization>
    </author>
    <date year="2001" month="November"/>
  </front>
  <seriesInfo name="FIPS PUB" value="197"/>
  <seriesInfo name="DOI" value="10.6028/NIST.FIPS.197"/>
</reference>

<reference anchor="GCM" >
  <front>
    <title>Recommendation for Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC</title>
    <author initials="M." surname="Dworkin" fullname="M. Dworkin">
    </author>
    <date year="2007" month="November"/>
  </front>
  <seriesInfo name="NIST Special Publication" value="800-38D"/>
  <seriesInfo name="DOI" value="10.6028/NIST.SP.800-38D"/>
</reference>
      </references>
      <references>
        <name>Informative References</name>

<xi:include                                                                    
href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4086.xml"/>
<xi:include                                                                    
href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5084.xml"/>
<xi:include                                                                    
href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7696.xml"/>

<reference anchor="F2005" target="https://csrc.nist.gov/csrc/media/projects/block-cipher-techniques/documents/bcm/comments/cwc-gcm/ferguson2.pdf">
  <front>
    <title>Authentication weaknesses in GCM</title>
    <author initials="N." surname="Ferguson" fullname="Niels Ferguson">
      <organization></organization>
    </author>
    <date year="2005" month="May"/>
  </front>
</reference>

<reference anchor="MV2005" target="https://csrc.nist.gov/CSRC/media/Projects/Block-Cipher-Techniques/documents/BCM/Comments/CWC-GCM/gcm-update.pdf">
  <front>
    <title>GCM Update</title>
    <author initials="D." surname="McGrew" fullname="David McGrew">
      <organization></organization>
    </author>
    <author initials="J." surname="Viega" fullname="John Viega">
      <organization></organization>
    </author>
    <date year="2005" month="May"/>
  </front>
</reference>
    </references>
    </references>
<section anchor="acknowledgements" numbered="false" title="Acknowledgements">

<t>Many thanks to 
<contact fullname="Hans Aschauer"/>,
<contact fullname="Hendrik Brockhaus"/>,
<contact fullname="Quynh Dang"/>,
<contact fullname="Roman Danyliw"/>,
<contact fullname="Tim Hollebeek"/>,
<contact fullname="Ben Kaduk"/>,
<contact fullname="Mike Ounsworth"/>, and
<contact fullname="Magnus Westerlund"/>
for their careful review and thoughtful improvements.</t>

</section>



  </back>
</rfc>

