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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +88 -0
- data/ext/mldsa_gh_native/extconf.rb +14 -0
- data/ext/mldsa_gh_native/mldsa_gh_native.c +222 -0
- data/ext/mldsa_gh_native/mldsa_gh_native_all.c +24 -0
- data/ext/mldsa_gh_native/mldsa_gh_native_all.h +26 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/BUILDING.md +108 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/LICENSE +305 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/README.md +247 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/README.md +23 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/mldsa_native.c +803 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/mldsa_native.h +956 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/mldsa_native_asm.S +830 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/mldsa_native_config.h +855 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/cbmc.h +233 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/common.h +301 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/context.h +152 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/ct.c +21 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/ct.h +373 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/debug.c +75 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/debug.h +125 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/fips202.c +270 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/fips202.h +224 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +187 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +125 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +510 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +110 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +85 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +69 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +378 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +207 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +262 -0
- 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
- 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
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +47 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +27 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +36 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +40 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +32 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +37 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/api.h +129 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/README.md +10 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +67 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +37 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +717 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +42 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_extract_bytes_mve.S +334 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_xor_bytes_mve.S +355 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +53 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +35 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +34 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +45 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +488 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +52 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +314 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +248 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +367 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_intt_aarch64_asm.S +786 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_ntt_aarch64_asm.S +686 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_pointwise_montgomery_aarch64_asm.S +106 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_caddq_aarch64_asm.S +69 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_chknorm_aarch64_asm.S +76 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_32_aarch64_asm.S +108 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_88_aarch64_asm.S +108 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_32_aarch64_asm.S +125 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_88_aarch64_asm.S +133 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +157 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +173 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +205 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_17_aarch64_asm.S +103 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_19_aarch64_asm.S +100 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_aarch64_asm.S +222 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta2_aarch64_asm.S +170 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta4_aarch64_asm.S +163 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +52 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +547 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +63 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/api.h +617 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/meta.h +24 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +323 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +330 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +157 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +27 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_intt_avx2_asm.S +2333 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_ntt_avx2_asm.S +2405 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_nttunpack_avx2_asm.S +254 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l4_avx2_asm.S +173 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l5_avx2_asm.S +189 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l7_avx2_asm.S +221 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_avx2_asm.S +158 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_caddq_avx2_asm.S +199 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_chknorm_avx2_asm.S +176 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_32_avx2_asm.S +490 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_88_avx2_asm.S +489 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_32_avx2_asm.S +123 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_88_avx2_asm.S +125 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_17_avx2_asm.S +355 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_19_avx2_asm.S +355 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_avx2_asm.S +132 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta2_avx2_asm.S +205 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S +176 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +161 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/packing.c +213 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/packing.h +277 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/params.h +153 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/poly.c +1066 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/poly.h +464 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/poly_kl.c +910 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/poly_kl.h +367 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/polyvec.c +509 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/polyvec.h +435 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +311 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +652 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/randombytes.h +26 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/reduce.h +144 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/rounding.h +265 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/sign.c +1720 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/sign.h +850 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/symmetric.h +68 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/sys.h +327 -0
- data/ext/mldsa_gh_native/vendor/mldsa-native/mldsa/src/zetas.inc +55 -0
- data/lib/mldsa/parameter_set.rb +82 -0
- data/lib/mldsa/signing_key.rb +147 -0
- data/lib/mldsa/verify_key.rb +72 -0
- data/lib/mldsa/version.rb +7 -0
- data/lib/mldsa_gh.rb +93 -0
- metadata +225 -0
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
#ifndef MLD_FIPS202_FIPS202X4_H
|
|
7
|
+
#define MLD_FIPS202_FIPS202X4_H
|
|
8
|
+
|
|
9
|
+
#include "../common.h"
|
|
10
|
+
|
|
11
|
+
#if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
|
|
12
|
+
|
|
13
|
+
#include <stddef.h>
|
|
14
|
+
|
|
15
|
+
#include "../cbmc.h"
|
|
16
|
+
#include "fips202.h"
|
|
17
|
+
#include "keccakf1600.h"
|
|
18
|
+
|
|
19
|
+
/** Context for the non-incremental 4-way SHAKE128 API. */
|
|
20
|
+
typedef struct
|
|
21
|
+
{
|
|
22
|
+
uint64_t ctx[MLD_KECCAK_LANES *
|
|
23
|
+
MLD_KECCAK_WAY]; /**< 4-way Keccak state, stored sequentially. */
|
|
24
|
+
} mld_shake128x4ctx;
|
|
25
|
+
|
|
26
|
+
/** Context for the 4-way batched SHAKE256 XOF. */
|
|
27
|
+
typedef struct
|
|
28
|
+
{
|
|
29
|
+
uint64_t ctx[MLD_KECCAK_LANES *
|
|
30
|
+
MLD_KECCAK_WAY]; /**< Interleaved 4-way Keccak state. */
|
|
31
|
+
} mld_shake256x4ctx;
|
|
32
|
+
|
|
33
|
+
#if !defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)
|
|
34
|
+
#define mld_shake128x4_absorb_once MLD_NAMESPACE(shake128x4_absorb_once)
|
|
35
|
+
MLD_INTERNAL_API
|
|
36
|
+
void mld_shake128x4_absorb_once(mld_shake128x4ctx *state, const uint8_t *in0,
|
|
37
|
+
const uint8_t *in1, const uint8_t *in2,
|
|
38
|
+
const uint8_t *in3, size_t inlen)
|
|
39
|
+
__contract__(
|
|
40
|
+
requires(inlen <= MLD_MAX_BUFFER_SIZE)
|
|
41
|
+
requires(memory_no_alias(state, sizeof(mld_shake128x4ctx)))
|
|
42
|
+
requires(memory_no_alias(in0, inlen))
|
|
43
|
+
requires(memory_no_alias(in1, inlen))
|
|
44
|
+
requires(memory_no_alias(in2, inlen))
|
|
45
|
+
requires(memory_no_alias(in3, inlen))
|
|
46
|
+
assigns(memory_slice(state, sizeof(mld_shake128x4ctx)))
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
#define mld_shake128x4_squeezeblocks MLD_NAMESPACE(shake128x4_squeezeblocks)
|
|
50
|
+
MLD_INTERNAL_API
|
|
51
|
+
void mld_shake128x4_squeezeblocks(uint8_t *out0, uint8_t *out1, uint8_t *out2,
|
|
52
|
+
uint8_t *out3, size_t nblocks,
|
|
53
|
+
mld_shake128x4ctx *state)
|
|
54
|
+
__contract__(
|
|
55
|
+
requires(nblocks <= 8 /* somewhat arbitrary bound */)
|
|
56
|
+
requires(memory_no_alias(state, sizeof(mld_shake128x4ctx)))
|
|
57
|
+
requires(memory_no_alias(out0, nblocks * SHAKE128_RATE))
|
|
58
|
+
requires(memory_no_alias(out1, nblocks * SHAKE128_RATE))
|
|
59
|
+
requires(memory_no_alias(out2, nblocks * SHAKE128_RATE))
|
|
60
|
+
requires(memory_no_alias(out3, nblocks * SHAKE128_RATE))
|
|
61
|
+
assigns(memory_slice(out0, nblocks * SHAKE128_RATE),
|
|
62
|
+
memory_slice(out1, nblocks * SHAKE128_RATE),
|
|
63
|
+
memory_slice(out2, nblocks * SHAKE128_RATE),
|
|
64
|
+
memory_slice(out3, nblocks * SHAKE128_RATE),
|
|
65
|
+
memory_slice(state, sizeof(mld_shake128x4ctx)))
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
#define mld_shake128x4_init MLD_NAMESPACE(shake128x4_init)
|
|
69
|
+
MLD_INTERNAL_API
|
|
70
|
+
void mld_shake128x4_init(mld_shake128x4ctx *state);
|
|
71
|
+
|
|
72
|
+
#define mld_shake128x4_release MLD_NAMESPACE(shake128x4_release)
|
|
73
|
+
MLD_INTERNAL_API
|
|
74
|
+
void mld_shake128x4_release(mld_shake128x4ctx *state);
|
|
75
|
+
#endif /* !MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST */
|
|
76
|
+
|
|
77
|
+
#if !defined(MLD_CONFIG_NO_KEYPAIR_API) || \
|
|
78
|
+
(!defined(MLD_CONFIG_NO_SIGN_API) && \
|
|
79
|
+
(!defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)))
|
|
80
|
+
#define mld_shake256x4_absorb_once MLD_NAMESPACE(shake256x4_absorb_once)
|
|
81
|
+
MLD_INTERNAL_API
|
|
82
|
+
void mld_shake256x4_absorb_once(mld_shake256x4ctx *state, const uint8_t *in0,
|
|
83
|
+
const uint8_t *in1, const uint8_t *in2,
|
|
84
|
+
const uint8_t *in3, size_t inlen)
|
|
85
|
+
__contract__(
|
|
86
|
+
requires(inlen <= MLD_MAX_BUFFER_SIZE)
|
|
87
|
+
requires(memory_no_alias(state, sizeof(mld_shake256x4ctx)))
|
|
88
|
+
requires(memory_no_alias(in0, inlen))
|
|
89
|
+
requires(memory_no_alias(in1, inlen))
|
|
90
|
+
requires(memory_no_alias(in2, inlen))
|
|
91
|
+
requires(memory_no_alias(in3, inlen))
|
|
92
|
+
assigns(memory_slice(state, sizeof(mld_shake256x4ctx)))
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
#define mld_shake256x4_squeezeblocks MLD_NAMESPACE(shake256x4_squeezeblocks)
|
|
96
|
+
MLD_INTERNAL_API
|
|
97
|
+
void mld_shake256x4_squeezeblocks(uint8_t *out0, uint8_t *out1, uint8_t *out2,
|
|
98
|
+
uint8_t *out3, size_t nblocks,
|
|
99
|
+
mld_shake256x4ctx *state)
|
|
100
|
+
__contract__(
|
|
101
|
+
requires(nblocks <= 8 /* somewhat arbitrary bound */)
|
|
102
|
+
requires(memory_no_alias(state, sizeof(mld_shake256x4ctx)))
|
|
103
|
+
requires(memory_no_alias(out0, nblocks * SHAKE256_RATE))
|
|
104
|
+
requires(memory_no_alias(out1, nblocks * SHAKE256_RATE))
|
|
105
|
+
requires(memory_no_alias(out2, nblocks * SHAKE256_RATE))
|
|
106
|
+
requires(memory_no_alias(out3, nblocks * SHAKE256_RATE))
|
|
107
|
+
assigns(memory_slice(out0, nblocks * SHAKE256_RATE),
|
|
108
|
+
memory_slice(out1, nblocks * SHAKE256_RATE),
|
|
109
|
+
memory_slice(out2, nblocks * SHAKE256_RATE),
|
|
110
|
+
memory_slice(out3, nblocks * SHAKE256_RATE),
|
|
111
|
+
memory_slice(state, sizeof(mld_shake256x4ctx)))
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
#define mld_shake256x4_init MLD_NAMESPACE(shake256x4_init)
|
|
115
|
+
MLD_INTERNAL_API
|
|
116
|
+
void mld_shake256x4_init(mld_shake256x4ctx *state);
|
|
117
|
+
|
|
118
|
+
#define mld_shake256x4_release MLD_NAMESPACE(shake256x4_release)
|
|
119
|
+
MLD_INTERNAL_API
|
|
120
|
+
void mld_shake256x4_release(mld_shake256x4ctx *state);
|
|
121
|
+
#endif /* !MLD_CONFIG_NO_KEYPAIR_API || (!MLD_CONFIG_NO_SIGN_API && \
|
|
122
|
+
(!MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST)) */
|
|
123
|
+
|
|
124
|
+
#endif /* !MLD_CONFIG_SERIAL_FIPS202_ONLY */
|
|
125
|
+
#endif /* !MLD_FIPS202_FIPS202X4_H */
|
|
@@ -0,0 +1,510 @@
|
|
|
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
|
+
* - [mupq]
|
|
11
|
+
* Common files for pqm4, pqm3, pqriscv
|
|
12
|
+
* Kannwischer, Petri, Rijneveld, Schwabe, Stoffelen
|
|
13
|
+
* https://github.com/mupq/mupq
|
|
14
|
+
*
|
|
15
|
+
* - [supercop]
|
|
16
|
+
* SUPERCOP benchmarking framework
|
|
17
|
+
* Daniel J. Bernstein
|
|
18
|
+
* http://bench.cr.yp.to/supercop.html
|
|
19
|
+
*
|
|
20
|
+
* - [tweetfips]
|
|
21
|
+
* 'tweetfips202' FIPS202 implementation
|
|
22
|
+
* Van Assche, Bernstein, Schwabe
|
|
23
|
+
* https://keccak.team/2015/tweetfips202.html
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/* Based on the CC0 implementation from @[mupq] and the public domain
|
|
27
|
+
* implementation @[supercop, crypto_hash/keccakc512/simple/]
|
|
28
|
+
* by Ronny Van Keer, and the public domain @[tweetfips] implementation. */
|
|
29
|
+
|
|
30
|
+
#include "keccakf1600.h"
|
|
31
|
+
#if !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
|
|
32
|
+
|
|
33
|
+
#define MLD_KECCAK_NROUNDS 24
|
|
34
|
+
#define MLD_KECCAK_ROL(a, offset) (((a) << (offset)) ^ ((a) >> (64 - (offset))))
|
|
35
|
+
|
|
36
|
+
MLD_INTERNAL_API
|
|
37
|
+
void mld_keccakf1600_extract_bytes(uint64_t *state, unsigned char *data,
|
|
38
|
+
unsigned offset, unsigned length)
|
|
39
|
+
{
|
|
40
|
+
unsigned i;
|
|
41
|
+
#if defined(MLD_SYS_LITTLE_ENDIAN)
|
|
42
|
+
uint8_t *state_ptr = (uint8_t *)state + offset;
|
|
43
|
+
for (i = 0; i < length; i++)
|
|
44
|
+
__loop__(invariant(i <= length)
|
|
45
|
+
decreases(length - i))
|
|
46
|
+
{
|
|
47
|
+
data[i] = state_ptr[i];
|
|
48
|
+
}
|
|
49
|
+
#else /* MLD_SYS_LITTLE_ENDIAN */
|
|
50
|
+
/* Portable version */
|
|
51
|
+
for (i = 0; i < length; i++)
|
|
52
|
+
__loop__(invariant(i <= length)
|
|
53
|
+
decreases(length - i))
|
|
54
|
+
{
|
|
55
|
+
data[i] = (state[(offset + i) >> 3] >> (8 * ((offset + i) & 0x07))) & 0xFF;
|
|
56
|
+
}
|
|
57
|
+
#endif /* !MLD_SYS_LITTLE_ENDIAN */
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
MLD_INTERNAL_API
|
|
61
|
+
void mld_keccakf1600_xor_bytes(uint64_t *state, const unsigned char *data,
|
|
62
|
+
unsigned offset, unsigned length)
|
|
63
|
+
{
|
|
64
|
+
unsigned i;
|
|
65
|
+
#if defined(MLD_SYS_LITTLE_ENDIAN)
|
|
66
|
+
uint8_t *state_ptr = (uint8_t *)state + offset;
|
|
67
|
+
for (i = 0; i < length; i++)
|
|
68
|
+
__loop__(invariant(i <= length)
|
|
69
|
+
decreases(length - i))
|
|
70
|
+
{
|
|
71
|
+
state_ptr[i] ^= data[i];
|
|
72
|
+
}
|
|
73
|
+
#else /* MLD_SYS_LITTLE_ENDIAN */
|
|
74
|
+
/* Portable version */
|
|
75
|
+
for (i = 0; i < length; i++)
|
|
76
|
+
__loop__(invariant(i <= length)
|
|
77
|
+
decreases(length - i))
|
|
78
|
+
{
|
|
79
|
+
state[(offset + i) >> 3] ^= (uint64_t)data[i]
|
|
80
|
+
<< (8 * ((offset + i) & 0x07));
|
|
81
|
+
}
|
|
82
|
+
#endif /* !MLD_SYS_LITTLE_ENDIAN */
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
#if (!defined(MLD_CONFIG_NO_KEYPAIR_API) || !defined(MLD_CONFIG_REDUCE_RAM) || \
|
|
86
|
+
defined(MLD_UNIT_TEST)) && \
|
|
87
|
+
!defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
|
|
88
|
+
static void mld_keccakf1600x4_extract_bytes_c(uint64_t *state,
|
|
89
|
+
unsigned char *data0,
|
|
90
|
+
unsigned char *data1,
|
|
91
|
+
unsigned char *data2,
|
|
92
|
+
unsigned char *data3,
|
|
93
|
+
unsigned offset, unsigned length)
|
|
94
|
+
__contract__(
|
|
95
|
+
requires(0 <= offset && offset <= MLD_KECCAK_LANES * sizeof(uint64_t) &&
|
|
96
|
+
0 <= length && length <= MLD_KECCAK_LANES * sizeof(uint64_t) - offset)
|
|
97
|
+
requires(memory_no_alias(state, sizeof(uint64_t) * MLD_KECCAK_LANES * MLD_KECCAK_WAY))
|
|
98
|
+
requires(memory_no_alias(data0, length))
|
|
99
|
+
requires(memory_no_alias(data1, length))
|
|
100
|
+
requires(memory_no_alias(data2, length))
|
|
101
|
+
requires(memory_no_alias(data3, length))
|
|
102
|
+
assigns(memory_slice(data0, length))
|
|
103
|
+
assigns(memory_slice(data1, length))
|
|
104
|
+
assigns(memory_slice(data2, length))
|
|
105
|
+
assigns(memory_slice(data3, length))
|
|
106
|
+
)
|
|
107
|
+
{
|
|
108
|
+
mld_keccakf1600_extract_bytes(state + MLD_KECCAK_LANES * 0, data0, offset,
|
|
109
|
+
length);
|
|
110
|
+
mld_keccakf1600_extract_bytes(state + MLD_KECCAK_LANES * 1, data1, offset,
|
|
111
|
+
length);
|
|
112
|
+
mld_keccakf1600_extract_bytes(state + MLD_KECCAK_LANES * 2, data2, offset,
|
|
113
|
+
length);
|
|
114
|
+
mld_keccakf1600_extract_bytes(state + MLD_KECCAK_LANES * 3, data3, offset,
|
|
115
|
+
length);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
MLD_INTERNAL_API
|
|
119
|
+
void mld_keccakf1600x4_extract_bytes(uint64_t *state, unsigned char *data0,
|
|
120
|
+
unsigned char *data1, unsigned char *data2,
|
|
121
|
+
unsigned char *data3, unsigned offset,
|
|
122
|
+
unsigned length)
|
|
123
|
+
{
|
|
124
|
+
#if defined(MLD_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES)
|
|
125
|
+
if (mld_keccakf1600_extract_bytes_x4_native(state, data0, data1, data2, data3,
|
|
126
|
+
offset, length) ==
|
|
127
|
+
MLD_NATIVE_FUNC_SUCCESS)
|
|
128
|
+
{
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
#endif /* MLD_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES */
|
|
132
|
+
mld_keccakf1600x4_extract_bytes_c(state, data0, data1, data2, data3, offset,
|
|
133
|
+
length);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
static void mld_keccakf1600x4_xor_bytes_c(uint64_t *state,
|
|
137
|
+
const unsigned char *data0,
|
|
138
|
+
const unsigned char *data1,
|
|
139
|
+
const unsigned char *data2,
|
|
140
|
+
const unsigned char *data3,
|
|
141
|
+
unsigned offset, unsigned length)
|
|
142
|
+
__contract__(
|
|
143
|
+
requires(0 <= offset && offset <= MLD_KECCAK_LANES * sizeof(uint64_t) &&
|
|
144
|
+
0 <= length && length <= MLD_KECCAK_LANES * sizeof(uint64_t) - offset)
|
|
145
|
+
requires(memory_no_alias(state, sizeof(uint64_t) * MLD_KECCAK_LANES * MLD_KECCAK_WAY))
|
|
146
|
+
requires(memory_no_alias(data0, length))
|
|
147
|
+
/* Case 1: all input buffers are distinct; Case 2: All input buffers are the same */
|
|
148
|
+
requires((data0 == data1 &&
|
|
149
|
+
data0 == data2 &&
|
|
150
|
+
data0 == data3) ||
|
|
151
|
+
(memory_no_alias(data1, length) &&
|
|
152
|
+
memory_no_alias(data2, length) &&
|
|
153
|
+
memory_no_alias(data3, length)))
|
|
154
|
+
assigns(memory_slice(state, sizeof(uint64_t) * MLD_KECCAK_LANES * MLD_KECCAK_WAY))
|
|
155
|
+
)
|
|
156
|
+
{
|
|
157
|
+
mld_keccakf1600_xor_bytes(state + MLD_KECCAK_LANES * 0, data0, offset,
|
|
158
|
+
length);
|
|
159
|
+
mld_keccakf1600_xor_bytes(state + MLD_KECCAK_LANES * 1, data1, offset,
|
|
160
|
+
length);
|
|
161
|
+
mld_keccakf1600_xor_bytes(state + MLD_KECCAK_LANES * 2, data2, offset,
|
|
162
|
+
length);
|
|
163
|
+
mld_keccakf1600_xor_bytes(state + MLD_KECCAK_LANES * 3, data3, offset,
|
|
164
|
+
length);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
MLD_INTERNAL_API
|
|
168
|
+
void mld_keccakf1600x4_xor_bytes(uint64_t *state, const unsigned char *data0,
|
|
169
|
+
const unsigned char *data1,
|
|
170
|
+
const unsigned char *data2,
|
|
171
|
+
const unsigned char *data3, unsigned offset,
|
|
172
|
+
unsigned length)
|
|
173
|
+
{
|
|
174
|
+
#if defined(MLD_USE_NATIVE_FIPS202_X4_XOR_BYTES)
|
|
175
|
+
if (mld_keccakf1600_xor_bytes_x4_native(state, data0, data1, data2, data3,
|
|
176
|
+
offset,
|
|
177
|
+
length) == MLD_NATIVE_FUNC_SUCCESS)
|
|
178
|
+
{
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
#endif /* MLD_USE_NATIVE_FIPS202_X4_XOR_BYTES */
|
|
182
|
+
mld_keccakf1600x4_xor_bytes_c(state, data0, data1, data2, data3, offset,
|
|
183
|
+
length);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
MLD_INTERNAL_API
|
|
187
|
+
void mld_keccakf1600x4_permute(uint64_t *state)
|
|
188
|
+
{
|
|
189
|
+
#if defined(MLD_USE_NATIVE_FIPS202_X4)
|
|
190
|
+
if (mld_keccak_f1600_x4_native(state) == MLD_NATIVE_FUNC_SUCCESS)
|
|
191
|
+
{
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
#endif /* MLD_USE_NATIVE_FIPS202_X4 */
|
|
195
|
+
mld_keccakf1600_permute(state + MLD_KECCAK_LANES * 0);
|
|
196
|
+
mld_keccakf1600_permute(state + MLD_KECCAK_LANES * 1);
|
|
197
|
+
mld_keccakf1600_permute(state + MLD_KECCAK_LANES * 2);
|
|
198
|
+
mld_keccakf1600_permute(state + MLD_KECCAK_LANES * 3);
|
|
199
|
+
}
|
|
200
|
+
#endif /* (!MLD_CONFIG_NO_KEYPAIR_API || !MLD_CONFIG_REDUCE_RAM || \
|
|
201
|
+
MLD_UNIT_TEST) && !MLD_CONFIG_SERIAL_FIPS202_ONLY */
|
|
202
|
+
|
|
203
|
+
static const uint64_t mld_KeccakF_RoundConstants[MLD_KECCAK_NROUNDS] = {
|
|
204
|
+
(uint64_t)0x0000000000000001ULL, (uint64_t)0x0000000000008082ULL,
|
|
205
|
+
(uint64_t)0x800000000000808aULL, (uint64_t)0x8000000080008000ULL,
|
|
206
|
+
(uint64_t)0x000000000000808bULL, (uint64_t)0x0000000080000001ULL,
|
|
207
|
+
(uint64_t)0x8000000080008081ULL, (uint64_t)0x8000000000008009ULL,
|
|
208
|
+
(uint64_t)0x000000000000008aULL, (uint64_t)0x0000000000000088ULL,
|
|
209
|
+
(uint64_t)0x0000000080008009ULL, (uint64_t)0x000000008000000aULL,
|
|
210
|
+
(uint64_t)0x000000008000808bULL, (uint64_t)0x800000000000008bULL,
|
|
211
|
+
(uint64_t)0x8000000000008089ULL, (uint64_t)0x8000000000008003ULL,
|
|
212
|
+
(uint64_t)0x8000000000008002ULL, (uint64_t)0x8000000000000080ULL,
|
|
213
|
+
(uint64_t)0x000000000000800aULL, (uint64_t)0x800000008000000aULL,
|
|
214
|
+
(uint64_t)0x8000000080008081ULL, (uint64_t)0x8000000000008080ULL,
|
|
215
|
+
(uint64_t)0x0000000080000001ULL, (uint64_t)0x8000000080008008ULL};
|
|
216
|
+
|
|
217
|
+
MLD_STATIC_TESTABLE
|
|
218
|
+
void mld_keccakf1600_permute_c(uint64_t *state)
|
|
219
|
+
__contract__(
|
|
220
|
+
requires(memory_no_alias(state, sizeof(uint64_t) * MLD_KECCAK_LANES))
|
|
221
|
+
assigns(memory_slice(state, sizeof(uint64_t) * MLD_KECCAK_LANES))
|
|
222
|
+
)
|
|
223
|
+
{
|
|
224
|
+
unsigned round;
|
|
225
|
+
|
|
226
|
+
uint64_t Aba, Abe, Abi, Abo, Abu;
|
|
227
|
+
uint64_t Aga, Age, Agi, Ago, Agu;
|
|
228
|
+
uint64_t Aka, Ake, Aki, Ako, Aku;
|
|
229
|
+
uint64_t Ama, Ame, Ami, Amo, Amu;
|
|
230
|
+
uint64_t Asa, Ase, Asi, Aso, Asu;
|
|
231
|
+
uint64_t BCa, BCe, BCi, BCo, BCu;
|
|
232
|
+
uint64_t Da, De, Di, Do, Du;
|
|
233
|
+
uint64_t Eba, Ebe, Ebi, Ebo, Ebu;
|
|
234
|
+
uint64_t Ega, Ege, Egi, Ego, Egu;
|
|
235
|
+
uint64_t Eka, Eke, Eki, Eko, Eku;
|
|
236
|
+
uint64_t Ema, Eme, Emi, Emo, Emu;
|
|
237
|
+
uint64_t Esa, Ese, Esi, Eso, Esu;
|
|
238
|
+
|
|
239
|
+
/* copyFromState(A, state) */
|
|
240
|
+
Aba = state[0];
|
|
241
|
+
Abe = state[1];
|
|
242
|
+
Abi = state[2];
|
|
243
|
+
Abo = state[3];
|
|
244
|
+
Abu = state[4];
|
|
245
|
+
Aga = state[5];
|
|
246
|
+
Age = state[6];
|
|
247
|
+
Agi = state[7];
|
|
248
|
+
Ago = state[8];
|
|
249
|
+
Agu = state[9];
|
|
250
|
+
Aka = state[10];
|
|
251
|
+
Ake = state[11];
|
|
252
|
+
Aki = state[12];
|
|
253
|
+
Ako = state[13];
|
|
254
|
+
Aku = state[14];
|
|
255
|
+
Ama = state[15];
|
|
256
|
+
Ame = state[16];
|
|
257
|
+
Ami = state[17];
|
|
258
|
+
Amo = state[18];
|
|
259
|
+
Amu = state[19];
|
|
260
|
+
Asa = state[20];
|
|
261
|
+
Ase = state[21];
|
|
262
|
+
Asi = state[22];
|
|
263
|
+
Aso = state[23];
|
|
264
|
+
Asu = state[24];
|
|
265
|
+
|
|
266
|
+
for (round = 0; round < MLD_KECCAK_NROUNDS; round += 2)
|
|
267
|
+
__loop__(invariant(round <= MLD_KECCAK_NROUNDS && round % 2 == 0)
|
|
268
|
+
decreases(MLD_KECCAK_NROUNDS - round))
|
|
269
|
+
{
|
|
270
|
+
/* prepareTheta */
|
|
271
|
+
BCa = Aba ^ Aga ^ Aka ^ Ama ^ Asa;
|
|
272
|
+
BCe = Abe ^ Age ^ Ake ^ Ame ^ Ase;
|
|
273
|
+
BCi = Abi ^ Agi ^ Aki ^ Ami ^ Asi;
|
|
274
|
+
BCo = Abo ^ Ago ^ Ako ^ Amo ^ Aso;
|
|
275
|
+
BCu = Abu ^ Agu ^ Aku ^ Amu ^ Asu;
|
|
276
|
+
|
|
277
|
+
/* thetaRhoPiChiIotaPrepareTheta(round, A, E) */
|
|
278
|
+
Da = BCu ^ MLD_KECCAK_ROL(BCe, 1);
|
|
279
|
+
De = BCa ^ MLD_KECCAK_ROL(BCi, 1);
|
|
280
|
+
Di = BCe ^ MLD_KECCAK_ROL(BCo, 1);
|
|
281
|
+
Do = BCi ^ MLD_KECCAK_ROL(BCu, 1);
|
|
282
|
+
Du = BCo ^ MLD_KECCAK_ROL(BCa, 1);
|
|
283
|
+
|
|
284
|
+
Aba ^= Da;
|
|
285
|
+
BCa = Aba;
|
|
286
|
+
Age ^= De;
|
|
287
|
+
BCe = MLD_KECCAK_ROL(Age, 44);
|
|
288
|
+
Aki ^= Di;
|
|
289
|
+
BCi = MLD_KECCAK_ROL(Aki, 43);
|
|
290
|
+
Amo ^= Do;
|
|
291
|
+
BCo = MLD_KECCAK_ROL(Amo, 21);
|
|
292
|
+
Asu ^= Du;
|
|
293
|
+
BCu = MLD_KECCAK_ROL(Asu, 14);
|
|
294
|
+
Eba = BCa ^ ((~BCe) & BCi);
|
|
295
|
+
Eba ^= (uint64_t)mld_KeccakF_RoundConstants[round];
|
|
296
|
+
Ebe = BCe ^ ((~BCi) & BCo);
|
|
297
|
+
Ebi = BCi ^ ((~BCo) & BCu);
|
|
298
|
+
Ebo = BCo ^ ((~BCu) & BCa);
|
|
299
|
+
Ebu = BCu ^ ((~BCa) & BCe);
|
|
300
|
+
|
|
301
|
+
Abo ^= Do;
|
|
302
|
+
BCa = MLD_KECCAK_ROL(Abo, 28);
|
|
303
|
+
Agu ^= Du;
|
|
304
|
+
BCe = MLD_KECCAK_ROL(Agu, 20);
|
|
305
|
+
Aka ^= Da;
|
|
306
|
+
BCi = MLD_KECCAK_ROL(Aka, 3);
|
|
307
|
+
Ame ^= De;
|
|
308
|
+
BCo = MLD_KECCAK_ROL(Ame, 45);
|
|
309
|
+
Asi ^= Di;
|
|
310
|
+
BCu = MLD_KECCAK_ROL(Asi, 61);
|
|
311
|
+
Ega = BCa ^ ((~BCe) & BCi);
|
|
312
|
+
Ege = BCe ^ ((~BCi) & BCo);
|
|
313
|
+
Egi = BCi ^ ((~BCo) & BCu);
|
|
314
|
+
Ego = BCo ^ ((~BCu) & BCa);
|
|
315
|
+
Egu = BCu ^ ((~BCa) & BCe);
|
|
316
|
+
|
|
317
|
+
Abe ^= De;
|
|
318
|
+
BCa = MLD_KECCAK_ROL(Abe, 1);
|
|
319
|
+
Agi ^= Di;
|
|
320
|
+
BCe = MLD_KECCAK_ROL(Agi, 6);
|
|
321
|
+
Ako ^= Do;
|
|
322
|
+
BCi = MLD_KECCAK_ROL(Ako, 25);
|
|
323
|
+
Amu ^= Du;
|
|
324
|
+
BCo = MLD_KECCAK_ROL(Amu, 8);
|
|
325
|
+
Asa ^= Da;
|
|
326
|
+
BCu = MLD_KECCAK_ROL(Asa, 18);
|
|
327
|
+
Eka = BCa ^ ((~BCe) & BCi);
|
|
328
|
+
Eke = BCe ^ ((~BCi) & BCo);
|
|
329
|
+
Eki = BCi ^ ((~BCo) & BCu);
|
|
330
|
+
Eko = BCo ^ ((~BCu) & BCa);
|
|
331
|
+
Eku = BCu ^ ((~BCa) & BCe);
|
|
332
|
+
|
|
333
|
+
Abu ^= Du;
|
|
334
|
+
BCa = MLD_KECCAK_ROL(Abu, 27);
|
|
335
|
+
Aga ^= Da;
|
|
336
|
+
BCe = MLD_KECCAK_ROL(Aga, 36);
|
|
337
|
+
Ake ^= De;
|
|
338
|
+
BCi = MLD_KECCAK_ROL(Ake, 10);
|
|
339
|
+
Ami ^= Di;
|
|
340
|
+
BCo = MLD_KECCAK_ROL(Ami, 15);
|
|
341
|
+
Aso ^= Do;
|
|
342
|
+
BCu = MLD_KECCAK_ROL(Aso, 56);
|
|
343
|
+
Ema = BCa ^ ((~BCe) & BCi);
|
|
344
|
+
Eme = BCe ^ ((~BCi) & BCo);
|
|
345
|
+
Emi = BCi ^ ((~BCo) & BCu);
|
|
346
|
+
Emo = BCo ^ ((~BCu) & BCa);
|
|
347
|
+
Emu = BCu ^ ((~BCa) & BCe);
|
|
348
|
+
|
|
349
|
+
Abi ^= Di;
|
|
350
|
+
BCa = MLD_KECCAK_ROL(Abi, 62);
|
|
351
|
+
Ago ^= Do;
|
|
352
|
+
BCe = MLD_KECCAK_ROL(Ago, 55);
|
|
353
|
+
Aku ^= Du;
|
|
354
|
+
BCi = MLD_KECCAK_ROL(Aku, 39);
|
|
355
|
+
Ama ^= Da;
|
|
356
|
+
BCo = MLD_KECCAK_ROL(Ama, 41);
|
|
357
|
+
Ase ^= De;
|
|
358
|
+
BCu = MLD_KECCAK_ROL(Ase, 2);
|
|
359
|
+
Esa = BCa ^ ((~BCe) & BCi);
|
|
360
|
+
Ese = BCe ^ ((~BCi) & BCo);
|
|
361
|
+
Esi = BCi ^ ((~BCo) & BCu);
|
|
362
|
+
Eso = BCo ^ ((~BCu) & BCa);
|
|
363
|
+
Esu = BCu ^ ((~BCa) & BCe);
|
|
364
|
+
|
|
365
|
+
/* prepareTheta */
|
|
366
|
+
BCa = Eba ^ Ega ^ Eka ^ Ema ^ Esa;
|
|
367
|
+
BCe = Ebe ^ Ege ^ Eke ^ Eme ^ Ese;
|
|
368
|
+
BCi = Ebi ^ Egi ^ Eki ^ Emi ^ Esi;
|
|
369
|
+
BCo = Ebo ^ Ego ^ Eko ^ Emo ^ Eso;
|
|
370
|
+
BCu = Ebu ^ Egu ^ Eku ^ Emu ^ Esu;
|
|
371
|
+
|
|
372
|
+
/* thetaRhoPiChiIotaPrepareTheta(round+1, E, A) */
|
|
373
|
+
Da = BCu ^ MLD_KECCAK_ROL(BCe, 1);
|
|
374
|
+
De = BCa ^ MLD_KECCAK_ROL(BCi, 1);
|
|
375
|
+
Di = BCe ^ MLD_KECCAK_ROL(BCo, 1);
|
|
376
|
+
Do = BCi ^ MLD_KECCAK_ROL(BCu, 1);
|
|
377
|
+
Du = BCo ^ MLD_KECCAK_ROL(BCa, 1);
|
|
378
|
+
|
|
379
|
+
Eba ^= Da;
|
|
380
|
+
BCa = Eba;
|
|
381
|
+
Ege ^= De;
|
|
382
|
+
BCe = MLD_KECCAK_ROL(Ege, 44);
|
|
383
|
+
Eki ^= Di;
|
|
384
|
+
BCi = MLD_KECCAK_ROL(Eki, 43);
|
|
385
|
+
Emo ^= Do;
|
|
386
|
+
BCo = MLD_KECCAK_ROL(Emo, 21);
|
|
387
|
+
Esu ^= Du;
|
|
388
|
+
BCu = MLD_KECCAK_ROL(Esu, 14);
|
|
389
|
+
Aba = BCa ^ ((~BCe) & BCi);
|
|
390
|
+
Aba ^= (uint64_t)mld_KeccakF_RoundConstants[round + 1];
|
|
391
|
+
Abe = BCe ^ ((~BCi) & BCo);
|
|
392
|
+
Abi = BCi ^ ((~BCo) & BCu);
|
|
393
|
+
Abo = BCo ^ ((~BCu) & BCa);
|
|
394
|
+
Abu = BCu ^ ((~BCa) & BCe);
|
|
395
|
+
|
|
396
|
+
Ebo ^= Do;
|
|
397
|
+
BCa = MLD_KECCAK_ROL(Ebo, 28);
|
|
398
|
+
Egu ^= Du;
|
|
399
|
+
BCe = MLD_KECCAK_ROL(Egu, 20);
|
|
400
|
+
Eka ^= Da;
|
|
401
|
+
BCi = MLD_KECCAK_ROL(Eka, 3);
|
|
402
|
+
Eme ^= De;
|
|
403
|
+
BCo = MLD_KECCAK_ROL(Eme, 45);
|
|
404
|
+
Esi ^= Di;
|
|
405
|
+
BCu = MLD_KECCAK_ROL(Esi, 61);
|
|
406
|
+
Aga = BCa ^ ((~BCe) & BCi);
|
|
407
|
+
Age = BCe ^ ((~BCi) & BCo);
|
|
408
|
+
Agi = BCi ^ ((~BCo) & BCu);
|
|
409
|
+
Ago = BCo ^ ((~BCu) & BCa);
|
|
410
|
+
Agu = BCu ^ ((~BCa) & BCe);
|
|
411
|
+
|
|
412
|
+
Ebe ^= De;
|
|
413
|
+
BCa = MLD_KECCAK_ROL(Ebe, 1);
|
|
414
|
+
Egi ^= Di;
|
|
415
|
+
BCe = MLD_KECCAK_ROL(Egi, 6);
|
|
416
|
+
Eko ^= Do;
|
|
417
|
+
BCi = MLD_KECCAK_ROL(Eko, 25);
|
|
418
|
+
Emu ^= Du;
|
|
419
|
+
BCo = MLD_KECCAK_ROL(Emu, 8);
|
|
420
|
+
Esa ^= Da;
|
|
421
|
+
BCu = MLD_KECCAK_ROL(Esa, 18);
|
|
422
|
+
Aka = BCa ^ ((~BCe) & BCi);
|
|
423
|
+
Ake = BCe ^ ((~BCi) & BCo);
|
|
424
|
+
Aki = BCi ^ ((~BCo) & BCu);
|
|
425
|
+
Ako = BCo ^ ((~BCu) & BCa);
|
|
426
|
+
Aku = BCu ^ ((~BCa) & BCe);
|
|
427
|
+
|
|
428
|
+
Ebu ^= Du;
|
|
429
|
+
BCa = MLD_KECCAK_ROL(Ebu, 27);
|
|
430
|
+
Ega ^= Da;
|
|
431
|
+
BCe = MLD_KECCAK_ROL(Ega, 36);
|
|
432
|
+
Eke ^= De;
|
|
433
|
+
BCi = MLD_KECCAK_ROL(Eke, 10);
|
|
434
|
+
Emi ^= Di;
|
|
435
|
+
BCo = MLD_KECCAK_ROL(Emi, 15);
|
|
436
|
+
Eso ^= Do;
|
|
437
|
+
BCu = MLD_KECCAK_ROL(Eso, 56);
|
|
438
|
+
Ama = BCa ^ ((~BCe) & BCi);
|
|
439
|
+
Ame = BCe ^ ((~BCi) & BCo);
|
|
440
|
+
Ami = BCi ^ ((~BCo) & BCu);
|
|
441
|
+
Amo = BCo ^ ((~BCu) & BCa);
|
|
442
|
+
Amu = BCu ^ ((~BCa) & BCe);
|
|
443
|
+
|
|
444
|
+
Ebi ^= Di;
|
|
445
|
+
BCa = MLD_KECCAK_ROL(Ebi, 62);
|
|
446
|
+
Ego ^= Do;
|
|
447
|
+
BCe = MLD_KECCAK_ROL(Ego, 55);
|
|
448
|
+
Eku ^= Du;
|
|
449
|
+
BCi = MLD_KECCAK_ROL(Eku, 39);
|
|
450
|
+
Ema ^= Da;
|
|
451
|
+
BCo = MLD_KECCAK_ROL(Ema, 41);
|
|
452
|
+
Ese ^= De;
|
|
453
|
+
BCu = MLD_KECCAK_ROL(Ese, 2);
|
|
454
|
+
Asa = BCa ^ ((~BCe) & BCi);
|
|
455
|
+
Ase = BCe ^ ((~BCi) & BCo);
|
|
456
|
+
Asi = BCi ^ ((~BCo) & BCu);
|
|
457
|
+
Aso = BCo ^ ((~BCu) & BCa);
|
|
458
|
+
Asu = BCu ^ ((~BCa) & BCe);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/* copyToState(state, A) */
|
|
462
|
+
state[0] = Aba;
|
|
463
|
+
state[1] = Abe;
|
|
464
|
+
state[2] = Abi;
|
|
465
|
+
state[3] = Abo;
|
|
466
|
+
state[4] = Abu;
|
|
467
|
+
state[5] = Aga;
|
|
468
|
+
state[6] = Age;
|
|
469
|
+
state[7] = Agi;
|
|
470
|
+
state[8] = Ago;
|
|
471
|
+
state[9] = Agu;
|
|
472
|
+
state[10] = Aka;
|
|
473
|
+
state[11] = Ake;
|
|
474
|
+
state[12] = Aki;
|
|
475
|
+
state[13] = Ako;
|
|
476
|
+
state[14] = Aku;
|
|
477
|
+
state[15] = Ama;
|
|
478
|
+
state[16] = Ame;
|
|
479
|
+
state[17] = Ami;
|
|
480
|
+
state[18] = Amo;
|
|
481
|
+
state[19] = Amu;
|
|
482
|
+
state[20] = Asa;
|
|
483
|
+
state[21] = Ase;
|
|
484
|
+
state[22] = Asi;
|
|
485
|
+
state[23] = Aso;
|
|
486
|
+
state[24] = Asu;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
MLD_INTERNAL_API
|
|
490
|
+
void mld_keccakf1600_permute(uint64_t *state)
|
|
491
|
+
{
|
|
492
|
+
#if defined(MLD_USE_NATIVE_FIPS202_X1)
|
|
493
|
+
if (mld_keccak_f1600_x1_native(state) == MLD_NATIVE_FUNC_SUCCESS)
|
|
494
|
+
{
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
#endif /* MLD_USE_NATIVE_FIPS202_X1 */
|
|
498
|
+
mld_keccakf1600_permute_c(state);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
#else /* !MLD_CONFIG_MULTILEVEL_NO_SHARED */
|
|
502
|
+
|
|
503
|
+
MLD_EMPTY_CU(keccakf1600)
|
|
504
|
+
|
|
505
|
+
#endif /* MLD_CONFIG_MULTILEVEL_NO_SHARED */
|
|
506
|
+
|
|
507
|
+
/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
|
|
508
|
+
* Don't modify by hand -- this is auto-generated by scripts/autogen. */
|
|
509
|
+
#undef MLD_KECCAK_NROUNDS
|
|
510
|
+
#undef MLD_KECCAK_ROL
|