<?xml version="1.0"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
<!ENTITY RFC2246 SYSTEM 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2246.xml'>
<!ENTITY RFC4346 SYSTEM 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4346.xml'>
<!ENTITY RFC5246 SYSTEM 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5246.xml'>
<!ENTITY RFC4347 SYSTEM 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4347.xml'>
<!ENTITY RFC6347 SYSTEM 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.6347.xml'>
<!ENTITY RFC4492 SYSTEM 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4492.xml'>
<!ENTITY RFC5489 SYSTEM 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5489.xml'>
<!ENTITY RFC5116 SYSTEM 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5116.xml'>
<!ENTITY RFC6101 SYSTEM 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.6101.xml'>
<!ENTITY RFC6234 SYSTEM 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.6234.xml'>
<!-- <!ENTITY CHACHAVECTORS SYSTEM 'http://xml.resource.org/public/rfc/bibxml-ids/reference.I-D.draft-strombergson-chacha-test-vectors-00.xml'>-->
]>

<?rfc compact="no"?>
<?rfc toc="yes"?>
<?rfc symrefs="yes"?>

<rfc category="std" ipr="trust200902"
    updates="5246, 6347"  docName="draft-mavrogiannopoulos-chacha-tls-01">

  <front>

    <title abbrev="chacha-tls">
      The ChaCha Stream Cipher for Transport Layer Security
    </title>

    <author initials="A." surname="Langley" fullname="Adam Langley">
      <organization>Google Inc</organization>
      <address>
        <email>agl@google.com</email>
      </address>
    </author>

    <author initials="W." surname="Chang" fullname="Wan-Teh Chang">
      <organization>Google Inc</organization>
      <address>
        <email>wtc@google.com</email>
      </address>
    </author>

    <author initials="N." surname="Mavrogiannopoulos"
            fullname="Nikos Mavrogiannopoulos">
      <organization>Red Hat</organization>
      <address>
        <email>nmav@redhat.com</email>
      </address>
    </author>

    <author initials="J." surname="Strombergson"
            fullname="Joachim Strombergson">
      <organization>Secworks Sweden AB</organization>
      <address>
        <email>joachim@secworks.se</email>
        <uri>http://secworks.se/</uri>
      </address>
    </author>

    <author initials="S." surname="Josefsson"
           fullname="Simon Josefsson">
      <organization>SJD AB</organization>
      <address>
        <email>simon@josefsson.org</email>
        <uri>http://josefsson.org/</uri>
      </address>
    </author>


    <date month="January" year="2014"/>

    <abstract>

      <t>This document describes the use of the ChaCha stream cipher with
      HMAC-SHA1 and Poly1305 in Transport Layer Security (TLS) and Datagram
      Transport Layer Security (DTLS) protocols.</t>

    </abstract>
    
  </front>

  <middle>

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

      <t>This document describes the use of the ChaCha stream cipher
      in the Transport Layer Security (TLS) version 1.0 <xref
      target="RFC2246"/>, TLS version 1.1 <xref target="RFC4346"/>,
      and TLS version 1.2 <xref target="RFC5246"/> protocols, as well
      as in the Datagram Transport Layer Security (DTLS) versions 1.0
      <xref target="RFC4347"/> and 1.2 <xref target="RFC6347"/>.  It
      can also be used with Secure Sockets Layer (SSL) version 3.0
      <xref target="RFC6101"/>.</t>

      <t><xref target="CHACHA">ChaCha</xref> is a stream cipher
      that has been designed for high performance in software
      implementations. The cipher has compact implementation and uses
      few resources and inexpensive operations that makes it suitable
      for implementation on a wide range of architectures. It 
      has been designed to prevent leakage of information through side 
      channel analysis, has a simple and fast key setup and provides
      good overall performance.
      It is a variant of Salsa20 <xref target="SALSA20SPEC"/> which is
      one of the selected ciphers in the eSTREAM
      portfolio <xref target="ESTREAM"/>.</t>

      <t>Recent attacks <xref target="CBC-ATTACK"/> have indicated
      problems with CBC-mode cipher suites in TLS and DTLS as well as
      issues with the only supported stream cipher (RC4) <xref
      target="RC4-ATTACK"/>.  While the existing AEAD (AES-GCM) ciphersuites 
      address some of these issues, concerns about the performance and ease of software
      implementation are sometimes raised.
