mldsa_gh 0.1.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 (128) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +88 -0
  4. data/ext/mldsa_gh_native/extconf.rb +14 -0
  5. data/ext/mldsa_gh_native/mldsa_gh_native.c +222 -0
  6. data/ext/mldsa_gh_native/mldsa_gh_native_all.c +24 -0
  7. data/ext/mldsa_gh_native/mldsa_gh_native_all.h +26 -0
  8. data/ext/mldsa_gh_native/vendor/mldsa-native/BUILDING.md +108 -0
  9. data/ext/mldsa_gh_native/vendor/mldsa-native/LICENSE +305 -0
  10. data/ext/mldsa_gh_native/vendor/mldsa-native/README.md +247 -0
  11. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/README.md +23 -0
  12. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/mldsa_native.c +803 -0
  13. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/mldsa_native.h +956 -0
  14. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/mldsa_native_asm.S +830 -0
  15. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/mldsa_native_config.h +855 -0
  16. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/cbmc.h +233 -0
  17. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/common.h +301 -0
  18. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/context.h +152 -0
  19. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/ct.c +21 -0
  20. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/ct.h +373 -0
  21. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/debug.c +75 -0
  22. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/debug.h +125 -0
  23. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/fips202.c +270 -0
  24. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/fips202.h +224 -0
  25. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +187 -0
  26. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +125 -0
  27. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +510 -0
  28. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +110 -0
  29. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +85 -0
  30. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +69 -0
  31. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +378 -0
  32. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +207 -0
  33. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +262 -0
  34. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +1080 -0
  35. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +990 -0
  36. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +47 -0
  37. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +27 -0
  38. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +36 -0
  39. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +40 -0
  40. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +32 -0
  41. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +37 -0
  42. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/api.h +129 -0
  43. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/README.md +10 -0
  44. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +67 -0
  45. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +37 -0
  46. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +717 -0
  47. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +42 -0
  48. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_extract_bytes_mve.S +334 -0
  49. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_xor_bytes_mve.S +355 -0
  50. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +53 -0
  51. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +35 -0
  52. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +34 -0
  53. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +45 -0
  54. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +488 -0
  55. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +52 -0
  56. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +314 -0
  57. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +248 -0
  58. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +367 -0
  59. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_intt_aarch64_asm.S +786 -0
  60. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_ntt_aarch64_asm.S +686 -0
  61. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_pointwise_montgomery_aarch64_asm.S +106 -0
  62. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_caddq_aarch64_asm.S +69 -0
  63. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_chknorm_aarch64_asm.S +76 -0
  64. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_32_aarch64_asm.S +108 -0
  65. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_88_aarch64_asm.S +108 -0
  66. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_32_aarch64_asm.S +125 -0
  67. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_88_aarch64_asm.S +133 -0
  68. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +157 -0
  69. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +173 -0
  70. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +205 -0
  71. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_17_aarch64_asm.S +103 -0
  72. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_19_aarch64_asm.S +100 -0
  73. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_aarch64_asm.S +222 -0
  74. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta2_aarch64_asm.S +170 -0
  75. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta4_aarch64_asm.S +163 -0
  76. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +52 -0
  77. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +547 -0
  78. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +63 -0
  79. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/api.h +617 -0
  80. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/meta.h +24 -0
  81. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +323 -0
  82. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +330 -0
  83. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +157 -0
  84. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +27 -0
  85. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_intt_avx2_asm.S +2333 -0
  86. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_ntt_avx2_asm.S +2405 -0
  87. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_nttunpack_avx2_asm.S +254 -0
  88. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l4_avx2_asm.S +173 -0
  89. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l5_avx2_asm.S +189 -0
  90. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l7_avx2_asm.S +221 -0
  91. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_avx2_asm.S +158 -0
  92. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_caddq_avx2_asm.S +199 -0
  93. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_chknorm_avx2_asm.S +176 -0
  94. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_32_avx2_asm.S +490 -0
  95. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_88_avx2_asm.S +489 -0
  96. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_32_avx2_asm.S +123 -0
  97. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_88_avx2_asm.S +125 -0
  98. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_17_avx2_asm.S +355 -0
  99. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_19_avx2_asm.S +355 -0
  100. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_avx2_asm.S +132 -0
  101. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta2_avx2_asm.S +205 -0
  102. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S +176 -0
  103. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +161 -0
  104. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/packing.c +213 -0
  105. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/packing.h +277 -0
  106. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/params.h +153 -0
  107. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/poly.c +1066 -0
  108. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/poly.h +464 -0
  109. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/poly_kl.c +910 -0
  110. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/poly_kl.h +367 -0
  111. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/polyvec.c +509 -0
  112. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/polyvec.h +435 -0
  113. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +311 -0
  114. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +652 -0
  115. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/randombytes.h +26 -0
  116. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/reduce.h +144 -0
  117. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/rounding.h +265 -0
  118. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/sign.c +1720 -0
  119. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/sign.h +850 -0
  120. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/symmetric.h +68 -0
  121. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/sys.h +327 -0
  122. data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/zetas.inc +55 -0
  123. data/lib/mldsa/parameter_set.rb +82 -0
  124. data/lib/mldsa/signing_key.rb +147 -0
  125. data/lib/mldsa/verify_key.rb +72 -0
  126. data/lib/mldsa/version.rb +7 -0
  127. data/lib/mldsa_gh.rb +93 -0
  128. metadata +225 -0
