kpqc 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/Gemfile +4 -0
  4. data/README.md +9 -6
  5. data/THIRD_PARTY_NOTICES.md +14 -47
  6. data/ext/kpqc/extconf_helper.rb +6 -3
  7. data/ext/kpqc/secure_clear.c +8 -0
  8. data/kpqc.gemspec +4 -5
  9. data/lib/kpqc/aimer.rb +6 -6
  10. data/lib/kpqc/version.rb +1 -2
  11. data/test/kat/aimer128f.rsp +4 -4
  12. data/test/kat/aimer128s.rsp +4 -4
  13. data/test/kat/aimer192f.rsp +4 -4
  14. data/test/kat/aimer192s.rsp +4 -4
  15. data/test/kat/aimer256f.rsp +4 -4
  16. data/test/kat/aimer256s.rsp +4 -4
  17. data/test/kat/haetae2.rsp +1 -1
  18. data/test/kat/haetae3.rsp +1 -1
  19. data/test/kat/haetae5.rsp +1 -1
  20. data/vendor/AIMer/LICENSE +1 -1
  21. data/vendor/AIMer/aim3.c +227 -0
  22. data/vendor/AIMer/aim3.h +63 -0
  23. data/vendor/AIMer/field.h +12 -4
  24. data/vendor/AIMer/field128.c +24 -381
  25. data/vendor/AIMer/field192.c +24 -400
  26. data/vendor/AIMer/field256.c +28 -447
  27. data/vendor/AIMer/field_common.c +98 -0
  28. data/vendor/AIMer/field_internal.h +218 -0
  29. data/vendor/AIMer/params/params-aimer-128f.h +8 -8
  30. data/vendor/AIMer/params/params-aimer-128s.h +8 -8
  31. data/vendor/AIMer/params/params-aimer-192f.h +8 -8
  32. data/vendor/AIMer/params/params-aimer-192s.h +8 -8
  33. data/vendor/AIMer/params/params-aimer-256f.h +8 -8
  34. data/vendor/AIMer/params/params-aimer-256s.h +8 -8
  35. data/vendor/AIMer/params.h +5 -0
  36. data/vendor/AIMer/sign.c +246 -167
  37. data/vendor/AIMer/sign.h +6 -6
  38. data/vendor/AIMer/tree.c +10 -4
  39. data/vendor/AIMer/tree.h +1 -1
  40. data/vendor/HAETAE/include/fixpoint.h +14 -14
  41. data/vendor/HAETAE/include/rans_byte.h +10 -9
  42. data/vendor/HAETAE/src/decompose.c +8 -4
  43. data/vendor/HAETAE/src/encoding.c +5 -5
  44. data/vendor/HAETAE/src/fft.c +1 -1
  45. data/vendor/HAETAE/src/fips202.c +26 -14
  46. data/vendor/HAETAE/src/fixpoint.c +21 -18
  47. data/vendor/HAETAE/src/ntt.c +2 -0
  48. data/vendor/HAETAE/src/packing.c +15 -15
  49. data/vendor/HAETAE/src/poly.c +30 -3
  50. data/vendor/HAETAE/src/polyfix.c +2 -2
  51. data/vendor/HAETAE/src/polymat.c +2 -2
  52. data/vendor/HAETAE/src/polyvec.c +7 -5
  53. data/vendor/HAETAE/src/reduce.c +2 -0
  54. data/vendor/HAETAE/src/sampler.c +231 -47
  55. data/vendor/HAETAE/src/sign.c +11 -10
  56. data/vendor/NTRUplus/NTRU+1152/api.h +27 -8
  57. data/vendor/NTRUplus/NTRU+1152/fips202/fips202.c +12 -269
  58. data/vendor/NTRUplus/NTRU+1152/fips202/fips202.h +4 -113
  59. data/vendor/NTRUplus/NTRU+1152/kem.c +110 -40
  60. data/vendor/NTRUplus/NTRU+1152/ntt.c +50 -54
  61. data/vendor/NTRUplus/NTRU+1152/poly.c +21 -13
  62. data/vendor/NTRUplus/NTRU+1152/poly.h +3 -3
  63. data/vendor/NTRUplus/NTRU+1152/randombytes.h +1 -0
  64. data/vendor/NTRUplus/NTRU+1152/symmetric.c +3 -9
  65. data/vendor/NTRUplus/NTRU+1152/symmetric.h +13 -3
  66. data/vendor/NTRUplus/NTRU+1152/util.h +15 -0
  67. data/vendor/NTRUplus/NTRU+768/api.h +27 -8
  68. data/vendor/NTRUplus/NTRU+768/fips202/fips202.c +12 -269
  69. data/vendor/NTRUplus/NTRU+768/fips202/fips202.h +4 -113
  70. data/vendor/NTRUplus/NTRU+768/kem.c +110 -40
  71. data/vendor/NTRUplus/NTRU+768/ntt.c +50 -54
  72. data/vendor/NTRUplus/NTRU+768/poly.c +23 -13
  73. data/vendor/NTRUplus/NTRU+768/poly.h +3 -3
  74. data/vendor/NTRUplus/NTRU+768/randombytes.h +1 -0
  75. data/vendor/NTRUplus/NTRU+768/symmetric.c +3 -9
  76. data/vendor/NTRUplus/NTRU+768/symmetric.h +13 -3
  77. data/vendor/NTRUplus/NTRU+768/util.h +15 -0
  78. data/vendor/NTRUplus/NTRU+864/api.h +27 -8
  79. data/vendor/NTRUplus/NTRU+864/fips202/fips202.c +12 -269
  80. data/vendor/NTRUplus/NTRU+864/fips202/fips202.h +4 -113
  81. data/vendor/NTRUplus/NTRU+864/kem.c +110 -40
  82. data/vendor/NTRUplus/NTRU+864/ntt.c +24 -28
  83. data/vendor/NTRUplus/NTRU+864/poly.c +26 -12
  84. data/vendor/NTRUplus/NTRU+864/poly.h +3 -3
  85. data/vendor/NTRUplus/NTRU+864/randombytes.h +1 -0
  86. data/vendor/NTRUplus/NTRU+864/symmetric.c +3 -9
  87. data/vendor/NTRUplus/NTRU+864/symmetric.h +13 -3
  88. data/vendor/NTRUplus/NTRU+864/util.h +15 -0
  89. data/vendor/SMAUG-T/src/cbd.c +4 -4
  90. data/vendor/SMAUG-T/src/ciphertext.c +2 -2
  91. data/vendor/SMAUG-T/src/dg.c +2 -2
  92. data/vendor/SMAUG-T/src/hwt.c +4 -4
  93. data/vendor/SMAUG-T/src/indcpa.c +5 -5
  94. data/vendor/SMAUG-T/src/kem.c +9 -7
  95. data/vendor/SMAUG-T/src/key.c +2 -2
  96. data/vendor/SMAUG-T/src/pack.c +8 -8
  97. metadata +17 -42
  98. data/vendor/AIMer/aim2.c +0 -163
  99. data/vendor/AIMer/aim2.h +0 -36
  100. data/vendor/AIMer/aim2_constant.h +0 -74
  101. data/vendor/SOURCES.json +0 -130