<!--      Moreover, the DTLS protocol cannot take advantage of the only
      available stream cipher (RC4) because it does not provide random access 
      in the key stream.-->
      </t>
      
      <t>Therefore, a new stream cipher to replace RC4 and address all the
      previous issues is needed. It is the purpose of this document to describe
      a secure stream cipher for both TLS and DTLS that is comparable to RC4 in
      speed on a wide range of platforms and can be implemented easily
      without being vulnerable to software side-channel attacks.</t>
    </section>

    <section anchor="chacha20cipher"
	     title="The ChaCha Cipher">

      <t>
      <xref target="CHACHA">ChaCha</xref> is a stream cipher developed by D. J. Bernstein
      in 2008. It is a refinement of Salsa20 and was used as the core of the SHA-3 finalist, BLAKE.
      </t>

      <t>The variant of ChaCha used in this document is
      ChaCha with 20 rounds and a 256 bit key, which will
      be referred to as ChaCha20 in the rest of this document.
      This is the conservative variant (with respect to security) of 
      the ChaCha family. 
      </t>

      <t>
        ChaCha maps 16, 32-bit input words to 16, 32-bit output words. By convention, 8 of 
        the input words consist of a 256-bit key, 4 are constants and the remaining four are 
        a nonce and block counter. The output words are converted to bytes and XORed with the
        plaintext to produce ciphertext. In order to generate sufficient output bytes to XOR 
        with the whole plaintext, the block counter is incremented and ChaCha is run again, 
        as many times as needed, for up to 2^70 bytes of output.
      </t>

      <t>
        ChaCha operates on a state of 16, 32-bit words which are initialised from the input 
        words. The first four input words are constants: 
      <figure>
	<artwork><![CDATA[
          (0x61707865, 0x3320646e, 0x79622d32, 0x6b206574)
]]></artwork>
      </figure>
        Input words 4 through 11 are taken from the 256-bit key by reading the bytes in 
        little-endian order, in 4-byte chunks. Input words 12 and 13 are a block counter, 
        with word 12 overflowing into word 13. Lastly, words 14 and 15 are taken from 
        an 8-byte nonce, again by reading the bytes in little-endian order, in 4-byte 
        chunks. The block counter words are initially zero.
      </t>

      <t>
        ChaCha20 consists of 20 rounds, alternating between "column" rounds and "diagonal" rounds. 
        Each round applies the following "quarter-round" function four times, to a different 
        set of words each time. The quarter-round function updates 4, 32-bit words (a, b, c, d) 
        as follows, where &lt;&lt;&lt; is a bitwise, left rotation:
      </t>

      <figure>
        <artwork>
