-
Notifications
You must be signed in to change notification settings - Fork 0
/
SP800-185.h
599 lines (535 loc) · 31.7 KB
/
SP800-185.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
/*
The eXtended Keccak Code Package (XKCP)
https://github.com/XKCP/XKCP
Keccak, designed by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche.
Implementation by Ronny Van Keer, hereby denoted as "the implementer".
For more information, feedback or questions, please refer to the Keccak Team website:
https://keccak.team/
To the extent possible under law, the implementer has waived all copyright
and related or neighboring rights to the source code in this file.
http://creativecommons.org/publicdomain/zero/1.0/
*/
#ifndef _SP800_185_h_
#define _SP800_185_h_
#include "config.h"
#ifdef XKCP_has_KeccakP1600
#include <stddef.h>
#include <stdint.h>
#include "align.h"
#include "KeccakSponge.h"
#include "Phases.h"
#ifndef _Keccak_BitTypes_
#define _Keccak_BitTypes_
typedef uint8_t BitSequence;
typedef size_t BitLength;
#endif
typedef struct {
KeccakWidth1600_SpongeInstance sponge;
BitLength fixedOutputLength;
unsigned int lastByteBitLen;
BitSequence lastByteValue;
int emptyNameCustom;
KCP_Phases phase;
} cSHAKE_Instance;
/** cSHAKE128 function, as defined in NIST's Special Publication 800-185,
* published December 2016.
* @param input Pointer to the input message (X).
* @param inputBitLen The length of the input message in bits.
* @param output Pointer to the output buffer.
* @param outputBitLen The desired number of output bits (L).
* @param name Pointer to the function name string (N).
* @param nameBitLen The length of the function name in bits.
* Only full bytes are supported, length must be a multiple of 8.
* @param customization Pointer to the customization string (S).
* @param customBitLen The length of the customization string in bits.
* @return 0 if successful, 1 otherwise.
*/
int cSHAKE128( const BitSequence *input, BitLength inputBitLen, BitSequence *output, BitLength outputBitLen, const BitSequence *name, BitLength nameBitLen, const BitSequence *customization, BitLength customBitLen );
/**
* Function to initialize the cSHAKE128 instance used in sequential hashing mode.
* @param cskInstance Pointer to the hash instance to be initialized.
* @param outputBitLen The desired number of output bits (L).
* or 0 for an arbitrarily-long output (XOF).
* @param name Pointer to the function name string (N).
* @param nameBitLen The length of the function name in bits.
* Only full bytes are supported, length must be a multiple of 8.
* @param customization Pointer to the customization string (S).
* @param customBitLen The length of the customization string in bits.
* @return 0 if successful, 1 otherwise.
*/
int cSHAKE128_Initialize(cSHAKE_Instance *cskInstance, BitLength outputBitLen, const BitSequence *name, BitLength nameBitLen, const BitSequence *customization, BitLength customBitLen);
/**
* Function to give input data to be absorbed.
* @param cskInstance Pointer to the hash instance initialized by cSHAKE128_Initialize().
* @param input Pointer to the input data.
* @param inputBitLen The number of input bits provided in the input data.
* Only the last update call can input a partial byte, other calls must have a length multiple of 8.
* @return 0 if successful, 1 otherwise.
*/
int cSHAKE128_Update(cSHAKE_Instance *cskInstance, const BitSequence *input, BitLength inputBitLen);
/**
* Function to call after all input blocks have been input and to get
* output bits if the length was specified when calling cSHAKE128_Initialize().
* @param cskInstance Pointer to the hash instance initialized by cSHAKE128_Initialize().
* If @a outputBitLen was not 0 in the call to cSHAKE128_Initialize(), the number of
* output bits is equal to @a outputBitLen.
* If @a outputBitLen was 0 in the call to cSHAKE128_Initialize(), the output bits
* must be extracted using the cSHAKE128_Squeeze() function.
* @param output Pointer to the buffer where to store the output data.
* @return 0 if successful, 1 otherwise.
*/
int cSHAKE128_Final(cSHAKE_Instance *cskInstance, BitSequence *output);
/**
* Function to squeeze output data.
* @param cskInstance Pointer to the hash instance initialized by cSHAKE128_Initialize().
* @param output Pointer to the buffer where to store the output data.
* @param outputBitLen The number of output bits desired.
* Only the last squeeze call can output a partial byte,
* other calls must have a length multiple of 8.
* @pre cSHAKE128_Final() must have been already called.
* @return 0 if successful, 1 otherwise.
*/
int cSHAKE128_Squeeze(cSHAKE_Instance *cskInstance, BitSequence *output, BitLength outputBitLen);
/* ------------------------------------------------------------------------- */
/** cSHAKE256 function, as defined in NIST's Special Publication 800-185,
* published December 2016.
* @param input Pointer to the input message (X).
* @param inputBitLen The length of the input message in bits.
* @param output Pointer to the output buffer.
* @param outputBitLen The desired number of output bits (L).
* @param name Pointer to the function name string (N).
* @param nameBitLen The length of the function name in bits.
* Only full bytes are supported, length must be a multiple of 8.
* @param customization Pointer to the customization string (S).
* @param customBitLen The length of the customization string in bits.
* @return 0 if successful, 1 otherwise.
*/
int cSHAKE256( const BitSequence *input, BitLength inputBitLen, BitSequence *output, BitLength outputBitLen, const BitSequence *name, BitLength nameBitLen, const BitSequence *customization, BitLength customBitLen );
/**
* Function to initialize the cSHAKE256 instance used in sequential hashing mode.
* @param cskInstance Pointer to the hash instance to be initialized.
* @param outputBitLen The desired number of output bits (L).
* or 0 for an arbitrarily-long output (XOF).
* @param name Pointer to the function name string (N).
* @param nameBitLen The length of the function name in bits.
* Only full bytes are supported, length must be a multiple of 8.
* @param customization Pointer to the customization string (S).
* @param customBitLen The length of the customization string in bits.
* @return 0 if successful, 1 otherwise.
*/
int cSHAKE256_Initialize(cSHAKE_Instance *cskInstance, BitLength outputBitLen, const BitSequence *name, BitLength nameBitLen, const BitSequence *customization, BitLength customBitLen);
/**
* Function to give input data to be absorbed.
* @param cskInstance Pointer to the hash instance initialized by cSHAKE256_Initialize().
* @param input Pointer to the input data.
* @param inputBitLen The number of input bits provided in the input data.
* Only the last update call can input a partial byte, other calls must have a length multiple of 8.
* @return 0 if successful, 1 otherwise.
*/
int cSHAKE256_Update(cSHAKE_Instance *cskInstance, const BitSequence *input, BitLength inputBitLen);
/**
* Function to call after all input blocks have been input and to get
* output bits if the length was specified when calling cSHAKE256_Initialize().
* @param cskInstance Pointer to the hash instance initialized by cSHAKE256_Initialize().
* If @a outputBitLen was not 0 in the call to cSHAKE256_Initialize(), the number of
* output bits is equal to @a outputBitLen.
* If @a outputBitLen was 0 in the call to cSHAKE256_Initialize(), the output bits
* must be extracted using the cSHAKE256_Squeeze() function.
* @param output Pointer to the buffer where to store the output data.
* @return 0 if successful, 1 otherwise.
*/
int cSHAKE256_Final(cSHAKE_Instance *cskInstance, BitSequence *output);
/**
* Function to squeeze output data.
* @param cskInstance Pointer to the hash instance initialized by cSHAKE256_Initialize().
* @param output Pointer to the buffer where to store the output data.
* @param outputBitLen The number of output bits desired.
* Only the last squeeze call can output a partial byte,
* other calls must have a length multiple of 8.
* @pre cSHAKE256_Final() must have been already called.
* @return 0 if successful, 1 otherwise.
*/
int cSHAKE256_Squeeze(cSHAKE_Instance *cskInstance, BitSequence *output, BitLength outputBitLen);
/* ------------------------------------------------------------------------- */
typedef struct {
cSHAKE_Instance csi;
BitLength outputBitLen;
} KMAC_Instance;
/** KMAC128 function, as defined in NIST's Special Publication 800-185,
* published December 2016.
* @param key Pointer to the key (K).
* @param keyBitLen The length of the key in bits.
* @param input Pointer to the input message (X).
* @param inputBitLen The length of the input message in bits.
* Only full bytes are supported, length must be a multiple of 8.
* @param output Pointer to the output buffer.
* @param outputBitLen The desired number of output bits (L).
* @param customization Pointer to the customization string (S).
* @param customBitLen The length of the customization string in bits.
* @return 0 if successful, 1 otherwise.
*/
int KMAC128(const BitSequence *key, BitLength keyBitLen, const BitSequence *input, BitLength inputBitLen,
BitSequence *output, BitLength outputBitLen, const BitSequence *customization, BitLength customBitLen);
/**
* Function to initialize the KMAC128 instance used in sequential MACing mode.
* @param kmInstance Pointer to the instance to be initialized.
* @param key Pointer to the key (K).
* @param keyBitLen The length of the key in bits.
* @param outputBitLen The desired number of output bits (L).
* or 0 for an arbitrarily-long output (XOF).
* @param customization Pointer to the customization string (S).
* @param customBitLen The length of the customization string in bits.
* @return 0 if successful, 1 otherwise.
*/
int KMAC128_Initialize(KMAC_Instance *kmkInstance, const BitSequence *key, BitLength keyBitLen, BitLength outputBitLen,
const BitSequence *customization, BitLength customBitLen);
/**
* Function to give input data to be MACed.
* @param kmInstance Pointer to the instance initialized by KMAC128_Initialize().
* @param input Pointer to the input data.
* @param inputBitLen The number of input bits provided in the input data.
* Only full bytes are supported, length must be a multiple of 8.
* @return 0 if successful, 1 otherwise.
*/
int KMAC128_Update(KMAC_Instance *kmkInstance, const BitSequence *input, BitLength inputBitLen);
/**
* Function to call after all input data have been input and to get
* output bits if the length was specified when calling KMAC128_Initialize().
* @param kmInstance Pointer to the instance initialized by KMAC128_Initialize().
* If @a outputBitLen was not 0 in the call to KMAC128_Initialize(), the number of
* output bits is equal to @a outputBitLen.
* If @a outputBitLen was 0 in the call to KMAC128_Initialize(), the output bits
* must be extracted using the KMAC128_Squeeze() function.
* @param output Pointer to the buffer where to store the output data.
* @return 0 if successful, 1 otherwise.
*/
int KMAC128_Final(KMAC_Instance *kmkInstance, BitSequence *output);
/**
* Function to squeeze output data.
* @param kmInstance Pointer to the instance initialized by KMAC128_Initialize().
* @param output Pointer to the buffer where to store the output data.
* @param outputBitLen The number of output bits desired.
* Only the last squeeze call can output a partial byte,
* other calls must have a length multiple of 8.
* @pre KMAC128_Final() must have been already called.
* @return 0 if successful, 1 otherwise.
*/
int KMAC128_Squeeze(KMAC_Instance *kmkInstance, BitSequence *output, BitLength outputBitLen);
/* ------------------------------------------------------------------------- */
/** KMAC256 function, as defined in NIST's Special Publication 800-185,
* published December 2016.
* @param key Pointer to the key (K).
* @param keyBitLen The length of the key in bits.
* @param input Pointer to the input message (X).
* @param inputBitLen The length of the input message in bits.
* Only full bytes are supported, length must be a multiple of 8.
* @param output Pointer to the output buffer.
* @param outputBitLen The desired number of output bits (L).
* @param customization Pointer to the customization string (S).
* @param customBitLen The length of the customization string in bits.
* @return 0 if successful, 1 otherwise.
*/
int KMAC256(const BitSequence *key, BitLength keyBitLen, const BitSequence *input, BitLength inputBitLen,
BitSequence *output, BitLength outputBitLen, const BitSequence *customization, BitLength customBitLen);
/**
* Function to initialize the KMAC256 instance used in sequential MACing mode.
* @param kmInstance Pointer to the instance to be initialized.
* @param key Pointer to the key (K).
* @param keyBitLen The length of the key in bits.
* @param outputBitLen The desired number of output bits (L).
* or 0 for an arbitrarily-long output (XOF).
* @param customization Pointer to the customization string (S).
* @param customBitLen The length of the customization string in bits.
* @return 0 if successful, 1 otherwise.
*/
int KMAC256_Initialize(KMAC_Instance *kmkInstance, const BitSequence *key, BitLength keyBitLen, BitLength outputBitLen,
const BitSequence *customization, BitLength customBitLen);
/**
* Function to give input data to be MACed.
* @param kmInstance Pointer to the instance initialized by KMAC256_Initialize().
* @param input Pointer to the input data.
* @param inputBitLen The number of input bits provided in the input data.
* Only full bytes are supported, length must be a multiple of 8.
* @return 0 if successful, 1 otherwise.
*/
int KMAC256_Update(KMAC_Instance *kmkInstance, const BitSequence *input, BitLength inputBitLen);
/**
* Function to call after all input data have been input and to get
* output bits if the length was specified when calling KMAC256_Initialize().
* @param kmInstance Pointer to the instance initialized by KMAC256_Initialize().
* If @a outputBitLen was not 0 in the call to KMAC256_Initialize(), the number of
* output bits is equal to @a outputBitLen.
* If @a outputBitLen was 0 in the call to KMAC256_Initialize(), the output bits
* must be extracted using the KMAC256_Squeeze() function.
* @param output Pointer to the buffer where to store the output data.
* @return 0 if successful, 1 otherwise.
*/
int KMAC256_Final(KMAC_Instance *kmkInstance, BitSequence *output);
/**
* Function to squeeze output data.
* @param kmInstance Pointer to the instance initialized by KMAC256_Initialize().
* @param output Pointer to the buffer where to store the output data.
* @param outputBitLen The number of output bits desired.
* Only the last squeeze call can output a partial byte,
* other calls must have a length multiple of 8.
* @pre KMAC256_Final() must have been already called.
* @return 0 if successful, 1 otherwise.
*/
int KMAC256_Squeeze(KMAC_Instance *kmkInstance, BitSequence *output, BitLength outputBitLen);
/* ------------------------------------------------------------------------- */
typedef struct {
KeccakWidth1600_SpongeInstance queueNode;
KeccakWidth1600_SpongeInstance finalNode;
size_t fixedOutputLength;
size_t blockLen;
size_t queueAbsorbedLen;
size_t totalInputSize;
KCP_Phases phase;
} ParallelHash_Instance;
/** Parallel hash function ParallelHash128, as defined in NIST's Special Publication 800-185,
* published December 2016.
* @param input Pointer to the input message (X).
* @param inputBitLen The number of input bits provided in the input data.
* Only full bytes are supported, length must be a multiple of 8.
* @param blockByteLen Block size (B) in bytes, must be a power of 2.
* The minimum value is 8 in this implementation.
* @param output Pointer to the output buffer.
* @param outputBitLen The desired number of output bits (L).
* @param customization Pointer to the customization string (S).
* @param customBitLen The length of the customization string in bits.
* @return 0 if successful, 1 otherwise.
*/
int ParallelHash128( const BitSequence *input, BitLength inputBitLen, size_t blockByteLen,
BitSequence *output, BitLength outputBitLen, const BitSequence *customization, BitLength customBitLen);
/**
* Function to initialize the parallel hash function ParallelHash128 instance used in sequential hashing mode.
* @param ParallelHashInstance Pointer to the hash instance to be initialized.
* @param blockByteLen Block size (B) in bytes, must be a power of 2.
* The minimum value is 8 in this implementation.
* @param outputBitLen The desired number of output bits (L).
* or 0 for an arbitrarily-long output (XOF).
* @param customization Pointer to the customization string (S).
* @param customBitLen The length of the customization string in bits.
* @return 0 if successful, 1 otherwise.
*/
int ParallelHash128_Initialize(ParallelHash_Instance *ParallelHashInstance, size_t blockByteLen,
BitLength outputBitLen, const BitSequence *customization, BitLength customBitLen);
/**
* Function to give input data to be absorbed.
* @param ParallelHashInstance Pointer to the hash instance initialized by ParallelHash128_Initialize().
* @param input Pointer to the input data (X).
* @param inputBitLen The number of input bits provided in the input data.
* Only full bytes are supported, length must be a multiple of 8.
* @return 0 if successful, 1 otherwise.
*/
int ParallelHash128_Update(ParallelHash_Instance *ParallelHashInstance, const BitSequence *input, BitLength inputBitLen);
/**
* Function to call after all input blocks have been input and to get
* output bits if the length was specified when calling ParallelHash128_Initialize().
* @param ParallelHashInstance Pointer to the hash instance initialized by ParallelHash128_Initialize().
* If @a outputBitLen was not 0 in the call to ParallelHash128_Initialize(), the number of
* output bits is equal to @a outputBitLen.
* If @a outputBitLen was 0 in the call to ParallelHash128_Initialize(), the output bits
* must be extracted using the ParallelHash128_Squeeze() function.
* @param output Pointer to the buffer where to store the output data.
* @return 0 if successful, 1 otherwise.
*/
int ParallelHash128_Final(ParallelHash_Instance *ParallelHashInstance, BitSequence * output);
/**
* Function to squeeze output data.
* @param ParallelHashInstance Pointer to the hash instance initialized by ParallelHash128_Initialize().
* @param output Pointer to the buffer where to store the output data.
* @param outputBitLen The number of output bits desired.
* Only the last squeeze call can output a partial byte,
* other calls must have a length multiple of 8.
* @pre ParallelHash128_Final() must have been already called.
* @return 0 if successful, 1 otherwise.
*/
int ParallelHash128_Squeeze(ParallelHash_Instance *ParallelHashInstance, BitSequence *output, BitLength outputBitLen);
/* ------------------------------------------------------------------------- */
/** Parallel hash function ParallelHash256, as defined in NIST's Special Publication 800-185,
* published December 2016.
* @param input Pointer to the input message (X).
* @param inputBitLen The number of input bits provided in the input data.
* Only full bytes are supported, length must be a multiple of 8.
* @param blockByteLen Block size (B) in bytes, must be a power of 2.
* The minimum value is 8 in this implementation.
* @param output Pointer to the output buffer.
* @param outputBitLen The desired number of output bits (L).
* @param customization Pointer to the customization string (S).
* @param customBitLen The length of the customization string in bits.
* @return 0 if successful, 1 otherwise.
*/
int ParallelHash256( const BitSequence *input, BitLength inputBitLen, size_t blockByteLen,
BitSequence *output, BitLength outputBitLen, const BitSequence *customization, BitLength customBitLen);
/**
* Function to initialize the parallel hash function ParallelHash256 instance used in sequential hashing mode.
* @param ParallelHashInstance Pointer to the hash instance to be initialized.
* @param blockByteLen Block size (B) in bytes, must be a power of 2.
* The minimum value is 8 in this implementation.
* @param outputBitLen The desired number of output bits (L).
* or 0 for an arbitrarily-long output (XOF).
* @param customization Pointer to the customization string (S).
* @param customBitLen The length of the customization string in bits.
* @return 0 if successful, 1 otherwise.
*/
int ParallelHash256_Initialize(ParallelHash_Instance *ParallelHashInstance, size_t blockByteLen,
BitLength outputBitLen, const BitSequence *customization, BitLength customBitLen);
/**
* Function to give input data to be absorbed.
* @param ParallelHashInstance Pointer to the hash instance initialized by ParallelHash256_Initialize().
* @param input Pointer to the input data (X).
* @param inputBitLen The number of input bits provided in the input data.
* Only full bytes are supported, length must be a multiple of 8.
* @return 0 if successful, 1 otherwise.
*/
int ParallelHash256_Update(ParallelHash_Instance *ParallelHashInstance, const BitSequence *input, BitLength inputBitLen);
/**
* Function to call after all input blocks have been input and to get
* output bits if the length was specified when calling ParallelHash256_Initialize().
* @param ParallelHashInstance Pointer to the hash instance initialized by ParallelHash256_Initialize().
* If @a outputBitLen was not 0 in the call to ParallelHash256_Initialize(), the number of
* output bits is equal to @a outputBitLen.
* If @a outputBitLen was 0 in the call to ParallelHash256_Initialize(), the output bits
* must be extracted using the ParallelHash256_Squeeze() function.
* @param output Pointer to the buffer where to store the output data.
* @return 0 if successful, 1 otherwise.
*/
int ParallelHash256_Final(ParallelHash_Instance *ParallelHashInstance, BitSequence * output);
/**
* Function to squeeze output data.
* @param ParallelHashInstance Pointer to the hash instance initialized by ParallelHash256_Initialize().
* @param output Pointer to the buffer where to store the output data.
* @param outputBitLen The number of output bits desired.
* Only the last squeeze call can output a partial byte,
* other calls must have a length multiple of 8.
* @pre ParallelHash256_Final() must have been already called.
* @return 0 if successful, 1 otherwise.
*/
int ParallelHash256_Squeeze(ParallelHash_Instance *ParallelHashInstance, BitSequence *output, BitLength outputBitLen);
/* ------------------------------------------------------------------------- */
typedef struct {
cSHAKE_Instance csi;
BitLength outputBitLen;
} TupleHash_Instance;
typedef struct {
/** Pointer to the tuple element data (Xn). */
const BitSequence *input;
/** The number of input bits provided in this tuple element.
* Only full bytes are supported, length must be a multiple of 8.
*/
BitLength inputBitLen;
} TupleElement;
/** Tuple hash function TupleHash128, as defined in NIST's Special Publication 800-185,
* published December 2016.
* @param tuple Pointer to an array of tuple elements (X).
* @param numberOfElements The number of tuple elements provided in the input data.
* @param output Pointer to the output buffer.
* @param outputBitLen The desired number of output bits (L).
* @param customization Pointer to the customization string (S).
* @param customBitLen The length of the customization string in bits.
* @return 0 if successful, 1 otherwise.
*/
int TupleHash128( const TupleElement *tuple, size_t numberOfElements,
BitSequence *output, BitLength outputBitLen, const BitSequence *customization, BitLength customBitLen);
/**
* Function to initialize the Tuple hash function TupleHash128 instance used in sequential hashing mode.
* @param TupleHashInstance Pointer to the hash instance to be initialized.
* @param outputBitLen The desired number of output bits (L).
* or 0 for an arbitrarily-long output (XOF).
* @param customization Pointer to the customization string (S).
* @param customBitLen The length of the customization string in bits.
* @return 0 if successful, 1 otherwise.
*/
int TupleHash128_Initialize(TupleHash_Instance *TupleHashInstance, BitLength outputBitLen,
const BitSequence *customization, BitLength customBitLen);
/**
* Function to give input data to be absorbed.
* @param TupleHashInstance Pointer to the hash instance initialized by TupleHash128_Initialize().
* @param tuple Pointer to an array of tuple elements (X).
* @param numberOfElements The number of tuple elements provided in the input data.
* @return 0 if successful, 1 otherwise.
*/
int TupleHash128_Update(TupleHash_Instance *TupleHashInstance, const TupleElement *tuple, size_t numberOfElements);
/**
* Function to call after all input blocks have been input and to get
* output bits if the length was specified when calling TupleHash128_Initialize().
* @param TupleHashInstance Pointer to the hash instance initialized by TupleHash128_Initialize().
* If @a outputBitLen was not 0 in the call to TupleHash128_Initialize(), the number of
* output bits is equal to @a outputBitLen.
* If @a outputBitLen was 0 in the call to TupleHash128_Initialize(), the output bits
* must be extracted using the TupleHash128_Squeeze() function.
* @param output Pointer to the buffer where to store the output data.
* @return 0 if successful, 1 otherwise.
*/
int TupleHash128_Final(TupleHash_Instance *TupleHashInstance, BitSequence * output);
/**
* Function to squeeze output data.
* @param TupleHashInstance Pointer to the hash instance initialized by TupleHash128_Initialize().
* @param output Pointer to the buffer where to store the output data.
* @param outputBitLen The number of output bits desired.
* Only the last squeeze call can output a partial byte,
* other calls must have a length multiple of 8.
* @pre TupleHash128_Final() must have been already called.
* @return 0 if successful, 1 otherwise.
*/
int TupleHash128_Squeeze(TupleHash_Instance *TupleHashInstance, BitSequence *output, BitLength outputBitLen);
/* ------------------------------------------------------------------------- */
/** Tuple hash function TupleHash256, as defined in NIST's Special Publication 800-185,
* published December 2016.
* @param tuple Pointer to an array of tuple elements (X).
* @param numberOfElements The number of tuple elements provided in the input data.
* @param output Pointer to the output buffer.
* @param outputBitLen The desired number of output bits (L).
* @param customization Pointer to the customization string (S).
* @param customBitLen The length of the customization string in bits.
* @return 0 if successful, 1 otherwise.
*/
int TupleHash256( const TupleElement *tuple, size_t numberOfElements,
BitSequence *output, BitLength outputBitLen, const BitSequence *customization, BitLength customBitLen);
/**
* Function to initialize the Tuple hash function TupleHash256 instance used in sequential hashing mode.
* @param TupleHashInstance Pointer to the hash instance to be initialized.
* @param outputBitLen The desired number of output bits (L).
* or 0 for an arbitrarily-long output (XOF).
* @param customization Pointer to the customization string (S).
* @param customBitLen The length of the customization string in bits.
* @return 0 if successful, 1 otherwise.
*/
int TupleHash256_Initialize(TupleHash_Instance *TupleHashInstance, BitLength outputBitLen,
const BitSequence *customization, BitLength customBitLen);
/**
* Function to give input data to be absorbed.
* @param TupleHashInstance Pointer to the hash instance initialized by TupleHash256_Initialize().
* @param tuple Pointer to an array of tuple elements (X).
* @param numberOfElements The number of tuple elements provided in the input data.
* @return 0 if successful, 1 otherwise.
*/
int TupleHash256_Update(TupleHash_Instance *TupleHashInstance, const TupleElement *tuple, size_t numberOfElements);
/**
* Function to call after all input blocks have been input and to get
* output bits if the length was specified when calling TupleHash256_Initialize().
* @param TupleHashInstance Pointer to the hash instance initialized by TupleHash256_Initialize().
* If @a outputBitLen was not 0 in the call to TupleHash256_Initialize(), the number of
* output bits is equal to @a outputBitLen.
* If @a outputBitLen was 0 in the call to TupleHash256_Initialize(), the output bits
* must be extracted using the TupleHash256_Squeeze() function.
* @param output Pointer to the buffer where to store the output data.
* @return 0 if successful, 1 otherwise.
*/
int TupleHash256_Final(TupleHash_Instance *TupleHashInstance, BitSequence * output);
/**
* Function to squeeze output data.
* @param TupleHashInstance Pointer to the hash instance initialized by TupleHash256_Initialize().
* @param output Pointer to the buffer where to store the output data.
* @param outputBitLen The number of output bits desired.
* Only the last squeeze call can output a partial byte,
* other calls must have a length multiple of 8.
* @pre TupleHash256_Final() must have been already called.
* @return 0 if successful, 1 otherwise.
*/
int TupleHash256_Squeeze(TupleHash_Instance *TupleHashInstance, BitSequence *output, BitLength outputBitLen);
#else
#error This requires an implementation of Keccak-p[1600]
#endif
#endif