idnits 2.17.1 draft-agl-tls-chacha20poly1305-04.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 (Nov 2013) is 3815 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) Summary: 1 error (**), 0 flaws (~~), 3 warnings (==), 1 comment (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Network Working Group A. Langley 3 Internet-Draft W. Chang 4 Expires: May 5, 2014 Google Inc 5 Nov 2013 7 ChaCha20 and Poly1305 based Cipher Suites for TLS 8 draft-agl-tls-chacha20poly1305-04 10 Abstract 12 This memo describes the use of the ChaCha20 cipher with a Poly1305 13 authenticator in Transport Layer Security (TLS). 15 Status of this Memo 17 This Internet-Draft is submitted in full conformance with the 18 provisions of BCP 78 and BCP 79. 20 Internet-Drafts are working documents of the Internet Engineering 21 Task Force (IETF). Note that other groups may also distribute 22 working documents as Internet-Drafts. The list of current Internet- 23 Drafts is at http://datatracker.ietf.org/drafts/current/. 25 Internet-Drafts are draft documents valid for a maximum of six months 26 and may be updated, replaced, or obsoleted by other documents at any 27 time. It is inappropriate to use Internet-Drafts as reference 28 material or to cite them other than as "work in progress." 30 This Internet-Draft will expire on May 5, 2014. 32 Copyright Notice 34 Copyright (c) 2013 IETF Trust and the persons identified as the 35 document authors. All rights reserved. 37 This document is subject to BCP 78 and the IETF Trust's Legal 38 Provisions Relating to IETF Documents 39 (http://trustee.ietf.org/license-info) in effect on the date of 40 publication of this document. Please review these documents 41 carefully, as they describe your rights and restrictions with respect 42 to this document. Code Components extracted from this document must 43 include Simplified BSD License text as described in Section 4.e of 44 the Trust Legal Provisions and are provided without warranty as 45 described in the Simplified BSD License. 47 Table of Contents 49 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 50 2. Requirements Notation . . . . . . . . . . . . . . . . . . . . 4 51 3. ChaCha20 . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 52 4. Poly1305 . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 53 5. AEAD construction . . . . . . . . . . . . . . . . . . . . . . 8 54 6. Cipher suites . . . . . . . . . . . . . . . . . . . . . . . . 10 55 7. Test vectors . . . . . . . . . . . . . . . . . . . . . . . . . 11 56 8. Security Considerations . . . . . . . . . . . . . . . . . . . 14 57 9. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 15 58 10. References . . . . . . . . . . . . . . . . . . . . . . . . . . 16 59 10.1. Normative References . . . . . . . . . . . . . . . . . . 16 60 10.2. Informative References . . . . . . . . . . . . . . . . . 16 61 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 17 63 1. Introduction 65 Existing TLS [RFC5246] cipher suites either suffer from cryptographic 66 weaknesses (RC4), major implementation pitfalls (CBC mode block 67 ciphers) or are difficult to efficiently and securely implement in 68 software (AES-GCM). In order to improve the state of software TLS 69 implementations, this memo specifies cipher suites that can be fast 70 and secure when implemented in software without sacrificing key 71 agility. 73 2. Requirements Notation 75 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 76 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 77 document are to be interpreted as described in RFC 2119 [RFC2119]. 79 3. ChaCha20 81 ChaCha20 [chacha] is a stream cipher developed by D. J. Bernstein. 82 It is a refinement of Salsa20 and was used as the core of the SHA-3 83 finalist, BLAKE. 85 ChaCha20 maps 16, 32-bit input words to 16, 32-bit output words. By 86 convention, 8 of the input words consist of a 256-bit key, 4 are 87 constants and the remaining four are an nonce and block counter. The 88 output words are converted to bytes and XORed with the plaintext to 89 produce ciphertext. In order to generate sufficient output bytes to 90 XOR with the whole plaintext, the block counter is incremented and 91 ChaCha20 is run again, as many times as needed, for up to 2^70 bytes 92 of output. 94 ChaCha20 operates on a state of 16, 32-bit words which are 95 initialised from the input words. The first four input words are 96 constants: (0x61707865, 0x3320646e, 0x79622d32, 0x6b206574). Input 97 words 4 through 11 are taken from the 256-bit key by reading the 98 bytes in little-endian order, in 4-byte chunks. Input words 12 and 99 13 are a block counter, with word 12 overflowing into word 13. 100 Lastly, words 14 and 15 are taken from an 8-byte nonce, again by 101 reading the bytes in little-endian order, in 4-byte chunks. The 102 block counter words are initially zero. 104 ChaCha20 consists of 20 rounds, alternating between "column" rounds 105 and "diagonal" rounds. Each round applies the following "quarter- 106 round" function four times, to a different set of words each time. 107 The quarter-round function updates 4, 32-bit words (a, b, c, d) as 108 follows, where <<< is a bitwise, left rotation: 110 a += b; d ^= a; d <<<= 16; 111 c += d; b ^= c; b <<<= 12; 112 a += b; d ^= a; d <<<= 8; 113 c += d; b ^= c; b <<<= 7; 115 The 16 words are conceptually arranged in a four by four grid with 116 the first word in the top-left position and the fourth word in the 117 top-right position. The "column" rounds then apply the quarter-round 118 function to the four columns, from left to right. The "diagonal" 119 rounds apply the quarter-round to the top-left, bottom-right 120 diagonal, followed by the pattern shifted one place to the right, for 121 three more quarter-rounds. 123 Specifically, a column round applies the quarter-round function to 124 the following indexes: (0, 4, 8, 12), (1, 5, 9, 13), (2, 6, 10, 14), 125 (3, 7, 11, 15). A diagonal round applies it to these indexes: (0, 5, 126 10, 15), (1, 6, 11, 12), (2, 7, 8, 13), (3, 4, 9, 14). 128 After 20 rounds of the above processing, the original 16 input words 129 are added to the 16 words to form the 16 output words. 131 The 64 output bytes are generated from the 16 output words by 132 serialising them in little-endian order and concatenating the 133 results. 135 4. Poly1305 137 Poly1305 [poly1305] is a Wegman-Carter, one-time authenticator 138 designed by D. J. Bernstein. Poly1305 takes a 32-byte, one-time key 139 and a message and produces a 16-byte tag that authenticates the 140 message such that an attacker has a negligible chance of producing a 141 valid tag for an inauthentic message. 143 The first 16 bytes of the one-time key form an integer, _r_, as 144 follows: the top four bits of the bytes at indexes 3, 7, 11 and 15 145 are cleared, the bottom 2 bits of the bytes at indexes 4, 8 and 12 146 are cleared and the 16 bytes are taken as a little-endian value. 148 An accumulator is set to zero. For each chunk of 16 bytes from the 149 input message, a byte with value 1 is appended and the 17 bytes are 150 treated as a little-endian number. If the last chunk has less than 151 16 bytes then zero bytes are appended after the 1 byte is appended 152 until there are 17 bytes. The value is added to the accumulator and 153 then the accumulator is multiplied by _r_, all mod 2^130 - 5. 155 Finally the last 16 bytes of the one-time key are treated as a 156 little-endian number and added to the accumulator, mod 2^128. The 157 result is serialised as a little-endian number, producing the 16 byte 158 tag. (The original specification of Poly1305 used AES to generate 159 the constant term of the polynomial from a counter nonce. For a more 160 recent treatment that avoids the use of a block cipher in this 161 fashion, as is done here, see section 9 of the NaCl specification 162 [naclcrypto].) 164 5. AEAD construction 166 The ChaCha20 and Poly1305 primitives are built into an AEAD algorithm 167 [RFC5116], AEAD_CHACHA20_POLY1305, that takes a 32 byte key and 8 168 byte nonce as follows: 170 ChaCha20 is run with the given key and nonce and with the two counter 171 words set to zero. The first 32 bytes of the 64 byte output are 172 saved to become the one-time key for Poly1305. The remainder of the 173 output is discarded. The first counter input word is set to one and 174 the plaintext is encrypted by XORing it with the output of 175 invocations of the ChaCha20 function as needed, incrementing the 176 first counter word after each block and overflowing into the second. 177 (In the case of the TLS, limits on the plaintext size mean that the 178 first counter word will never overflow in practice.) 180 The reason for generating the Poly1305 key like this rather than 181 using key material from the handshake is that handshake key material 182 is per-session, but for a polynomial MAC, a unique, secret key is 183 needed per-record. 185 The Poly1305 key is used to calculate a tag for the following input: 186 the concatenation of the additional data, the number of bytes of 187 additional data, the ciphertext and the number of bytes of 188 ciphertext. Numbers are represented as 8-byte, little-endian values. 189 The resulting tag is appended to the ciphertext, resulting in the 190 output of the AEAD operation. 192 Authenticated decryption is largely the reverse of the encryption 193 process: generate one block of ChaCha20 keystream and use the first 194 32 bytes as a Poly1305 key. Feed Poly1305 the additional data and 195 ciphertext, with the length suffixing as described above. Verify, in 196 constant time, that the calculated Poly1305 authenticator matches the 197 final 16 bytes of the input. If not, the input can be rejected 198 immediately. Otherwise, run ChaCha20, starting with a counter value 199 of one, to decrypt the ciphertext. 201 When used in TLS, the "record_iv_length" is zero and the nonce is the 202 sequence number for the record, as an 8-byte, big-endian number. The 203 additional data is seq_num + TLSCompressed.type + 204 TLSCompressed.version + TLSCompressed.length, where "+" denotes 205 concatenation. 207 (In DTLS, the sequence number is only 48 bits. Thus, when used in 208 DTLS, AEAD_CHACHA20_POLY1305 based cipher suites use the 209 concatenation of the 16-bit epoch with the 48-bit sequence number as 210 a replacement for TLS's 64-bit sequence number.) 211 In accordance with section 4 of RFC 5116 [RFC5116], the constants for 212 this AEAD algorithm are as follows: K_LEN is 32 bytes, N_MIN and 213 N_MAX are 8 bytes, P_MAX and A_MAX are 2^64, C_MAX is 2^64+16. An 214 AEAD_CHACHA20_POLY1305 ciphertext is exactly 16 octets longer than 215 its corresponding plaintext. 217 6. Cipher suites 219 The following cipher suites are defined which use the 220 AEAD_CHACHA20_POLY1305 algorithm: 222 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = {0xcc, 0x13} 223 TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 = {0xcc, 0x14} 224 TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = {0xcc, 0x15} 226 These cipher suites use the TLS PRF [RFC5246] with SHA-256 as the 227 hash function. 229 7. Test vectors 231 The following blocks contain test vectors for ChaCha20. The first 232 line contains the 256-bit key, the second the 64-bit nonce and the 233 last line contains a prefix of the resulting ChaCha20 key-stream. 235 KEY: 00000000000000000000000000000000000000000000000000000000 236 00000000 237 NONCE: 0000000000000000 238 KEYSTREAM: 76b8e0ada0f13d90405d6ae55386bd28bdd219b8a08ded1aa836efcc 239 8b770dc7da41597c5157488d7724e03fb8d84a376a43b8f41518a11c 240 c387b669b2ee6586 242 KEY: 00000000000000000000000000000000000000000000000000000000 243 00000001 244 NONCE: 0000000000000000 245 KEYSTREAM: 4540f05a9f1fb296d7736e7b208e3c96eb4fe1834688d2604f450952 246 ed432d41bbe2a0b6ea7566d2a5d1e7e20d42af2c53d792b1c43fea81 247 7e9ad275ae546963 249 KEY: 00000000000000000000000000000000000000000000000000000000 250 00000000 251 NONCE: 0000000000000001 252 KEYSTREAM: de9cba7bf3d69ef5e786dc63973f653a0b49e015adbff7134fcb7df1 253 37821031e85a050278a7084527214f73efc7fa5b5277062eb7a0433e 254 445f41e3 256 KEY: 00000000000000000000000000000000000000000000000000000000 257 00000000 258 NONCE: 0100000000000000 259 KEYSTREAM: ef3fdfd6c61578fbf5cf35bd3dd33b8009631634d21e42ac33960bd1 260 38e50d32111e4caf237ee53ca8ad6426194a88545ddc497a0b466e7d 261 6bbdb0041b2f586b 263 KEY: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b 264 1c1d1e1f 265 NONCE: 0001020304050607 266 KEYSTREAM: f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56 267 f85ac3c134a4547b733b46413042c9440049176905d3be59ea1c53f1 268 5916155c2be8241a38008b9a26bc35941e2444177c8ade6689de9526 269 4986d95889fb60e84629c9bd9a5acb1cc118be563eb9b3a4a472f82e 270 09a7e778492b562ef7130e88dfe031c79db9d4f7c7a899151b9a4750 271 32b63fc385245fe054e3dd5a97a5f576fe064025d3ce042c566ab2c5 272 07b138db853e3d6959660996546cc9c4a6eafdc777c040d70eaf46f7 273 6dad3979e5c5360c3317166a1c894c94a371876a94df7628fe4eaaf2 274 ccb27d5aaae0ad7ad0f9d4b6ad3b54098746d4524d38407a6deb3ab7 275 8fab78c9 277 The following blocks contain test vectors for Poly1305. The first 278 line contains a variable length input. The second contains the 256- 279 bit key and the last contains the resulting, 128-bit tag. 281 INPUT: 000000000000000000000000000000000000000000000000000000000000 282 0000 283 KEY: 746869732069732033322d62797465206b657920666f7220506f6c793133 284 3035 285 TAG: 49ec78090e481ec6c26b33b91ccc0307 287 INPUT: 48656c6c6f20776f726c6421 288 KEY: 746869732069732033322d62797465206b657920666f7220506f6c793133 289 3035 290 TAG: a6f745008f81c916a20dcc74eef2b2f0 292 The following block contains a test vector for the 293 AEAD_CHACHA20_POLY1305 algorithm. The first four lines consist of 294 the standard inputs to an AEAD algorithm and the last line contains 295 the encrypted and authenticated result. 297 KEY: 4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd110 298 0a1007 299 INPUT: 86d09974840bded2a5ca 300 NONCE: cd7cf67be39c794a 301 AD: 87e229d4500845a079c0 302 OUTPUT: e3e446f7ede9a19b62a4677dabf4e3d24b876bb284753896e1d6 304 To aid implementations, the next block contains some intermediate 305 values in the AEAD_CHACHA20_POLY1305 algorithm. The first line 306 contains the Poly1305 key that is derived and the second contains the 307 raw bytes that are authenticated by Poly1305. 309 KEY: 9052a6335505b6d507341169783dccac0e26f84ea84906b1558c05bf4815 310 0fbe 311 INPUT: 87e229d4500845a079c00a00000000000000e3e446f7ede9a19b62a40a00 312 000000000000 314 8. Security Considerations 316 ChaCha20 is designed to provide a 256-bit security level. Poly1305 317 is designed to ensure that forged messages are rejected with a 318 probability of 1-(n/2^102) for a 16*n byte message, even after 319 sending 2^64 legitimate messages. 321 The AEAD_CHACHA20_POLY1305 algorithm is designed to meet the standard 322 notions of privacy and authenticity. For formal definitions see 323 Authenticated Encryption [AE]. 325 These cipher suites require that an nonce never be repeated for the 326 same key. This is achieved by simply using the TLS sequence number. 328 Only forward secure cipher suites are defined as it's incongruous to 329 define a high-security cipher suite without forward security. 331 9. IANA Considerations 333 IANA is requested to assign the values for the cipher suites defined 334 in this document from the TLS registry. 336 IANA is requested to assign a value for AEAD_CHACHA20_POLY1305 in the 337 registry of AEAD algorithms. 339 10. References 341 10.1. Normative References 343 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 344 Requirement Levels", BCP 14, RFC 2119, March 1997. 346 [RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security 347 (TLS) Protocol Version 1.2", RFC 5246, August 2008. 349 [RFC5116] McGrew, D., "An Interface and Algorithms for Authenticated 350 Encryption", RFC 5116, January 2008. 352 [chacha] Bernstein, D., "ChaCha, a variant of Salsa20.", Jan 2008, 353 . 355 [poly1305] 356 Bernstein, D., "The Poly1305-AES message-authentication 357 code.", March 2005, 358 . 360 10.2. Informative References 362 [AE] Bellare, M. and C. Namprempre, "Authenticated Encryption: 363 Relations among notions and analysis of the generic 364 composition paradigm", 365 . 367 [naclcrypto] 368 Bernstein, D., 369 "http://cr.yp.to/highspeed/naclcrypto-20090310.pdf", 370 March 2009, 371 . 373 Authors' Addresses 375 Adam Langley 376 Google Inc 378 Email: agl@google.com 380 Wan-Teh Chang 381 Google Inc 383 Email: wtc@google.com