a += b; d ^= a; d &lt;&lt;&lt;= 16;
c += d; b ^= c; b &lt;&lt;&lt;= 12;
a += b; d ^= a; d &lt;&lt;&lt;= 8;
c += d; b ^= c; b &lt;&lt;&lt;= 7;
        </artwork>
      </figure>

      <t>
        The 16 words are conceptually arranged in a four by four grid with the first word in 
        the top-left position and the fourth word in the top-right position. The "column" rounds 
        then apply the quarter-round function to the four columns, from left to right. The 
        "diagonal" rounds apply the quarter-round to the top-left, bottom-right diagonal, 
        followed by the pattern shifted one place to the right, for three more quarter-rounds.
      </t>

      <t>
        Specifically, a column round applies the quarter-round function to the following 
        indexes: (0, 4, 8, 12), (1, 5, 9, 13), (2, 6, 10, 14), (3, 7, 11, 15). A diagonal 
        round applies it to these indexes: (0, 5, 10, 15), (1, 6, 11, 12), (2, 7, 8, 13), 
        (3, 4, 9, 14).
      </t>

      <t>
        After 20 rounds of the above processing, the original 16 input words are added to 
        the 16 words to form the 16 output words.
      </t>

      <t>
        The 64 output bytes are generated from the 16 output words by
        serializing them in little-endian order and concatenating the results.
      </t>
      <t>
       Test vectors for this cipher can be found in <xref target="chacha-test-vectors"/>.
      </t>
    </section>

    <section title="The Poly1305 Authenticator">
      <t>
        <xref target="POLY1305">Poly1305</xref> is a Wegman-Carter, one-time authenticator
        designed by D. J. Bernstein. Poly1305 takes a 32-byte, one-time key and a message 
        and produces a 16-byte tag that authenticates the message such that an attacker has 
        a negligible chance of producing a valid tag for an inauthentic message.
      </t>

      <t>
        The first 16 bytes of the one-time key form an integer, <spanx style="emph">r</spanx>, 
        as follows: the top four bits of the bytes at indexes 3, 7, 11 and 15 are cleared, 
        the bottom 2 bits of the bytes at indexes 4, 8 and 12 are cleared and the 16 bytes 
        are taken as a little-endian value.
      </t>

      <t>
        An accumulator is set to zero. For each chunk of 16 bytes from the input message, 
        a byte with value 1 is appended and the 17 bytes are treated as a little-endian 
        number. If the last chunk has less than 16 bytes then zero bytes are appended after 
        the 1 byte is appended until there are 17 bytes. The value is added to the 
        accumulator and then the accumulator is multiplied by <spanx style="emph">r</spanx>, 
        all mod 2^130 - 5.
      </t>

      <t>
        Finally the last 16 bytes of the one-time key are treated as a little-endian number 
        and added to the accumulator, mod 2^128. The result is serialised as a little-endian 
        number, producing the 16 byte tag. Note that the original specification of Poly1305 
        used a different construction with AES to generate the constant term of the polynomial 
        from a counter nonce. For a more recent treatment that avoids the use of a block cipher 
        in this fashion, as is done here, see section 9 of <xref target="NACLCRYPTO">the NaCl specification</xref>.
      </t>
      <t>
       Test vectors for this authenticator can be found in <xref target="poly1305-test-vectors"/>.
      </t>
    </section>

    <section anchor="chacha20suites"
	     title="ChaCha20 Cipher Suites">
      <t>In the next sections different ciphersuites are defined that utilize the
      ChaCha20 cipher combined with various message authentication methods.</t>

      <t>In all cases, the pseudorandom function (PRF) for TLS 1.2 is the TLS PRF
      with SHA-256 as the hash function.  When used with TLS versions
      prior to 1.2, the PRF is calculated as specified in the
      appropriate version of the TLS specification.</t>

      <t>The RSA, DHE_RSA, ECDHE_RSA, ECDHE_ECDSA, PSK, DHE_PSK,
      RSA_PSK, ECDHE_PSK key exchanges are performed as defined in
      <xref target="RFC5246"/>, <xref target="RFC4492"/>, and <xref
      target="RFC5489"/>.</t>

    <section anchor="chacha20suites-sha1"
	     title="ChaCha20 Cipher Suites with HMAC-SHA1">

      <t>The following CipherSuites are defined.</t>

      <figure>
	<artwork><![CDATA[
  TLS_RSA_WITH_CHACHA20_SHA              = {0xTBD, 0xTBD} {0xCC, 0x20}
  TLS_ECDHE_RSA_WITH_CHACHA20_SHA        = {0xTBD, 0xTBD} {0xCC, 0x21}
  TLS_ECDHE_ECDSA_WITH_CHACHA20_SHA      = {0xTBD, 0xTBD} {0xCC, 0x22}

  TLS_DHE_RSA_WITH_CHACHA20_SHA          = {0xTBD, 0xTBD} {0xCC, 0x23}
  TLS_DHE_PSK_WITH_CHACHA20_SHA          = {0xTBD, 0xTBD} {0xCC, 0x24}

  TLS_PSK_WITH_CHACHA20_SHA              = {0xTBD, 0xTBD} {0xCC, 0x25}
  TLS_ECDHE_PSK_WITH_CHACHA20_SHA        = {0xTBD, 0xTBD} {0xCC, 0x26}
  TLS_RSA_PSK_WITH_CHACHA20_SHA          = {0xTBD, 0xTBD} {0xCC, 0x27}
]]></artwork>
      </figure>

      <t>Note that ChaCha20 requires a 64-bit nonce. That nonce is
      updated on the encryption of every TLS record, and is set to be
      the 64-bit TLS record sequence number. In case of DTLS the
      64-bit nonce is formed as the concatenation of the 16-bit epoch 
      with the 48-bit sequence number.</t>

      <t>The MAC algorithm used in the ciphersuites above is HMAC-SHA1 <xref
      target="RFC6234"/>.</t>

    </section>

    <section anchor="chacha20suites-poly1305"
	     title="ChaCha20 Cipher Suites with Poly1305">
      <t>
        The ChaCha20 and Poly1305 primitives are built into an 
        <xref target="RFC5116">AEAD algorithm</xref>, AEAD_CHACHA20_POLY1305, that takes 
        a 32 byte key and 8 byte nonce as follows.
      </t>

      <t>
        ChaCha20 is run with the given key and nonce and with the two counter words set to zero. 
        The first 32 bytes of the 64 byte output are saved to become the one-time key for Poly1305. 
        The remainder of the output is discarded. The first counter input word is set to one 
        and the plaintext is encrypted by XORing it with the output of invocations of the 
        ChaCha20 function as needed, incrementing the first counter word after each block and 
        overflowing into the second. The limits on the TLS plaintext size mean 
        that the first counter word will never overflow in practice.
      </t>

      <t>
        The reason for generating the Poly1305 key like this rather than using key material 
        from the handshake is that handshake key material is per-session, but for a polynomial 
        MAC, a unique, secret key is needed per-record.
      </t>

      <t>
        The Poly1305 key is used to calculate a tag for the following input: the concatenation 
        of the additional data, the number of bytes of additional data, the ciphertext and the 
        number of bytes of ciphertext. Numbers are represented as 8-byte, little-endian values. 
        The resulting tag is appended to the ciphertext, resulting in the output of the AEAD 
        operation.
      </t>

      <t>
        Authenticated decryption is largely the reverse of the encryption process: generate one 
        block of ChaCha20 keystream and use the first 32 bytes as a Poly1305 key. Feed Poly1305 the 
        additional data and ciphertext, with the length suffixing as described above. Verify, in 
        constant time, that the calculated Poly1305 authenticator matches the final 16 bytes of 
        the input. If not, the input can be rejected immediately. Otherwise, run ChaCha20, 
        starting with a counter value of one, to decrypt the ciphertext.
      </t>

      <t>
        When used in TLS, the <spanx style="verb">record_iv_length</spanx> is zero and the nonce is 
        the sequence number for the record, as an 8-byte, big-endian number. The additional data is 
        seq_num + TLSCompressed.type + TLSCompressed.version + TLSCompressed.length, where "+" denotes
        concatenation.
      </t>

      <t>
        In DTLS, the nonce is formed as the concatenation of the 16-bit epoch with the 
        48-bit sequence number.
      </t>

      <t>
        In accordance with section 4 of <xref target="RFC5116">RFC 5116</xref>, the constants for 
        this AEAD algorithm are as follows: K_LEN is 32 bytes, N_MIN and N_MAX are 8 bytes, P_MAX 
        and A_MAX are 2^64, C_MAX is 2^64+16. An AEAD_CHACHA20_POLY1305 ciphertext is exactly 16 octets 
        longer than its corresponding plaintext.
      </t>

      <t>
       Test vectors for this authenticator can be found in <xref target="aead-chacha-poly1305-test-vectors"/>.
      </t>

      <t>The following CipherSuites are defined.</t>
      <figure>
	<artwork><![CDATA[
  TLS_RSA_WITH_CHACHA20_POLY1305         = {0xTBD, 0xTBD} {0xCC, 0x12}
  TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305   = {0xTBD, 0xTBD} {0xCC, 0x13}
  TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 = {0xTBD, 0xTBD} {0xCC, 0x14}

  TLS_DHE_RSA_WITH_CHACHA20_POLY1305     = {0xTBD, 0xTBD} {0xCC, 0x15}
  TLS_DHE_PSK_WITH_CHACHA20_POLY1305     = {0xTBD, 0xTBD} {0xCC, 0x16}

  TLS_PSK_WITH_CHACHA20_POLY1305         = {0xTBD, 0xTBD} {0xCC, 0x17}
  TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305   = {0xTBD, 0xTBD} {0xCC, 0x18}
  TLS_RSA_PSK_WITH_CHACHA20_POLY1305     = {0xTBD, 0xTBD} {0xCC, 0x19}
]]></artwork>
      </figure>


    </section>
    </section>

    <section anchor="updates-tls"
	     title="Updates to the TLS Standard Stream Cipher">
