File: cryptlib_hash.h

package info (click to toggle)
nvidia-open-gpu-kernel-modules 550.163.01-4
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 87,488 kB
  • sloc: ansic: 1,143,669; cpp: 22,547; sh: 3,721; makefile: 627; python: 315
file content (772 lines) | stat: -rw-r--r-- 31,006 bytes parent folder | download | duplicates (17)
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
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
/**
 *  Copyright Notice:
 *  Copyright 2021-2022 DMTF. All rights reserved.
 *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
 **/

#ifndef CRYPTLIB_HASH_H
#define CRYPTLIB_HASH_H

/* SHA-256 digest size in bytes. */
#define LIBSPDM_SHA256_DIGEST_SIZE 32

/* SHA-384 digest size in bytes. */
#define LIBSPDM_SHA384_DIGEST_SIZE 48

/* SHA-512 digest size in bytes. */
#define LIBSPDM_SHA512_DIGEST_SIZE 64

/* SHA3-256 digest size in bytes. */
#define LIBSPDM_SHA3_256_DIGEST_SIZE 32

/* SHA3-384 digest size in bytes. */
#define LIBSPDM_SHA3_384_DIGEST_SIZE 48

/* SHA3-512 digest size in bytes. */
#define LIBSPDM_SHA3_512_DIGEST_SIZE 64

/* SM3_256 digest size in bytes. */
#define LIBSPDM_SM3_256_DIGEST_SIZE 32

/*=====================================================================================
 *    One-way cryptographic hash SHA2 primitives.
 *=====================================================================================
 */
#if LIBSPDM_SHA256_SUPPORT
/**
 * Allocates and initializes one HASH_CTX context for subsequent SHA-256 use.
 *
 * @return  Pointer to the HASH_CTX context that has been initialized.
 *          If the allocations fails, sha256_new() returns NULL. *
 **/
extern void *libspdm_sha256_new(void);

/**
 * Release the specified HASH_CTX context.
 *
 * @param[in]  sha256_context  Pointer to the HASH_CTX context to be released.
 **/
extern void libspdm_sha256_free(void *sha256_context);

/**
 * Initializes user-supplied memory pointed to by sha256_context as SHA-256 hash context for
 * subsequent use.
 *
 * If sha256_context is NULL, then return false.
 *
 * @param[out]  sha256_context  Pointer to SHA-256 context being initialized.
 *
 * @retval true   SHA-256 context initialization succeeded.
 * @retval false  SHA-256 context initialization failed.
 **/
extern bool libspdm_sha256_init(void *sha256_context);

/**
 * Makes a copy of an existing SHA-256 context.
 *
 * If sha256_context is NULL, then return false.
 * If new_sha256_context is NULL, then return false.
 * If this interface is not supported, then return false.
 *
 * @param[in]  sha256_context      Pointer to SHA-256 context being copied.
 * @param[out] new_sha256_context  Pointer to new SHA-256 context.
 *
 * @retval true   SHA-256 context copy succeeded.
 * @retval false  SHA-256 context copy failed.
 * @retval false  This interface is not supported.
 **/
extern bool libspdm_sha256_duplicate(const void *sha256_context, void *new_sha256_context);

/**
 * Digests the input data and updates SHA-256 context.
 *
 * This function performs SHA-256 digest on a data buffer of the specified size.
 * It can be called multiple times to compute the digest of long or discontinuous data streams.
 * SHA-256 context should be already correctly initialized by libspdm_sha256_init(), and must not
 * have been finalized by libspdm_sha256_final(). Behavior with invalid context is undefined.
 *
 * If sha256_context is NULL, then return false.
 *
 * @param[in, out]  sha256_context  Pointer to the SHA-256 context.
 * @param[in]       data            Pointer to the buffer containing the data to be hashed.
 * @param[in]       data_size       Size of data buffer in bytes.
 *
 * @retval true   SHA-256 data digest succeeded.
 * @retval false  SHA-256 data digest failed.
 **/
extern bool libspdm_sha256_update(void *sha256_context, const void *data, size_t data_size);

