idnits 2.17.1 draft-viguier-kangarootwelve-00.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 issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The abstract seems to contain references ([FIPS202]), which it shouldn't. Please replace those with straight textual mentions of the documents in question. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (June 14, 2017) is 2505 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Informational ---------------------------------------------------------------------------- == Missing Reference: 'FIPS 202' is mentioned on line 20, but not defined -- Looks like a reference, but probably isn't: '1600' on line 440 -- Looks like a reference, but probably isn't: '0' on line 482 -- Looks like a reference, but probably isn't: '1' on line 453 -- Looks like a reference, but probably isn't: '2' on line 454 -- Looks like a reference, but probably isn't: '3' on line 455 -- Looks like a reference, but probably isn't: '4' on line 456 Summary: 1 error (**), 0 flaws (~~), 2 warnings (==), 8 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Internet Research Task Force (IRTF) B. Viguier 3 Internet-Draft Radboud University 4 Intended status: Informational June 14, 2017 5 Expires: December 16, 2017 7 KangarooTwelve 8 draft-viguier-kangarootwelve-00 10 Abstract 12 This document defines the KangarooTwelve eXtendable Output Function 13 (XOF), a hash function with arbitrary output length. It provides an 14 efficient and secure hashing primitive, which is able to exploit the 15 parallelism of the implementation in a scalable way. It uses tree 16 hashing over a round-reduced version of SHAKE128 as underlying 17 primitive. 19 This document builds up on the definitions of the permutations and of 20 the sponge construction in [FIPS 202], and is meant to serve as a 21 stable reference and an implementation guide. 23 Status of This Memo 25 This Internet-Draft is submitted in full conformance with the 26 provisions of BCP 78 and BCP 79. 28 Internet-Drafts are working documents of the Internet Engineering 29 Task Force (IETF). Note that other groups may also distribute 30 working documents as Internet-Drafts. The list of current Internet- 31 Drafts is at http://datatracker.ietf.org/drafts/current/. 33 Internet-Drafts are draft documents valid for a maximum of six months 34 and may be updated, replaced, or obsoleted by other documents at any 35 time. It is inappropriate to use Internet-Drafts as reference 36 material or to cite them other than as "work in progress." 38 This Internet-Draft will expire on December 16, 2017. 40 Copyright Notice 42 Copyright (c) 2017 IETF Trust and the persons identified as the 43 document authors. All rights reserved. 45 This document is subject to BCP 78 and the IETF Trust's Legal 46 Provisions Relating to IETF Documents 47 (http://trustee.ietf.org/license-info) in effect on the date of 48 publication of this document. Please review these documents 49 carefully, as they describe your rights and restrictions with respect 50 to this document. Code Components extracted from this document must 51 include Simplified BSD License text as described in Section 4.e of 52 the Trust Legal Provisions and are provided without warranty as 53 described in the Simplified BSD License. 55 Table of Contents 57 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2 58 1.1. Conventions . . . . . . . . . . . . . . . . . . . . . . . 3 59 2. Specifications . . . . . . . . . . . . . . . . . . . . . . . 4 60 2.1. Inner function: F . . . . . . . . . . . . . . . . . . . . 4 61 2.2. Tree hashing over F . . . . . . . . . . . . . . . . . . . 5 62 2.3. right_encode( x ) . . . . . . . . . . . . . . . . . . . . 7 63 3. Test vectors . . . . . . . . . . . . . . . . . . . . . . . . 7 64 4. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 9 65 5. Security Considerations . . . . . . . . . . . . . . . . . . . 9 66 6. References . . . . . . . . . . . . . . . . . . . . . . . . . 9 67 6.1. Normative References . . . . . . . . . . . . . . . . . . 10 68 6.2. Informative References . . . . . . . . . . . . . . . . . 10 69 Appendix A. Pseudo code . . . . . . . . . . . . . . . . . . . . 11 70 A.1. Keccak-p[1600] over 12 rounds . . . . . . . . . . . . . . 11 71 A.2. Inner function F . . . . . . . . . . . . . . . . . . . . 12 72 A.3. KangarooTwelve . . . . . . . . . . . . . . . . . . . . . 13 73 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 13 75 1. Introduction 77 This document defines the KangarooTwelve eXtendable Output Function 78 (XOF) [K12], i.e. a generalization of a hash function that can return 79 arbitrary output length. KangarooTwelve is based on a Keccak-p 80 permutation specified in [FIPS202] and aims at higher speed than 81 SHAKE and SHA-3. 83 The SHA-3 functions process data in a serial manner and unable to 84 optimally exploit parallelism available in modern CPU architectures. 85 KangarooTwelve splits the input message in fragments and applies an 86 inner hash function F on each of them separately. It then applies F 87 again on the concatenation of the digests. It makes use of Sakura 88 coding for ensuring soundness of the tree hashing mode [SAKURA]. The 89 inner hash function F is a sponge function and uses a round-reduced 90 version of the permutation used in Keccak. Its security builds up on 91 the scrutiny that Keccak has received since its publication 92 [KECCAK_CRYPTANALYSIS]. 94 1.1. Conventions 96 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 97 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 98 document are to be interpreted as described in RFC 2119 [RFC2119]. 100 The following notations are used throughout the document: 102 `...` denotes a bit-string. For example, `1010101`. 104 A 8 bit string `b_0 b_1 b_2 b_3 b_4 b_5 b_6 b_7` is a byte 105 represented by an integer value v following the LSB 0 convention, 106 i.e. 108 v = sum for i=0..7 of 2^i * b_i 110 For example, `11100000` = 7. The following diagram represents the 111 byte "07" with value 7 (decimal). 113 Significance of Bits 114 MSB 7 6 5 4 3 2 1 0 LSB 115 +-+-+-+-+-+-+-+-+ 116 |0 0 0 0 0 1 1 1| 117 +-+-+-+-+-+-+-+-+ 118 hex: 0 7 120 "..." denotes a string of bytes given in hexadecimal. For example, 121 "0B 80", which can be also be seen as a bit-string : `11010000 122 00000001`. 124 |s| denotes the length of a byte string "s". For example, |"FF FF"| 125 = 2. 127 `0^b` denotes the repetition of bit `0` b times. For example, `0^4` 128 = `0000`. 130 `0^0` denotes the empty bit-string. 132 `1^b` denotes the repetition of bit `1` b times. For example, `1^3` 133 = `111`. 135 "00^b" denotes the b times the repetition of byte "00". For 136 example, "00^7" = "00 00 00 00 00 00 00". 138 a||b denotes the concatenation of two strings 'a' and 'b'. For 139 example, `10`||`01` = `1001` 141 s[n:m] denotes the selection of bytes from n to m exclusive of a 142 string 's'. For example, for s = "A5 C6 D7", s[0:1] = "A5" and 143 s[1:3] = "C6 D7". 145 2. Specifications 147 KangarooTwelve is an eXtendable Output Function (XOF). It takes as 148 an input a pair of byte-strings (M, C) and a positive integer L where 150 M byte-string, is the Message and 152 C byte-string, is a Customization string and 154 L positive integer, the length of the output in bytes. 156 The Customization string serves as domain separation. It is 157 typically a short string such as a name or an identifier (e.g. URI, 158 ODI...) 160 2.1. Inner function: F 162 The inner function F makes use of the permutation Keccak- 163 p[1600,n_r=12], i.e., a version of the one used in SHAKE and SHA-3 164 instances reduced to n_r=12 rounds and specified in FIPS 202 165 [FIPS202]. F is a sponge function calling this permutation, multi- 166 rate padding pad10*1 and with a rate of 168 bytes (= 1344 bits): 168 F = Sponge[Keccak-p[1600,n_r=12], pad10*1, r=1344] 170 It follows that F has a capacity of 1600 - 1344 = 256 bits. 172 The sponge function F takes as an input a bit-string S and a positive 173 integer L where 175 S bit-string, is the input String and 177 L positive integer, the Length of the output in bytes 179 The input string S SHOULD be represented as a pair (Sbytes, dS), 180 where Sbytes contains only bytes and where dS is the delimited suffix 181 representing the trailing bits. 183 First, let S = Sbytes || Sbits, where Sbytes contains only bytes and 184 Sbits contains at most 7 bits. Then, convert Sbits into the 185 delimited suffix dS by appending a bit `1` and as many bits `0` as 186 necessary so that dS is a byte. The numerical value of dS is thus: 188 dS = 2^|Sbits| + sum for i=0..|Sbits|-1 of 2^i*Sbits_i 190 Notice that the most significant bit `1` of dS coincides with the 191 first bit of padding in the multi-rate padding rule pad10*1. The 192 implementation of F therefore SHOULD add dS to the state and then the 193 second bit of padding. Appendix A.2 provides a pseudo code version. 195 In the table below, here are some examples of values, including those 196 that are used in this document: 198 +---------+---------------+---------------+-------------------------+ 199 | Sbits | bit-string | value (dec) | delimited Suffix (dS) | 200 +---------+---------------+---------------+-------------------------+ 201 | `` | `10000000` | 1 | "01" | 202 | | | | | 203 | `01` | `01100000` | 6 | "06" | 204 | | | | | 205 | `11` | `11100000` | 7 | "07" | 206 | | | | | 207 | `110` | `11010000` | 11 | "0B" | 208 +---------+---------------+---------------+-------------------------+ 210 2.2. Tree hashing over F 212 On top of the sponge function F, KangarooTwelve uses a Sakura- 213 compatible tree hash mode [SAKURA]. First, merge M and C to a single 214 input string S in a reversible way. right_encode( |C| ) gives the 215 length in bytes of C as a byte-string. See Section 2.3. 217 S = M || C || right_encode( |C| ) 219 Then, split S into n chunks of 8192 bytes. 221 S = S_0 || .. || S_n-1 222 |S_0| = .. = |S_n-2| = 8192 bytes 223 |S_n-1| <= 8192 bytes 225 From S_1 .. S_n-1, compute the 32-bytes hashes CV_0 .. CV_n-2. This 226 computation SHOULD exploit the parallelism available on the platform 227 in order to be optimally efficient. 229 Node_i = S_i+1 || `110` 230 CV_i = F( Node_i, 32 ) 232 Compute the final node: Node*. 234 o If |S| <= 8192 bytes, then Node* = S || `11` 236 o Otherwise compute Node* as follow: 238 Node* = S_0 || "03 00 00 00 00 00 00 00" 239 Node* = Node* || CV_0 240 .. 241 Node* = Node* || CV_n-2 242 Node* = Node* || right_encode(n-1) 243 Node* = Node* || "FF FF" || `01` 245 Finally, KangarooTwelve output is retrieved from F( Node* ). 247 KangarooTwelve( M, C, L ) = F( Node*, L ) 249 For |S| > 8192 bytes, KangarooTwelve computation flow is as follow: 251 +--------------+ 252 | S_0 | 253 +--------------+ 254 || 255 +--------------+ 256 | `11`||`0^62` | 257 +--------------+ 258 || 259 +-------------------+ F +--------------+ 260 | S_1 || `110` |------>| CV_0 | 261 +-------------------+ +--------------+ 262 || 263 +-------------------+ F +--------------+ 264 | S_2 || `110` |------>| CV_1 | 265 +-------------------+ +--------------+ 266 || 267 ... ... 268 || 269 +-------------------+ F +--------------+ 270 | S_n-1 || `110` |------>| CV_n-2 | 271 +-------------------+ +--------------+ 272 || 273 +--------------+ 274 | r_e(n-1) | 275 +--------------+ 276 || 277 +------------------+ F 278 | "FF FF" || `01` |----------> output 279 +------------------+ 281 We provide a pseudo code version in Appendix A.3. 283 2.3. right_encode( x ) 285 The function right_encode takes as inputs a non negative integer x < 286 256^255 and outputs a string of bytes x_n || .. || x_0 || n where 288 x = sum from i=0..n of 256^i * x_i 290 A pseudo code version is as follow. 292 right_encode(x): 293 S = 0^0 295 while x > 0 296 S = x % 256 || S 297 x = x / 256 299 S = S || length(S) 301 return S 302 end 304 3. Test vectors 306 Test vectors are based on the repetition of pattern the "00 01 .. FA" 307 with a specific length. ptn(n) defines a string by repeating the 308 pattern "00 01 .. FA" as many times as necessary and truncated to n 309 bytes e.g. 311 Pattern for a length of 17 bytes: 312 ptn(17) = 313 "00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10" 315 Pattern for a length of 17^2 bytes: 316 ptn(17^2) = 317 "00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 318 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 319 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 320 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 321 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 322 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 323 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 324 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F 325 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 326 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F 327 A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF 328 B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF 329 C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF 330 D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF 331 E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF 332 F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA 333 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 334 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 335 20 21 22 23 24 25" 337 KangarooTwelve(M=0^0, C=0^0, 32): 338 "1A C2 D4 50 FC 3B 42 05 D1 9D A7 BF CA 1B 37 51 339 3C 08 03 57 7A C7 16 7F 06 FE 2C E1 F0 EF 39 E5" 341 KangarooTwelve(M=0^0, C=0^0, 64): 342 "1A C2 D4 50 FC 3B 42 05 D1 9D A7 BF CA 1B 37 51 343 3C 08 03 57 7A C7 16 7F 06 FE 2C E1 F0 EF 39 E5 344 42 69 C0 56 B8 C8 2E 48 27 60 38 B6 D2 92 96 6C 345 C0 7A 3D 46 45 27 2E 31 FF 38 50 81 39 EB 0A 71" 347 KangarooTwelve(M=0^0, C=0^0, 10032), last 32 bytes: 348 "E8 DC 56 36 42 F7 22 8C 84 68 4C 89 84 05 D3 A8 349 34 79 91 58 C0 79 B1 28 80 27 7A 1D 28 E2 FF 6D" 351 KangarooTwelve(M=ptn(1 bytes), C=0^0, 32): 352 "2B DA 92 45 0E 8B 14 7F 8A 7C B6 29 E7 84 A0 58 353 EF CA 7C F7 D8 21 8E 02 D3 45 DF AA 65 24 4A 1F" 355 KangarooTwelve(M=ptn(17 bytes), C=0^0, 32): 356 "6B F7 5F A2 23 91 98 DB 47 72 E3 64 78 F8 E1 9B 357 0F 37 12 05 F6 A9 A9 3A 27 3F 51 DF 37 12 28 88" 359 KangarooTwelve(M=ptn(17^2 bytes), C=0^0, 32): 360 "0C 31 5E BC DE DB F6 14 26 DE 7D CF 8F B7 25 D1 361 E7 46 75 D7 F5 32 7A 50 67 F3 67 B1 08 EC B6 7C" 363 KangarooTwelve(M=ptn(17^3 bytes), C=0^0, 32): 364 "CB 55 2E 2E C7 7D 99 10 70 1D 57 8B 45 7D DF 77 365 2C 12 E3 22 E4 EE 7F E4 17 F9 2C 75 8F 0D 59 D0" 367 KangarooTwelve(M=ptn(17^4 bytes), C=0^0, 32): 368 "87 01 04 5E 22 20 53 45 FF 4D DA 05 55 5C BB 5C 369 3A F1 A7 71 C2 B8 9B AE F3 7D B4 3D 99 98 B9 FE" 371 KangarooTwelve(M=ptn(17^5 bytes), C=0^0, 32): 372 "84 4D 61 09 33 B1 B9 96 3C BD EB 5A E3 B6 B0 5C 373 C7 CB D6 7C EE DF 88 3E B6 78 A0 A8 E0 37 16 82" 375 KangarooTwelve(M=ptn(17^6 bytes), C=0^0, 32): 376 "3C 39 07 82 A8 A4 E8 9F A6 36 7F 72 FE AA F1 32 377 55 C8 D9 58 78 48 1D 3C D8 CE 85 F5 8E 88 0A F8" 379 KangarooTwelve(M=0^0, C=ptn(1 bytes), 32): 380 "FA B6 58 DB 63 E9 4A 24 61 88 BF 7A F6 9A 13 30 381 45 F4 6E E9 84 C5 6E 3C 33 28 CA AF 1A A1 A5 83" 383 KangarooTwelve(M=0xff, C=ptn(41 bytes), 32): 384 "D8 48 C5 06 8C ED 73 6F 44 62 15 9B 98 67 FD 4C 385 20 B8 08 AC C3 D5 BC 48 E0 B0 6B A0 A3 76 2E C4" 387 KangarooTwelve(M=0xff ff ff, C=ptn(41^2), 32): 388 "C3 89 E5 00 9A E5 71 20 85 4C 2E 8C 64 67 0A C0 389 13 58 CF 4C 1B AF 89 44 7A 72 42 34 DC 7C ED 74" 391 KangarooTwelve(M=0xff ff ff ff ff ff ff, C=ptn(41^3 bytes), 32): 392 "75 D2 F8 6A 2E 64 45 66 72 6B 4F BC FC 56 57 B9 393 DB CF 07 0C 7B 0D CA 06 45 0A B2 91 D7 44 3B CF" 395 4. IANA Considerations 397 None. 399 5. Security Considerations 401 This document is meant to serve as a stable reference and an 402 implementation guide for the KangarooTwelve eXtendable Output 403 Function. It makes no assertion to its security and relies on the 404 cryptanalysis of Keccak [KECCAK_CRYPTANALYSIS]. 406 6. References 407 6.1. Normative References 409 [FIPS202] National Institute of Standards and Technology, "FIPS PUB 410 202 - SHA-3 Standard: Permutation-Based Hash and 411 Extendable-Output Functions", 412 WWW http://dx.doi.org/10.6028/NIST.FIPS.202, August 2015. 414 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 415 Requirement Levels", BCP 14, RFC 2119, 416 DOI 10.17487/RFC2119, March 1997, 417 . 419 6.2. Informative References 421 [K12] Bertoni, G., Daemen, J., Peeters, M., Van Assche, G., and 422 R. Van Keer, "KangarooTwelve: fast hashing based on 423 Keccak-p", WWW http://eprint.iacr.org/2016/770.pdf, August 424 2016. 426 [KECCAK_CRYPTANALYSIS] 427 Keccak Team, "Summary of Third-party cryptanalysis of 428 Keccak", WWW https://www.keccak.team/third_party.html, 429 2017. 431 [SAKURA] Bertoni, G., Daemen, J., Peeters, M., and G. Van Assche, 432 "Sakura: a flexible coding for tree hashing", 433 WWW http://eprint.iacr.org/2013/231.pdf, April 2013. 435 Appendix A. Pseudo code 437 The sub-sections of this appendix contain pseudo code definitions of 438 KangarooTwelve. 440 A.1. Keccak-p[1600] over 12 rounds 442 Keccak-p_1600_12(state): 443 R = "D5" 445 for x from 0 to 4 446 for y from 0 to 4 447 lanes[x][y] = state[8*(x+5*y):8*(x+5*y)+8] 449 for round from 12 to 23 450 # theta 451 for x from 0 to 4 452 C[x] = lanes[x][0] 453 C[x] ^= lanes[x][1] 454 C[x] ^= lanes[x][2] 455 C[x] ^= lanes[x][3] 456 C[x] ^= lanes[x][4] 457 for x from 0 to 4 458 D[x] = C[(x+4)%5] ^ ROL64(C[(x+1)%5], 1) 459 for y from 0 to 4 460 for x from 0 to 4 461 lanes = lanes[x][y]^D[x] 463 # rho and pi 464 (x, y) = (1, 0) 465 current = lanes[x][y] 466 for t from 0 to 23 467 (x, y) = (y, (2*x+3*y)%5) 468 (current, lanes[x][y]) = 469 (lanes[x][y], ROL64(current, (t+1)*(t+2)/2)) 471 # chi 472 for y from 0 to 4 473 for x from 0 to 4 474 T[x] = lanes[x][y] 475 for x from 0 to 4 476 lanes[x][y] = T[x] ^((not T[(x+1)%5]) & T[(x+2)%5]) 478 # iota 479 for j from 0 to 6 480 R = ((R << 1) ^ ((R >> 7)* "71")) % 256 481 if (R & 2) 482 lanes[0][0] = lanes[0][0] ^ (1 << ((1< 0 522 blockSize = min(outputByteLen, 168) 523 outputBytes = outputBytes || state[0:blockSize] 524 outputByteLen = outputByteLen - blockSize 526 if outputByteLen > 0 527 state = Keccak-p_1600_12(state) 529 return outputBytes 530 end 532 A.3. KangarooTwelve 534 KangarooTwelve(inputMessage, customString, outputByteLen): 535 S = inputMessage || customString 536 S = S || right_encode( |customString| ) 538 if |S| <= 8192 539 return F(S, "07", outputByteLen) 540 else 541 # === Kangaroo hopping === 542 Node* = S[0:8192] || "03 00^7" 543 offset = 8192 544 while offset < |inputBytes| 545 blockSize = min( |inputBytes| - offset, 8192) 546 CV = F(inputBytes[offset : offset + blockSize], "0B", 32) 547 Node* = Node* || CV 548 offset = offset + blockSize 550 Node* = Node* || right_encode( |S| / 8192 ) || "FF FF" 551 return F(Node*, "06", outputByteLen) 552 end 554 Author's Address 556 Benoit Viguier 557 Radboud University 558 Toernooiveld 212 559 Nijmegen 560 The Netherlands 562 EMail: b.viguier@cs.ru.nl