<t>The ChaCha20 ciphersuites with HMAC-SHA1 defined in this document differ 
from the TLS RC4 ciphersuites that have been the basis for the definition of 
Standard Stream Cipher.
Unlike RC4, ChaCha20 requires a nonce per record. This however, does not affect 
the description of the Standard Stream Cipher if one assumes that a nonce is
optional and depends on the cipher's characteristics.
</t>
<t>
Hence, this document modifies the Standard Stream Cipher by adding an
implicit nonce of 8-bytes, which is set to be the 64-bit TLS record sequence number.
If the stream cipher needs more than 8 byte of nonce, it can obtain
additional bytes for the implicit nonce from the client_write_iv
and server_write_iv of the key_block.
</t>
<t>
Stream ciphers that don't require
a nonce such as RC4 shall ignore it. Other stream ciphers that require
a nonce, such as ChaCha20 with HMAC-SHA1, will use the nonce and reset their 
state on each record.
</t>
<t>
Note that in case of DTLS the 8-byte nonce is formed as the concatenation of the 
16-bit epoch with the 48-bit sequence number, which are sent as part of the
record.
</t>
   </section>
    <section anchor="updates-dtls"
	     title="Updates to DTLS">
<t>
The DTLS protocol requires the cipher in use to introduce no dependencies
between TLS Records to allow lost or rearranged records. For that
it explicitly bans stream ciphers (see Section 3.1 of <xref
target="RFC6347"/>).
</t>
<t>
As the stream cipher described in this document, unlike RC4, does not require 
dependencies between records, this ban of stream ciphers is lifted with
this document. Stream ciphers can be used with DTLS if they introduce no
dependencies between records.
</t>
    </section>
    
    <section anchor="ack"
             title="Acknowledgements">

      <t>The authors would like to thank Zooko Wilcox-OHearn and
      Samuel Neves.</t> <!-- for suggestions that led to this draft.</t>-->

    </section>

    <section anchor="iana"
             title="IANA Considerations">