/**
 * Completes computation of the SHA-256 digest value.
 *
 * This function completes SHA-256 hash computation and populates the digest value into
 * the specified memory. After this function has been called, the SHA-256 context cannot
 * be used again. SHA-256 context should be already correctly initialized by libspdm_sha256_init(),
 * and must not have been finalized by libspdm_sha256_final(). Behavior with invalid SHA-256 context
 * is undefined.
 *
 * If sha256_context is NULL, then return false.
 * If hash_value is NULL, then return false.
 *
 * @param[in, out]  sha256_context  Pointer to the SHA-256 context.
 * @param[out]      hash_value      Pointer to a buffer that receives the SHA-256 digest
 *                                  value (32 bytes).
 *
 * @retval true   SHA-256 digest computation succeeded.
 * @retval false  SHA-256 digest computation failed.
 **/
extern bool libspdm_sha256_final(void *sha256_context, uint8_t *hash_value);

/**
 * Computes the SHA-256 message digest of an input data buffer.
 *
 * This function performs the SHA-256 message digest of a given data buffer, and places
 * the digest value into the specified memory.
 *
 * If this interface is not supported, then return false.
 *
 * @param[in]   data        Pointer to the buffer containing the data to be hashed.
 * @param[in]   data_size   Size of data buffer in bytes.
 * @param[out]  hash_value  Pointer to a buffer that receives the SHA-256 digest value (32 bytes).
 *
 * @retval true   SHA-256 digest computation succeeded.
 * @retval false  SHA-256 digest computation failed.
 * @retval false  This interface is not supported.
 **/
extern bool libspdm_sha256_hash_all(const void *data, size_t data_size, uint8_t *hash_value);
#endif /* LIBSPDM_SHA256_SUPPORT */

#if LIBSPDM_SHA384_SUPPORT
/**
 * Allocates and initializes one HASH_CTX context for subsequent SHA-384 use.
 *
 * @return  Pointer to the HASH_CTX context that has been initialized.
 *          If the allocations fails, libspdm_sha384_new() returns NULL.
 **/
extern void *libspdm_sha384_new(void);

/**
 * Release the specified HASH_CTX context.
 *
 * @param[in]  sha384_context  Pointer to the HASH_CTX context to be released.
 **/
extern void libspdm_sha384_free(void *sha384_context);

/**
 * Initializes user-supplied memory pointed to by sha384_context as SHA-384 hash context for
 * subsequent use.
 *
 * If sha384_context is NULL, then return false.
 *
 * @param[out]  sha384_context  Pointer to SHA-384 context being initialized.
 *
 * @retval true   SHA-384 context initialization succeeded.
 * @retval false  SHA-384 context initialization failed.
 **/
extern bool libspdm_sha384_init(void *sha384_context);

/**
 * Makes a copy of an existing SHA-384 context.
 *
 * If sha384_context is NULL, then return false.
 * If new_sha384_context is NULL, then return false.
 * If this interface is not supported, then return false.
 *
 * @param[in]  sha384_context      Pointer to SHA-384 context being copied.
 * @param[out] new_sha384_context  Pointer to new SHA-384 context.
 *
 * @retval true   SHA-384 context copy succeeded.
 * @retval false  SHA-384 context copy failed.
 * @retval false  This interface is not supported.
 **/
extern bool libspdm_sha384_duplicate(const void *sha384_context, void *new_sha384_context);

/**
 * Digests the input data and updates SHA-384 context.
 *
 * This function performs SHA-384 digest on a data buffer of the specified size.
 * It can be called multiple times to compute the digest of long or discontinuous data streams.
 * SHA-384 context should be already correctly initialized by libspdm_sha384_init(), and must not
 * have been finalized by libspdm_sha384_final(). Behavior with invalid context is undefined.
 *
 * If sha384_context is NULL, then return false.
 *
 * @param[in, out]  sha384_context  Pointer to the SHA-384 context.
 * @param[in]       data            Pointer to the buffer containing the data to be hashed.
 * @param[in]       data_size       Size of data buffer in bytes.
 *
 * @retval true   SHA-384 data digest succeeded.
 * @retval false  SHA-384 data digest failed.
 **/
