pq_crypto 0.6.1 → 0.6.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/SECURITY.md +7 -0
- data/ext/pqcrypto/pqcrypto_version.h +1 -1
- data/ext/pqcrypto/vendor/.vendored +4 -4
- data/ext/pqcrypto/vendor/mldsa-native/README.md +23 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/README.md +23 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +114 -58
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +498 -461
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +145 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +456 -422
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +47 -25
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +26 -14
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +56 -81
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +17 -24
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.c +33 -40
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +67 -87
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +19 -14
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +13 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +84 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +10 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +6 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +22 -15
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +376 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +204 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +259 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +1077 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +987 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +16 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +2 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +4 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +60 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +48 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +18 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +658 -582
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +5 -100
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +26 -25
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +334 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +355 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +8 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/{xkcp.h → keccak_f1600_x4_avx2.h} +11 -8
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +44 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +454 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +52 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +37 -28
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +213 -196
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +248 -64
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt_aarch64_asm.S +753 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +129 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +145 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +177 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt_aarch64_asm.S +653 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery_aarch64_asm.S +84 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_aarch64_asm.S +53 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_aarch64_asm.S +55 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_aarch64_asm.S +86 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_aarch64_asm.S +86 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_aarch64_asm.S +103 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_aarch64_asm.S +111 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_aarch64_asm.S +75 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_aarch64_asm.S +72 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +23 -11
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_aarch64_asm.S +189 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_aarch64_asm.S +137 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_aarch64_asm.S +130 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +520 -516
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +34 -33
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +202 -242
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +25 -17
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +112 -28
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt_avx2_asm.S +2311 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt_avx2_asm.S +2383 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack_avx2_asm.S +238 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4_avx2_asm.S +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5_avx2_asm.S +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7_avx2_asm.S +187 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_avx2_asm.S +130 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2_asm.S +190 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +9 -8
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +10 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +8 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +8 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +130 -129
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +109 -180
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +169 -150
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +56 -40
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +149 -164
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +52 -57
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +132 -167
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +57 -424
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +167 -474
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +308 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +653 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +22 -29
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +37 -43
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +511 -367
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +456 -417
- data/lib/pq_crypto/version.rb +1 -1
- data/script/vendor_libs.rb +3 -3
- metadata +41 -35
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +0 -376
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +0 -204
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +0 -259
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +0 -1077
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +0 -987
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +0 -488
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +0 -16
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +0 -753
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +0 -129
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +0 -145
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +0 -177
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +0 -653
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +0 -79
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +0 -53
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +0 -55
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +0 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +0 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +0 -102
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +0 -110
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +0 -72
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +0 -69
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +0 -189
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +0 -135
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +0 -128
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +0 -2311
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +0 -2383
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +0 -239
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +0 -131
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +0 -139
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +0 -155
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +0 -187
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +0 -61
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
#ifndef MLD_CBMC_H
|
|
7
7
|
#define MLD_CBMC_H
|
|
8
|
+
|
|
8
9
|
/***************************************************
|
|
9
10
|
* Basic replacements for __CPROVER_XXX contracts
|
|
10
11
|
***************************************************/
|
|
@@ -20,6 +21,15 @@
|
|
|
20
21
|
#define __contract__(x) x
|
|
21
22
|
#define __loop__(x) x
|
|
22
23
|
|
|
24
|
+
/* Conditionally expand to __VA_ARGS__ depending on MLD_CONFIG_REDUCE_RAM. */
|
|
25
|
+
#if defined(MLD_CONFIG_REDUCE_RAM)
|
|
26
|
+
#define MLD_IF_REDUCE_RAM(...) __VA_ARGS__
|
|
27
|
+
#define MLD_IF_NOT_REDUCE_RAM(...)
|
|
28
|
+
#else
|
|
29
|
+
#define MLD_IF_REDUCE_RAM(...)
|
|
30
|
+
#define MLD_IF_NOT_REDUCE_RAM(...) __VA_ARGS__
|
|
31
|
+
#endif
|
|
32
|
+
|
|
23
33
|
/* https://diffblue.github.io/cbmc/contracts-assigns.html */
|
|
24
34
|
#define assigns(...) __CPROVER_assigns(__VA_ARGS__)
|
|
25
35
|
|
|
@@ -83,24 +93,36 @@
|
|
|
83
93
|
* Quantifiers
|
|
84
94
|
* Note that the range on qvar is _exclusive_ between qvar_lb .. qvar_ub
|
|
85
95
|
* https://diffblue.github.io/cbmc/contracts-quantifiers.html
|
|
96
|
+
*
|
|
97
|
+
* The quantified variable is declared as uint32_t, so these macros
|
|
98
|
+
* quantify only over indices in [0, UINT32_MAX). Bounds larger than
|
|
99
|
+
* UINT32_MAX (4 GiB) are NOT supported: the explicit (uint32_t) casts
|
|
100
|
+
* on the bounds will trigger CBMC's conversion check if a wider bound
|
|
101
|
+
* (e.g. a size_t > UINT32_MAX) is passed.
|
|
102
|
+
*
|
|
103
|
+
* Quantifying over size_t (64-bit) was found to blow up SMT proof
|
|
104
|
+
* times, so we deliberately keep the index width at 32 bits. Callers
|
|
105
|
+
* dealing with size_t-typed buffers must add an explicit
|
|
106
|
+
* requires(len <= UINT32_MAX)
|
|
107
|
+
* precondition.
|
|
86
108
|
*/
|
|
87
109
|
|
|
88
110
|
/*
|
|
89
111
|
* Prevent clang-format from corrupting CBMC's special ==> operator
|
|
90
112
|
*/
|
|
91
113
|
/* clang-format off */
|
|
92
|
-
#define forall(qvar, qvar_lb, qvar_ub, predicate)
|
|
93
|
-
__CPROVER_forall
|
|
94
|
-
{
|
|
95
|
-
|
|
96
|
-
((qvar_lb) <= (qvar) && (qvar) < (qvar_ub)) ==> (predicate)
|
|
114
|
+
#define forall(qvar, qvar_lb, qvar_ub, predicate) \
|
|
115
|
+
__CPROVER_forall \
|
|
116
|
+
{ \
|
|
117
|
+
uint32_t qvar; \
|
|
118
|
+
((uint32_t) (qvar_lb) <= (qvar) && (qvar) < (uint32_t) (qvar_ub)) ==> (predicate) \
|
|
97
119
|
}
|
|
98
120
|
|
|
99
|
-
#define exists(qvar, qvar_lb, qvar_ub, predicate)
|
|
100
|
-
__CPROVER_exists
|
|
101
|
-
{
|
|
102
|
-
|
|
103
|
-
((qvar_lb) <= (qvar) && (qvar) < (qvar_ub)) && (predicate)
|
|
121
|
+
#define exists(qvar, qvar_lb, qvar_ub, predicate) \
|
|
122
|
+
__CPROVER_exists \
|
|
123
|
+
{ \
|
|
124
|
+
uint32_t qvar; \
|
|
125
|
+
((uint32_t) (qvar_lb) <= (qvar) && (qvar) < (uint32_t) (qvar_ub)) && (predicate) \
|
|
104
126
|
}
|
|
105
127
|
/* clang-format on */
|
|
106
128
|
|
|
@@ -118,32 +140,32 @@
|
|
|
118
140
|
value_lb, value_ub) \
|
|
119
141
|
__CPROVER_forall \
|
|
120
142
|
{ \
|
|
121
|
-
|
|
122
|
-
((qvar_lb) <= (qvar) && (qvar) < (qvar_ub)) ==>
|
|
123
|
-
(((int)(value_lb) <= ((array_var)[(qvar)])) &&
|
|
124
|
-
(((array_var)[(qvar)]) < (int)(value_ub)))
|
|
143
|
+
uint32_t qvar; \
|
|
144
|
+
((uint32_t) (qvar_lb) <= (qvar) && (qvar) < (uint32_t) (qvar_ub)) ==> \
|
|
145
|
+
(((int)(value_lb) <= ((array_var)[(qvar)])) && \
|
|
146
|
+
(((array_var)[(qvar)]) < (int)(value_ub))) \
|
|
125
147
|
}
|
|
126
148
|
|
|
127
149
|
#define array_bound(array_var, qvar_lb, qvar_ub, value_lb, value_ub) \
|
|
128
|
-
array_bound_core(CBMC_CONCAT(_cbmc_idx, __COUNTER__), (qvar_lb),
|
|
150
|
+
array_bound_core(CBMC_CONCAT(_cbmc_idx, __COUNTER__), (qvar_lb), \
|
|
129
151
|
(qvar_ub), (array_var), (value_lb), (value_ub))
|
|
130
152
|
|
|
131
|
-
#define array_unchanged_core(qvar, qvar_lb, qvar_ub, array_var)
|
|
132
|
-
__CPROVER_forall
|
|
133
|
-
{
|
|
134
|
-
|
|
135
|
-
((qvar_lb) <= (qvar) && (qvar) < (qvar_ub)) ==>
|
|
153
|
+
#define array_unchanged_core(qvar, qvar_lb, qvar_ub, array_var) \
|
|
154
|
+
__CPROVER_forall \
|
|
155
|
+
{ \
|
|
156
|
+
uint32_t qvar; \
|
|
157
|
+
((uint32_t) (qvar_lb) <= (qvar) && (qvar) < (uint32_t) (qvar_ub)) ==> \
|
|
136
158
|
((array_var)[(qvar)]) == (old(* (int32_t (*)[(qvar_ub)])(array_var)))[(qvar)] \
|
|
137
159
|
}
|
|
138
160
|
|
|
139
161
|
#define array_unchanged(array_var, N) \
|
|
140
162
|
array_unchanged_core(CBMC_CONCAT(_cbmc_idx, __COUNTER__), 0, (N), (array_var))
|
|
141
163
|
|
|
142
|
-
#define array_unchanged_u64_core(qvar, qvar_lb, qvar_ub, array_var)
|
|
143
|
-
__CPROVER_forall
|
|
144
|
-
{
|
|
145
|
-
|
|
146
|
-
((qvar_lb) <= (qvar) && (qvar) < (qvar_ub)) ==>
|
|
164
|
+
#define array_unchanged_u64_core(qvar, qvar_lb, qvar_ub, array_var) \
|
|
165
|
+
__CPROVER_forall \
|
|
166
|
+
{ \
|
|
167
|
+
uint32_t qvar; \
|
|
168
|
+
((uint32_t) (qvar_lb) <= (qvar) && (qvar) < (uint32_t) (qvar_ub)) ==> \
|
|
147
169
|
((array_var)[(qvar)]) == (old(* (uint64_t (*)[(qvar_ub)])(array_var)))[(qvar)] \
|
|
148
170
|
}
|
|
149
171
|
|
|
@@ -26,8 +26,12 @@
|
|
|
26
26
|
* this can be overwritten by the user, e.g. for single-CU builds. */
|
|
27
27
|
#if !defined(MLD_CONFIG_INTERNAL_API_QUALIFIER)
|
|
28
28
|
#define MLD_INTERNAL_API
|
|
29
|
+
#define MLD_INTERNAL_DATA_DECLARATION extern
|
|
30
|
+
#define MLD_INTERNAL_DATA_DEFINITION
|
|
29
31
|
#else
|
|
30
32
|
#define MLD_INTERNAL_API MLD_CONFIG_INTERNAL_API_QUALIFIER
|
|
33
|
+
#define MLD_INTERNAL_DATA_DECLARATION MLD_CONFIG_INTERNAL_API_QUALIFIER
|
|
34
|
+
#define MLD_INTERNAL_DATA_DEFINITION MLD_CONFIG_INTERNAL_API_QUALIFIER
|
|
31
35
|
#endif
|
|
32
36
|
|
|
33
37
|
#if !defined(MLD_CONFIG_EXTERNAL_API_QUALIFIER)
|
|
@@ -128,6 +132,14 @@
|
|
|
128
132
|
#error Bad configuration: MLD_CONFIG_NO_RANDOMIZED_API is incompatible with MLD_CONFIG_KEYGEN_PCT as the current PCT implementation requires crypto_sign_signature()
|
|
129
133
|
#endif
|
|
130
134
|
|
|
135
|
+
#if defined(MLD_CONFIG_NO_SIGN_API) && defined(MLD_CONFIG_KEYGEN_PCT)
|
|
136
|
+
#error Bad configuration: MLD_CONFIG_NO_SIGN_API is incompatible with MLD_CONFIG_KEYGEN_PCT as the current PCT implementation requires crypto_sign_signature()
|
|
137
|
+
#endif
|
|
138
|
+
|
|
139
|
+
#if defined(MLD_CONFIG_NO_VERIFY_API) && defined(MLD_CONFIG_KEYGEN_PCT)
|
|
140
|
+
#error Bad configuration: MLD_CONFIG_NO_VERIFY_API is incompatible with MLD_CONFIG_KEYGEN_PCT as the current PCT implementation requires crypto_sign_verify()
|
|
141
|
+
#endif
|
|
142
|
+
|
|
131
143
|
#if defined(MLD_CONFIG_USE_NATIVE_BACKEND_ARITH)
|
|
132
144
|
#include MLD_CONFIG_ARITH_BACKEND_FILE
|
|
133
145
|
/* Include to enforce consistency of API and implementation,
|
|
@@ -290,20 +302,6 @@
|
|
|
290
302
|
|
|
291
303
|
#endif /* MLD_CONFIG_CUSTOM_ALLOC_FREE */
|
|
292
304
|
|
|
293
|
-
/*
|
|
294
|
-
* We are facing severe CBMC performance issues when using unions.
|
|
295
|
-
* As a temporary workaround, we use unions only when MLD_CONFIG_REDUCE_RAM is
|
|
296
|
-
* set.
|
|
297
|
-
* TODO: Remove the workaround once
|
|
298
|
-
* https://github.com/diffblue/cbmc/issues/8813
|
|
299
|
-
* is resolved
|
|
300
|
-
*/
|
|
301
|
-
#if defined(MLD_CONFIG_REDUCE_RAM)
|
|
302
|
-
#define MLD_UNION_OR_STRUCT union
|
|
303
|
-
#else
|
|
304
|
-
#define MLD_UNION_OR_STRUCT struct
|
|
305
|
-
#endif
|
|
306
|
-
|
|
307
305
|
/****************************** Error codes ***********************************/
|
|
308
306
|
|
|
309
307
|
/* Generic failure condition */
|
|
@@ -314,6 +312,20 @@
|
|
|
314
312
|
/* An rng failure occured. Might be due to insufficient entropy or
|
|
315
313
|
* system misconfiguration. */
|
|
316
314
|
#define MLD_ERR_RNG_FAIL -3
|
|
315
|
+
/* The signing rejection-sampling loop exceeded
|
|
316
|
+
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS iterations without producing a valid
|
|
317
|
+
* signature. With a FIPS 204 Appendix C compliant bound (>= 814) this
|
|
318
|
+
* has probability < 2^-256. */
|
|
319
|
+
#define MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED -4
|
|
320
|
+
|
|
321
|
+
/* Disjunction over the full set of MLD_ERR_XXX failure codes.
|
|
322
|
+
*
|
|
323
|
+
* Intended for use in top-level `ensures` clauses that admit every
|
|
324
|
+
* possible error. Narrower contracts should enumerate only the
|
|
325
|
+
* specific errors they can actually return. */
|
|
326
|
+
#define MLD_ANY_ERROR(err) \
|
|
327
|
+
((err) == MLD_ERR_FAIL || (err) == MLD_ERR_OUT_OF_MEMORY || \
|
|
328
|
+
(err) == MLD_ERR_RNG_FAIL || (err) == MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED)
|
|
317
329
|
|
|
318
330
|
|
|
319
331
|
#endif /* !__ASSEMBLER__ */
|
|
@@ -143,19 +143,16 @@ __contract__(ensures(return_value == b))
|
|
|
143
143
|
#pragma CPROVER check disable "conversion"
|
|
144
144
|
#endif
|
|
145
145
|
|
|
146
|
-
|
|
147
|
-
*
|
|
146
|
+
/**
|
|
147
|
+
* Cast uint32 value to int32.
|
|
148
148
|
*
|
|
149
|
-
*
|
|
149
|
+
* @param x Input value.
|
|
150
150
|
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
|
|
156
|
-
* - x >= 2^31: returns x - 2^31
|
|
157
|
-
*
|
|
158
|
-
**************************************************/
|
|
151
|
+
* @return For uint32_t x, the unique y in int32_t so that x == y mod 2^32.
|
|
152
|
+
* Concretely:
|
|
153
|
+
* - x < 2^31: returns x
|
|
154
|
+
* - x >= 2^31: returns x - 2^31
|
|
155
|
+
*/
|
|
159
156
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
160
157
|
static MLD_ALWAYS_INLINE int32_t mld_cast_uint32_to_int32(uint32_t x)
|
|
161
158
|
{
|
|
@@ -174,47 +171,42 @@ static MLD_ALWAYS_INLINE int32_t mld_cast_uint32_to_int32(uint32_t x)
|
|
|
174
171
|
#endif
|
|
175
172
|
|
|
176
173
|
|
|
177
|
-
|
|
178
|
-
*
|
|
174
|
+
/**
|
|
175
|
+
* Cast int64 value to uint32 as per C standard.
|
|
179
176
|
*
|
|
180
|
-
*
|
|
177
|
+
* @param x Input value.
|
|
181
178
|
*
|
|
182
|
-
*
|
|
183
|
-
|
|
184
|
-
**************************************************/
|
|
179
|
+
* @return For int64_t x, the unique y in uint32_t so that x == y mod 2^32.
|
|
180
|
+
*/
|
|
185
181
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
186
182
|
static MLD_ALWAYS_INLINE uint32_t mld_cast_int64_to_uint32(int64_t x)
|
|
187
183
|
{
|
|
188
184
|
return (uint32_t)(x & (int64_t)UINT32_MAX);
|
|
189
185
|
}
|
|
190
186
|
|
|
191
|
-
|
|
192
|
-
*
|
|
187
|
+
/**
|
|
188
|
+
* Cast int32 value to uint32 as per C standard.
|
|
193
189
|
*
|
|
194
|
-
*
|
|
190
|
+
* @param x Input value.
|
|
195
191
|
*
|
|
196
|
-
*
|
|
197
|
-
|
|
198
|
-
**************************************************/
|
|
192
|
+
* @return For int32_t x, the unique y in uint32_t so that x == y mod 2^32.
|
|
193
|
+
*/
|
|
199
194
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
200
195
|
static MLD_ALWAYS_INLINE uint32_t mld_cast_int32_to_uint32(int32_t x)
|
|
201
196
|
{
|
|
202
197
|
return mld_cast_int64_to_uint32((int64_t)x);
|
|
203
198
|
}
|
|
204
199
|
|
|
205
|
-
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* Description: Functionally equivalent to cond ? a : b,
|
|
209
|
-
* but implemented with guards against
|
|
210
|
-
* compiler-introduced branches.
|
|
200
|
+
/**
|
|
201
|
+
* Functionally equivalent to cond ? a : b, but implemented with guards against
|
|
202
|
+
* compiler-introduced branches.
|
|
211
203
|
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
204
|
+
* @param a First alternative.
|
|
205
|
+
* @param b Second alternative.
|
|
206
|
+
* @param cond Condition variable.
|
|
215
207
|
*
|
|
216
|
-
*
|
|
217
|
-
|
|
208
|
+
* @return a if cond is 0xFFFFFFFF, b if cond is 0.
|
|
209
|
+
*/
|
|
218
210
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
219
211
|
static MLD_INLINE int32_t mld_ct_sel_int32(int32_t a, int32_t b, uint32_t cond)
|
|
220
212
|
__contract__(
|
|
@@ -228,14 +220,11 @@ __contract__(
|
|
|
228
220
|
return mld_cast_uint32_to_int32(res);
|
|
229
221
|
}
|
|
230
222
|
|
|
231
|
-
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
* Description: Return 0 if input is zero, and -1 otherwise.
|
|
223
|
+
/**
|
|
224
|
+
* Return 0 if input is zero, and -1 otherwise.
|
|
235
225
|
*
|
|
236
|
-
*
|
|
237
|
-
|
|
238
|
-
**************************************************/
|
|
226
|
+
* @param x Value to be converted into a mask.
|
|
227
|
+
*/
|
|
239
228
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
240
229
|
static MLD_INLINE uint32_t mld_ct_cmask_nonzero_u32(uint32_t x)
|
|
241
230
|
__contract__(ensures(return_value == ((x == 0) ? 0 : 0xFFFFFFFF)))
|
|
@@ -245,14 +234,11 @@ __contract__(ensures(return_value == ((x == 0) ? 0 : 0xFFFFFFFF)))
|
|
|
245
234
|
return mld_cast_int64_to_uint32(tmp);
|
|
246
235
|
}
|
|
247
236
|
|
|
248
|
-
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
* Description: Return 0 if input is zero, and -1 otherwise.
|
|
237
|
+
/**
|
|
238
|
+
* Return 0 if input is zero, and -1 otherwise.
|
|
252
239
|
*
|
|
253
|
-
*
|
|
254
|
-
|
|
255
|
-
**************************************************/
|
|
240
|
+
* @param x Value to be converted into a mask.
|
|
241
|
+
*/
|
|
256
242
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
257
243
|
static MLD_INLINE uint8_t mld_ct_cmask_nonzero_u8(uint8_t x)
|
|
258
244
|
__contract__(ensures(return_value == ((x == 0) ? 0 : 0xFF)))
|
|
@@ -261,14 +247,11 @@ __contract__(ensures(return_value == ((x == 0) ? 0 : 0xFF)))
|
|
|
261
247
|
return (uint8_t)(mask & 0xFF);
|
|
262
248
|
}
|
|
263
249
|
|
|
264
|
-
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
* Description: Return 0 if input is non-negative, and -1 otherwise.
|
|
250
|
+
/**
|
|
251
|
+
* Return 0 if input is non-negative, and -1 otherwise.
|
|
268
252
|
*
|
|
269
|
-
*
|
|
270
|
-
|
|
271
|
-
**************************************************/
|
|
253
|
+
* @param x Value to be converted into a mask.
|
|
254
|
+
*/
|
|
272
255
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
273
256
|
static MLD_INLINE uint32_t mld_ct_cmask_neg_i32(int32_t x)
|
|
274
257
|
__contract__(
|
|
@@ -280,14 +263,11 @@ __contract__(
|
|
|
280
263
|
return mld_cast_int64_to_uint32(tmp);
|
|
281
264
|
}
|
|
282
265
|
|
|
283
|
-
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
* Description: Return -x if x<0, x otherwise
|
|
266
|
+
/**
|
|
267
|
+
* Return -x if x<0, x otherwise.
|
|
287
268
|
*
|
|
288
|
-
*
|
|
289
|
-
|
|
290
|
-
**************************************************/
|
|
269
|
+
* @param x Input value.
|
|
270
|
+
*/
|
|
291
271
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
292
272
|
static MLD_INLINE int32_t mld_ct_abs_i32(int32_t x)
|
|
293
273
|
__contract__(
|
|
@@ -298,19 +278,16 @@ __contract__(
|
|
|
298
278
|
return mld_ct_sel_int32(-x, x, mld_ct_cmask_neg_i32(x));
|
|
299
279
|
}
|
|
300
280
|
|
|
301
|
-
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
* Description: Compare two arrays for equality in constant time.
|
|
281
|
+
/**
|
|
282
|
+
* Compare two arrays for equality in constant time.
|
|
305
283
|
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
* only.
|
|
284
|
+
* @param[in] a Pointer to first byte array.
|
|
285
|
+
* @param[in] b Pointer to second byte array.
|
|
286
|
+
* @param len Length of the byte arrays, upper-bounded to UINT16_MAX to
|
|
287
|
+
* control proof complexity only.
|
|
311
288
|
*
|
|
312
|
-
*
|
|
313
|
-
|
|
289
|
+
* @return 0 if the byte arrays are equal, 0xFF otherwise.
|
|
290
|
+
*/
|
|
314
291
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
315
292
|
static MLD_INLINE uint8_t mld_ct_memcmp(const uint8_t *a, const uint8_t *b,
|
|
316
293
|
const size_t len)
|
|
@@ -345,16 +322,14 @@ __contract__(
|
|
|
345
322
|
return (mld_value_barrier_u8(mld_ct_cmask_nonzero_u8(r) ^ s) ^ s);
|
|
346
323
|
}
|
|
347
324
|
|
|
348
|
-
|
|
349
|
-
*
|
|
325
|
+
/**
|
|
326
|
+
* Force-zeroize a buffer.
|
|
350
327
|
*
|
|
351
|
-
*
|
|
352
|
-
* @[FIPS204, Section 3.6.3] Destruction of intermediate
|
|
353
|
-
* values.
|
|
328
|
+
* @[FIPS204, Section 3.6.3] Destruction of intermediate values.
|
|
354
329
|
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
|
|
330
|
+
* @param[out] ptr Pointer to buffer to be zeroed.
|
|
331
|
+
* @param len Amount of bytes to be zeroed.
|
|
332
|
+
*/
|
|
358
333
|
#if !defined(MLD_CONFIG_CUSTOM_ZEROIZE)
|
|
359
334
|
#if defined(MLD_SYS_WINDOWS)
|
|
360
335
|
#include <windows.h>
|
|
@@ -9,37 +9,30 @@
|
|
|
9
9
|
|
|
10
10
|
#if defined(MLDSA_DEBUG)
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
*
|
|
12
|
+
/**
|
|
13
|
+
* Check debug assertion.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
15
|
+
* Prints an error message to stderr and calls exit(1) if not.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
* - line: line number
|
|
22
|
-
* - val: Value asserted to be non-zero
|
|
23
|
-
**************************************************/
|
|
17
|
+
* @param file Filename.
|
|
18
|
+
* @param line Line number.
|
|
19
|
+
* @param val Value asserted to be non-zero.
|
|
20
|
+
*/
|
|
24
21
|
#define mld_debug_check_assert MLD_NAMESPACE(mldsa_debug_assert)
|
|
25
22
|
void mld_debug_check_assert(const char *file, int line, const int val);
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
*
|
|
24
|
+
/**
|
|
25
|
+
* Check whether values in an array of int32_t are within specified bounds.
|
|
29
26
|
*
|
|
30
|
-
*
|
|
31
|
-
* are within specified bounds.
|
|
27
|
+
* Prints an error message to stderr and calls exit(1) if not.
|
|
32
28
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
|
|
40
|
-
* - lower_bound_exclusive: Exclusive lower bound
|
|
41
|
-
* - upper_bound_exclusive: Exclusive upper bound
|
|
42
|
-
**************************************************/
|
|
29
|
+
* @param file Filename.
|
|
30
|
+
* @param line Line number.
|
|
31
|
+
* @param[in] ptr Base of array to be checked.
|
|
32
|
+
* @param len Number of int32_t in ptr.
|
|
33
|
+
* @param lower_bound_exclusive Exclusive lower bound.
|
|
34
|
+
* @param upper_bound_exclusive Exclusive upper bound.
|
|
35
|
+
*/
|
|
43
36
|
#define mld_debug_check_bounds MLD_NAMESPACE(mldsa_debug_check_bounds)
|
|
44
37
|
void mld_debug_check_bounds(const char *file, int line, const int32_t *ptr,
|
|
45
38
|
unsigned len, int64_t lower_bound_exclusive,
|
|
@@ -39,13 +39,11 @@
|
|
|
39
39
|
#include "keccakf1600.h"
|
|
40
40
|
#if !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
*
|
|
42
|
+
/**
|
|
43
|
+
* Initializes the Keccak state.
|
|
44
44
|
*
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
* Arguments: - uint64_t *s: pointer to Keccak state
|
|
48
|
-
**************************************************/
|
|
45
|
+
* @param[out] s Pointer to Keccak state.
|
|
46
|
+
*/
|
|
49
47
|
static void keccak_init(uint64_t s[MLD_KECCAK_LANES])
|
|
50
48
|
__contract__(
|
|
51
49
|
requires(memory_no_alias(s, sizeof(uint64_t) * MLD_KECCAK_LANES))
|
|
@@ -55,19 +53,17 @@ __contract__(
|
|
|
55
53
|
mld_memset(s, 0, sizeof(uint64_t) * MLD_KECCAK_LANES);
|
|
56
54
|
}
|
|
57
55
|
|
|
58
|
-
|
|
59
|
-
*
|
|
56
|
+
/**
|
|
57
|
+
* Absorb step of Keccak; incremental.
|
|
60
58
|
*
|
|
61
|
-
*
|
|
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.
|
|
62
64
|
*
|
|
63
|
-
*
|
|
64
|
-
|
|
65
|
-
* - unsigned int r: rate in bytes (e.g., 168 for SHAKE128)
|
|
66
|
-
* - const uint8_t *in: pointer to input to be absorbed into s
|
|
67
|
-
* - size_t inlen: length of input in bytes
|
|
68
|
-
*
|
|
69
|
-
* Returns new position pos in current block
|
|
70
|
-
**************************************************/
|
|
65
|
+
* @return New position pos in current block.
|
|
66
|
+
*/
|
|
71
67
|
static unsigned int keccak_absorb(uint64_t s[MLD_KECCAK_LANES],
|
|
72
68
|
unsigned int pos, unsigned int r,
|
|
73
69
|
const uint8_t *in, size_t inlen)
|
|
@@ -104,16 +100,14 @@ __contract__(
|
|
|
104
100
|
return (unsigned)(pos + inlen);
|
|
105
101
|
}
|
|
106
102
|
|
|
107
|
-
|
|
108
|
-
*
|
|
103
|
+
/**
|
|
104
|
+
* Finalize absorb step.
|
|
109
105
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
|
|
115
|
-
* - uint8_t p: domain separation byte
|
|
116
|
-
**************************************************/
|
|
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
|
+
*/
|
|
117
111
|
static void keccak_finalize(uint64_t s[MLD_KECCAK_LANES], unsigned int pos,
|
|
118
112
|
unsigned int r, uint8_t p)
|
|
119
113
|
__contract__(
|
|
@@ -128,22 +122,19 @@ __contract__(
|
|
|
128
122
|
mld_keccakf1600_xor_bytes(s, &b, r - 1, 1);
|
|
129
123
|
}
|
|
130
124
|
|
|
131
|
-
|
|
132
|
-
*
|
|
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.
|
|
133
129
|
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
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).
|
|
137
135
|
*
|
|
138
|
-
*
|
|
139
|
-
|
|
140
|
-
* - uint64_t *s: pointer to input/output Keccak state
|
|
141
|
-
* - unsigned int pos: number of bytes in current block already
|
|
142
|
-
*squeezed
|
|
143
|
-
* - unsigned int r: rate in bytes (e.g., 168 for SHAKE128)
|
|
144
|
-
*
|
|
145
|
-
* Returns new position pos in current block
|
|
146
|
-
**************************************************/
|
|
136
|
+
* @return New position pos in current block.
|
|
137
|
+
*/
|
|
147
138
|
static unsigned int keccak_squeeze(uint8_t *out, size_t outlen,
|
|
148
139
|
uint64_t s[MLD_KECCAK_LANES],
|
|
149
140
|
unsigned int pos, unsigned int r)
|
|
@@ -262,6 +253,7 @@ void mld_shake256_release(mld_shake256ctx *state)
|
|
|
262
253
|
mld_zeroize(state, sizeof(mld_shake256ctx));
|
|
263
254
|
}
|
|
264
255
|
|
|
256
|
+
#if !defined(MLD_CONFIG_NO_KEYPAIR_API) || !defined(MLD_CONFIG_CORE_API_ONLY)
|
|
265
257
|
MLD_INTERNAL_API
|
|
266
258
|
void mld_shake256(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen)
|
|
267
259
|
{
|
|
@@ -273,5 +265,6 @@ void mld_shake256(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen)
|
|
|
273
265
|
mld_shake256_squeeze(out, outlen, &state);
|
|
274
266
|
mld_shake256_release(&state);
|
|
275
267
|
}
|
|
268
|
+
#endif /* !MLD_CONFIG_NO_KEYPAIR_API || !MLD_CONFIG_CORE_API_ONLY */
|
|
276
269
|
|
|
277
270
|
#endif /* !MLD_CONFIG_MULTILEVEL_NO_SHARED */
|