<t>
   IANA is requested to assign a value for AEAD_CHACHA20_POLY1305 in the
      <xref target="RFC5116">registry of AEAD algorithms</xref>, and
      also allocate the following Cipher Suites in the
      TLS Cipher Suite Registry (note that the third column
      contains the suggested ciphersuite numbers):</t>

      <figure>
	<artwork><![CDATA[
  TLS_RSA_WITH_CHACHA20_POLY1305         = {0xTBD, 0xTBD} {0xCC, 0x12}
  TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305   = {0xTBD, 0xTBD} {0xCC, 0x13}
  TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 = {0xTBD, 0xTBD} {0xCC, 0x14}

  TLS_DHE_RSA_WITH_CHACHA20_POLY1305     = {0xTBD, 0xTBD} {0xCC, 0x15}
  TLS_DHE_PSK_WITH_CHACHA20_POLY1305     = {0xTBD, 0xTBD} {0xCC, 0x16}

  TLS_PSK_WITH_CHACHA20_POLY1305         = {0xTBD, 0xTBD} {0xCC, 0x17}
  TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305   = {0xTBD, 0xTBD} {0xCC, 0x18}
  TLS_RSA_PSK_WITH_CHACHA20_POLY1305     = {0xTBD, 0xTBD} {0xCC, 0x19}

  TLS_RSA_WITH_CHACHA20_SHA              = {0xTBD, 0xTBD} {0xCC, 0x20}
  TLS_ECDHE_RSA_WITH_CHACHA20_SHA        = {0xTBD, 0xTBD} {0xCC, 0x21}
  TLS_ECDHE_ECDSA_WITH_CHACHA20_SHA      = {0xTBD, 0xTBD} {0xCC, 0x22}

  TLS_DHE_RSA_WITH_CHACHA20_SHA          = {0xTBD, 0xTBD} {0xCC, 0x23}
  TLS_DHE_PSK_WITH_CHACHA20_SHA          = {0xTBD, 0xTBD} {0xCC, 0x24}

  TLS_PSK_WITH_CHACHA20_SHA              = {0xTBD, 0xTBD} {0xCC, 0x25}
  TLS_ECDHE_PSK_WITH_CHACHA20_SHA        = {0xTBD, 0xTBD} {0xCC, 0x26}
  TLS_RSA_PSK_WITH_CHACHA20_SHA          = {0xTBD, 0xTBD} {0xCC, 0x27}
]]></artwork>
      </figure>

    </section>

    <section anchor="security"
             title="Security Considerations">

      <t>ChaCha20 follows the same basic principle as Salsa20, a cipher
      with significant security review <xref target="SALSA20-SECURITY"/><xref target="ESTREAM"/>.
      At the time of writing this document, there are no known significant 
      security problems with either cipher, and ChaCha20 is shown to be more
      resistant in certain attacks than Salsa20 <xref target="SALSA20-ATTACK"/>.
      Furthermore ChaCha20 was used as the core of the BLAKE hash function,
      a SHA3 finalist, that had received considerable cryptanalytic
      attention <xref target="NIST-SHA3"/>.
      </t>

      <t>
        Poly1305 is designed to 
        ensure that forged messages are rejected with a probability of 1-(n/2^102) for 
        a 16*n byte message, even after sending 2^64 legitimate messages.
      </t>
      <t>
        The cipher suites described in this document require that an nonce
        is never repeated under the same key. The design presented ensures
        that by using the TLS sequence number which is unique and does not
        wrap <xref target="RFC5246"/>.
      </t>

      <t>This document should not introduce any other security
      considerations than those that directly follow from the use of
      the stream cipher ChaCha20, the AEAD_CHACHA20_POLY1305 construction, and 
      those that directly follow from introducing any set of stream cipher 
      suites into TLS and DTLS.</t>

    </section>
    
  </middle>

  <back>

    <references title="Normative References">

      &RFC2246;
      &RFC4346;
      &RFC4347;
      &RFC4492;
      &RFC5116;
      &RFC5246;
      &RFC5489;
      &RFC6234;
      &RFC6347;
      
      <reference anchor="CHACHA" target="http://cr.yp.to/chacha/chacha-20080128.pdf">
	<front>
	  <title>ChaCha, a variant of Salsa20</title>
	  <author initials="D.J." surname="Bernstein"
		  fullname="D.J. Bernstein"/>
	  <date month="January" year="2008" />
	</front>
      </reference>

      <reference anchor="POLY1305" target="http://cr.yp.to/mac/poly1305-20050329.pdf">
        <front>
          <title>The Poly1305-AES message-authentication code.</title>
          <author initials="D. J." surname="Bernstein"></author>
          <date month="March" year="2005"/>
        </front>
      </reference>

    </references>

    <references title="Informative References">
    