extern bool libspdm_sha384_update(void *sha384_context, const void *data, size_t data_size);

/**
 * Completes computation of the SHA-384 digest value.
 *
 * This function completes SHA-384 hash computation and populates the digest value into
 * the specified memory. After this function has been called, the SHA-384 context cannot
 * be used again. SHA-384 context should be already correctly initialized by libspdm_sha384_init(),
 * and must not have been finalized by libspdm_sha384_final(). Behavior with invalid SHA-384 context
 * is undefined.
 *
 * If sha384_context is NULL, then return false.
 * If hash_value is NULL, then return false.
 *
 * @param[in, out]  sha384_context  Pointer to the SHA-384 context.
 * @param[out]      hash_value      Pointer to a buffer that receives the SHA-384 digest
 *                                  value (48 bytes).
 *
 * @retval true   SHA-384 digest computation succeeded.
 * @retval false  SHA-384 digest computation failed.
 **/
extern bool libspdm_sha384_final(void *sha384_context, uint8_t *hash_value);

/**
 * Computes the SHA-384 message digest of an input data buffer.
 *
 * This function performs the SHA-384 message digest of a given data buffer, and places
 * the digest value into the specified memory.
 *
 * If this interface is not supported, then return false.
 *
 * @param[in]   data        Pointer to the buffer containing the data to be hashed.
 * @param[in]   data_size   Size of data buffer in bytes.
 * @param[out]  hash_value  Pointer to a buffer that receives the SHA-384 digest value (48 bytes).
 *
 * @retval true   SHA-384 digest computation succeeded.
 * @retval false  SHA-384 digest computation failed.
 * @retval false  This interface is not supported.
 **/
extern bool libspdm_sha384_hash_all(const void *data, size_t data_size, uint8_t *hash_value);
#endif /* LIBSPDM_SHA384_SUPPORT */

#if LIBSPDM_SHA512_SUPPORT
/**
 * Allocates and initializes one HASH_CTX context for subsequent SHA-512 use.
 *
 * @return  Pointer to the HASH_CTX context that has been initialized.
 *          If the allocations fails, libspdm_sha512_new() returns NULL.
 **/
extern void *libspdm_sha512_new(void);

/**
 * Release the specified HASH_CTX context.
 *
 * @param[in]  sha512_context  Pointer to the HASH_CTX context to be released.
 **/
extern void libspdm_sha512_free(void *sha512_context);

/**
 * Initializes user-supplied memory pointed by sha512_context as SHA-512 hash context for
 * subsequent use.
 *
 * If sha512_context is NULL, then return false.
 *
 * @param[out]  sha512_context  Pointer to SHA-512 context being initialized.
 *
 * @retval true   SHA-512 context initialization succeeded.
 * @retval false  SHA-512 context initialization failed.
 **/
extern bool libspdm_sha512_init(void *sha512_context);

/**
 * Makes a copy of an existing SHA-512 context.
 *
 * If sha512_context is NULL, then return false.
 * If new_sha512_context is NULL, then return false.
 * If this interface is not supported, then return false.
 *
 * @param[in]  sha512_context      Pointer to SHA-512 context being copied.
 * @param[out] new_sha512_context  Pointer to new SHA-512 context.
 *
 * @retval true   SHA-512 context copy succeeded.
 * @retval false  SHA-512 context copy failed.
 * @retval false  This interface is not supported.
 **/
extern bool libspdm_sha512_duplicate(const void *sha512_context, void *new_sha512_context);