@@ -0,0 +1,270 @@
1
+ /*
2
+ * Copyright (c) The mldsa-native project authors
3
+ * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4
+ */
5
+
6
+ /* References
7
+ * ==========
8
+ *
9
+ * - [FIPS204]
10
+ * FIPS 204 Module-Lattice-Based Digital Signature Standard
11
+ * National Institute of Standards and Technology
12
+ * https://csrc.nist.gov/pubs/fips/204/final
13
+ *
14
+ * - [mupq]
15
+ * Common files for pqm4, pqm3, pqriscv
16
+ * Kannwischer, Petri, Rijneveld, Schwabe, Stoffelen
17
+ * https://github.com/mupq/mupq
18
+ *
19
+ * - [supercop]
20
+ * SUPERCOP benchmarking framework
21
+ * Daniel J. Bernstein
22
+ * http://bench.cr.yp.to/supercop.html
23
+ *
24
+ * - [tweetfips]
25
+ * 'tweetfips202' FIPS202 implementation
26
+ * Van Assche, Bernstein, Schwabe
27
+ * https://keccak.team/2015/tweetfips202.html
28
+ */
29
+
30
+ /* Based on the CC0 implementation from @[mupq] and the public domain
31
+ * implementation @[supercop, crypto_hash/keccakc512/simple/]
32
+ * by Ronny Van Keer, and the public domain @[tweetfips] implementation. */
33
+
34
+ #include <stddef.h>
35
+
36
+ #include "../common.h"
37
+ #include "../ct.h"
38
+ #include "fips202.h"
39
+ #include "keccakf1600.h"
40
+ #if !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
41
+
42
+ /**
43
+ * Initializes the Keccak state.
44
+ *
45
+ * @param[out] s Pointer to Keccak state.
46
+ */
47
+ static void keccak_init(uint64_t s[MLD_KECCAK_LANES])
48
+ __contract__(
49
+ requires(memory_no_alias(s, sizeof(uint64_t) * MLD_KECCAK_LANES))
50
+ assigns(memory_slice(s, sizeof(uint64_t) * MLD_KECCAK_LANES))
51
+ )
52
+ {
53
+ mld_memset(s, 0, sizeof(uint64_t) * MLD_KECCAK_LANES);
54
+ }
55
+
56
+ /**
57
+ * Absorb step of Keccak; incremental.
58
+ *
59
+ * @param[in,out] s Pointer to Keccak state.
60
+ * @param pos Position in current block to be absorbed.
61
+ * @param r Rate in bytes (e.g., 168 for SHAKE128).
62
+ * @param[in] in Pointer to input to be absorbed into s.
63
+ * @param inlen Length of input in bytes.
64
+ *
65
+ * @return New position pos in current block.
66
+ */
67
+ static unsigned int keccak_absorb(uint64_t s[MLD_KECCAK_LANES],
68
+ unsigned int pos, unsigned int r,
69
+ const uint8_t *in, size_t inlen)
70
+ __contract__(
71
+ requires(inlen <= MLD_MAX_BUFFER_SIZE)
72
+ requires(r > 0)
73
+ requires(r < sizeof(uint64_t) * MLD_KECCAK_LANES)
74
+ requires(pos <= r)
75
+ requires(memory_no_alias(s, sizeof(uint64_t) * MLD_KECCAK_LANES))
76
+ requires(memory_no_alias(in, inlen))
77
+ assigns(memory_slice(s, sizeof(uint64_t) * MLD_KECCAK_LANES))
78
+ ensures(return_value < r))
79
+ {
80
+ while (inlen >= r - pos)
81
+ __loop__(
82
+ assigns(pos, in, inlen,
83
+ memory_slice(s, sizeof(uint64_t) * MLD_KECCAK_LANES))
84
+ invariant(inlen <= loop_entry(inlen))
85
+ invariant(pos <= r)
86
+ invariant(in == loop_entry(in) + (loop_entry(inlen) - inlen))
87
+ decreases(inlen + pos))
88
+ {
89
+ mld_keccakf1600_xor_bytes(s, in, pos, r - pos);
90
+ inlen -= r - pos;
91
+ in += r - pos;
92
+ mld_keccakf1600_permute(s);
93
+ pos = 0;
94
+ }
95
+ /* Safety: At this point, inlen < r, so the truncation to unsigned is safe. */
96
+ mld_keccakf1600_xor_bytes(s, in, pos, (unsigned)inlen);
97
+
98
+ /* Safety: At this point, inlen < r and pos <= r so the truncation to unsigned
99
+ * is safe. */
100
+ return (unsigned)(pos + inlen);
101
+ }
102
+
103
+ /**
104
+ * Finalize absorb step.
105
+ *
106
+ * @param[in,out] s Pointer to Keccak state.
107
+ * @param pos Position in current block to be absorbed.
108
+ * @param r Rate in bytes (e.g., 168 for SHAKE128).
109
+ * @param p Domain separation byte.
110
+ */
111
+ static void keccak_finalize(uint64_t s[MLD_KECCAK_LANES], unsigned int pos,
112
+ unsigned int r, uint8_t p)
113
+ __contract__(
114
+ requires(pos <= r && r < sizeof(uint64_t) * MLD_KECCAK_LANES)
115
+ requires((r / 8) >= 1)
116
+ requires(memory_no_alias(s, sizeof(uint64_t) * MLD_KECCAK_LANES))
117
+ assigns(memory_slice(s, sizeof(uint64_t) * MLD_KECCAK_LANES))
118
+ )
119
+ {
120
+ uint8_t b = 0x80;
121
+ mld_keccakf1600_xor_bytes(s, &p, pos, 1);
122
+ mld_keccakf1600_xor_bytes(s, &b, r - 1, 1);
123
+ }
124
+
125
+ /**
126
+ * Squeeze step of Keccak. Squeezes arbitrarily many bytes. Modifies the
127
+ * state. Can be called multiple times to keep squeezing, i.e., is
128
+ * incremental.
129
+ *
130
+ * @param[out] out Pointer to output data.
131
+ * @param outlen Number of bytes to be squeezed (written to out).
132
+ * @param[in,out] s Pointer to input/output Keccak state.
133
+ * @param pos Number of bytes in current block already squeezed.
134
+ * @param r Rate in bytes (e.g., 168 for SHAKE128).
135
+ *
136
+ * @return New position pos in current block.
137
+ */
138
+ static unsigned int keccak_squeeze(uint8_t *out, size_t outlen,
139
+ uint64_t s[MLD_KECCAK_LANES],
140
+ unsigned int pos, unsigned int r)
141
+ __contract__(
142
+ requires((r == SHAKE128_RATE && pos <= SHAKE128_RATE) ||
143
+ (r == SHAKE256_RATE && pos <= SHAKE256_RATE) ||
144
+ (r == SHA3_512_RATE && pos <= SHA3_512_RATE))
145
+ requires(outlen <= 8 * r /* somewhat arbitrary bound */)
146
+ requires(memory_no_alias(s, sizeof(uint64_t) * MLD_KECCAK_LANES))
147
+ requires(memory_no_alias(out, outlen))
148
+ assigns(memory_slice(s, sizeof(uint64_t) * MLD_KECCAK_LANES))
149
+ assigns(memory_slice(out, outlen))
150
+ ensures(return_value <= r))
151
+ {
152
+ unsigned int i;
153
+ size_t out_offset = 0;
154
+
155
+ /* Reference: This code is re-factored from the reference implementation
156
+ * to facilitate proof with CBMC and to improve readability.
157
+ *
158
+ * Take a mutable copy of outlen to count down the number of bytes
159
+ * still to squeeze. The initial value of outlen is needed for the CBMC
160
+ * assigns() clauses. */
161
+ size_t bytes_to_go = outlen;
162
+
163
+ while (bytes_to_go > 0)
164
+ __loop__(
165
+ assigns(i, bytes_to_go, pos, out_offset, memory_slice(s, sizeof(uint64_t) * MLD_KECCAK_LANES), memory_slice(out, outlen))
166
+ invariant(bytes_to_go <= outlen)
167
+ invariant(out_offset == outlen - bytes_to_go)
168
+ invariant(pos <= r)
169
+ decreases(bytes_to_go)
170
+ )
171
+ {
172
+ if (pos == r)
173
+ {
174
+ mld_keccakf1600_permute(s);
175
+ pos = 0;
176
+ }
177
+ /* Safety: If bytes_to_go < r - pos, truncation to unsigned is safe. */
178
+ i = bytes_to_go < r - pos ? (unsigned)bytes_to_go : r - pos;
179
+ mld_keccakf1600_extract_bytes(s, out + out_offset, pos, i);
180
+ bytes_to_go -= i;
181
+ pos += i;
182
+ out_offset += i;
183
+ }
184
+
185
+ return pos;
186
+ }
187
+
188
+ MLD_INTERNAL_API
189
+ void mld_shake128_init(mld_shake128ctx *state)
190
+ {
191
+ keccak_init(state->s);
192
+ state->pos = 0;
193
+ }
194
+
195
+ MLD_INTERNAL_API
196
+ void mld_shake128_absorb(mld_shake128ctx *state, const uint8_t *in,
197
+ size_t inlen)
198
+ {
199
+ state->pos = keccak_absorb(state->s, state->pos, SHAKE128_RATE, in, inlen);
200
+ }
201
+
202
+ MLD_INTERNAL_API
203
+ void mld_shake128_finalize(mld_shake128ctx *state)
204
+ {
205
+ keccak_finalize(state->s, state->pos, SHAKE128_RATE, 0x1F);
206
+ state->pos = SHAKE128_RATE;
207
+ }
208
+
209
+ MLD_INTERNAL_API
210
+ void mld_shake128_squeeze(uint8_t *out, size_t outlen, mld_shake128ctx *state)
211
+ {
212
+ state->pos = keccak_squeeze(out, outlen, state->s, state->pos, SHAKE128_RATE);
213
+ }
214
+
215
+ MLD_INTERNAL_API
216
+ void mld_shake128_release(mld_shake128ctx *state)
217
+ {
218
+ /* @[FIPS204, Section 3.6.3] Destruction of intermediate values. */
219
+ mld_zeroize(state, sizeof(mld_shake128ctx));
220
+ }
221
+
222
+ MLD_INTERNAL_API
223
+ void mld_shake256_init(mld_shake256ctx *state)
224
+ {
225
+ keccak_init(state->s);
226
+ state->pos = 0;
227
+ }
228
+
229
+ MLD_INTERNAL_API
230
+ void mld_shake256_absorb(mld_shake256ctx *state, const uint8_t *in,
231
+ size_t inlen)
232
+ {
233
+ state->pos = keccak_absorb(state->s, state->pos, SHAKE256_RATE, in, inlen);
234
+ }
235
+
236
+ MLD_INTERNAL_API
237
+ void mld_shake256_finalize(mld_shake256ctx *state)
238
+ {
239
+ keccak_finalize(state->s, state->pos, SHAKE256_RATE, 0x1F);
240
+ state->pos = SHAKE256_RATE;
241
+ }
242
+
243
+ MLD_INTERNAL_API
244
+ void mld_shake256_squeeze(uint8_t *out, size_t outlen, mld_shake256ctx *state)
245
+ {
246
+ state->pos = keccak_squeeze(out, outlen, state->s, state->pos, SHAKE256_RATE);
247
+ }
248
+
249
+ MLD_INTERNAL_API
250
+ void mld_shake256_release(mld_shake256ctx *state)
251
+ {
252
+ /* @[FIPS204, Section 3.6.3] Destruction of intermediate values. */
253
+ mld_zeroize(state, sizeof(mld_shake256ctx));
254
+ }
255
+
256
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API) || !defined(MLD_CONFIG_CORE_API_ONLY)
257
+ MLD_INTERNAL_API
258
+ void mld_shake256(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen)
259
+ {
260
+ mld_shake256ctx state;
261
+
262
+ mld_shake256_init(&state);
263
+ mld_shake256_absorb(&state, in, inlen);
264
+ mld_shake256_finalize(&state);
265
+ mld_shake256_squeeze(out, outlen, &state);
266
+ mld_shake256_release(&state);
267
+ }
268
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API || !MLD_CONFIG_CORE_API_ONLY */
269
+
270
+ #endif /* !MLD_CONFIG_MULTILEVEL_NO_SHARED */
@@ -0,0 +1,224 @@
1
+ /*
2
+ * Copyright (c) The mldsa-native project authors
3
+ * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4
+ */
5
+ #ifndef MLD_FIPS202_FIPS202_H
6
+ #define MLD_FIPS202_FIPS202_H
7
+
8
+ #include <stddef.h>
9
+ #include "../cbmc.h"
10
+ #include "../common.h"
11
+
12
+ #define SHAKE128_RATE 168
13
+ #define SHAKE256_RATE 136
14
+ #define SHA3_256_RATE 136
15
+ #define SHA3_512_RATE 72
16
+ #define MLD_KECCAK_LANES 25
17
+ #define SHA3_256_HASHBYTES 32
18
+ #define SHA3_512_HASHBYTES 64
19
+
20
+
21
+ /** Context for the incremental SHAKE128 XOF. */
22
+ typedef struct
23
+ {
24
+ uint64_t s[MLD_KECCAK_LANES]; /**< Keccak state. */
25
+ unsigned int pos; /**< Byte position within the current Keccak block. */
26
+ } mld_shake128ctx;
27
+
28
+ /** Context for the incremental SHAKE256 XOF. */
29
+ typedef struct
30
+ {
31
+ uint64_t s[MLD_KECCAK_LANES]; /**< Keccak state. */
32
+ unsigned int pos; /**< Byte position within the current Keccak block. */
33
+ } mld_shake256ctx;
34
+
35
+ #define mld_shake128_init MLD_NAMESPACE(shake128_init)
36
+ /**
37
+ * Initializes state for use as SHAKE128 XOF.
38
+ *
39
+ * @param[out] state Pointer to (uninitialized) state.
40
+ */
41
+ MLD_INTERNAL_API
42
+ void mld_shake128_init(mld_shake128ctx *state)
43
+ __contract__(
44
+ requires(memory_no_alias(state, sizeof(mld_shake128ctx)))
45
+ assigns(memory_slice(state, sizeof(mld_shake128ctx)))
46
+ ensures(state->pos == 0)
47
+ );
48
+
49
+ #define mld_shake128_absorb MLD_NAMESPACE(shake128_absorb)
50
+ /**
51
+ * Absorb step of the SHAKE128 XOF. Absorbs arbitrarily many bytes. Can be
52
+ * called multiple times to absorb multiple chunks of data.
53
+ *
54
+ * @param[in,out] state Pointer to (initialized) output state.
55
+ * @param[in] in Pointer to input to be absorbed into s.
56
+ * @param inlen Length of input in bytes.
57
+ */
58
+ MLD_INTERNAL_API
59
+ void mld_shake128_absorb(mld_shake128ctx *state, const uint8_t *in,
60
+ size_t inlen)
61
+ __contract__(
62
+ requires(inlen <= MLD_MAX_BUFFER_SIZE)
63
+ requires(memory_no_alias(state, sizeof(mld_shake128ctx)))
64
+ requires(memory_no_alias(in, inlen))
65
+ requires(state->pos <= SHAKE128_RATE)
66
+ assigns(memory_slice(state, sizeof(mld_shake128ctx)))
67
+ ensures(state->pos <= SHAKE128_RATE)
68
+ );
69
+
70
+ #define mld_shake128_finalize MLD_NAMESPACE(shake128_finalize)
71
+ /**
72
+ * Concludes the absorb phase of the SHAKE128 XOF.
73
+ *
74
+ * @param[in,out] state Pointer to state.
75
+ */
76
+ MLD_INTERNAL_API
77
+ void mld_shake128_finalize(mld_shake128ctx *state)
78
+ __contract__(
79
+ requires(memory_no_alias(state, sizeof(mld_shake128ctx)))
80
+ requires(state->pos <= SHAKE128_RATE)
81
+ assigns(memory_slice(state, sizeof(mld_shake128ctx)))
82
+ ensures(state->pos <= SHAKE128_RATE)
83
+ );
84
+
85
+ #define mld_shake128_squeeze MLD_NAMESPACE(shake128_squeeze)
86
+ /**
87
+ * Squeeze step of SHAKE128 XOF. Squeezes arbitrarily many bytes. Can be
88
+ * called multiple times to keep squeezing.
89
+ *
90
+ * @param[out] out Pointer to output blocks.
91
+ * @param outlen Number of bytes to be squeezed (written to output).
92
+ * @param[in,out] state Pointer to input/output state.
93
+ */
94
+ MLD_INTERNAL_API
95
+ void mld_shake128_squeeze(uint8_t *out, size_t outlen, mld_shake128ctx *state)
96
+ __contract__(
97
+ requires(outlen <= 8 * SHAKE128_RATE /* somewhat arbitrary bound */)
98
+ requires(memory_no_alias(state, sizeof(mld_shake128ctx)))
99
+ requires(memory_no_alias(out, outlen))
100
+ requires(state->pos <= SHAKE128_RATE)
101
+ assigns(memory_slice(state, sizeof(mld_shake128ctx)))
102
+ assigns(memory_slice(out, outlen))
103
+ ensures(state->pos <= SHAKE128_RATE)
104
+ );
105
+
106
+ #define mld_shake128_release MLD_NAMESPACE(shake128_release)
107
+ /**
108
+ * Release and securely zero the SHAKE128 state.
109
+ *
110
+ * @param[in,out] state Pointer to state.
111
+ */
112
+ MLD_INTERNAL_API
113
+ void mld_shake128_release(mld_shake128ctx *state)
114
+ __contract__(
115
+ requires(memory_no_alias(state, sizeof(mld_shake128ctx)))
116
+ assigns(memory_slice(state, sizeof(mld_shake128ctx)))
117
+ );
118
+
119
+ #define mld_shake256_init MLD_NAMESPACE(shake256_init)
120
+ /**
121
+ * Initializes state for use as SHAKE256 XOF.
122
+ *
123
+ * @param[out] state Pointer to (uninitialized) state.
124
+ */
125
+ MLD_INTERNAL_API
126
+ void mld_shake256_init(mld_shake256ctx *state)
127
+ __contract__(
128
+ requires(memory_no_alias(state, sizeof(mld_shake256ctx)))
129
+ assigns(memory_slice(state, sizeof(mld_shake256ctx)))
130
+ ensures(state->pos == 0)
131
+ );
132
+
133
+ #define mld_shake256_absorb MLD_NAMESPACE(shake256_absorb)
134
+ /**
135
+ * Absorb step of the SHAKE256 XOF. Absorbs arbitrarily many bytes. Can be
136
+ * called multiple times to absorb multiple chunks of data.
137
+ *
138
+ * @param[in,out] state Pointer to (initialized) output state.
139
+ * @param[in] in Pointer to input to be absorbed into s.
140
+ * @param inlen Length of input in bytes.
141
+ */
142
+ MLD_INTERNAL_API
143
+ void mld_shake256_absorb(mld_shake256ctx *state, const uint8_t *in,
144
+ size_t inlen)
145
+ __contract__(
146
+ requires(inlen <= MLD_MAX_BUFFER_SIZE)
147
+ requires(memory_no_alias(state, sizeof(mld_shake256ctx)))
148
+ requires(memory_no_alias(in, inlen))
149
+ requires(state->pos <= SHAKE256_RATE)
150
+ assigns(memory_slice(state, sizeof(mld_shake256ctx)))
151
+ ensures(state->pos <= SHAKE256_RATE)
152
+ );
153
+
154
+ #define mld_shake256_finalize MLD_NAMESPACE(shake256_finalize)
155
+ /**
156
+ * Concludes the absorb phase of the SHAKE256 XOF.
157
+ *
158
+ * @param[in,out] state Pointer to state.
159
+ */
160
+ MLD_INTERNAL_API
161
+ void mld_shake256_finalize(mld_shake256ctx *state)
162
+ __contract__(
163
+ requires(memory_no_alias(state, sizeof(mld_shake256ctx)))
164
+ requires(state->pos <= SHAKE256_RATE)
165
+ assigns(memory_slice(state, sizeof(mld_shake256ctx)))
166
+ ensures(state->pos <= SHAKE256_RATE)
167
+ );
168
+
169
+ #define mld_shake256_squeeze MLD_NAMESPACE(shake256_squeeze)
170
+ /**
171
+ * Squeeze step of SHAKE256 XOF. Squeezes arbitrarily many bytes. Can be
172
+ * called multiple times to keep squeezing.
173
+ *
174
+ * @param[out] out Pointer to output blocks.
175
+ * @param outlen Number of bytes to be squeezed (written to output).
176
+ * @param[in,out] state Pointer to input/output state.
177
+ */
178
+ MLD_INTERNAL_API
179
+ void mld_shake256_squeeze(uint8_t *out, size_t outlen, mld_shake256ctx *state)
180
+ __contract__(
181
+ requires(outlen <= 8 * SHAKE256_RATE /* somewhat arbitrary bound */)
182
+ requires(memory_no_alias(state, sizeof(mld_shake256ctx)))
183
+ requires(memory_no_alias(out, outlen))
184
+ requires(state->pos <= SHAKE256_RATE)
185
+ assigns(memory_slice(state, sizeof(mld_shake256ctx)))
186
+ assigns(memory_slice(out, outlen))
187
+ ensures(state->pos <= SHAKE256_RATE)
188
+ );
189
+
190
+ #define mld_shake256_release MLD_NAMESPACE(shake256_release)
191
+ /**
192
+ * Release and securely zero the SHAKE256 state.
193
+ *
194
+ * @param[in,out] state Pointer to state.
195
+ */
196
+ MLD_INTERNAL_API
197
+ void mld_shake256_release(mld_shake256ctx *state)
198
+ __contract__(
199
+ requires(memory_no_alias(state, sizeof(mld_shake256ctx)))
200
+ assigns(memory_slice(state, sizeof(mld_shake256ctx)))
201
+ );
202
+
203
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API) || !defined(MLD_CONFIG_CORE_API_ONLY)
204
+ #define mld_shake256 MLD_NAMESPACE(shake256)
205
+ /**
206
+ * SHAKE256 XOF with non-incremental API.
207
+ *
208
+ * @param[out] out Pointer to output.
209
+ * @param outlen Requested output length in bytes.
210
+ * @param[in] in Pointer to input.
211
+ * @param inlen Length of input in bytes.
212
+ */
213
+ MLD_INTERNAL_API
214
+ void mld_shake256(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen)
215
+ __contract__(
216
+ requires(inlen <= MLD_MAX_BUFFER_SIZE)
217
+ requires(outlen <= 8 * SHAKE256_RATE /* somewhat arbitrary bound */)
218
+ requires(memory_no_alias(in, inlen))
219
+ requires(memory_no_alias(out, outlen))
220
+ assigns(memory_slice(out, outlen))
221
+ );
222
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API || !MLD_CONFIG_CORE_API_ONLY */
223
+
224
+ #endif /* !MLD_FIPS202_FIPS202_H */
@@ -0,0 +1,187 @@
1
+ /*
2
+ * Copyright (c) The mlkem-native project authors
3
+ * Copyright (c) The mldsa-native project authors
4
+ * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
5
+ */
6
+
7
+ /* References
8
+ * ==========
9
+ *
10
+ * - [FIPS204]
11
+ * FIPS 204 Module-Lattice-Based Digital Signature Standard
12
+ * National Institute of Standards and Technology
13
+ * https://csrc.nist.gov/pubs/fips/204/final
14
+ */
15
+
16
+ #include "../common.h"
17
+ #if !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED) && \
18
+ !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
19
+
20
+ #include "../ct.h"
21
+ #include "fips202.h"
22
+ #include "fips202x4.h"
23
+ #include "keccakf1600.h"
24
+
25
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API) || !defined(MLD_CONFIG_REDUCE_RAM) || \
26
+ defined(MLD_UNIT_TEST)
27
+ static void mld_keccak_absorb_once_x4(uint64_t *s, unsigned r,
28
+ const uint8_t *in0, const uint8_t *in1,
29
+ const uint8_t *in2, const uint8_t *in3,
30
+ size_t inlen, uint8_t p)
31
+ __contract__(
32
+ requires(inlen <= MLD_MAX_BUFFER_SIZE)
33
+ requires(memory_no_alias(s, sizeof(uint64_t) * MLD_KECCAK_LANES * MLD_KECCAK_WAY))
34
+ requires(r > 0)
35
+ requires(r <= sizeof(uint64_t) * MLD_KECCAK_LANES)
36
+ requires(memory_no_alias(in0, inlen))
37
+ requires(memory_no_alias(in1, inlen))
38
+ requires(memory_no_alias(in2, inlen))
39
+ requires(memory_no_alias(in3, inlen))
40
+ assigns(memory_slice(s, sizeof(uint64_t) * MLD_KECCAK_LANES * MLD_KECCAK_WAY)))
41
+ {
42
+ while (inlen >= r)
43
+ __loop__(
44
+ assigns(inlen, in0, in1, in2, in3, memory_slice(s, sizeof(uint64_t) * MLD_KECCAK_LANES * MLD_KECCAK_WAY))
45
+ invariant(inlen <= loop_entry(inlen))
46
+ invariant(in0 == loop_entry(in0) + (loop_entry(inlen) - inlen))
47
+ invariant(in1 == loop_entry(in1) + (loop_entry(inlen) - inlen))
48
+ invariant(in2 == loop_entry(in2) + (loop_entry(inlen) - inlen))
49
+ invariant(in3 == loop_entry(in3) + (loop_entry(inlen) - inlen))
50
+ decreases(inlen))
51
+ {
52
+ mld_keccakf1600x4_xor_bytes(s, in0, in1, in2, in3, 0, r);
53
+ mld_keccakf1600x4_permute(s);
54
+
55
+ in0 += r;
56
+ in1 += r;
57
+ in2 += r;
58
+ in3 += r;
59
+ inlen -= r;
60
+ }
61
+
62
+ /* Safety: At this point, inlen < r, so the truncations to unsigned are safe
63
+ * below. */
64
+ if (inlen > 0)
65
+ {
66
+ mld_keccakf1600x4_xor_bytes(s, in0, in1, in2, in3, 0, (unsigned)inlen);
67
+ }
68
+
69
+ if (inlen == r - 1)
70
+ {
71
+ p |= 128;
72
+ mld_keccakf1600x4_xor_bytes(s, &p, &p, &p, &p, (unsigned)inlen, 1);
73
+ }
74
+ else
75
+ {
76
+ mld_keccakf1600x4_xor_bytes(s, &p, &p, &p, &p, (unsigned)inlen, 1);
77
+ p = 128;
78
+ mld_keccakf1600x4_xor_bytes(s, &p, &p, &p, &p, r - 1, 1);
79
+ }
80
+ }
81
+
82
+ static void mld_keccak_squeezeblocks_x4(uint8_t *out0, uint8_t *out1,
83
+ uint8_t *out2, uint8_t *out3,
84
+ size_t nblocks, uint64_t *s, unsigned r)
85
+ __contract__(
86
+ requires(r <= sizeof(uint64_t) * MLD_KECCAK_LANES)
87
+ requires(nblocks <= 8 /* somewhat arbitrary bound */)
88
+ requires(memory_no_alias(s, sizeof(uint64_t) * MLD_KECCAK_LANES * MLD_KECCAK_WAY))
89
+ requires(memory_no_alias(out0, nblocks * r))
90
+ requires(memory_no_alias(out1, nblocks * r))
91
+ requires(memory_no_alias(out2, nblocks * r))
92
+ requires(memory_no_alias(out3, nblocks * r))
93
+ assigns(memory_slice(s, sizeof(uint64_t) * MLD_KECCAK_LANES * MLD_KECCAK_WAY))
94
+ assigns(memory_slice(out0, nblocks * r))
95
+ assigns(memory_slice(out1, nblocks * r))
96
+ assigns(memory_slice(out2, nblocks * r))
97
+ assigns(memory_slice(out3, nblocks * r)))
98
+ {
99
+ size_t current_offset = 0;
100
+ while (nblocks > 0)
101
+ __loop__(
102
+ assigns(nblocks, current_offset,
103
+ memory_slice(s, sizeof(uint64_t) * MLD_KECCAK_LANES * MLD_KECCAK_WAY),
104
+ memory_slice(out0, nblocks * r),
105
+ memory_slice(out1, nblocks * r),
106
+ memory_slice(out2, nblocks * r),
107
+ memory_slice(out3, nblocks * r))
108
+ invariant(nblocks <= loop_entry(nblocks))
109
+ invariant(current_offset == (loop_entry(nblocks) - nblocks) * r)
110
+ decreases(nblocks))
111
+ {
112
+ mld_keccakf1600x4_permute(s);
113
+ mld_keccakf1600x4_extract_bytes(
114
+ s, &out0[current_offset], &out1[current_offset], &out2[current_offset],
115
+ &out3[current_offset], 0, r);
116
+ current_offset += r;
117
+ nblocks--;
118
+ }
119
+ }
120
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API || !MLD_CONFIG_REDUCE_RAM || \
121
+ MLD_UNIT_TEST */
122
+
123
+ #if !defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)
124
+ MLD_INTERNAL_API
125
+ void mld_shake128x4_absorb_once(mld_shake128x4ctx *state, const uint8_t *in0,
126
+ const uint8_t *in1, const uint8_t *in2,
127
+ const uint8_t *in3, size_t inlen)
128
+ {
129
+ mld_memset(state, 0, sizeof(mld_shake128x4ctx));
130
+ mld_keccak_absorb_once_x4(state->ctx, SHAKE128_RATE, in0, in1, in2, in3,
131
+ inlen, 0x1F);
132
+ }
133
+
134
+ MLD_INTERNAL_API
135
+ void mld_shake128x4_squeezeblocks(uint8_t *out0, uint8_t *out1, uint8_t *out2,
136
+ uint8_t *out3, size_t nblocks,
137
+ mld_shake128x4ctx *state)
138
+ {
139
+ mld_keccak_squeezeblocks_x4(out0, out1, out2, out3, nblocks, state->ctx,
140
+ SHAKE128_RATE);
141
+ }
142
+
143
+ MLD_INTERNAL_API
144
+ void mld_shake128x4_init(mld_shake128x4ctx *state) { (void)state; }
145
+ MLD_INTERNAL_API
146
+ void mld_shake128x4_release(mld_shake128x4ctx *state)
147
+ {
148
+ /* @[FIPS204, Section 3.6.3] Destruction of intermediate values. */
149
+ mld_zeroize(state, sizeof(mld_shake128x4ctx));
150
+ }
151
+ #endif /* !MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST */
152
+
153
+ #if !defined(MLD_CONFIG_NO_KEYPAIR_API) || \
154
+ (!defined(MLD_CONFIG_NO_SIGN_API) && \
155
+ (!defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)))
156
+ MLD_INTERNAL_API
157
+ void mld_shake256x4_absorb_once(mld_shake256x4ctx *state, const uint8_t *in0,
158
+ const uint8_t *in1, const uint8_t *in2,
159
+ const uint8_t *in3, size_t inlen)
160
+ {
161
+ mld_memset(state, 0, sizeof(mld_shake256x4ctx));
162
+ mld_keccak_absorb_once_x4(state->ctx, SHAKE256_RATE, in0, in1, in2, in3,
163
+ inlen, 0x1F);
164
+ }
165
+
166
+ MLD_INTERNAL_API
167
+ void mld_shake256x4_squeezeblocks(uint8_t *out0, uint8_t *out1, uint8_t *out2,
168
+ uint8_t *out3, size_t nblocks,
169
+ mld_shake256x4ctx *state)
170
+ {
171
+ mld_keccak_squeezeblocks_x4(out0, out1, out2, out3, nblocks, state->ctx,
172
+ SHAKE256_RATE);
173
+ }
174
+
175
+ MLD_INTERNAL_API
176
+ void mld_shake256x4_init(mld_shake256x4ctx *state) { (void)state; }
177
+ MLD_INTERNAL_API
178
+ void mld_shake256x4_release(mld_shake256x4ctx *state)
179
+ {
180
+ /* @[FIPS204, Section 3.6.3] Destruction of intermediate values. */
181
+ mld_zeroize(state, sizeof(mld_shake256x4ctx));
182
+ }
183
+ #endif /* !MLD_CONFIG_NO_KEYPAIR_API || (!MLD_CONFIG_NO_SIGN_API && \
184
+ (!MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST)) */
185
+
186
+ #endif /* !MLD_CONFIG_MULTILEVEL_NO_SHARED && !MLD_CONFIG_SERIAL_FIPS202_ONLY \
187
+ */