<!--      &CHACHAVECTORS;-->

      <reference anchor="SALSA20SPEC" target="http://cr.yp.to/snuffle/spec.pdf">
	<front>
	  <title>Salsa20 specification</title>
	  <author initials="D.J." surname="Bernstein"
		  fullname="D.J. Bernstein"/>
	  <date month="April" year="2005" />
	</front>
      </reference>

      &RFC6101;

      <reference anchor="SALSA20-SECURITY" target="http://cr.yp.to/snuffle/security.pdf">
	<front>
	  <title>Salsa20 security</title>
	  <author initials="D.J." surname="Bernstein"
		  fullname="D.J. Bernstein"/>
	  <date month="April" year="2005" />
	</front>
      </reference>

      <reference anchor="ESTREAM" target="http://www.ecrypt.eu.org/stream/finallist.html">
	<front>
	  <title>The eSTREAM Portfolio (rev. 1)</title>
	  <author initials="S." surname="Babbage"
		  fullname="Steve Babbage"/>
	  <author initials="C." surname="DeCanniere"
		  fullname="Christophe De Canniere"/>
	  <author initials="A." surname="Cantenaut"
		  fullname="Anne Cantenaut"/>
	  <author initials="C." surname="Cid"
		  fullname="Carlos Cid"/>
	  <author initials="H." surname="Gilbert"
		  fullname="Henri Gilbert"/>
	  <author initials="T." surname="Johansson"
		  fullname="Thomas Johansson"/>
	  <author initials="M." surname="Parker"
		  fullname="Matthew Parker"/>
	  <author initials="B." surname="Preneel"
		  fullname="Bart Preneel"/>
	  <author initials="V." surname="Rijmen"
		  fullname="Vincent Rijmen"/>
	  <author initials="M." surname="Robshaw"
		  fullname="Matthew Robshaw"/>
	  <date month="September" year="2008" />
	</front>
      </reference>

      <reference anchor="CBC-ATTACK">
	<front>
	  <title>Lucky Thirteen: Breaking the 
	  TLS and DTLS Record Protocols</title>
	  <author initials="N.J." surname="AlFardan"
		  fullname="Nadhem J. AlFardan"/>
	  <author initials="K." surname="Paterson"
		  fullname="K. Paterson"/>
	  <date year="2013" />
	</front>
        <seriesInfo name="IEEE Symposium on Security and Privacy" value=""/>
      </reference>

      <reference anchor="RC4-ATTACK">
	<front>
	  <title>Full Plaintext Recovery Attack on Broadcast RC4</title>
	  <author initials="T." surname="Isobe"
		  fullname="Takanori Isobe"/>
	  <author initials="T." surname="Ohigashi"
		  fullname="Toshihiro Ohigashi"/>
	  <author initials="Y." surname="Watanabe"
		  fullname="Yuhei Watanabe"/>
	  <author initials="M." surname="Morii"
		  fullname="Masakatu Morii"/>
	  <date year="2013" />
	</front>
	<seriesInfo name="International Workshop on Fast Software Encryption" value=""/>
      </reference>

      <reference anchor="SALSA20-ATTACK" target="http://eprint.iacr.org/2007/472.pdf">
	<front>
	  <title>New Features of Latin Dances: Analysis of Salsa, ChaCha, and Rumba</title>
	  <author initials="J-P." surname="Aumasson"
		  fullname="Jean-Philippe Aumasson"/>
	  <author initials="S." surname="Fischer"
		  fullname="Simon Fischer"/>
	  <author initials="S." surname="Khazaei"
		  fullname="Shahram Khazaei"/>
	  <author initials="W." surname="Meier"
		  fullname="Willi Meier"/>
	  <author initials="C." surname="Rechberger"
		  fullname="Christian Rechberger"/>
	  <date year="2007" />
	</front>
      </reference>

      <reference anchor="NACLCRYPTO" target="http://cr.yp.to/highspeed/naclcrypto-20090310.pdf">
        <front>
          <title>Cryptography in NaCl</title>
          <author initials="D. J." surname="Bernstein"></author>
          <date month="March" year="2009"/>
        </front>
      </reference>

      <reference anchor="NIST-SHA3" target="http://dx.doi.org/10.6028/NIST.IR.7896">
	<front>
	  <title>Third-Round Report of the SHA-3
	  Cryptographic Hash Algorithm Competition</title>
	  <author initials="S." surname="Chang"
		  fullname="Shu-jen Chang"/>
	  <author initials="W." surname="Burr"
		  fullname="William E. Burr"/>
	  <author initials="J." surname="Kelsey"
		  fullname="John M. Kelsey"/>
	  <author initials="S." surname="Paul"
		  fullname="Souradyuti Paul"/>
	  <author initials="L." surname="Bassham"
		  fullname="Lawrence E. Bassham"/>
	  <date year="2012" />
	</front>
      </reference>