/**
 * Digests the input data and updates SHA-512 context.
 *
 * This function performs SHA-512 digest on a data buffer of the specified size.
 * It can be called multiple times to compute the digest of long or discontinuous data streams.
 * SHA-512 context should be already correctly initialized by libspdm_sha512_init(), and must not
 * have been finalized by libspdm_sha512_final(). Behavior with invalid context is undefined.
 *
 * If sha512_context is NULL, then return false.
 *
 * @param[in, out]  sha512_context  Pointer to the SHA-512 context.
 * @param[in]       data            Pointer to the buffer containing the data to be hashed.
 * @param[in]       data_size       Size of data buffer in bytes.
 *
 * @retval true   SHA-512 data digest succeeded.
 * @retval false  SHA-512 data digest failed.
 **/
extern bool libspdm_sha512_update(void *sha512_context, const void *data, size_t data_size);

/**
 * Completes computation of the SHA-512 digest value.
 *
 * This function completes SHA-512 hash computation and populates the digest value into
 * the specified memory. After this function has been called, the SHA-512 context cannot
 * be used again. SHA-512 context should be already correctly initialized by libspdm_sha512_init(),
 * and must not have been finalized by libspdm_sha512_final(). Behavior with invalid SHA-512 context
 * is undefined.
 *
 * If sha512_context is NULL, then return false.
 * If hash_value is NULL, then return false.
 *
 * @param[in, out]  sha512_context  Pointer to the SHA-512 context.
 * @param[out]      hash_value      Pointer to a buffer that receives the SHA-512 digest
 *                                value (64 bytes).
 *
 * @retval true   SHA-512 digest computation succeeded.
 * @retval false  SHA-512 digest computation failed.
 **/
extern bool libspdm_sha512_final(void *sha512_context, uint8_t *hash_value);

/**
 * Computes the SHA-512 message digest of an input data buffer.
 *
 * This function performs the SHA-512 message digest of a given data buffer, and places
 * the digest value into the specified memory.
 *
 * If this interface is not supported, then return false.
 *
 * @param[in]   data        Pointer to the buffer containing the data to be hashed.
 * @param[in]   data_size   Size of data buffer in bytes.
 * @param[out]  hash_value  Pointer to a buffer that receives the SHA-512 digest value (64 bytes).
 *
 * @retval true   SHA-512 digest computation succeeded.
 * @retval false  SHA-512 digest computation failed.
 * @retval false  This interface is not supported.
 **/
extern bool libspdm_sha512_hash_all(const void *data, size_t data_size, uint8_t *hash_value);
#endif /* LIBSPDM_SHA512_SUPPORT */

/*=====================================================================================
 *    One-way cryptographic hash SHA3 primitives.
 *=====================================================================================
 */
#if LIBSPDM_SHA3_256_SUPPORT
/**
 * Allocates and initializes one HASH_CTX context for subsequent SHA3-256 use.
 *
 * @return  Pointer to the HASH_CTX context that has been initialized.
 *          If the allocations fails, libspdm_sha3_256_new() returns NULL.
 **/
extern void *libspdm_sha3_256_new(void);

/**
 * Release the specified HASH_CTX context.
 *
 * @param[in]  sha3_256_context  Pointer to the HASH_CTX context to be released.
 **/
extern void libspdm_sha3_256_free(void *sha3_256_context);

/**
 * Initializes user-supplied memory pointed by sha3_256_context as SHA3-256 hash context for
 * subsequent use.
 *
 * If sha3_256_context is NULL, then return false.
 *
 * @param[out]  sha3_256_context  Pointer to SHA3-256 context being initialized.
 *
 * @retval true   SHA3-256 context initialization succeeded.
 * @retval false  SHA3-256 context initialization failed.
 **/
extern bool libspdm_sha3_256_init(void *sha3_256_context);

/**
 * Makes a copy of an existing SHA3-256 context.
 *
 * If sha3_256_context is NULL, then return false.
 * If new_sha3_256_context is NULL, then return false.
 * If this interface is not supported, then return false.
 *
 * @param[in]  sha3_256_context      Pointer to SHA3-256 context being copied.
 * @param[out] new_sha3_256_context  Pointer to new SHA3-256 context.
 *
 * @retval true   SHA3-256 context copy succeeded.
 * @retval false  SHA3-256 context copy failed.
 * @retval false  This interface is not supported.
 **/