@@ -5,6 +5,8 @@
5
5
  * from https://twitter.com/tweetfips202
6
6
  * by Gilles Van Assche, Daniel J. Bernstein, and Peter Schwabe */
7
7
 
8
+ #include "util.h"
9
+
8
10
  #include <stddef.h>
9
11
  #include <stdint.h>
10
12
  #include <string.h>
@@ -14,13 +16,6 @@
14
16
  #define NROUNDS 24
15
17
  #define ROL(a, offset) (((a) << (offset)) ^ ((a) >> (64 - (offset))))
16
18
 
17
- static void clear_state(uint64_t *state, size_t words) {
18
- volatile uint64_t *p = state;
19
- while (words-- > 0) {
20
- *p++ = 0;
21
- }
22
- }
23
-
24
19
  /*************************************************
25
20
  * Name: load64
26
21
  *
@@ -346,7 +341,7 @@ static void KeccakF1600_StatePermute(uint64_t *state) {
346
341
  * non-incremental, starts by zeroeing the state.
347
342
  *
348
343
  * Arguments: - uint64_t *s: pointer to (uninitialized) output Keccak state
349
- * - uint32_t r: rate in bytes (e.g., 168 for SHAKE128)
344
+ * - uint32_t r: rate in bytes (e.g., 136 for SHAKE256)
350
345
  * - const uint8_t *m: pointer to input to be absorbed into s
351
346
  * - size_t mlen: length of input in bytes
352
347
  * - uint8_t p: domain-separation byte for different
@@ -383,6 +378,7 @@ static void keccak_absorb(uint64_t *s, uint32_t r, const uint8_t *m,
383
378
  for (i = 0; i < r / 8; ++i) {
384
379
  s[i] ^= load64(t + 8 * i);
385
380
  }
381
+ secure_clear(t, sizeof t);
386
382
  }
387
383
 
388
384
  /*************************************************
@@ -396,7 +392,7 @@ static void keccak_absorb(uint64_t *s, uint32_t r, const uint8_t *m,
396
392
  * - size_t nblocks: number of blocks to be
397
393
  * squeezed (written to h)
398
394
  * - uint64_t *s: pointer to input/output Keccak state
399
- * - uint32_t r: rate in bytes (e.g., 168 for SHAKE128)
395
+ * - uint32_t r: rate in bytes (e.g., 136 for SHAKE256)
400
396
  **************************************************/