<!--      <reference anchor="KEY-RECOVERY-MAC">
	<front>
	  <title>Key-recovery attacks on universal hash function based
          MAC algorithms.</title>
	  <author initials="H." surname="Handschuh"
		  fullname="Helena Handschuh"/>
	  <author initials="B." surname="Preneel"
		  fullname="Bart Preneel"/>
	  <date year="2008" />
	</front>
      </reference>-->

    </references>

    <section title="Test vectors">
    <section title="ChaCha20"
        anchor="chacha-test-vectors">
      <t>
        The following blocks contain test vectors for ChaCha20. The first line contains the 256-bit key, the second the 64-bit nonce and the last line contains a prefix of the resulting ChaCha20 key-stream.
      </t>

      <figure>
        <artwork>
KEY:       00000000000000000000000000000000000000000000000000000000
           00000000
NONCE:     0000000000000000
KEYSTREAM: 76b8e0ada0f13d90405d6ae55386bd28bdd219b8a08ded1aa836efcc
           8b770dc7da41597c5157488d7724e03fb8d84a376a43b8f41518a11c
           c387b669b2ee6586
        </artwork>
      </figure>

      <figure>
        <artwork>
KEY:       00000000000000000000000000000000000000000000000000000000
           00000001
NONCE:     0000000000000000
KEYSTREAM: 4540f05a9f1fb296d7736e7b208e3c96eb4fe1834688d2604f450952
           ed432d41bbe2a0b6ea7566d2a5d1e7e20d42af2c53d792b1c43fea81
           7e9ad275ae546963
        </artwork>
      </figure>

      <figure>
        <artwork>