extern bool libspdm_sha3_256_duplicate(const void *sha3_256_context, void *new_sha3_256_context);

/**
 * Digests the input data and updates SHA3-256 context.
 *
 * This function performs SHA3-256 digest on a data buffer of the specified size.
 * It can be called multiple times to compute the digest of long or discontinuous data streams.
 * SHA3-256 context should be already correctly initialized by libspdm_sha3_256_init(), and must not
 * have been finalized by libspdm_sha3_256_final(). Behavior with invalid context is undefined.
 *
 * If sha3_256_context is NULL, then return false.
 *
 * @param[in, out]  sha3_256_context  Pointer to the SHA3-256 context.
 * @param[in]       data              Pointer to the buffer containing the data to be hashed.
 * @param[in]       data_size       size of data buffer in bytes.
 *
 * @retval true   SHA3-256 data digest succeeded.
 * @retval false  SHA3-256 data digest failed.
 **/
extern bool libspdm_sha3_256_update(void *sha3_256_context, const void *data, size_t data_size);

/**
 * Completes computation of the SHA3-256 digest value.
 *
 * This function completes SHA3-256 hash computation and populates the digest value into
 * the specified memory. After this function has been called, the SHA3-512 context cannot
 * be used again. SHA3-256 context should be already correctly initialized by
 * libspdm_sha3_256_init(), and must not have been finalized by libspdm_sha3_256_final().
 * Behavior with invalid SHA3-256 context is undefined.
 *
 * If sha3_256_context is NULL, then return false.
 * If hash_value is NULL, then return false.
 *
 * @param[in, out]  sha3_256_context  Pointer to the SHA3-256 context.
 * @param[out]      hash_value        Pointer to a buffer that receives the SHA3-256 digest
 *                                    value (32 bytes).
 *
 * @retval true   SHA3-256 digest computation succeeded.
 * @retval false  SHA3-256 digest computation failed.
 **/
extern bool libspdm_sha3_256_final(void *sha3_256_context, uint8_t *hash_value);

/**
 * Computes the SHA3-256 message digest of an input data buffer.
 *
 * This function performs the SHA3-256 message digest of a given data buffer, and places
 * the digest value into the specified memory.
 *
 * If this interface is not supported, then return false.
 *
 * @param[in]   data        Pointer to the buffer containing the data to be hashed.
 * @param[in]   data_size   Size of data buffer in bytes.
 * @param[out]  hash_value  Pointer to a buffer that receives the SHA3-256 digest value (32 bytes).
 *
 * @retval true   SHA3-256 digest computation succeeded.
 * @retval false  SHA3-256 digest computation failed.
 * @retval false  This interface is not supported.
 **/
extern bool libspdm_sha3_256_hash_all(const void *data, size_t data_size, uint8_t *hash_value);
#endif /* LIBSPDM_SHA3_256_SUPPORT */

#if LIBSPDM_SHA3_384_SUPPORT
/**
 * Allocates and initializes one HASH_CTX context for subsequent SHA3-384 use.
 *
 * @return  Pointer to the HASH_CTX context that has been initialized.
 *          If the allocations fails, libspdm_sha3_384_new() returns NULL.
 **/
extern void *libspdm_sha3_384_new(void);

/**
 * Release the specified HASH_CTX context.
 *
 * @param[in]  sha3_384_context  Pointer to the HASH_CTX context to be released.
 **/
extern void libspdm_sha3_384_free(void *sha3_384_context);

/**
 * Initializes user-supplied memory pointed by sha3_384_context as SHA3-384 hash context for
 * subsequent use.
 *
 * If sha3_384_context is NULL, then return false.
 *
 * @param[out]  sha3_384_context  Pointer to SHA3-384 context being initialized.
 *
 * @retval true   SHA3-384 context initialization succeeded.
 * @retval false  SHA3-384 context initialization failed.
 **/
extern bool libspdm_sha3_384_init(void *sha3_384_context);

