<?xml version="1.0"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
<!ENTITY RFC2119 PUBLIC '' 'http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml'>
<!ENTITY RFC3610 PUBLIC '' 'http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.3610.xml'>
<!ENTITY RFC3629 PUBLIC '' 'http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.3629.xml'>
<!ENTITY RFC4493 PUBLIC '' 'http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4493.xml'>
<!ENTITY RFC4868 PUBLIC '' 'http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4868.xml'>
<!ENTITY RFC4949 PUBLIC '' 'http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4949.xml'>
<!ENTITY RFC5297 PUBLIC '' 'http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5297.xml'>
<!ENTITY RFC7515 PUBLIC '' 'http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7515.xml'>
<!ENTITY RFC7516 PUBLIC '' 'http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7516.xml'>
<!ENTITY RFC7518 PUBLIC '' 'http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7518.xml'>
<!ENTITY RFC7519 PUBLIC '' 'http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7519.xml'>
]>

<?xml-stylesheet type='text/xsl' href='http://xml2rfc.tools.ietf.org/authoring/rfc2629.xslt' ?>
<?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-madden-jose-siv-mode-01">

    <front>

        <title>
            Synthetic IV (SIV) encryption modes for JWE
        </title>

        <author initials="N.E." surname="Madden" fullname="Neil Madden">
            <organization>ForgeRock</organization>
            <address>
                <postal>
                    <street>Broad Quay House</street>
                    <street>Prince Street</street>
                    <city>Bristol</city>
                    <code>BS1 4DJ</code>
                    <country>United Kingdom</country>
                </postal>
                <email>neil.madden@forgerock.com</email>
            </address>
        </author>

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

        <area>Security</area>
        <!-- <workgroup>JOSE Working Group</workgroup> - disbanded -->

        <keyword>RFC</keyword>
        <keyword>Request for Comments</keyword>
        <keyword>I-D</keyword>
        <keyword>Internet-Draft</keyword>
        <keyword>JavaScript Object Notation</keyword>
        <keyword>JSON</keyword>
        <keyword>JSON Object Signing and Encryption</keyword>
        <keyword>JOSE</keyword>
        <keyword>JSON Web Encryption</keyword>
        <keyword>JWE</keyword>
        <keyword>JSON Web Algorithms</keyword>
        <keyword>JWA</keyword>
        <keyword>Synthetic Initialization Vector</keyword>
        <keyword>Synthetic IV</keyword>
        <keyword>SIV</keyword>

        <abstract>
            <t>
                This document defines how to use Synthetic Initialization Vector (SIV)
                encryption and key-wrapping modes with JSON Web Encryption (JWE), and registers
                identifiers for SIV-based key-wrapping and content encryption algorithms. 
                SIV provides either deterministic authenticated encryption and key-wrapping,
                or nonce-based misuse-resistant authenticated encryption depending on usage.</t>
        </abstract>

    </front>

    <middle>

        <section anchor="intro" title="Introduction">
            <t>This specification registers cryptographic algorithms and identifiers to be used
                with JSON Web Encryption (JWE) <xref target="RFC7516" /> for key-wrapping, deterministic
                authenticated encryption and nonce-based misuse-resistant authenticated
                content encryption based on Synthetic Initialization Vectors (SIV, or &quot;Synthetic IV&quot;)
                <xref target="RFC5297"/>.
                SIV mode takes as input a key, the JWE Protected Header, an optional nonce (IV), and
                the plaintext payload, and produces a ciphertext having the same length as the
                plaintext and an authentication tag that also serves as the synthetic initialization
                vector. 
            </t>

            <t>This extends <xref target="RFC7518" />.</t>

            <section title="Requirements Terminology">
                <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
                    "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
                    interpreted as described in <xref target="RFC2119" />.</t>
            </section>


            <section title="Motivation">
                <t>The motivations from <xref target="RFC5297"/> apply here.</t>

                <t>Compared to the existing JWE AES Key Wrap algorithm <xref target="RFC7516"/> (Section 4.4), SIV
                    provides a provable security bound, and a more efficient construction. To wrap a 128-bit key,
                    AES Key Wrap requires 12 calls to the AES block cipher, while SIV (with CMAC and as described
                    in this specification) requires just 3.</t>
                
                <t>For Content Encryption with a nonce, SIV is typically slightly faster than AES_CBC_HMAC_SHA2 for
                    short messages and typically
                    slower than AES GCM.  However, while the security of AES GCM
                    collapses catastrophically if a key-nonce pair is reused <xref target="SP800-38D"/> (Appendix A), in
                    SIV an attacker would only learn whether the same plaintext (and the same associated data) has been
                    encrypted with the same key and
                    nonce. This property, known as nonce misuse resistance (NMR), provides a measure of safety in the
                    face of programming errors or poor quality nonce generation, such as misconfigured or compromised
                    random data generators, or accidental reuse due to logic errors in deterministic nonce
                    generation algorithms (for instance, reusing nonces after a restart).</t>

                <t>For randomly-generated IVs, AES-GCM can only safely encrypt less than 2^32 messages with the same
                    key, before the risk of an accidental repetition becomes too high <xref target="SP800-38D"/> (Section 8.3). This
                    limit can be easily reached in practice. For instance, an application producing JWE-encrypted tokens
                    at a rate of 1000 per second will need to rotate the key at most every 49 days. For SIV (and CBC)
                    this limit is around 2^48 (for short messages), which would allow the same application to keep using
                    one key for almost 9000 years.</t>

                <t>Where the content or associated data of a JWE is known to contain a non-repeating value or
                    key (such as a unique JWT ID <xref target="RFC7519"/>), then the nonce can be omitted, resulting in
                    a more compact serialisation. The nonce can also be omitted if deterministic authenticated
                    encryption is desired.</t>

                <t>For constrained devices, the abstract SIV scheme can be instantiated with AES in CTR
                    mode for confidentiality, and CMAC <xref target="RFC4493"/> for authentication. In this
                    instantiation the mode requires only an AES encryption circuit, providing similar benefits
                    (and comparable performance) to AES CCM mode <xref target="RFC3610"/>, but with the added robustness
                    of nonce misuse resistance. The NMR property is particularly attractive for devices that have
                    limited access to high-quality sources of entropy.</t>

                <t>Finally, SIV allows a single construction to be used for both authenticated content encryption
                    and key wrapping, and the construction itself is simple to describe and implement correctly
                    from standard building blocks.</t>

                <t>The main drawback of SIV is that it cannot be performed online as data is produced. The full data
                    must be processed to produce an authentication tag (and synthetic IV) before any part can be
                    encrypted. It is therefore most suitable for relatively short content such as JWTs <xref target="RFC7519"/>.
                    Once the authentication tag has been produced, CTR mode encryption is fast and can be
                    parallelised easily. Decryption can be performed online and in parallel.</t>
            </section>

            <section title="Notational Conventions">
                <t>BASE64URL(OCTETS) denotes the base64url encoding of OCTETS, per
                    Section 2 of <xref target="RFC7515"/>.</t>

                <t>UTF8(STRING) denotes the octets of the UTF-8 <xref target="RFC3629"/> representation
                    of STRING, where STRING is a sequence of zero or more Unicode
                    <xref target="UNICODE"/> characters.</t>

                <t>ASCII(STRING) denotes the octets of the ASCII <xref target="RFC20"/> representation
                    of STRING, where STRING is a sequence of zero or more ASCII
                    characters.</t>

                <t>The concatenation of two values A and B is denoted as A || B.</t>
            </section>
            <section title="Terminology" anchor="Terminology">

                <t>
                    These terms defined by the
                    JSON Web Signature (JWS) <xref target="RFC7515"/>
                    specification are incorporated into this specification:
                    "Base64url Encoding"
                </t>

                <t>
                    These terms defined by the
                    JSON Web Encryption (JWE) <xref target="RFC7516"/>
                    specification are incorporated into this specification:
                    "JSON Web Encryption (JWE)",
                    "Additional Authenticated Data (AAD)",
                    "Authentication Tag",
                    "Content Encryption Key (CEK)",
                    "JWE Authentication Tag",
                    "JWE Ciphertext",
                    "JWE Encrypted Key",
                    "JWE Initialization Vector",
                    "JWE Protected Header",
                    and "Key Wrapping".
                </t>

                <t>
                    These terms defined by the
                    <xref target="RFC4949">Internet Security Glossary, Version 2</xref>
                    are incorporated into this specification:
                    "Ciphertext",
                    "Message Authentication Code (MAC)",
                    and "Plaintext".
                </t>

            </section>

        </section>

        <section anchor="algorithms" title="Algorithms">
            <section anchor="genericsiv" title="Generic SIV Construction">
                <t>This section defines a family of authenticated encryption algorithms built using a
                    combination of AES in Counter (CTR) mode and either CMAC or HMAC-SHA2 operations. The
                    presentation here is based on the abstract SIV scheme in Section 4 of <xref target="SIV"/>.
                    The generic construction is parameterised by the size of the key and the instantiation of the MAC
                    algorithm. We use MAC(K, M) to denote the application of the MAC algorithm to the given message M
                    using the given key K. We use AES-CTR(K, IV, M) to denote the application of AES in CTR mode to the
                    message M, using the key K and Initialization Vector IV.
                </t>
                <t>
                    Rather than adopting the S2V construction of <xref target="RFC5297"/> for providing multiple Additional
                    Authentication Data (AAD) blocks to the MAC, we instead adopt a simpler method 
                    based on the base64url-encoded compact serialisation of the JWE Protected Header and IV separated by
                    dots, and the unencoded plaintext octets. This encoding uniquely determines the components of the AAD
                    while being simpler, and uses encoded components that are already produced if the Compact Serialization
                    is being used. As stated in Section 5 of <xref target="SIV"/>, the motivation for the S2V construction is 
                    efficiency rather than security, and any unambiguous encoding will suffice. It is expected that
                    a simpler construction will aid adoption of these safer encryption modes in situations where performance
                    is not of paramount importance.
                </t>

                <t><cref source="N. Madden">There is an I-D defining an AES-GCM-SIV mode currently in progress 
                    (https://tools.ietf.org/html/draft-irtf-cfrg-gcmsiv-05). This is a much more high-performance SIV mode
                    than the ones defined in this document. I have left it out of this specification because it is more
                    complex to implement and still in draft form. A further I-D/RFC could be proposed to also add that mode
                    for in this same framework, but I believe the modes defined in the present I-D will be useful for
                    many years to come, especially on constrained devices.</cref>
                </t>

                <t>For the CMAC-based algorithms, we only define modes for an overall 128-bit security level. That is, the
                    expected effort for an attacker to either produce an authentication tag forgery, recover either
                    the encryption or MAC keys, or to compromise the privacy of a any SIV-encrypted JWE, is on the order of 2^128
                    operations.  For the HMAC-based algorithms we define modes at overall 128-bit, 192-bit and 256-bit 
                    security levels. The reason for this is that AES-CMAC is only capable of producing a maximum authentication
                    tag of 128 bits and so cannot provide more than 128 bits of protection against authentication tag forgery.
                </t>

                <section anchor="encryption" title="Encryption">
                    <t>The authenticated encryption algorithm takes as input for octet strings: a secret key K, a plaintext P,
                        additional authenticated data AAD (computed as per Steps 13-14 of Section 5.1 of <xref target="RFC7516"/>), 
                        and an optional initialization vector IV. It produces the
                        ciphertext value E and an authentication tag T as outputs. The data in the plaintext are encrypted, and
                        the additional authenticated data are authenticated, but not encrypted.</t>
                    <t>Encryption is performed using the following steps:
                        <list style="numbers">
                            <t>The secondary keys MAC_KEY and ENC_KEY are generated from the
                                input key K as follows. Each of these two keys is an octet string.
                                <list style="empty">
                                    <t>MAC_KEY consists of the initial MAC_KEY_LEN octets of K, in order.</t>
                                    <t>ENC_KEY consists of the final ENC_KEY_LEN octets of K, in order.</t>
                                </list>
                                The number of octets in the input key K MUST be the sum of MAC_KEY_LEN and ENC_KEY_LEN.</t>
                            <t>If a nonce is to be used, then the IV SHOULD be a 128-bit value generated randomly
                                or pseudorandomly.</t>
                            <t>A message Authentication Tag T is computed as:
                                <list style="empty"><t>T = MAC(MAC_KEY, ASCII(AAD || '.' || BASE64URL(IV) || '.') || plaintext).</t></list>
                                If no IV (nonce) is being used, then an empty octet sequence MUST be used instead.</t>
                            <t>The Synthetic IV, SIV, is set to the first 16 octets of T, in order.</t>
                            <t>The plaintext is encrypted using AES-CTR with ENC_KEY as the key and SIV as the IV. We denote the ciphertext
                                output of this step as E.</t>
                            <t>The ciphertext E and the Authentication Tag T are returned as the outputs of the authenticated encryption.</t>
                    </list></t>
                    <t>The encryption process can be illustrated as follows. Here K, P, AAD, IV, SIV, T, and E denote the key,
                        plaintext, Additional Authenticated Data, Initialization Vector, Synthetic IV, Authentication Tag, and ciphertext, respectively.
                        <list>
                            <t>MAC_KEY = initial MAC_KEY_LEN octets of K,</t>
                            <t>ENC_KEY = final ENC_KEY_LEN octets of K,</t>
                            <t>T = MAC(MAC_KEY, ASCII(AAD || '.' || BASE64URL(IV) || '.') || P),</t>
                            <t>SIV = initial 16 octets of T,</t>
                            <t>E = AES-CTR(ENC_KEY, SIV, P).</t>
                    </list></t>
                </section>

                <section anchor="decryption" title="Decryption">
                    <t>Decryption is performed using the following steps:</t>
                    <t><list style="numbers">
                            <t>The secondary keys MAC_KEY and ENC_KEY are generated from the input key K as in Step 1 of <xref target="encryption"/>.</t>
                            <t>The Synthetic IV is set to the first 16 octets of the Authentication Tag T. If the Authentication Tag is missing or
                                not of the expected length for the algorithm (which is always at least 16 octets) then decryption MUST halt 
                                with an indication of failure.</t>
                            <t>The plaintext P is decrypted using AES-CTR with ENC_KEY as the key, SIV as the IV, and the ciphertext, E.</t>
                            <t>The Authentication Tag T is checked by recomputing the tag T' as in Step 3 of <xref target="encryption"/>. If T and T' are
                                identical then H and P are considered valid and processing is continued. Otherwise, all of the data used
                                in the MAC computation MUST be discarded and the decryption operation MUST halt with an indication of failure.
                                Tag comparison MUST use a constant-time octet string comparison operation using the known length of the 
                                Authentication Tag as specified by the algorithm in use.</t>
                            <t>The plaintext P is returned.</t>
                    </list></t>
                </section>

            </section>
            <section anchor="keywrap" title="SIV Key Wrapping">
                <t>The following JWE algorithms are defined here (to be applied as values of "alg" parameter):</t>

                <texttable>
                    <ttcol align="left" width="13%">"alg" Param Value</ttcol>
                    <ttcol align="left">Key Management Algorithm</ttcol>

                    <c>A128SIVKW</c>
                    <c>AES SIV Key Wrap using CMAC and 256 bit key.</c>

                    <c>A128SIVKW-HS256</c>
                    <c>AES SIV Key Wrap using HMAC-SHA-256-128 and 256 bit key.</c>

                    <c>A192SIVKW-HS384</c>
                    <c>AES SIV Key Wrap using HMAC-SHA-384-192 and 384 bit key.</c>

                    <c>A256SIVKW-HS512</c>
                    <c>AES SIV Key Wrap using HMAC-SHA-512-256 and 512 bit key.</c>
                </texttable>

                <t>All of the key wrapping modes use the generic construction from <xref target="genericsiv"/>,
                    with the following inputs:
                    <list>
                        <t>The plaintext P is the octets of the Content Encryption Key (CEK) to be wrapped.</t>
                        <t>The input key K is the Key Encryption Key (KEK).</t>
                        <t>The IV is an empty octet sequence.</t>
                        <t>The AAD is the UTF8 octets of the value of the "alg" parameter (e.g., &quot;A128SIVKW&quot;).</t>
                    </list>
                </t>

                <t>In all cases the output ciphertext length will be the same as the input plaintext CEK, in octets. The authentication
                    tag will either be 16, 24 or 32 octets long depending on the algorithm.
                </t>

                <t>The JWE Encrypted Key value is the Ciphertext output.</t>

                <t>The Authentication Tag output is represented in base64url encoded form
                    as the <spanx style="verb">tag</spanx> (authentication tag) Header
                    Parameter value, as in Section 4.7.1.2 of <xref target="RFC7518"/>. This
                    specification extends that header value to allow authentication tags of 192
                    or 256 bits. NB: this has the added advantage of binding the wrapped key
                    into the JWE authenticated data, which would otherwise not happen.</t>

                <section anchor="A128SIVKW" title="A128SIVKW">
                    <t>This algorithm uses the CMAC message authentication
                        code <xref target="RFC4493"/> to provide message authentication and
                        the synthetic IV.</t>
                    <t>The parameters are as follows:
                        <list>
                            <t>The input key K is 32 octets long.</t>
                            <t>MAC_KEY_LEN is 16 octets.</t>
                            <t>ENC_KEY_LEN is 16 octets.</t>
                            <t>MAC is CMAC.</t>
                            <t>The output tag length is 16 octets.</t>
                        </list>
                    </t>
                </section>

                <section anchor="A128SIVKW-HS256" title="A128SIVKW-HS256">
                    <t>This algorithm uses the HMAC-SHA-256-128 message authentication code as defined
                        in <xref target="RFC4868"/> to provide message authentication and the synthetic IV.</t>
                    <t>The parameters are as follows:
                        <list>
                            <t>The input key K is 32 octets long.</t>
                            <t>MAC_KEY_LEN is 16 octets.</t>
                            <t>ENC_KEY_LEN is 16 octets.</t>
                            <t>MAC is HMAC-SHA-256-128.</t>
                            <t>The output tag length is 16 octets.</t>
                        </list>
                    </t>
                </section>

                <section anchor="A192SIVKW-HS384" title="A192SIVKW-HS384">
                    <t>This algorithm uses the HMAC-SHA-384-192 message authentication code as defined
                        in <xref target="RFC4868"/> to provide message authentication and the synthetic IV.</t>
                    <t>The parameters are as follows:
                        <list>
                            <t>The input key K is 48 octets long.</t>
                            <t>MAC_KEY_LEN is 24 octets.</t>
                            <t>ENC_KEY_LEN is 24 octets.</t>
                            <t>MAC is HMAC-SHA-384-192.</t>
                            <t>The output tag length is 24 octets.</t>
                        </list>
                    </t>
                </section>

                <section anchor="A256SIVKW-HS512" title="A256SIVKW-HS512">
                    <t>This algorithm uses the HMAC-SHA-512-256 message authentication code as defined
                        in <xref target="RFC4868"/> to provide message authentication and the synthetic IV.</t>
                    <t>The parameters are as follows:
                        <list>
                            <t>The input key K is 64 octets long.</t>
                            <t>MAC_KEY_LEN is 32 octets.</t>
                            <t>ENC_KEY_LEN is 32 octets.</t>
                            <t>MAC is HMAC-SHA-512-256.</t>
                            <t>The output tag length is 32 octets.</t>
                        </list>
                    </t>
                </section>
            </section>

            <section anchor="contentenc" title="SIV Content Encryption">
                <t>The following content encryption methods are defined here (to be applied as values of
                    the "enc" parameter):</t>
                <texttable>
                    <ttcol align="left" width="13%">"enc" Param Value</ttcol>
                    <ttcol align="left">Content Encryption Method</ttcol>

                    <c>A128SIV</c>
                    <c>AES SIV using CMAC and 256 bit key.</c>

                    <c>A128SIV-HS256</c>
                    <c>AES SIV using HMAC-SHA-256-128 and 256 bit key.</c>

                    <c>A192SIV-HS384</c>
                    <c>AES SIV using HMAC-SHA-384-192 and 384 bit key.</c>

                    <c>A256SIV-HS512</c>
                    <c>AES SIV using HMAC-SHA-512-256 and 512 bit key.</c>
                </texttable>

                <t>All of the SIV content encryption methods use the generic construction from <xref target="genericsiv"/>,
                    with the following inputs:
                    <list>
                        <t>The plaintext P is the octets of JWE plaintext.</t>
                        <t>The input key K is the Content Encryption Key (CEK).</t>
                        <t>The IV is either a randomly or pseudorandomly generated 16 octet value, or an empty octet string.</t>
                        <t>The AAD is the UTF8 octets of the JWE Protected Header.</t>
                    </list>
                </t>

                <t>In all cases the output ciphertext length will be the same as the input plaintext, in octets. The authentication
                    tag will either be 16, 24 or 32 octets long depending on the algorithm. The Ciphertext and Authentication Tag
                    outputs become the JWE Ciphertext and JWE Authentication Tag values respectively.
                </t>

                <section anchor="A128SIV" title="A128SIV">
                    <t>This algorithm uses the CMAC message authentication
                        code <xref target="RFC4493"/> to provide message authentication and
                        the synthetic IV.</t>
                    <t>The parameters are as follows:
                        <list>
                            <t>The input key K is 32 octets long.</t>
                            <t>MAC_KEY_LEN is 16 octets.</t>
                            <t>ENC_KEY_LEN is 16 octets.</t>
                            <t>MAC is CMAC.</t>
                            <t>The output tag length is 16 octets.</t>
                        </list>
                    </t>
                </section>

                <section anchor="A128SIV-HS256" title="A128SIV-HS256">
                    <t>This algorithm uses the HMAC-SHA-256-128 message authentication code as defined
                        in <xref target="RFC4868"/> to provide message authentication and the synthetic IV.</t>
                    <t>The parameters are as follows:
                        <list>
                            <t>The input key K is 32 octets long.</t>
                            <t>MAC_KEY_LEN is 16 octets.</t>
                            <t>ENC_KEY_LEN is 16 octets.</t>
                            <t>MAC is HMAC-SHA-256-128.</t>
                            <t>The output tag length is 16 octets.</t>
                        </list>
                    </t>
                </section>

                <section anchor="A192SIV-HS384" title="A192SIV-HS384">
                    <t>This algorithm uses the HMAC-SHA-384-192 message authentication code as defined
                        in <xref target="RFC4868"/> to provide message authentication and the synthetic IV.</t>
                    <t>The parameters are as follows:
                        <list>
                            <t>The input key K is 48 octets long.</t>
                            <t>MAC_KEY_LEN is 24 octets.</t>
                            <t>ENC_KEY_LEN is 24 octets.</t>
                            <t>MAC is HMAC-SHA-384-192.</t>
                            <t>The output tag length is 24 octets.</t>
                        </list>
                    </t>
                </section>

                <section anchor="A256SIV-HS512" title="A256SIV-HS512">
                    <t>This algorithm uses the HMAC-SHA-512-256 message authentication code as defined
                        in <xref target="RFC4868"/> to provide message authentication and the synthetic IV.</t>
                    <t>The parameters are as follows:
                        <list>
                            <t>The input key K is 64 octets long.</t>
                            <t>MAC_KEY_LEN is 32 octets.</t>
                            <t>ENC_KEY_LEN is 32 octets.</t>
                            <t>MAC is HMAC-SHA-512-256.</t>
                            <t>The output tag length is 32 octets.</t>
                        </list>
                    </t>
                </section>
            </section>
        </section>

        <section anchor="IANA" title="IANA considerations">
            <?rfc subcompact="yes" ?>
            <t>The following are added to JSON Web Signature and Encryption Algorithms registry:</t>
            <t><list style="symbols">
                    <t>Algorithm Name: "A128SIVKW"</t>
                    <t>Algorithm Description: AES SIV Key Wrap with CMAC using 256 bit key</t>
                    <t>Algorithm Usage Location(s): "alg"</t>
                    <t>JOSE Implementation Requirements: Recommended</t>
                    <t>Change Controller: IESG</t>
                    <t>Specification Document(s): <xref target="A128SIVKW"/></t>
            </list><vspace blankLines="1" /></t>
            <t><list style="symbols">
                    <t>Algorithm Name: "A128SIVKW-HS256"</t>
                    <t>Algorithm Description: AES SIV Key Wrap with HMAC-SHA-256-128 using 256 bit key</t>
                    <t>Algorithm Usage Location(s): "alg"</t>
                    <t>JOSE Implementation Requirements: Recommended</t>
                    <t>Change Controller: IESG</t>
                    <t>Specification Document(s): <xref target="A128SIVKW-HS256"/></t>
            </list><vspace blankLines="1" /></t>
            <t><list style="symbols">
                    <t>Algorithm Name: "A192SIVKW-HS384"</t>
                    <t>Algorithm Description: AES SIV Key Wrap with HMAC-SHA-384-192 using 384 bit key</t>
                    <t>Algorithm Usage Location(s): "alg"</t>
                    <t>JOSE Implementation Requirements: Optional</t>
                    <t>Change Controller: IESG</t>
                    <t>Specification Document(s): <xref target="A192SIVKW-HS384"/></t>
            </list><vspace blankLines="1" /></t>
            <t><list style="symbols">
                    <t>Algorithm Name: "A256SIVKW-HS512"</t>
                    <t>Algorithm Description: AES SIV Key Wrap with HMAC-SHA-512-256 using 512 bit key</t>
                    <t>Algorithm Usage Location(s): "alg"</t>
                    <t>JOSE Implementation Requirements: Optional</t>
                    <t>Change Controller: IESG</t>
                    <t>Specification Document(s): <xref target="A256SIVKW-HS512"/></t>
            </list><vspace blankLines="1" /></t>
            <t><list style="symbols">
                    <t>Algorithm Name: "A128SIV"</t>
                    <t>Algorithm Description: AES SIV with CMAC using 256 bit key</t>
                    <t>Algorithm Usage Location(s): "enc"</t>
                    <t>JOSE Implementation Requirements: Recommended</t>
                    <t>Change Controller: IESG</t>
                    <t>Specification Document(s): <xref target="A128SIV"/></t>
            </list><vspace blankLines="1" /></t>
            <t><list style="symbols">
                    <t>Algorithm Name: "A128SIV-HS256"</t>
                    <t>Algorithm Description: AES SIV with HMAC-SHA-256-128 using 256 bit key</t>
                    <t>Algorithm Usage Location(s): "enc"</t>
                    <t>JOSE Implementation Requirements: Recommended</t>
                    <t>Change Controller: IESG</t>
                    <t>Specification Document(s): <xref target="A128SIV-HS256"/></t>
            </list><vspace blankLines="1" /></t>
            <t><list style="symbols">
                    <t>Algorithm Name: "A192SIV-HS284"</t>
                    <t>Algorithm Description: AES SIV with HMAC-SHA-384-192 using 384 bit key</t>
                    <t>Algorithm Usage Location(s): "enc"</t>
                    <t>JOSE Implementation Requirements: Optional</t>
                    <t>Change Controller: IESG</t>
                    <t>Specification Document(s): <xref target="A192SIV-HS384"/></t>
            </list><vspace blankLines="1" /></t>
            <t><list style="symbols">
                    <t>Algorithm Name: "A256SIV-HS512"</t>
                    <t>Algorithm Description: AES SIV with HMAC-SHA-512-256 using 512 bit key</t>
                    <t>Algorithm Usage Location(s): "enc"</t>
                    <t>JOSE Implementation Requirements: Optional</t>
                    <t>Change Controller: IESG</t>
                    <t>Specification Document(s): <xref target="A256SIV-HS512"/></t>
            </list><vspace blankLines="1" /></t>
            <?rfc subcompact="no" ?>
        </section>

        <section anchor="security" title="Security Considerations">
            <t>The security considerations of <xref target="RFC5297"/> apply here.</t>
            <t>
                In total, no more than 16 * 2^48 octets of data (approx. 4 exabytes) should be encrypted with the same key 
                in any SIV mode. For example, when using SIV128KW to wrap 128-bit keys, then no more than 2^48 messages should
                be encrypted with the same key encryption key (KEK). This is over 281 trillion messages, so is expected
                to provide sufficient capacity for extremely long-lived or high-usage keys.
            </t>
            <t>
                SIV uses AES in CTR mode for encryption, which produces ciphertexts that are exactly the same length as the
                plaintext. If the length of the plaintext is sensitive (for instance, when encrypting a password that may be
                short) then the application should pad such values to some minimum/fixed size before encryption. If such
                padding is performed, then it MUST be applied before calling the AES-SIV encryption modes defined in this
                specification, so that the padding is included in the authentication tag. When decrypting, authentication
                tag validation in Step 4 of <xref target="decryption"/> MUST be performed before any validation or processing
                of the padding is performed.
            </t>
            <t>
                Care should be taken when combining JWE plaintext compression with SIV encryption for a related reason: compression
                varies the size of the plaintext based on the (confidential) content of that plaintext. In SIV mode (and other
                cipher modes, such as GCM and, to a lesser extent, CBC), this will vary the size of the ciphertext by
                the same amount. If an attacker is able to control any part of the content of the plaintext then they
                may be able to infer confidential parts of the same plaintext according to variations in the size of the
                compressed and encrypted ciphertext. It is therefore recommended not to use compression with SIV mode
                encryption (or any encryption) unless the expected information leakage is acceptable.
            </t>
        </section>

    </middle>
    <back>
        <references title="Normative References">
            &RFC2119;
            &RFC3629;
            &RFC4868;
            &RFC7515;
            &RFC7516;
            &RFC7518;

            <reference anchor="RFC20">
                <front>
                    <title>ASCII format for Network Interchange</title>
                    <author fullname="Vint Cerf" surname="Cerf" initials="V.">
                        <organization>University California Los Angeles (UCLA)</organization>
                    </author>
                    <date month="October" day="16" year="1969"/>
                    <abstract><t>For concreteness, we suggest the use of standard 7-bit ASCII embedded in an 8 bit byte whose high order bit is always 0.</t></abstract>
                </front>
                <seriesInfo value="20" name="RFC"/>
                <format target="http://www.rfc-editor.org/rfc/rfc20.txt" octets="18504" type="TXT"/>
            </reference>

           
  </references>

  <references title="Informative References">
      &RFC3610;
      &RFC4493;
      &RFC4949;
      &RFC5297;
      &RFC7519;
      <reference anchor="SIV">
          <front>
              <title>Deterministic Authenticated-Encryption. A Provable-Security Treatment of the Key-Wrap Problem.</title>
              <author surname="Rogaway" initials="P.">
                  <organization>University of California at Davis</organization>
              </author>
              <author surname="Shrimpton" initials="T.">
                  <organization>Portland State University</organization>
              </author>
              <date month="August" day="20" year="2007"/>
          </front>
          <seriesInfo name="IACR" value="ePrint 2006/221"/>
          <format target="https://eprint.iacr.org/2006/221.pdf" type="PDF" />
      </reference>
      <reference anchor="UNICODE" target="http://www.unicode.org/versions/latest/">
                <front>
                    <title abbrev="Unicode">The Unicode Standard</title>
                    <author>
                        <organization>The Unicode Consortium</organization>
                        <address />
                    </author>
                    <date year="1991-"/>
                </front>
                <!--
        <annotation>
          Note that this reference is to the latest version of Unicode,
          rather than to a specific release.  It is not expected that future changes in
          the UNICODE specification will impact the syntax of JSON or the UTF-8 encoding.
        </annotation>
        -->
      </reference>


      <reference anchor="SP800-38D">
          <front>
              <title>Recommendation for Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC.</title>
              <author surname="Dworkin" initials="M.">
                  <organization>NIST</organization>
              </author>
              <date month="November" year="2007"/>
          </front>
          <seriesInfo name="NIST Special Publication" value="800-38D"/>
          <format target="http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf" type="PDF"/>
      </reference>

  </references>

  <section anchor="TestCases" title="Test Cases">
      <t>
          The following test cases can be used to validate implementations of
          the AES SIV algorithms defined in this specification.
      </t>

      <t>
          The variable names are those defined in <xref target="encryption"/>.
          All values are hexadecimal.
      </t>

      <section title="Test Cases for A128SIVKW" anchor="A128SIVKW_TestCases">
          <t>NB: K here is the KEK, and P is the CEK to be wrapped, T is the output "tag" value, and E is the wrapped CEK.</t>
          <figure>
              <artwork><![CDATA[
A128SIVKW

  K =       00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
            10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f

  MAC_KEY = 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f

  ENC_KEY = 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f

  P =       0f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00

  IV =      <empty octet sequence>

  AAD =     41 31 32 38 53 49 56 4b 57

  T =       c3 eb 04 f1 c7 07 8b 92 e0 dc f6 fe 17 f5 82 46

  SIV =     c3 eb 04 f1 c7 07 8b 92 e0 dc f6 fe 17 f5 82 46

  E =       ef 96 fd 87 24 ea f9 9b 54 15 8a fa 20 5f 77 de

  ]]>
  </artwork>
  </figure>
      </section>

      <section title="Test Cases for A192SIVKW-HS384" anchor="A192SIVKW-HS384_TestCases">
          <t>NB: K here is the KEK, and P is the CEK to be wrapped, T is the output "tag" value, and E is the wrapped CEK.</t>
          <figure>
              <artwork><![CDATA[
A192SIVKW-HS384

  K =       00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
            10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
            20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f

  MAC_KEY = 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
            10 11 12 13 14 15 16 17

  ENC_KEY = 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27
            28 29 2a 2b 2c 2d 2e 2f

  P =       17 16 15 14 13 12 11 10 0f 0e 0d 0c 0b 0a 09 08
            07 06 05 04 03 02 01 00

  IV =      <empty octet sequence>

  AAD =     41 31 39 32 53 49 56 4b 57 2d 48 53 33 38 34

  T =       27 86 b6 03 3b b1 4f f7 cb 85 6d ae 69 6e 3d 98 
            ff e2 0b 59 77 b3 e5 36 

  SIV =     c3 eb 04 f1 c7 07 8b 92 e0 dc f6 fe 17 f5 82 46

  E =       65 c5 52 72 4e d3 4f 9e ab 20 32 4d af 0d 2d 31 
            7f df 69 13 06 c5 0a c8 
  ]]>
  </artwork>
  </figure>
      </section>

      <section title="Test Cases for A128SIV-HS256" anchor="A128SIV-HS256_TestCases">
          <figure>
              <artwork><![CDATA[
A128SIV-HS256

  K =       00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
            10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f

  MAC_KEY = 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f

  ENC_KEY = 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f

  P =       41 20 63 69 70 68 65 72 20 73 79 73 74 65 6d 20
            6d 75 73 74 20 6e 6f 74 20 62 65 20 72 65 71 75
            69 72 65 64 20 74 6f 20 62 65 20 73 65 63 72 65
            74 2c 20 61 6e 64 20 69 74 20 6d 75 73 74 20 62
            65 20 61 62 6c 65 20 74 6f 20 66 61 6c 6c 20 69
            6e 74 6f 20 74 68 65 20 68 61 6e 64 73 20 6f 66
            20 74 68 65 20 65 6e 65 6d 79 20 77 69 74 68 6f
            75 74 20 69 6e 63 6f 6e 76 65 6e 69 65 6e 63 65

  IV =      1a f3 8c 2d c2 b9 6f fd d8 66 94 09 23 41 bc 04

  AAD =     7b 22 61 6c 67 22 3a 22 64 69 72 22 2c 22 65 6e 
            63 22 3a 22 41 31 32 38 53 49 56 2d 48 53 32 35 
            36 22 7d

  T =       5e cd e7 ca 4a eb 39 bc 05 11 2b a9 00 17 a3 76 

  SIV =     5e cd e7 ca 4a eb 39 bc 05 11 2b a9 00 17 a3 76

  E =       22 70 54 15 99 71 ca d6 01 8c d9 30 29 e6 e5 20
            5d 0a d3 d2 1e 8c 10 ce 6f 84 36 e3 68 20 24 42 
            59 e8 ae bd 55 16 ce 37 ab 5a 44 3b 22 0a 94 a0
            03 7f 4a ad 4d 11 57 db 55 cb 6a 01 70 8b 05 0d
            6f 39 ad b4 d8 3b 5c 77 ac 16 6a 98 cc 0e 0a 75
            93 f6 34 6e 67 b1 9d 4c 43 17 11 95 7b b5 e3 8b
            ee cb df 2e 7f 49 c0 ba c3 58 5b 90 32 b4 bc ca
            08 6b 51 a8 c5 d3 81 a7 fd d8 c3 fb 99 6e 25 46 

  ]]>
  </artwork>
  </figure>
      </section>

      <section title="Test Cases for A256SIV-HS512" anchor="A256SIV-HS512_TestCases">
          <figure>
              <artwork><![CDATA[
A256SIV-HS512

  K =       00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
            10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
            20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
            30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f

  MAC_KEY = 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
            10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f

  ENC_KEY = 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
            30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f

  P =       41 20 63 69 70 68 65 72 20 73 79 73 74 65 6d 20
            6d 75 73 74 20 6e 6f 74 20 62 65 20 72 65 71 75
            69 72 65 64 20 74 6f 20 62 65 20 73 65 63 72 65
            74 2c 20 61 6e 64 20 69 74 20 6d 75 73 74 20 62
            65 20 61 62 6c 65 20 74 6f 20 66 61 6c 6c 20 69
            6e 74 6f 20 74 68 65 20 68 61 6e 64 73 20 6f 66
            20 74 68 65 20 65 6e 65 6d 79 20 77 69 74 68 6f
            75 74 20 69 6e 63 6f 6e 76 65 6e 69 65 6e 63 65

  IV =      1a f3 8c 2d c2 b9 6f fd d8 66 94 09 23 41 bc 04

  AAD =     7b 22 61 6c 67 22 3a 22 64 69 72 22 2c 22 65 6e 
            63 22 3a 22 41 32 35 36 53 49 56 2d 48 53 35 31 
            32 22 7d

  T =       f9 e5 2d 5c 58 9d 3a f8 3f 98 3f ce 3b 98 aa ae 
            97 aa 0c 02 e1 80 a4 ec a3 0b 5e 7b 47 97 a5 b2 

  SIV =     f9 e5 2d 5c 58 9d 3a f8 3f 98 3f ce 3b 98 aa ae

  E =       cc 05 71 16 ad 3d 44 9b 50 ba 7b bd b4 42 f7 08
            20 fe bc d0 58 0e 8d 4d e0 f3 61 70 6b db b6 17
            a6 d6 a9 56 e5 69 cc 74 d3 16 7d 2c a2 a6 54 2e
            e7 69 64 9c db 4d 9b 68 b7 01 74 f8 a4 4e eb 9e
            a0 26 8a 3c 48 e9 c8 88 56 c4 2c eb 36 95 d2 90
            39 18 34 5d d2 f8 17 20 bb ce be 24 bf f1 74 68
            26 bb c9 c8 11 92 9d 45 ce dd 63 49 2d ed b6 c0
            b2 b5 bd c4 93 a6 0f e6 c7 c6 e7 fd 94 90 3d 03 
  ]]>
  </artwork>
  </figure>
      </section>
  </section>
    </back>
</rfc>
