<?xml version='1.0' encoding='us-ascii'?>
<?xml-stylesheet type='text/xsl' href='http://xml2rfc.tools.ietf.org/authoring/rfc2629.xslt' ?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">

<?rfc toc="yes"?>
<?rfc tocompact="yes"?>
<?rfc tocdepth="4"?>
<?rfc tocindent="yes"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>

<rfc category="std" ipr="trust200902" docName="draft-jones-cose-rsa-00">
  <front>
    <title>Using RSA Algorithms with COSE Messages</title>

    <author fullname="Michael B. Jones" surname="Jones" initials="M.B.">
      <organization>Microsoft</organization>
      <address>
	<email>mbj@microsoft.com</email>
	<uri>http://self-issued.info/</uri>
      </address>
    </author>

    <date day="4" month="April" year="2016" />

    <area>Security</area>
    <workgroup>COSE Working Group</workgroup>

    <abstract>
      <t>
	The CBOR Object Signing and Encryption (COSE) specification
	defines cryptographic message encodings using
	Concise Binary Object Representation (CBOR).
	This specification defines algorithm encodings and representations
	enabling RSA algorithms to be used for COSE messages.
      </t>
    </abstract>
  </front>
  <middle>
    <section anchor="Introduction" title="Introduction">
      <t>
	The CBOR Object Signing and Encryption (COSE) <xref target="I-D.ietf-cose-msg" /> specification
	defines cryptographic message encodings using
	Concise Binary Object Representation (CBOR) <xref target="RFC7049"/>.
	This specification defines algorithm encodings and representations
	enabling RSA algorithms to be used for COSE messages.
      </t>

      <section anchor="rnc" title="Requirements Notation and Conventions">
        <t>
	  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
	  RFC 2119 <xref target="RFC2119"/>.
	</t>
      </section>
    </section>

    <section title="Signature Algorithms" anchor="SignatureAlgs">
      <section title="RSASSA-PSS" anchor="RSASSA-PSS">
        <t>The RSASSA-PSS signature algorithm is defined in <xref target="RFC3447"/>.  </t>
        <t>The RSASSA-PSS signature algorithm is parameterized with a hash function (h), a mask generation function (mgf) and a salt length (sLen).  For this specification, the mask generation function is fixed to be MGF1 as defined in <xref target="RFC3447"/>.  It has been recommended that the same hash function be used for hashing the data as well as in the mask generation function, for this specification we following this recommendation.  The salt length is the same length as the hash function output.  </t>
        <t>Implementations need to check that the key type is 'RSA' when creating or verifying a signature.  </t>
        <t>The algorithms defined in this document can be found in <xref target="table-rsa-algs"/>.  </t>
        <texttable anchor="table-rsa-algs" title="RSASSA-PSS Algorithm Values" suppress-title="false" align="center" style="full">
          <ttcol align="left">name</ttcol>
          <ttcol align="left">value</ttcol>
          <ttcol align="left">hash</ttcol>
          <ttcol align="left">salt length</ttcol>
          <ttcol align="left">description</ttcol>
          <c>PS256</c>
          <c>-26</c>
          <c>SHA-256</c>
          <c>32</c>
          <c>RSASSA-PSS w/ SHA-256</c>
          <c>PS384</c>
          <c>-27</c>
          <c>SHA-384</c>
          <c>48</c>
          <c>RSASSA-PSS w/ SHA-384</c>
          <c>PS512</c>
          <c>-28</c>
          <c>SHA-512</c>
          <c>64</c>
          <c>RSASSA-PSS w/ SHA-512</c>
        </texttable>
        <section title="Security Considerations" anchor="RSASSA-PSS-considerations">
          <t>In addition to needing to worry about keys that are too small to provide the required security,  there are issues with keys that are too large.  Denial of service attacks have been mounted with overly large keys.  This has the potential to consume resources with potentially bad keys.  There are two reasonable ways to address this attack.  First, a key should not be used for a cryptographic operation until it has been matched back to an authorized user.  This approach means that no cryptography would be done except for authorized users.  Second, applications can impose maximum as well as minimum length requirements on keys.  This limits the resources consumed even if the matching is not performed until the cryptography has been done.  </t>
          <t>There is a theoretical hash substitution attack that can be mounted against RSASSA-PSS.  However, the requirement that the same hash function be used consistently for all operations is an effective mitigation against it.  Unlike ECDSA, hash functions are not truncated so that the full hash value is always signed.  The internal padding structure of RSASSA-PSS means that one needs to have multiple collisions between the two hash functions in order to be successful in producing a forgery based on changing the hash function.  This is highly unlikely.  </t>
        </section>
      </section>
    </section>

    <section title="Recipient Algorithm Classes" anchor="key-management-algs">
      <section title="Key Encryption">
        <t>Key Encryption mode is also called key transport mode in some standards.  Key Encryption mode differs from Key Wrap mode in that it uses an asymmetric encryption algorithm rather than a symmetric encryption algorithm to protect the key.  This document defines one Key Encryption mode algorithm.  </t>
        <t>When using a key encryption algorithm, the COSE_encrypt structure for the recipient is organized as follows: <list style="symbols"><t>The 'protected' field MUST be absent.  </t><t>The plain text to be encrypted is the key from next layer down (usually the content layer).  </t><t>At a minimum, the 'unprotected' field MUST contain the 'alg' parameter and SHOULD contain a parameter identifying the asymmetric key.  </t></list> </t>
        <section title="RSAES-OAEP">
          <t>RSAES-OAEP is an asymmetric key encryption algorithm.  The definition of RSAEA-OAEP can be find in Section 7.1 of <xref target="RFC3447"/>.  The algorithm is parameterized using a masking generation function (mgf), a hash function (h) and encoding parameters (P).  For the algorithm identifiers defined in this section: <list style="symbols"><t>mgf is always set to MFG1 from <xref target="RFC3447"/> and uses the same hash function as h.</t><t>P is always set to the empty octet string.</t></list> <xref target="table-RSA-OAEP"/> summarizes the rest of the values.  </t>
          <texttable anchor="table-RSA-OAEP" title="RSAES-OAEP Algorithm Values" suppress-title="false" align="center" style="full">
            <ttcol align="left">name</ttcol>
            <ttcol align="left">value</ttcol>
            <ttcol align="left">hash</ttcol>
            <ttcol align="left">description</ttcol>
            <c>RSAES-OAEP w/SHA-256</c>
            <c>-25</c>
            <c>SHA-256</c>
            <c>RSAES OAEP w/ SHA-256</c>
            <c>RSAES-OAEP w/SHA-512</c>
            <c>-26</c>
            <c>SHA-512</c>
            <c>RSAES OAEP w/ SHA-512</c>
          </texttable>
          <t>The key type MUST be 'RSA'.  </t>
          <section title="Security Considerations for RSAES-OAEP" anchor="RSAES-OAEP-considerations">
            <t>A key size of 2048 bits or larger MUST be used with these algorithms.  This key size corresponds roughly to the same strength as provided by a 128-bit symmetric encryption algorithm.  </t>
            <t>It is highly recommended that checks on the key length  be done before starting a decryption operation.  One potential denial of service operation is to provide encrypted objects using either abnormally long or oddly sized RSA modulus values.  Implementations SHOULD be able to encrypt and decrypt with modulus between 2048 and 16K bits in length.  Applications can impose additional restrictions on the length of the modulus.  </t>
          </section>
        </section>
      </section>
    </section>
    <section title="Keys" anchor="Key-specific-labels">
      <t>Key types are identified by the 'kty' member of the COSE_Key object.  In this document we define one value for the member.  </t>
      <texttable title="Key Type Values" anchor="table_key_types" suppress-title="false" align="center" style="full">
        <ttcol align="left">name</ttcol>
        <ttcol align="left">value</ttcol>
        <ttcol align="left">description</ttcol>
        <c>RSA</c>
        <c>3</c>
        <c>RSA Keys</c>
      </texttable>
      <section title="RSA Keys">
        <t>This document defines a key structure for both the public and private halves of RSA keys.  Together, an RSA public key and an RSA private key form an RSA key pair.  <cref source="JLS">Looking at the CBOR specification, the bstr that we are looking in our table below should most likely be specified as big numbers rather than as binary strings.  This means that we would use the tag 6.2 instead.  From my reading of the specification, there is no difference in the encoded size of the resulting output.  The specification of bignum does explicitly allow for integers encoded with leading zeros.  </cref> </t>
        <t>The document also provides support for the so-called "multi-prime" RSA where the modulus may have more than two prime factors.  The benefit of multi-prime RSA is lower computational cost for the decryption and signature primitives.  For a discussion on how multi-prime affects the security of RSA crypto-systems, the reader is referred to <xref target="MultiPrimeRSA"/>.  </t>
        <t>This document follows the naming convention of <xref target="RFC3447"/> for the naming of the fields of an RSA public or private key.  The table <xref target="table-rsa-keys"/> provides a summary of the label values and the types associated with each of those labels.  The requirements for fields for RSA keys are as follows: <list style="symbols"><t>For all keys, 'kty' MUST be present and MUST have a value of 3.  </t><t>For public keys, the fields 'n' and 'e' MUST be present.  All other fields defined in <xref target="table-rsa-keys"/> MUST be absent.  </t><t>For private keys with two primes, the fields 'other', 'r_i', 'd_i' and 't_i' MUST be absent, all other fields MUST be present.  </t><t>For private keys with more than two primes, all fields MUST  be present.  For the third to nth primes, each of the primes is represented as a map containing the fields 'r_i', 'd_i' and 't_i'.  The field 'other' is an array of those maps.  </t></list> </t>
        <texttable title="RSA Key Parameters" anchor="table-rsa-keys" suppress-title="false" align="center" style="full">
          <ttcol align="left">name</ttcol>
          <ttcol align="left">key type</ttcol>
          <ttcol align="left">value</ttcol>
          <ttcol align="left">type</ttcol>
          <ttcol align="left">description</ttcol>
          <c>n</c>
          <c>3</c>
          <c>-1</c>
          <c>bstr</c>
          <c>Modulus Parameter</c>
          <c>e</c>
          <c>3</c>
          <c>-2</c>
          <c>int</c>
          <c>Exponent Parameter</c>
          <c>d</c>
          <c>3</c>
          <c>-3</c>
          <c>bstr</c>
          <c>Private Exponent Parameter</c>
          <c>p</c>
          <c>3</c>
          <c>-4</c>
          <c>bstr</c>
          <c>First Prime Factor</c>
          <c>q</c>
          <c>3</c>
          <c>-5</c>
          <c>bstr</c>
          <c>Second Prime Factor</c>
          <c>dP</c>
          <c>3</c>
          <c>-6</c>
          <c>bstr</c>
          <c>First Factor CRT Exponent</c>
          <c>dQ</c>
          <c>3</c>
          <c>-7</c>
          <c>bstr</c>
          <c>Second Factor CRT Exponent</c>
          <c>qInv</c>
          <c>3</c>
          <c>-8</c>
          <c>bstr</c>
          <c>First CRT Coefficient</c>
          <c>other</c>
          <c>3</c>
          <c>-9</c>
          <c>array</c>
          <c>Other Primes Info</c>
          <c>r_i</c>
          <c>3</c>
          <c>-10</c>
          <c>bstr</c>
          <c>i-th factor, Prime Factor</c>
          <c>d_i</c>
          <c>3</c>
          <c>-11</c>
          <c>bstr</c>
          <c>i-th factor, Factor CRT Exponent</c>
          <c>t_i</c>
          <c>3</c>
          <c>-12</c>
          <c>bstr</c>
          <c>i-th factor, Factor CRT Coefficient</c>
        </texttable>
      </section>
    </section>

    <section anchor="iana-considerations" title="IANA Considerations">

      <section anchor="cose-algorithm-registry" title="COSE Algorithm Registry">
        <t>
	  This section registers values in the IANA "COSE Algorithm Registry" registry.
	</t>
        <t>
	  The values in <xref target="table-rsa-algs"/> are to be added to the registry.
	</t>
      </section>

      <section anchor="cose-key-parameter-registry" title="COSE Key Type Parameter Registry">
        <t>
	  This section registers values in the IANA "COSE Key Type Parameters" registry.
	</t>
        <t>
	  The values in <xref target="table-rsa-keys"/> are to be added to the registry.
	</t>
      </section>

    </section>

    <section anchor="Security" title="Security Considerations">
      <t>
	See the per-algorithm security considerations described in
	<xref target="RSASSA-PSS-considerations"/>
	and <xref target="RSAES-OAEP-considerations"/>.
      </t>
    </section>

  </middle>

  <back>
    <references title="Normative References">
      <?rfc include="http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"?>
      <?rfc include="http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.3447.xml"?>
      <?rfc include="http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.7049.xml"?>
      <?rfc include="http://xml2rfc.tools.ietf.org/public/rfc/bibxml3/reference.I-D.ietf-cose-msg"?>
    </references>

    <references title="Informative References">
      <reference anchor="MultiPrimeRSA"><front><title>On the Security of Multi-prime RSA</title><author initials="M. J." surname="Hinek"><organization>University of Waterloo</organization></author><author initials="D. R." surname="Cheriton"><organization>University of Waterloo</organization></author><date year="2006" month="June"/></front><format target="http://cacr.uwaterloo.ca/techreports/2006/cacr2006-16.pdf" type="PDF"/></reference>
    </references>

    <section title="Acknowledgements" anchor="Acknowledgements">
      <t>
	The initial version of this specification incorporates text from draft-ietf-cose-msg-05 by Jim Schaad.
      </t>
    </section>

    <section title="Document History" anchor="History">
      <t>
        [[ to be removed by the RFC Editor before publication as an RFC ]]
      </t>
      <t>
        -00
        <list style='symbols'>
          <t>
	    This specification addresses COSE issue #21: Restore RSA-PSS and the "RSA" key type.
            The initial version of this specification incorporates text from draft-ietf-cose-msg-05 --
	    the last COSE message specification version before the RSA algorithms were removed.
          </t>
        </list>
      </t>
    </section>

  </back>
</rfc>