/**
 * Makes a copy of an existing SHA3-384 context.
 *
 * If sha3_384_context is NULL, then return false.
 * If new_sha3_384_context is NULL, then return false.
 * If this interface is not supported, then return false.
 *
 * @param[in]  sha3_384_context      Pointer to SHA3-384 context being copied.
 * @param[out] new_sha3_384_context  Pointer to new SHA3-384 context.
 *
 * @retval true   SHA3-384 context copy succeeded.
 * @retval false  SHA3-384 context copy failed.
 * @retval false  This interface is not supported.
 **/
extern bool libspdm_sha3_384_duplicate(const void *sha3_384_context, void *new_sha3_384_context);

/**
 * Digests the input data and updates SHA3-384 context.
 *
 * This function performs SHA3-384 digest on a data buffer of the specified size.
 * It can be called multiple times to compute the digest of long or discontinuous data streams.
 * SHA3-384 context should be already correctly initialized by libspdm_sha3_384_init(), and must not
 * have been finalized by libspdm_sha3_384_final(). Behavior with invalid context is undefined.
 *
 * If sha3_384_context is NULL, then return false.
 *
 * @param[in, out]  sha3_384_context  Pointer to the SHA3-384 context.
 * @param[in]       data              Pointer to the buffer containing the data to be hashed.
 * @param[in]       data_size         Size of data buffer in bytes.
 *
 * @retval true   SHA3-384 data digest succeeded.
 * @retval false  SHA3-384 data digest failed.
 **/
extern bool libspdm_sha3_384_update(void *sha3_384_context, const void *data, size_t data_size);

/**
 * Completes computation of the SHA3-384 digest value.
 *
 * This function completes SHA3-384 hash computation and populates the digest value into
 * the specified memory. After this function has been called, the SHA3-384 context cannot
 * be used again. SHA3-384 context should be already correctly initialized by
 * libspdm_sha3_384_init(), and must not have been finalized by libspdm_sha3_384_final().
 * Behavior with invalid SHA3-384 context is undefined.
 *
 * If sha3_384_context is NULL, then return false.
 * If hash_value is NULL, then return false.
 *
 * @param[in, out]  sha3_384_context  Pointer to the SHA3-384 context.
 * @param[out]      hash_value        Pointer to a buffer that receives the SHA3-384 digest
 *                                    value (48 bytes).
 *
 * @retval true   SHA3-384 digest computation succeeded.
 * @retval false  SHA3-384 digest computation failed.
 *
 **/
extern bool libspdm_sha3_384_final(void *sha3_384_context, uint8_t *hash_value);

/**
 * Computes the SHA3-384 message digest of an input data buffer.
 *
 * This function performs the SHA3-384 message digest of a given data buffer, and places
 * the digest value into the specified memory.
 *
 * If this interface is not supported, then return false.
 *
 * @param[in]   data        Pointer to the buffer containing the data to be hashed.
 * @param[in]   data_size   Size of data buffer in bytes.
 * @param[out]  hash_value  Pointer to a buffer that receives the SHA3-384 digest value (48 bytes).
 *
 * @retval true   SHA3-384 digest computation succeeded.
 * @retval false  SHA3-384 digest computation failed.
 * @retval false  This interface is not supported.
 **/
extern bool libspdm_sha3_384_hash_all(const void *data, size_t data_size, uint8_t *hash_value);
#endif /* LIBSPDM_SHA3_384_SUPPORT */

#if LIBSPDM_SHA3_512_SUPPORT
/**
 * Allocates and initializes one HASH_CTX context for subsequent SHA3-512 use.
 *
 * @return  Pointer to the HASH_CTX context that has been initialized.
 *          If the allocations fails, libspdm_sha3_512_new() returns NULL.
 **/
extern void *libspdm_sha3_512_new(void);

/**
 * Release the specified HASH_CTX context.
 *
 * @param[in]  sha3_512_context  Pointer to the HASH_CTX context to be released.
 **/
extern void libspdm_sha3_512_free(void *sha3_512_context);