KEY:       00000000000000000000000000000000000000000000000000000000
           00000000
NONCE:     0000000000000001
KEYSTREAM: de9cba7bf3d69ef5e786dc63973f653a0b49e015adbff7134fcb7df1
           37821031e85a050278a7084527214f73efc7fa5b5277062eb7a0433e
           445f41e3
        </artwork>
      </figure>

      <figure>
        <artwork>
KEY:       00000000000000000000000000000000000000000000000000000000
           00000000
NONCE:     0100000000000000
KEYSTREAM: ef3fdfd6c61578fbf5cf35bd3dd33b8009631634d21e42ac33960bd1
           38e50d32111e4caf237ee53ca8ad6426194a88545ddc497a0b466e7d
           6bbdb0041b2f586b
        </artwork>
      </figure>

      <figure>
        <artwork>
KEY:       000102030405060708090a0b0c0d0e0f101112131415161718191a1b
           1c1d1e1f
NONCE:     0001020304050607
KEYSTREAM: f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56
           f85ac3c134a4547b733b46413042c9440049176905d3be59ea1c53f1
           5916155c2be8241a38008b9a26bc35941e2444177c8ade6689de9526
           4986d95889fb60e84629c9bd9a5acb1cc118be563eb9b3a4a472f82e
           09a7e778492b562ef7130e88dfe031c79db9d4f7c7a899151b9a4750
           32b63fc385245fe054e3dd5a97a5f576fe064025d3ce042c566ab2c5
           07b138db853e3d6959660996546cc9c4a6eafdc777c040d70eaf46f7
           6dad3979e5c5360c3317166a1c894c94a371876a94df7628fe4eaaf2
           ccb27d5aaae0ad7ad0f9d4b6ad3b54098746d4524d38407a6deb3ab7
           8fab78c9
        </artwork>
      </figure>
</section>
    <section title="Poly1305"
        anchor="poly1305-test-vectors">
      <t>
        The following blocks contain test vectors for Poly1305. The first line contains a variable length input. The second contains the 256-bit key and the last contains the resulting, 128-bit tag.
      </t>

      <figure>
        <artwork>
INPUT: 000000000000000000000000000000000000000000000000000000000000
       0000
KEY:   746869732069732033322d62797465206b657920666f7220506f6c793133
       3035
TAG:   49ec78090e481ec6c26b33b91ccc0307
        </artwork>
      </figure>

      <figure>
        <artwork>
INPUT: 48656c6c6f20776f726c6421
KEY:   746869732069732033322d62797465206b657920666f7220506f6c793133
       3035
TAG:   a6f745008f81c916a20dcc74eef2b2f0
        </artwork>
      </figure>

</section>
    <section title="AEAD_CHACHA20_POLY1305"
    	anchor="aead-chacha-poly1305-test-vectors">
      <t>
        The following block contains a test vector for the AEAD_CHACHA20_POLY1305 algorithm. The first four lines consist of the standard inputs to an AEAD algorithm and the last line contains the encrypted and authenticated result.
      </t>

      <figure>
        <artwork>
KEY:    4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd110
        0a1007
INPUT:  86d09974840bded2a5ca
NONCE:  cd7cf67be39c794a
AD:     87e229d4500845a079c0
OUTPUT: e3e446f7ede9a19b62a4677dabf4e3d24b876bb284753896e1d6
        </artwork>
      </figure>

      <t>
        To aid implementations, the next block contains some intermediate values in the AEAD_CHACHA20_POLY1305 algorithm. The first line contains the Poly1305 key that is derived and the second contains the raw bytes that are authenticated by Poly1305.
      </t>

      <figure>
        <artwork>
KEY:   9052a6335505b6d507341169783dccac0e26f84ea84906b1558c05bf4815
       0fbe
INPUT: 87e229d4500845a079c00a00000000000000e3e446f7ede9a19b62a40a00
       000000000000
        </artwork>
      </figure>
    </section>
    </section>

  </back>

</rfc>
