idnits 2.17.1 draft-agl-tls-chacha20poly1305-01.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- == No 'Intended status' indicated for this document; assuming Proposed Standard Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == The document doesn't use any RFC 2119 keywords, yet seems to have RFC 2119 boilerplate text. -- The document date (Sept 2013) is 4142 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) ** Obsolete normative reference: RFC 5246 (Obsoleted by RFC 8446) -- Possible downref: Non-RFC (?) normative reference: ref. 'AE' Summary: 1 error (**), 0 flaws (~~), 3 warnings (==), 2 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Network Working Group A. Langley 3 Internet-Draft Google Inc 4 Expires: March 5, 2014 Sept 2013 6 ChaCha20 and Poly1305 based Cipher Suites for TLS 7 draft-agl-tls-chacha20poly1305-01 9 Abstract 11 This memo describes the use of the ChaCha20 cipher with a Poly1305 12 authenticator as a cipher suite for Transport Layer Security (TLS). 14 Status of this Memo 16 This Internet-Draft is submitted in full conformance with the 17 provisions of BCP 78 and BCP 79. 19 Internet-Drafts are working documents of the Internet Engineering 20 Task Force (IETF). Note that other groups may also distribute 21 working documents as Internet-Drafts. The list of current Internet- 22 Drafts is at http://datatracker.ietf.org/drafts/current/. 24 Internet-Drafts are draft documents valid for a maximum of six months 25 and may be updated, replaced, or obsoleted by other documents at any 26 time. It is inappropriate to use Internet-Drafts as reference 27 material or to cite them other than as "work in progress." 29 This Internet-Draft will expire on March 5, 2014. 31 Copyright Notice 33 Copyright (c) 2013 IETF Trust and the persons identified as the 34 document authors. All rights reserved. 36 This document is subject to BCP 78 and the IETF Trust's Legal 37 Provisions Relating to IETF Documents 38 (http://trustee.ietf.org/license-info) in effect on the date of 39 publication of this document. Please review these documents 40 carefully, as they describe your rights and restrictions with respect 41 to this document. Code Components extracted from this document must 42 include Simplified BSD License text as described in Section 4.e of 43 the Trust Legal Provisions and are provided without warranty as 44 described in the Simplified BSD License. 46 Table of Contents 48 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 49 2. Requirements Notation . . . . . . . . . . . . . . . . . . . . 4 50 3. ChaCha20 . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 51 4. Poly1305 . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 52 5. AEAD construction . . . . . . . . . . . . . . . . . . . . . . 7 53 6. Cipher suites . . . . . . . . . . . . . . . . . . . . . . . . 8 54 7. Test vectors . . . . . . . . . . . . . . . . . . . . . . . . . 9 55 8. Security Considerations . . . . . . . . . . . . . . . . . . . 12 56 9. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 13 57 10. Normative References . . . . . . . . . . . . . . . . . . . . . 14 58 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 15 60 1. Introduction 62 Existing TLS [RFC5246] cipher suites either suffer from cryptographic 63 weaknesses (RC4), major implementation pitfalls (CBC mode ciphers) or 64 are difficult to effectively implement in software (AES-GCM). In 65 order to improve the state of software TLS implementations, this memo 66 specifies cipher suites that can be fast and secure when implemented 67 in software without sacrificing key agility. 69 2. Requirements Notation 71 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 72 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 73 document are to be interpreted as described in RFC 2119 [RFC2119]. 75 3. ChaCha20 77 ChaCha20 [chacha] is a stream cipher developed by D. J. Bernstein. 78 It is a refinement of Salsa20 and was used as the core of the SHA-3 79 finalist, BLAKE. 81 ChaCha20 maps 16, 32-bit input words to 64 output bytes. By 82 convention, 8 of the input words consist of a 256-bit key, 4 are 83 constants and the remaining four are a block counter. The output 84 bytes are XORed with the plaintext to produce ciphertext. 86 ChaCha20 consists of 20 rounds, alternating between "column" rounds 87 and "diagonal" rounds. Each round applies the following "quarter- 88 round" function four times. The quarter-round function updates 4, 89 32-bit words (a, b, c, d) as follows: 91 a += b; d ^= a; d <<<= 16; 92 c += d; b ^= c; b <<<= 12; 93 a += b; d ^= a; d <<<= 8; 94 c += d; b ^= c; b <<<= 7; 96 The 16 input words are conceptually arranged in a four by four grid 97 with the first input word in the top-left position and the forth 98 input word in the top-right position. The "column" rounds then apply 99 the quarter-round function to the four columns, from left to right. 100 The "diagonal" rounds apply the quarter-round to the top-left, 101 bottom-right diagonal, followed by the pattern shifted one place to 102 the right, for three more quarter-rounds. 104 Specifically, a column round applies the quarter-round function to 105 the following input indexes: (0, 4, 8, 12), (1, 5, 9, 13), (2, 6, 10, 106 14), (3, 7, 11, 15). A diagonal round applies it to these indexes: 107 (0, 5, 10, 15), (1, 6, 11, 12), (2, 7, 8, 13), (3, 4, 9, 14). 109 Finally the original 16 words of input are added to the 16 words 110 after 20 rounds of the above processing. The sums are written out, 111 in little-endian form, to produce the 64 bytes of output. 113 The first four input words are constants: (1634760805, 857760878, 114 2036477234, 1797285236). Input words 4 through 11 are taken from the 115 256-bit key by reading the bytes in little-endian order. Input words 116 12 and 13 are taken from an 8-byte nonce, again by reading the bytes 117 in little-endian order. The final two input words are a block 118 counter, with word 14 overflowing into word 15. 120 4. Poly1305 122 Poly1305 [poly1305] is a Wegman-Carter, one-time authenticator 123 designed by D. J. Bernstein. Poly1305 takes a 32-byte, one-time key 124 and a message and produces a 16-byte tag that authenticates the 125 message such that an attacker has a negligible chance of producing a 126 valid tag for a inauthentic message. 128 The first 16 bytes of the one-time key form an integer, _r_, as 129 follows: the top four bits of the bytes at indexes 3, 7, 11 and 15 130 are cleared, the bottom 2 bits of the bytes at indexes 4, 8 and 12 131 are cleared and the 16 bytes are taken as a little-endian value. 133 An accumulator is set to zero and, for each chunk of 16 bytes from 134 the input message, a byte with value 1 is appended and the 17 bytes 135 are treated as a little-endian number. If the last chunk has less 136 than 16 bytes then zero bytes are appended after the 1 until there 137 are 17 bytes. The value is added to the accumulator and then the 138 accumulator is multiplied by _r_, all mod 2^130 - 5. 140 Finally the last 16 bytes of the one-time key are treated as a 141 little-endian number and added to the accumulator, mod 2^128. The 142 result is serialised as a little-endian number, producing the 16 byte 143 tag. 145 5. AEAD construction 147 The ChaCha20 and Poly1305 primitives are built into an AEAD [RFC5116] 148 that takes a 32 byte key and 8 byte nonce as follows: 150 ChaCha20 is run with the given key and nonce and with the two counter 151 words set to zero. The first 32 bytes of the 64 byte output are 152 saved to become the one-time key for Poly1305. The remainder of the 153 output is discarded. The first counter input word is set to one and 154 the plaintext is encrypted by XORing it with the output of 155 invocations of the ChaCha20 function as needed, incrementing the 156 first counter word for each block and overflowing into the second. 157 (In the case of the TLS, limits on the plaintext size mean that the 158 first counter word will never overflow in practice.) 160 The Poly1305 key is used to calculate a tag for the following input: 161 the concatenation of the number of bytes of additional data, the 162 additional data itself, the number of bytes of ciphertext and the 163 ciphertext itself. Numbers are represented as 8-byte, little-endian 164 values. The resulting tag is appended to the ciphertext, resulting 165 in the output of the AEAD operation. 167 Authenticated decryption is largely the reverse of the encryption 168 process: the Poly1305 key is generated and the authentication tag 169 calculated. The calculated tag is compared against the final 16 170 bytes of the authenticated ciphertext in constant time. If they 171 match, the remaining ciphertext is decrypted to produce the 172 plaintext. 174 When used in TLS, the "record_iv_length" is zero and the nonce is the 175 sequence number for the record, as an 8-byte, big-endian number. The 176 additional data is seq_num + TLSCompressed.type + 177 TLSCompressed.version + TLSCompressed.length, where "+" denotes 178 concatenation. 180 6. Cipher suites 182 The following cipher suites are defined which use the ChaCha20, 183 Poly1305, AEAD construction: 185 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = {0xcc, 0x13} 186 TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 = {0xcc, 0x14} 187 TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = {0xcc, 0x15} 189 7. Test vectors 191 The following blocks contain test vectors for ChaCha20. The first 192 line contains the 256-bit key, the second the 64-bit nonce and the 193 last line contains a prefix of the resulting ChaCha20 key-stream. 195 KEY: 00000000000000000000000000000000000000000000000000000000 196 00000000 197 NONCE: 0000000000000000 198 KEYSTREAM: 76b8e0ada0f13d90405d6ae55386bd28bdd219b8a08ded1aa836efcc 199 8b770dc7da41597c5157488d7724e03fb8d84a376a43b8f41518a11c 200 c387b669 202 KEY: 00000000000000000000000000000000000000000000000000000000 203 00000001 204 NONCE: 0000000000000000 205 KEYSTREAM: 4540f05a9f1fb296d7736e7b208e3c96eb4fe1834688d2604f450952 206 ed432d41bbe2a0b6ea7566d2a5d1e7e20d42af2c53d792b1c43fea81 207 7e9ad275 209 KEY: 00000000000000000000000000000000000000000000000000000000 210 00000000 211 NONCE: 0000000000000001 212 KEYSTREAM: de9cba7bf3d69ef5e786dc63973f653a0b49e015adbff7134fcb7df1 213 37821031e85a050278a7084527214f73efc7fa5b5277062eb7a0433e 214 445f41e3 216 KEY: 00000000000000000000000000000000000000000000000000000000 217 00000000 218 NONCE: 0100000000000000 219 KEYSTREAM: ef3fdfd6c61578fbf5cf35bd3dd33b8009631634d21e42ac33960bd1 220 38e50d32111e4caf237ee53ca8ad6426194a88545ddc497a0b466e7d 221 6bbdb004 223 KEY: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b 224 1c1d1e1f 225 NONCE: 0001020304050607 226 KEYSTREAM: f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56 227 f85ac3c134a4547b733b46413042c9440049176905d3be59ea1c53f1 228 5916155c2be8241a38008b9a26bc35941e2444177c8ade6689de9526 229 4986d95889fb60e84629c9bd9a5acb1cc118be563eb9b3a4a472f82e 230 09a7e778492b562ef7130e88dfe031c79db9d4f7c7a899151b9a4750 231 32b63fc385245fe054e3dd5a97a5f576fe064025d3ce042c566ab2c5 232 07b138db853e3d6959660996546cc9c4a6eafdc777c040d70eaf46f7 233 6dad3979e5c5360c3317166a1c894c94a371876a94df7628fe4eaaf2 234 ccb27d5aaae0ad7ad0f9d4b6ad3b54098746d4524d38407a6deb 236 The following blocks contain test vectors for Poly1305. The first 237 line contains a variable length input. The second contains the 256- 238 bit key and the last contains the resulting, 128-bit tag. 240 INPUT: 000000000000000000000000000000000000000000000000000000000000 241 0000 242 KEY: 746869732069732033322d62797465206b657920666f7220506f6c793133 243 3035 244 TAG: 49ec78090e481ec6c26b33b91ccc0307 246 INPUT: 48656c6c6f20776f726c6421 247 KEY: 746869732069732033322d62797465206b657920666f7220506f6c793133 248 3035 249 TAG: a6f745008f81c916a20dcc74eef2b2f0 251 The following block contains a test vector for the AEAD construction. 252 The first four lines consist of the standard inputs to an AEAD and 253 the last line contains the encrypted and authenticated result. 255 KEY: e3c37ba4984da482b4f978f314b149857f4f3027470bced382ad92889e 256 d4fcb6 257 INPUT: 1400000cbe2f24b0b1bf5276fc91a9ad 258 NONCE: 0000000000000000 259 AD: 00000000000000001603030010 260 OUTPUT: 46d4b8cfb0323dcad49cafe58ad009602fe190ebb314ddab20e541fdb7 261 b7541c 263 To aid implementations, the next block contains some intermediate 264 values in the AEAD construction. The first line contains the 265 Poly1305 key that is derived and the second contains the raw bytes 266 that are authenticated by Poly1305. 268 KEY: 7fd1df7665397ae3f54ee182d229d9487e927cacc4b145791dcc4b61d7d4 269 da18 270 INPUT: 0d000000000000000000000000000000160303001010000000000000005a 271 a35eb8027a60a34f418566ea548767 273 8. Security Considerations 275 ChaCha20 is designed to provide a 256-bit security level. Poly1305 276 is designed to ensure that forged messages are rejected with a 277 probability of n/2^102 for a 16*n byte message, even after sending 278 2^64 legitimate messages. 280 The AEAD construction is designed to meet the standard notions of 281 privacy and authenticity. For formal definitions see Authenticated 282 Encryption [AE]. 284 These cipher suites require that an nonce never be repeated for the 285 same key. This is achieved by simply using the TLS sequence number. 287 Only forward secure cipher suites are defined as it's incongruous to 288 define a high-security cipher suite without forward security. 290 9. IANA Considerations 292 IANA is requested to assign the values for the cipher suites defined 293 in this document from the TLS registry. 295 10. Normative References 297 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 298 Requirement Levels", BCP 14, RFC 2119, March 1997. 300 [RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security 301 (TLS) Protocol Version 1.2", RFC 5246, August 2008. 303 [RFC5116] McGrew, D., "An Interface and Algorithms for Authenticated 304 Encryption", RFC 5116, January 2008. 306 [chacha] Bernstein, D., "ChaCha, a variant of Salsa20.", Jan 2008, 307 . 309 [poly1305] 310 Bernstein, D., "The Poly1305-AES message-authentication 311 code.", March 2005, 312 . 314 [AE] Bellare, M. and C. Namprempre, "Authenticated Encryption: 315 Relations among notions and analysis of the generic 316 composition paradigm", 317 . 319 Author's Address 321 Adam Langley 322 Google Inc 324 Email: agl@google.com