/**
 * Initializes user-supplied memory pointed by sha3_512_context as SHA3-512 hash context for
 * subsequent use.
 *
 * If sha3_512_context is NULL, then return false.
 *
 * @param[out]  sha3_512_context  Pointer to SHA3-512 context being initialized.
 *
 * @retval true   SHA3-512 context initialization succeeded.
 * @retval false  SHA3-512 context initialization failed.
 **/
extern bool libspdm_sha3_512_init(void *sha3_512_context);

/**
 * Makes a copy of an existing SHA3-512 context.
 *
 * If sha3_512_context is NULL, then return false.
 * If new_sha3_512_context is NULL, then return false.
 * If this interface is not supported, then return false.
 *
 * @param[in]  sha3_512_context      Pointer to SHA3-512 context being copied.
 * @param[out] new_sha3_512_context  Pointer to new SHA3-512 context.
 *
 * @retval true   SHA3-512 context copy succeeded.
 * @retval false  SHA3-512 context copy failed.
 * @retval false  This interface is not supported.
 *
 **/
extern bool libspdm_sha3_512_duplicate(const void *sha3_512_context, void *new_sha3_512_context);

/**
 * Digests the input data and updates SHA3-512 context.
 *
 * This function performs SHA3-512 digest on a data buffer of the specified size.
 * It can be called multiple times to compute the digest of long or discontinuous data streams.
 * SHA3-512 context should be already correctly initialized by libspdm_sha3_512_init(), and must not
 * have been finalized by libspdm_sha3_512_final(). Behavior with invalid context is undefined.
 *
 * If sha3_512_context is NULL, then return false.
 *
 * @param[in, out]  sha3_512_context  Pointer to the SHA3-512 context.
 * @param[in]       data              Pointer to the buffer containing the data to be hashed.
 * @param[in]       data_size         Size of data buffer in bytes.
 *
 * @retval true   SHA3-512 data digest succeeded.
 * @retval false  SHA3-512 data digest failed.
 **/
extern bool libspdm_sha3_512_update(void *sha3_512_context, const void *data, size_t data_size);

/**
 * Completes computation of the SHA3-512 digest value.
 *
 * This function completes SHA3-512 hash computation and populates the digest value into
 * the specified memory. After this function has been called, the SHA3-512 context cannot
 * be used again. SHA3-512 context should be already correctly initialized by
 * libspdm_sha3_512_init(), and must not have been finalized by libspdm_sha3_512_final().
 * Behavior with invalid SHA3-512 context is undefined.
 *
 * If sha3_512_context is NULL, then return false.
 * If hash_value is NULL, then return false.
 *
 * @param[in, out]  sha3_512_context  Pointer to the SHA3-512 context.
 * @param[out]      hash_value        Pointer to a buffer that receives the SHA3-512 digest
 *                                    value (64 bytes).
 *
 * @retval true   SHA3-512 digest computation succeeded.
 * @retval false  SHA3-512 digest computation failed.
 **/
extern bool libspdm_sha3_512_final(void *sha3_512_context, uint8_t *hash_value);

/**
 * Computes the SHA3-512 message digest of an input data buffer.
 *
 * This function performs the SHA3-512 message digest of a given data buffer, and places
 * the digest value into the specified memory.
 *
 * If this interface is not supported, then return false.
 *
 * @param[in]   data        Pointer to the buffer containing the data to be hashed.
 * @param[in]   data_size   Size of data buffer in bytes.
 * @param[out]  hash_value  Pointer to a buffer that receives the SHA3-512 digest value (64 bytes).
 *
 * @retval true   SHA3-512 digest computation succeeded.
 * @retval false  SHA3-512 digest computation failed.
 * @retval false  This interface is not supported.
 **/
extern bool libspdm_sha3_512_hash_all(const void *data, size_t data_size, uint8_t *hash_value);
#endif /* LIBSPDM_SHA3_512_SUPPORT */

/*=====================================================================================
 *    One-Way Cryptographic hash SM3 Primitives
 *=====================================================================================
 */