401
397
  static void keccak_squeezeblocks(uint8_t *h, size_t nblocks,
402
398
  uint64_t *s, uint32_t r) {
@@ -439,7 +435,7 @@ static void keccak_inc_init(uint64_t *s_inc) {
439
435
  * First 25 values represent Keccak state.
440
436
  * 26th value represents either the number of absorbed bytes
441
437
  * that have not been permuted, or not-yet-squeezed bytes.
442
- * - uint32_t r: rate in bytes (e.g., 168 for SHAKE128)
438
+ * - uint32_t r: rate in bytes (e.g., 136 for SHAKE256)
443
439
  * - const uint8_t *m: pointer to input to be absorbed into s
444
440
  * - size_t mlen: length of input in bytes
445
441
  **************************************************/
@@ -476,7 +472,7 @@ static void keccak_inc_absorb(uint64_t *s_inc, uint32_t r, const uint8_t *m,
476
472
  * First 25 values represent Keccak state.
477
473
  * 26th value represents either the number of absorbed bytes
478
474
  * that have not been permuted, or not-yet-squeezed bytes.
479
- * - uint32_t r: rate in bytes (e.g., 168 for SHAKE128)
475
+ * - uint32_t r: rate in bytes (e.g., 136 for SHAKE256)
480
476
  * - uint8_t p: domain-separation byte for different
481
477
  * Keccak-derived functions
482
478
  **************************************************/
@@ -499,7 +495,7 @@ static void keccak_inc_finalize(uint64_t *s_inc, uint32_t r, uint8_t p) {
499
495
  * First 25 values represent Keccak state.
500
496
  * 26th value represents either the number of absorbed bytes
501
497
  * that have not been permuted, or not-yet-squeezed bytes.
502
- * - uint32_t r: rate in bytes (e.g., 168 for SHAKE128)
498
+ * - uint32_t r: rate in bytes (e.g., 136 for SHAKE256)
503
499
  **************************************************/
504
500
  static void keccak_inc_squeeze(uint8_t *h, size_t outlen,
505
501
  uint64_t *s_inc, uint32_t r) {
@@ -528,30 +524,6 @@ static void keccak_inc_squeeze(uint8_t *h, size_t outlen,
528
524
  }
529
525
  }
530
526
 
531
- void shake128_inc_init(shake128incctx *state) {
532
- keccak_inc_init(state->ctx);
533
- }
534
-
535
- void shake128_inc_absorb(shake128incctx *state, const uint8_t *input, size_t inlen) {
536
- keccak_inc_absorb(state->ctx, SHAKE128_RATE, input, inlen);
537
- }
538
-
539
- void shake128_inc_finalize(shake128incctx *state) {
540
- keccak_inc_finalize(state->ctx, SHAKE128_RATE, 0x1F);
541
- }
542
-
543
- void shake128_inc_squeeze(uint8_t *output, size_t outlen, shake128incctx *state) {
544
- keccak_inc_squeeze(output, outlen, state->ctx, SHAKE128_RATE);
545
- }
546
-
547
- void shake128_inc_ctx_clone(shake128incctx *dest, const shake128incctx *src) {
548
- memcpy(dest->ctx, src->ctx, PQC_SHAKEINCCTX_BYTES);
549
- }
550
-
551
- void shake128_inc_ctx_release(shake128incctx *state) {
552
- clear_state(state->ctx, 26);
553
- }
554
-
555
527
  void shake256_inc_init(shake256incctx *state) {
556
528
  keccak_inc_init(state->ctx);
557
529
  }
@@ -573,47 +545,7 @@ void shake256_inc_ctx_clone(shake256incctx *dest, const shake256incctx *src) {
573
545
  }
574
546
 
575
547
  void shake256_inc_ctx_release(shake256incctx *state) {
576
- clear_state(state->ctx, 26);
577
- }
578
-
579
- /*************************************************
580
- * Name: shake128_absorb
581
- *
582
- * Description: Absorb step of the SHAKE128 XOF.
583
- * non-incremental, starts by zeroeing the state.
584
- *
585
- * Arguments: - uint64_t *s: pointer to (uninitialized) output Keccak state
586
- * - const uint8_t *input: pointer to input to be absorbed
587
- * into s
588
- * - size_t inlen: length of input in bytes
589
- **************************************************/
590
- void shake128_absorb(shake128ctx *state, const uint8_t *input, size_t inlen) {
591
- keccak_absorb(state->ctx, SHAKE128_RATE, input, inlen, 0x1F);
592
- }
593
-
594
- /*************************************************
595
- * Name: shake128_squeezeblocks
596
- *
597
- * Description: Squeeze step of SHAKE128 XOF. Squeezes full blocks of
598
- * SHAKE128_RATE bytes each. Modifies the state. Can be called
599
- * multiple times to keep squeezing, i.e., is incremental.
600
- *
601
- * Arguments: - uint8_t *output: pointer to output blocks
602
- * - size_t nblocks: number of blocks to be squeezed
603
- * (written to output)
604
- * - shake128ctx *state: pointer to input/output Keccak state
605
- **************************************************/
606
- void shake128_squeezeblocks(uint8_t *output, size_t nblocks, shake128ctx *state) {
607
- keccak_squeezeblocks(output, nblocks, state->ctx, SHAKE128_RATE);
608
- }
609
-
610
- void shake128_ctx_clone(shake128ctx *dest, const shake128ctx *src) {
611
- memcpy(dest->ctx, src->ctx, PQC_SHAKECTX_BYTES);
612
- }
613
-
614
- /** Release the allocated state. Call only once. */
615
- void shake128_ctx_release(shake128ctx *state) {
616
- clear_state(state->ctx, 25);
548
+ secure_clear(state->ctx, PQC_SHAKEINCCTX_BYTES);
617
549
  }
618
550
 
619
551
  /*************************************************
@@ -651,40 +583,9 @@ void shake256_ctx_clone(shake256ctx *dest, const shake256ctx *src) {
651
583
  memcpy(dest->ctx, src->ctx, PQC_SHAKECTX_BYTES);
652
584
  }
653
585
 
654
- /** Release the allocated state. Call only once. */
586
+ /** Clear the state. */
655
587
  void shake256_ctx_release(shake256ctx *state) {
656
- clear_state(state->ctx, 25);
657
- }
658
-
659
- /*************************************************
660
- * Name: shake128
661
- *
662
- * Description: SHAKE128 XOF with non-incremental API
663
- *
664
- * Arguments: - uint8_t *output: pointer to output
665
- * - size_t outlen: requested output length in bytes
666
- * - const uint8_t *input: pointer to input
667
- * - size_t inlen: length of input in bytes
668
- **************************************************/
669
- void shake128(uint8_t *output, size_t outlen,
670
- const uint8_t *input, size_t inlen) {
671
- size_t nblocks = outlen / SHAKE128_RATE;
672
- uint8_t t[SHAKE128_RATE];
673
- shake128ctx s;
674
-
675
- shake128_absorb(&s, input, inlen);
676
- shake128_squeezeblocks(output, nblocks, &s);
677
-
678
- output += nblocks * SHAKE128_RATE;
679
- outlen -= nblocks * SHAKE128_RATE;
680
-
681
- if (outlen) {
682
- shake128_squeezeblocks(t, 1, &s);
683
- for (size_t i = 0; i < outlen; ++i) {
684
- output[i] = t[i];
685
- }
686
- }
687
- shake128_ctx_release(&s);
588
+ secure_clear(state->ctx, PQC_SHAKECTX_BYTES);
688
589
  }
689
590
 
690
591
  /*************************************************
@@ -715,164 +616,6 @@ void shake256(uint8_t *output, size_t outlen,
715
616
  output[i] = t[i];
716
617
  }
717
618
  }
619
+ secure_clear(t, sizeof(t));
718
620
  shake256_ctx_release(&s);
719
621
  }
720
-
721
- void sha3_256_inc_init(sha3_256incctx *state) {
722
- keccak_inc_init(state->ctx);
723
- }
724
-
725
- void sha3_256_inc_ctx_clone(sha3_256incctx *dest, const sha3_256incctx *src) {
726
- memcpy(dest->ctx, src->ctx, PQC_SHAKEINCCTX_BYTES);
727
- }
728
-
729
- void sha3_256_inc_ctx_release(sha3_256incctx *state) {
730
- clear_state(state->ctx, 26);
731
- }
732
-
733
- void sha3_256_inc_absorb(sha3_256incctx *state, const uint8_t *input, size_t inlen) {
734
- keccak_inc_absorb(state->ctx, SHA3_256_RATE, input, inlen);
735
- }
736
-
737
- void sha3_256_inc_finalize(uint8_t *output, sha3_256incctx *state) {
738
- uint8_t t[SHA3_256_RATE];
739
- keccak_inc_finalize(state->ctx, SHA3_256_RATE, 0x06);
740
-
741
- keccak_squeezeblocks(t, 1, state->ctx, SHA3_256_RATE);
742
-
743
- sha3_256_inc_ctx_release(state);
744
-
745
- for (size_t i = 0; i < 32; i++) {
746
- output[i] = t[i];
747
- }
748
- }
749
-
750
- /*************************************************
751
- * Name: sha3_256
752
- *
753
- * Description: SHA3-256 with non-incremental API
754
- *
755
- * Arguments: - uint8_t *output: pointer to output
756
- * - const uint8_t *input: pointer to input
757
- * - size_t inlen: length of input in bytes
758
- **************************************************/
759
- void sha3_256(uint8_t *output, const uint8_t *input, size_t inlen) {
760
- uint64_t s[25];
761
- uint8_t t[SHA3_256_RATE];
762
-
763
- /* Absorb input */
764
- keccak_absorb(s, SHA3_256_RATE, input, inlen, 0x06);
765
-
766
- /* Squeeze output */
767
- keccak_squeezeblocks(t, 1, s, SHA3_256_RATE);
768
-
769
- for (size_t i = 0; i < 32; i++) {
770
- output[i] = t[i];
771
- }
772
- }
773
-
774
- void sha3_384_inc_init(sha3_384incctx *state) {
775
- keccak_inc_init(state->ctx);
776
- }
777
-
778
- void sha3_384_inc_ctx_clone(sha3_384incctx *dest, const sha3_384incctx *src) {
779
- memcpy(dest->ctx, src->ctx, PQC_SHAKEINCCTX_BYTES);
780
- }
781
-
782
- void sha3_384_inc_absorb(sha3_384incctx *state, const uint8_t *input, size_t inlen) {
783
- keccak_inc_absorb(state->ctx, SHA3_384_RATE, input, inlen);
784
- }
785
-
786
- void sha3_384_inc_ctx_release(sha3_384incctx *state) {
787
- clear_state(state->ctx, 26);
788
- }
789
-
790
- void sha3_384_inc_finalize(uint8_t *output, sha3_384incctx *state) {
791
- uint8_t t[SHA3_384_RATE];
792
- keccak_inc_finalize(state->ctx, SHA3_384_RATE, 0x06);
793
-
794
- keccak_squeezeblocks(t, 1, state->ctx, SHA3_384_RATE);
795
-
796
- sha3_384_inc_ctx_release(state);
797
-
798
- for (size_t i = 0; i < 48; i++) {
799
- output[i] = t[i];
800
- }
801
- }
802
-
803
- /*************************************************
804
- * Name: sha3_384
805
- *
806
- * Description: SHA3-256 with non-incremental API
807
- *
808
- * Arguments: - uint8_t *output: pointer to output
809
- * - const uint8_t *input: pointer to input
810
- * - size_t inlen: length of input in bytes
811
- **************************************************/
812
- void sha3_384(uint8_t *output, const uint8_t *input, size_t inlen) {
813
- uint64_t s[25];
814
- uint8_t t[SHA3_384_RATE];
815
-
816
- /* Absorb input */
817
- keccak_absorb(s, SHA3_384_RATE, input, inlen, 0x06);
818
-
819
- /* Squeeze output */
820
- keccak_squeezeblocks(t, 1, s, SHA3_384_RATE);
821
-
822
- for (size_t i = 0; i < 48; i++) {
823
- output[i] = t[i];
824
- }
825
- }
826
-
827
- void sha3_512_inc_init(sha3_512incctx *state) {
828
- keccak_inc_init(state->ctx);
829
- }
830
-
831
- void sha3_512_inc_ctx_clone(sha3_512incctx *dest, const sha3_512incctx *src) {
832
- memcpy(dest->ctx, src->ctx, PQC_SHAKEINCCTX_BYTES);
833
- }
834
-
835
- void sha3_512_inc_absorb(sha3_512incctx *state, const uint8_t *input, size_t inlen) {
836
- keccak_inc_absorb(state->ctx, SHA3_512_RATE, input, inlen);
837
- }
838
-
839
- void sha3_512_inc_ctx_release(sha3_512incctx *state) {
840
- clear_state(state->ctx, 26);
841
- }
842
-
843
- void sha3_512_inc_finalize(uint8_t *output, sha3_512incctx *state) {
844
- uint8_t t[SHA3_512_RATE];
845
- keccak_inc_finalize(state->ctx, SHA3_512_RATE, 0x06);
846
-
847
- keccak_squeezeblocks(t, 1, state->ctx, SHA3_512_RATE);
848
-
849
- sha3_512_inc_ctx_release(state);
850
-
851
- for (size_t i = 0; i < 64; i++) {
852
- output[i] = t[i];
853
- }
854
- }
855
-
856
- /*************************************************
857
- * Name: sha3_512
858
- *
859
- * Description: SHA3-512 with non-incremental API
860
- *
861
- * Arguments: - uint8_t *output: pointer to output
862
- * - const uint8_t *input: pointer to input
863
- * - size_t inlen: length of input in bytes
864
- **************************************************/
865
- void sha3_512(uint8_t *output, const uint8_t *input, size_t inlen) {
866
- uint64_t s[25];
867
- uint8_t t[SHA3_512_RATE];
868
-
869
- /* Absorb input */
870
- keccak_absorb(s, SHA3_512_RATE, input, inlen, 0x06);
871
-
872
- /* Squeeze output */
873
- keccak_squeezeblocks(t, 1, s, SHA3_512_RATE);
874
-
875
- for (size_t i = 0; i < 64; i++) {
876
- output[i] = t[i];
877
- }
878
- }
@@ -4,24 +4,10 @@
4
4
  #include <stddef.h>
5
5
  #include <stdint.h>
6
6
 
7
- #define SHAKE128_RATE 168
8
7
  #define SHAKE256_RATE 136
9
- #define SHA3_256_RATE 136
10
- #define SHA3_384_RATE 104
11
- #define SHA3_512_RATE 72
12
8
 
13
- #define PQC_SHAKEINCCTX_BYTES (sizeof(uint64_t)*26)
14
- #define PQC_SHAKECTX_BYTES (sizeof(uint64_t)*25)
15
-
16
- // Context for incremental API
17
- typedef struct {
18
- uint64_t ctx[26];
19
- } shake128incctx;
20
-
21
- // Context for non-incremental API
22
- typedef struct {
23
- uint64_t ctx[25];
24
- } shake128ctx;
9
+ #define PQC_SHAKEINCCTX_BYTES (sizeof(uint64_t) * 26)
10
+ #define PQC_SHAKECTX_BYTES (sizeof(uint64_t) * 25)
25
11
 
26
12
  // Context for incremental API
27
13
  typedef struct {
@@ -33,56 +19,6 @@ typedef struct {
33
19
  uint64_t ctx[25];
34
20
  } shake256ctx;
35
21
 
36
- // Context for incremental API
37
- typedef struct {
38
- uint64_t ctx[26];
39
- } sha3_256incctx;
40
-
41
- // Context for incremental API
42
- typedef struct {
43
- uint64_t ctx[26];
44
- } sha3_384incctx;
45
-
46
- // Context for incremental API
47
- typedef struct {
48
- uint64_t ctx[26];
49
- } sha3_512incctx;
50
-
51
- /* Initialize the state and absorb the provided input.
52
- *
53
- * This function does not support being called multiple times
54
- * with the same state.
55
- */
56
- void shake128_absorb(shake128ctx *state, const uint8_t *input, size_t inlen);
57
- /* Squeeze output out of the sponge.
58
- *
59
- * Supports being called multiple times
60
- */
61
- void shake128_squeezeblocks(uint8_t *output, size_t nblocks, shake128ctx *state);
62
- /* Free the state */
63
- void shake128_ctx_release(shake128ctx *state);
64
- /* Copy the state. */
65
- void shake128_ctx_clone(shake128ctx *dest, const shake128ctx *src);
66
-
67
- /* Initialize incremental hashing API */
68
- void shake128_inc_init(shake128incctx *state);
69
- /* Absorb more information into the XOF.
70
- *
71
- * Can be called multiple times.
72
- */
73
- void shake128_inc_absorb(shake128incctx *state, const uint8_t *input, size_t inlen);
74
- /* Finalize the XOF for squeezing */
75
- void shake128_inc_finalize(shake128incctx *state);
76
- /* Squeeze output out of the sponge.
77
- *
78
- * Supports being called multiple times
79
- */
80
- void shake128_inc_squeeze(uint8_t *output, size_t outlen, shake128incctx *state);
81
- /* Copy the context of the SHAKE128 XOF */
82
- void shake128_inc_ctx_clone(shake128incctx *dest, const shake128incctx *src);
83
- /* Free the context of the SHAKE128 XOF */
84
- void shake128_inc_ctx_release(shake128incctx *state);
85
-
86
22
  /* Initialize the state and absorb the provided input.
87
23
  *
88
24
  * This function does not support being called multiple times
@@ -94,7 +30,7 @@ void shake256_absorb(shake256ctx *state, const uint8_t *input, size_t inlen);
94
30
  * Supports being called multiple times
95
31
  */
96
32
  void shake256_squeezeblocks(uint8_t *output, size_t nblocks, shake256ctx *state);
97
- /* Free the context held by this XOF */
33
+ /* Clear the context held by this XOF */
98
34
  void shake256_ctx_release(shake256ctx *state);
99
35
  /* Copy the context held by this XOF */
100
36
  void shake256_ctx_clone(shake256ctx *dest, const shake256ctx *src);
@@ -111,56 +47,11 @@ void shake256_inc_finalize(shake256incctx *state);
111
47
  void shake256_inc_squeeze(uint8_t *output, size_t outlen, shake256incctx *state);
112
48
  /* Copy the state */
113
49
  void shake256_inc_ctx_clone(shake256incctx *dest, const shake256incctx *src);
114
- /* Free the state */
50
+ /* Clear the state */
115
51
  void shake256_inc_ctx_release(shake256incctx *state);
116
52
 
117
- /* One-stop SHAKE128 call */
118
- void shake128(uint8_t *output, size_t outlen,
119
- const uint8_t *input, size_t inlen);
120
-
121
53
  /* One-stop SHAKE256 call */
122
54
  void shake256(uint8_t *output, size_t outlen,
123
55
  const uint8_t *input, size_t inlen);
124
56
 
125
- /* Initialize the incremental hashing state */
126
- void sha3_256_inc_init(sha3_256incctx *state);
127
- /* Absorb blocks into SHA3 */
128
- void sha3_256_inc_absorb(sha3_256incctx *state, const uint8_t *input, size_t inlen);
129
- /* Obtain the output of the function and free `state` */
130
- void sha3_256_inc_finalize(uint8_t *output, sha3_256incctx *state);
131
- /* Copy the context */
132
- void sha3_256_inc_ctx_clone(sha3_256incctx *dest, const sha3_256incctx *src);
133
- /* Release the state, don't use if `_finalize` has been used */
134
- void sha3_256_inc_ctx_release(sha3_256incctx *state);
135
-
136
- void sha3_256(uint8_t *output, const uint8_t *input, size_t inlen);
137
-
138
- /* Initialize the incremental hashing state */
139
- void sha3_384_inc_init(sha3_384incctx *state);
140
- /* Absorb blocks into SHA3 */
141
- void sha3_384_inc_absorb(sha3_384incctx *state, const uint8_t *input, size_t inlen);
142
- /* Obtain the output of the function and free `state` */
143
- void sha3_384_inc_finalize(uint8_t *output, sha3_384incctx *state);
144
- /* Copy the context */
145
- void sha3_384_inc_ctx_clone(sha3_384incctx *dest, const sha3_384incctx *src);
146
- /* Release the state, don't use if `_finalize` has been used */
147
- void sha3_384_inc_ctx_release(sha3_384incctx *state);
148
-
149
- /* One-stop SHA3-384 shop */
150
- void sha3_384(uint8_t *output, const uint8_t *input, size_t inlen);
151
-
152
- /* Initialize the incremental hashing state */
153
- void sha3_512_inc_init(sha3_512incctx *state);
154
- /* Absorb blocks into SHA3 */
155
- void sha3_512_inc_absorb(sha3_512incctx *state, const uint8_t *input, size_t inlen);
156
- /* Obtain the output of the function and free `state` */
157
- void sha3_512_inc_finalize(uint8_t *output, sha3_512incctx *state);
158
- /* Copy the context */
159
- void sha3_512_inc_ctx_clone(sha3_512incctx *dest, const sha3_512incctx *src);
160
- /* Release the state, don't use if `_finalize` has been used */
161
- void sha3_512_inc_ctx_release(sha3_512incctx *state);
162
-
163
- /* One-stop SHA3-512 shop */
164
- void sha3_512(uint8_t *output, const uint8_t *input, size_t inlen);
165
-
166
57
  #endif