#if LIBSPDM_SM3_256_SUPPORT
/**
 * Allocates and initializes one HASH_CTX context for subsequent SM3-256 use.
 *
 * @return  Pointer to the HASH_CTX context that has been initialized.
 *          If the allocations fails, libspdm_sm3_256_new() returns NULL.
 **/
extern void *libspdm_sm3_256_new(void);

/**
 * Release the specified HASH_CTX context.
 *
 * @param[in]  sm3_context  Pointer to the HASH_CTX context to be released.
 **/
extern void libspdm_sm3_256_free(void *sm3_context);

/**
 * Initializes user-supplied memory pointed by sm3_context as SM3 hash context for
 * subsequent use.
 *
 * If sm3_context is NULL, then return false.
 *
 * @param[out]  sm3_context  Pointer to SM3 context being initialized.
 *
 * @retval true   SM3 context initialization succeeded.
 * @retval false  SM3 context initialization failed.
 **/
extern bool libspdm_sm3_256_init(void *sm3_context);

/**
 * Makes a copy of an existing SM3 context.
 *
 * If sm3_context is NULL, then return false.
 * If new_sm3_context is NULL, then return false.
 * If this interface is not supported, then return false.
 *
 * @param[in]  sm3_context      Pointer to SM3 context being copied.
 * @param[out] new_sm3_context  Pointer to new SM3 context.
 *
 * @retval true   SM3 context copy succeeded.
 * @retval false  SM3 context copy failed.
 * @retval false  This interface is not supported.
 **/
extern bool libspdm_sm3_256_duplicate(const void *sm3_context, void *new_sm3_context);

/**
 * Digests the input data and updates SM3 context.
 *
 * This function performs SM3 digest on a data buffer of the specified size.
 * It can be called multiple times to compute the digest of long or discontinuous data streams.
 * SM3 context should be already correctly initialized by sm3_init(), and should not be finalized
 * by sm3_final(). Behavior with invalid context is undefined.
 *
 * If sm3_context is NULL, then return false.
 *
 * @param[in, out]  sm3_context  Pointer to the SM3 context.
 * @param[in]       data         Pointer to the buffer containing the data to be hashed.
 * @param[in]       data_size    Size of data buffer in bytes.
 *
 * @retval true   SM3 data digest succeeded.
 * @retval false  SM3 data digest failed.
 **/
extern bool libspdm_sm3_256_update(void *sm3_context, const void *data, size_t data_size);

/**
 * Completes computation of the SM3 digest value.
 *
 * This function completes SM3 hash computation and retrieves the digest value into
 * the specified memory. After this function has been called, the SM3 context cannot
 * be used again. SM3 context should be already correctly initialized by sm3_init(), and should not
 * be finalized by sm3_final(). Behavior with invalid SM3 context is undefined.
 *
 * If sm3_context is NULL, then return false.
 * If hash_value is NULL, then return false.
 *
 * @param[in, out]  sm3_context  Pointer to the SM3 context.
 * @param[out]      hash_value   Pointer to a buffer that receives the SM3 digest value (32 bytes).
 *
 * @retval true   SM3 digest computation succeeded.
 * @retval false  SM3 digest computation failed.
 **/
extern bool libspdm_sm3_256_final(void *sm3_context, uint8_t *hash_value);

/**
 * Computes the SM3 message digest of an input data buffer.
 *
 * This function performs the SM3 message digest of a given data buffer, and places
 * the digest value into the specified memory.
 *
 * If this interface is not supported, then return false.
 *
 * @param[in]   data        Pointer to the buffer containing the data to be hashed.
 * @param[in]   data_size   Size of data buffer in bytes.
 * @param[out]  hash_value  Pointer to a buffer that receives the SM3 digest value (32 bytes).
 *
 * @retval true   SM3 digest computation succeeded.
 * @retval false  SM3 digest computation failed.
 * @retval false  This interface is not supported.
 **/
extern bool libspdm_sm3_256_hash_all(const void *data, size_t data_size, uint8_t *hash_value);
#endif /* LIBSPDM_SM3_256_SUPPORT */

#endif /* CRYPTLIB_HASH_H */