pq_crypto 0.6.2 → 0.6.3
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/ext/pqcrypto/pqcrypto_version.h +1 -1
- data/ext/pqcrypto/vendor/.vendored +4 -4
- data/ext/pqcrypto/vendor/mlkem-native/README.md +6 -3
- data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +22 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +77 -36
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +135 -146
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +116 -72
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +351 -415
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +43 -20
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +16 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +57 -31
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +260 -349
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.h +17 -24
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +35 -37
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +43 -57
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +14 -15
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +5 -4
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +42 -6
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/fips202_native_aarch64.h +31 -20
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x1_scalar_asm.S → keccak_f1600_x1_scalar_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x1_v84a_asm.S → keccak_f1600_x1_v84a_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x2_v84a_asm.S → keccak_f1600_x2_v84a_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x4_v8a_scalar_hybrid_asm.S → keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S → keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +10 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +2 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +1 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +4 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +1 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/fips202_native_armv81m.h +2 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +55 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +26 -25
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +58 -14
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +57 -16
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +2 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +2 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +10 -7
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/{keccak_f1600_x4_avx2.S → keccak_f1600_x4_avx2_asm.S} +13 -11
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +12 -11
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +167 -136
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +75 -68
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +135 -157
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +15 -13
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +143 -135
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +52 -46
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{intt.S → intt_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{ntt.S → ntt_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_mulcache_compute_asm.S → poly_mulcache_compute_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_reduce_asm.S → poly_reduce_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tobytes_asm.S → poly_tobytes_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tomont_asm.S → poly_tomont_aarch64_asm.S} +10 -12
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_asm_k2.S → polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_asm_k3.S → polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_asm_k4.S → polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{rej_uniform_asm.S → rej_uniform_aarch64_asm.S} +12 -12
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_table.c +514 -513
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +254 -253
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +6 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/README.md +6 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/meta.h +77 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/arith_native_ppc64le.h +24 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/consts.c +299 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/consts.h +34 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/intt_ppc_asm.S +3222 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/ntt_ppc_asm.S +1651 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/poly_tomont_ppc_asm.S +294 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/reduce_ppc_asm.S +710 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +5 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +18 -16
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +19 -24
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +53 -65
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +20 -20
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +106 -88
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +45 -35
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.c +1 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.h +1 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{intt.S → intt_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntt.S → ntt_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttfrombytes.S → nttfrombytes_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntttobytes.S → ntttobytes_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttunpack.S → nttunpack_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d10.S → poly_compress_d10_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d11.S → poly_compress_d11_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d4.S → poly_compress_d4_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d5.S → poly_compress_d5_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d10.S → poly_decompress_d10_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d11.S → poly_decompress_d11_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d4.S → poly_decompress_d4_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d5.S → poly_decompress_d5_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{mulcache_compute.S → poly_mulcache_compute_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_asm_k2.S → polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_asm_k3.S → polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_asm_k4.S → polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{reduce.S → reduce_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{rej_uniform_asm.S → rej_uniform_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_table.c +514 -513
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{tomont.S → tomont_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +61 -57
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +89 -116
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +31 -32
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +226 -301
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/randombytes.h +21 -29
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +68 -63
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +37 -48
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +44 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +141 -159
- data/lib/pq_crypto/version.rb +1 -1
- data/script/vendor_libs.rb +3 -3
- metadata +47 -38
|
@@ -28,40 +28,37 @@
|
|
|
28
28
|
#define mlk_polyvec_mulcache MLK_ADD_PARAM_SET(mlk_polyvec_mulcache)
|
|
29
29
|
/* End of parameter set namespacing */
|
|
30
30
|
|
|
31
|
+
/** Vector of MLKEM_K polynomials. */
|
|
31
32
|
typedef struct
|
|
32
33
|
{
|
|
33
|
-
mlk_poly vec[MLKEM_K];
|
|
34
|
+
mlk_poly vec[MLKEM_K]; /**< Component polynomials. */
|
|
34
35
|
} MLK_ALIGN mlk_polyvec;
|
|
35
36
|
|
|
37
|
+
/** MLKEM_K x MLKEM_K matrix of polynomials. */
|
|
36
38
|
typedef struct
|
|
37
39
|
{
|
|
38
|
-
mlk_polyvec vec[MLKEM_K];
|
|
40
|
+
mlk_polyvec vec[MLKEM_K]; /**< Rows of the matrix. */
|
|
39
41
|
} MLK_ALIGN mlk_polymat;
|
|
40
42
|
|
|
43
|
+
/** Vector of MLKEM_K mlk_poly_mulcache entries. */
|
|
41
44
|
typedef struct
|
|
42
45
|
{
|
|
43
|
-
mlk_poly_mulcache vec[MLKEM_K];
|
|
46
|
+
mlk_poly_mulcache vec[MLKEM_K]; /**< Per-component caches. */
|
|
44
47
|
} MLK_ALIGN mlk_polyvec_mulcache;
|
|
45
48
|
|
|
46
49
|
#define mlk_poly_compress_du MLK_NAMESPACE_K(poly_compress_du)
|
|
47
|
-
|
|
48
|
-
*
|
|
50
|
+
/**
|
|
51
|
+
* Compression (du bits) and subsequent serialization of a polynomial.
|
|
49
52
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
53
|
+
* @spec{Implements `ByteEncode_{d_u} (Compress_{d_u} (u))` in @[FIPS203,
|
|
54
|
+
* Algorithm 14 (K-PKE.Encrypt), L22], with level-specific d_u defined in
|
|
55
|
+
* @[FIPS203, Table 2], and given by MLKEM_DU here.}
|
|
52
56
|
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
|
|
58
|
-
*
|
|
59
|
-
* Specification: Implements `ByteEncode_{d_u} (Compress_{d_u} (u))`
|
|
60
|
-
* in @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L22],
|
|
61
|
-
* with level-specific d_u defined in @[FIPS203, Table 2],
|
|
62
|
-
* and given by MLKEM_DU here.
|
|
63
|
-
*
|
|
64
|
-
**************************************************/
|
|
57
|
+
* @param[out] r Output byte array (of length MLKEM_POLYCOMPRESSEDBYTES_DU
|
|
58
|
+
* bytes).
|
|
59
|
+
* @param[in] a Input polynomial. Coefficients must be unsigned canonical,
|
|
60
|
+
* i.e. in [0,1,..,MLKEM_Q-1].
|
|
61
|
+
*/
|
|
65
62
|
static MLK_INLINE void mlk_poly_compress_du(
|
|
66
63
|
uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_DU], const mlk_poly *a)
|
|
67
64
|
__contract__(
|
|
@@ -80,25 +77,21 @@ __contract__(
|
|
|
80
77
|
}
|
|
81
78
|
|
|
82
79
|
#define mlk_poly_decompress_du MLK_NAMESPACE_K(poly_decompress_du)
|
|
83
|
-
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* Description: De-serialization and subsequent decompression (du bits) of a
|
|
87
|
-
* polynomial; approximate inverse of mlk_poly_compress_du
|
|
80
|
+
/**
|
|
81
|
+
* De-serialization and subsequent decompression (du bits) of a polynomial;
|
|
82
|
+
* approximate inverse of mlk_poly_compress_du.
|
|
88
83
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* (of length MLKEM_POLYCOMPRESSEDBYTES_DU bytes)
|
|
84
|
+
* Upon return, the coefficients of the output polynomial are
|
|
85
|
+
* unsigned-canonical (non-negative and smaller than MLKEM_Q).
|
|
92
86
|
*
|
|
93
|
-
*
|
|
94
|
-
* (
|
|
87
|
+
* @spec{Implements `Decompress_{d_u} (ByteDecode_{d_u} (u))` in @[FIPS203,
|
|
88
|
+
* Algorithm 15 (K-PKE.Decrypt), L3], with level-specific d_u defined in
|
|
89
|
+
* @[FIPS203, Table 2], and given by MLKEM_DU here.}
|
|
95
90
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
|
|
100
|
-
*
|
|
101
|
-
**************************************************/
|
|
91
|
+
* @param[out] r Output polynomial.
|
|
92
|
+
* @param[in] a Input byte array (of length MLKEM_POLYCOMPRESSEDBYTES_DU
|
|
93
|
+
* bytes).
|
|
94
|
+
*/
|
|
102
95
|
static MLK_INLINE void mlk_poly_decompress_du(
|
|
103
96
|
mlk_poly *r, const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_DU])
|
|
104
97
|
__contract__(
|
|
@@ -117,24 +110,18 @@ __contract__(
|
|
|
117
110
|
}
|
|
118
111
|
|
|
119
112
|
#define mlk_poly_compress_dv MLK_NAMESPACE_K(poly_compress_dv)
|
|
120
|
-
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* Description: Compression (dv bits) and subsequent serialization of a
|
|
124
|
-
* polynomial
|
|
113
|
+
/**
|
|
114
|
+
* Compression (dv bits) and subsequent serialization of a polynomial.
|
|
125
115
|
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* Coefficients must be unsigned canonical,
|
|
130
|
-
* i.e. in [0,1,..,MLKEM_Q-1].
|
|
116
|
+
* @spec{Implements `ByteEncode_{d_v} (Compress_{d_v} (v))` in @[FIPS203,
|
|
117
|
+
* Algorithm 14 (K-PKE.Encrypt), L23], with level-specific d_v defined in
|
|
118
|
+
* @[FIPS203, Table 2], and given by MLKEM_DV here.}
|
|
131
119
|
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
|
|
137
|
-
**************************************************/
|
|
120
|
+
* @param[out] r Output byte array (of length MLKEM_POLYCOMPRESSEDBYTES_DV
|
|
121
|
+
* bytes).
|
|
122
|
+
* @param[in] a Input polynomial. Coefficients must be unsigned canonical,
|
|
123
|
+
* i.e. in [0,1,..,MLKEM_Q-1].
|
|
124
|
+
*/
|
|
138
125
|
static MLK_INLINE void mlk_poly_compress_dv(
|
|
139
126
|
uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_DV], const mlk_poly *a)
|
|
140
127
|
__contract__(
|
|
@@ -154,25 +141,21 @@ __contract__(
|
|
|
154
141
|
|
|
155
142
|
|
|
156
143
|
#define mlk_poly_decompress_dv MLK_NAMESPACE_K(poly_decompress_dv)
|
|
157
|
-
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* Description: De-serialization and subsequent decompression (dv bits) of a
|
|
161
|
-
* polynomial; approximate inverse of poly_compress
|
|
144
|
+
/**
|
|
145
|
+
* De-serialization and subsequent decompression (dv bits) of a polynomial;
|
|
146
|
+
* approximate inverse of mlk_poly_compress_dv.
|
|
162
147
|
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
* (of length MLKEM_POLYCOMPRESSEDBYTES_DV bytes)
|
|
148
|
+
* Upon return, the coefficients of the output polynomial are
|
|
149
|
+
* unsigned-canonical (non-negative and smaller than MLKEM_Q).
|
|
166
150
|
*
|
|
167
|
-
*
|
|
168
|
-
* (
|
|
151
|
+
* @spec{Implements `Decompress_{d_v} (ByteDecode_{d_v} (v))` in @[FIPS203,
|
|
152
|
+
* Algorithm 15 (K-PKE.Decrypt), L4], with level-specific d_v defined in
|
|
153
|
+
* @[FIPS203, Table 2], and given by MLKEM_DV here.}
|
|
169
154
|
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
|
|
174
|
-
*
|
|
175
|
-
**************************************************/
|
|
155
|
+
* @param[out] r Output polynomial.
|
|
156
|
+
* @param[in] a Input byte array (of length MLKEM_POLYCOMPRESSEDBYTES_DV
|
|
157
|
+
* bytes).
|
|
158
|
+
*/
|
|
176
159
|
static MLK_INLINE void mlk_poly_decompress_dv(
|
|
177
160
|
mlk_poly *r, const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_DV])
|
|
178
161
|
__contract__(
|
|
@@ -191,23 +174,18 @@ __contract__(
|
|
|
191
174
|
}
|
|
192
175
|
|
|
193
176
|
#define mlk_polyvec_compress_du MLK_NAMESPACE_K(polyvec_compress_du)
|
|
194
|
-
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
* Description: Compress and serialize vector of polynomials
|
|
177
|
+
/**
|
|
178
|
+
* Compress and serialize a vector of polynomials.
|
|
198
179
|
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
* Coefficients must be unsigned canonical,
|
|
203
|
-
* i.e. in [0,1,..,MLKEM_Q-1].
|
|
180
|
+
* @spec{Implements `ByteEncode_{d_u} (Compress_{d_u} (u))` in @[FIPS203,
|
|
181
|
+
* Algorithm 14 (K-PKE.Encrypt), L22], with level-specific d_u defined in
|
|
182
|
+
* @[FIPS203, Table 2], and given by MLKEM_DU here.}
|
|
204
183
|
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
|
|
210
|
-
**************************************************/
|
|
184
|
+
* @param[out] r Output byte array (needs space for
|
|
185
|
+
* MLKEM_POLYVECCOMPRESSEDBYTES_DU bytes).
|
|
186
|
+
* @param[in] a Input vector of polynomials. Coefficients must be unsigned
|
|
187
|
+
* canonical, i.e. in [0,1,..,MLKEM_Q-1].
|
|
188
|
+
*/
|
|
211
189
|
MLK_INTERNAL_API
|
|
212
190
|
void mlk_polyvec_compress_du(uint8_t r[MLKEM_POLYVECCOMPRESSEDBYTES_DU],
|
|
213
191
|
const mlk_polyvec *a)
|
|
@@ -220,23 +198,19 @@ __contract__(
|
|
|
220
198
|
);
|
|
221
199
|
|
|
222
200
|
#define mlk_polyvec_decompress_du MLK_NAMESPACE_K(polyvec_decompress_du)
|
|
223
|
-
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
|
|
236
|
-
* with level-specific d_u defined in @[FIPS203, Table 2],
|
|
237
|
-
* and given by MLKEM_DU here.
|
|
238
|
-
*
|
|
239
|
-
**************************************************/
|
|
201
|
+
/**
|
|
202
|
+
* De-serialize and decompress a vector of polynomials; approximate inverse
|
|
203
|
+
* of mlk_polyvec_compress_du.
|
|
204
|
+
*
|
|
205
|
+
* @spec{Implements `Decompress_{d_u} (ByteDecode_{d_u} (u))` in @[FIPS203,
|
|
206
|
+
* Algorithm 15 (K-PKE.Decrypt), L3], with level-specific d_u defined in
|
|
207
|
+
* @[FIPS203, Table 2], and given by MLKEM_DU here.}
|
|
208
|
+
*
|
|
209
|
+
* @param[out] r Output vector of polynomials. Coefficients are normalized
|
|
210
|
+
* to [0,1,..,MLKEM_Q-1].
|
|
211
|
+
* @param[in] a Input byte array (of length MLKEM_POLYVECCOMPRESSEDBYTES_DU
|
|
212
|
+
* bytes).
|
|
213
|
+
*/
|
|
240
214
|
MLK_INTERNAL_API
|
|
241
215
|
void mlk_polyvec_decompress_du(mlk_polyvec *r,
|
|
242
216
|
const uint8_t a[MLKEM_POLYVECCOMPRESSEDBYTES_DU])
|
|
@@ -249,22 +223,17 @@ __contract__(
|
|
|
249
223
|
);
|
|
250
224
|
|
|
251
225
|
#define mlk_polyvec_tobytes MLK_NAMESPACE_K(polyvec_tobytes)
|
|
252
|
-
|
|
253
|
-
*
|
|
226
|
+
/**
|
|
227
|
+
* Serialize a vector of polynomials.
|
|
254
228
|
*
|
|
255
|
-
*
|
|
229
|
+
* @spec{Implements ByteEncode_12 @[FIPS203, Algorithm 5]. Extended to
|
|
230
|
+
* vectors as per @[FIPS203, 2.4.8 Applying Algorithms to Arrays] and
|
|
231
|
+
* @[FIPS203, 2.4.6, Matrices and Vectors].}
|
|
256
232
|
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
|
|
261
|
-
*
|
|
262
|
-
* Specification: Implements ByteEncode_12 @[FIPS203, Algorithm 5].
|
|
263
|
-
* Extended to vectors as per
|
|
264
|
-
* @[FIPS203, 2.4.8 Applying Algorithms to Arrays]
|
|
265
|
-
* and @[FIPS203, 2.4.6, Matrices and Vectors]
|
|
266
|
-
*
|
|
267
|
-
**************************************************/
|
|
233
|
+
* @param[out] r Output byte array (needs space for MLKEM_POLYVECBYTES bytes).
|
|
234
|
+
* @param[in] a Input vector of polynomials. Each polynomial must have
|
|
235
|
+
* coefficients in [0,1,..,MLKEM_Q-1].
|
|
236
|
+
*/
|
|
268
237
|
MLK_INTERNAL_API
|
|
269
238
|
void mlk_polyvec_tobytes(uint8_t r[MLKEM_POLYVECBYTES], const mlk_polyvec *a)
|
|
270
239
|
__contract__(
|
|
@@ -276,23 +245,17 @@ __contract__(
|
|
|
276
245
|
);
|
|
277
246
|
|
|
278
247
|
#define mlk_polyvec_frombytes MLK_NAMESPACE_K(polyvec_frombytes)
|
|
279
|
-
|
|
280
|
-
*
|
|
248
|
+
/**
|
|
249
|
+
* De-serialize a vector of polynomials; inverse of mlk_polyvec_tobytes.
|
|
281
250
|
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
251
|
+
* @spec{Implements ByteDecode_12 @[FIPS203, Algorithm 6]. Extended to
|
|
252
|
+
* vectors as per @[FIPS203, 2.4.8 Applying Algorithms to Arrays] and
|
|
253
|
+
* @[FIPS203, 2.4.6, Matrices and Vectors].}
|
|
284
254
|
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
|
|
289
|
-
*
|
|
290
|
-
* Specification: Implements ByteDecode_12 @[FIPS203, Algorithm 6].
|
|
291
|
-
* Extended to vectors as per
|
|
292
|
-
* @[FIPS203, 2.4.8 Applying Algorithms to Arrays]
|
|
293
|
-
* and @[FIPS203, 2.4.6, Matrices and Vectors]
|
|
294
|
-
*
|
|
295
|
-
**************************************************/
|
|
255
|
+
* @param[out] r Output vector of polynomials. Coefficients will be
|
|
256
|
+
* normalized in [0,1,..,4095].
|
|
257
|
+
* @param[in] a Input byte array (of length MLKEM_POLYVECBYTES bytes).
|
|
258
|
+
*/
|
|
296
259
|
MLK_INTERNAL_API
|
|
297
260
|
void mlk_polyvec_frombytes(mlk_polyvec *r, const uint8_t a[MLKEM_POLYVECBYTES])
|
|
298
261
|
__contract__(
|
|
@@ -304,24 +267,20 @@ __contract__(
|
|
|
304
267
|
);
|
|
305
268
|
|
|
306
269
|
#define mlk_polyvec_ntt MLK_NAMESPACE_K(polyvec_ntt)
|
|
307
|
-
|
|
308
|
-
*
|
|
270
|
+
/**
|
|
271
|
+
* Apply forward NTT to all elements of a vector of polynomials.
|
|
309
272
|
*
|
|
310
|
-
*
|
|
273
|
+
* The input is assumed to be in normal order and coefficient-wise bound by
|
|
274
|
+
* MLKEM_Q in absolute value.
|
|
311
275
|
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
276
|
+
* The output polynomial is in bitreversed order, and coefficient-wise bound
|
|
277
|
+
* by MLK_NTT_BOUND in absolute value.
|
|
314
278
|
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
279
|
+
* @spec{Implements @[FIPS203, Algorithm 9, NTT]. Extended to vectors as per
|
|
280
|
+
* @[FIPS203, 2.4.6, Matrices and Vectors].}
|
|
317
281
|
*
|
|
318
|
-
*
|
|
319
|
-
|
|
320
|
-
* Specification:
|
|
321
|
-
* - Implements @[FIPS203, Algorithm 9, NTT]
|
|
322
|
-
* - Extended to vectors as per @[FIPS203, 2.4.6, Matrices and Vectors]
|
|
323
|
-
*
|
|
324
|
-
**************************************************/
|
|
282
|
+
* @param[in,out] r Input/output vector of polynomials.
|
|
283
|
+
*/
|
|
325
284
|
MLK_INTERNAL_API
|
|
326
285
|
void mlk_polyvec_ntt(mlk_polyvec *r)
|
|
327
286
|
__contract__(
|
|
@@ -334,25 +293,21 @@ __contract__(
|
|
|
334
293
|
);
|
|
335
294
|
|
|
336
295
|
#define mlk_polyvec_invntt_tomont MLK_NAMESPACE_K(polyvec_invntt_tomont)
|
|
337
|
-
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
* Description: Apply inverse NTT to all elements of a vector of polynomials
|
|
341
|
-
* and multiply by Montgomery factor 2^16
|
|
296
|
+
/**
|
|
297
|
+
* Apply inverse NTT to all elements of a vector of polynomials and multiply
|
|
298
|
+
* by Montgomery factor 2^16.
|
|
342
299
|
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
300
|
+
* The input is assumed to be in bitreversed order, and can have arbitrary
|
|
301
|
+
* coefficients in int16_t.
|
|
345
302
|
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
303
|
+
* The output polynomial is in normal order, and coefficient-wise bound by
|
|
304
|
+
* MLK_INVNTT_BOUND in absolute value.
|
|
348
305
|
*
|
|
349
|
-
*
|
|
306
|
+
* @spec{Implements @[FIPS203, Algorithm 10, NTT^{-1}]. Extended to vectors
|
|
307
|
+
* as per @[FIPS203, 2.4.6, Matrices and Vectors].}
|
|
350
308
|
*
|
|
351
|
-
*
|
|
352
|
-
|
|
353
|
-
* - Extended to vectors as per @[FIPS203, 2.4.6, Matrices and Vectors]
|
|
354
|
-
*
|
|
355
|
-
**************************************************/
|
|
309
|
+
* @param[in,out] r Input/output vector of polynomials.
|
|
310
|
+
*/
|
|
356
311
|
MLK_INTERNAL_API
|
|
357
312
|
void mlk_polyvec_invntt_tomont(mlk_polyvec *r)
|
|
358
313
|
__contract__(
|
|
@@ -364,30 +319,23 @@ __contract__(
|
|
|
364
319
|
|
|
365
320
|
#define mlk_polyvec_basemul_acc_montgomery_cached \
|
|
366
321
|
MLK_NAMESPACE_K(polyvec_basemul_acc_montgomery_cached)
|
|
367
|
-
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
|
|
384
|
-
*
|
|
385
|
-
* Specification: Implements
|
|
386
|
-
* - @[FIPS203, Section 2.4.7, Eq (2.14)]
|
|
387
|
-
* - @[FIPS203, Algorithm 11, MultiplyNTTs]
|
|
388
|
-
* - @[FIPS203, Algorithm 12, BaseCaseMultiply]
|
|
389
|
-
*
|
|
390
|
-
**************************************************/
|
|
322
|
+
/**
|
|
323
|
+
* Scalar product of two vectors of polynomials in NTT domain, using
|
|
324
|
+
* mulcache for the second operand.
|
|
325
|
+
*
|
|
326
|
+
* Bounds: every coefficient of @p a is assumed to be in [0,1,..,4095]. No
|
|
327
|
+
* bounds guarantees for the coefficients in the result.
|
|
328
|
+
*
|
|
329
|
+
* @spec{Implements @[FIPS203, Section 2.4.7, Eq (2.14)], @[FIPS203,
|
|
330
|
+
* Algorithm 11, MultiplyNTTs], and @[FIPS203, Algorithm 12,
|
|
331
|
+
* BaseCaseMultiply].}
|
|
332
|
+
*
|
|
333
|
+
* @param[out] r Output polynomial.
|
|
334
|
+
* @param[in] a First input polynomial vector.
|
|
335
|
+
* @param[in] b Second input polynomial vector.
|
|
336
|
+
* @param[in] b_cache Mulcache for the second input polynomial vector. Can
|
|
337
|
+
* be computed via mlk_polyvec_mulcache_compute().
|
|
338
|
+
*/
|
|
391
339
|
MLK_INTERNAL_API
|
|
392
340
|
void mlk_polyvec_basemul_acc_montgomery_cached(
|
|
393
341
|
mlk_poly *r, const mlk_polyvec *a, const mlk_polyvec *b,
|
|
@@ -403,30 +351,26 @@ __contract__(
|
|
|
403
351
|
);
|
|
404
352
|
|
|
405
353
|
#define mlk_polyvec_mulcache_compute MLK_NAMESPACE_K(polyvec_mulcache_compute)
|
|
406
|
-
|
|
407
|
-
*
|
|
354
|
+
/**
|
|
355
|
+
* Compute the mulcache for a vector of polynomials in NTT domain.
|
|
408
356
|
*
|
|
409
|
-
*
|
|
357
|
+
* The mulcache of a degree-2 polynomial b := b0 + b1*X in Fq[X]/(X^2-zeta)
|
|
358
|
+
* is the value b1*zeta, needed when computing products of b in
|
|
359
|
+
* Fq[X]/(X^2-zeta).
|
|
410
360
|
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
361
|
+
* The mulcache of a polynomial in NTT domain -- which is a 128-tuple of
|
|
362
|
+
* degree-2 polynomials in Fq[X]/(X^2-zeta), for varying zeta, is the
|
|
363
|
+
* 128-tuple of mulcaches of those polynomials.
|
|
414
364
|
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
* for varying zeta, is the 128-tuple of mulcaches of those
|
|
418
|
-
* polynomials.
|
|
365
|
+
* The mulcache of a vector of polynomials is the vector of mulcaches of
|
|
366
|
+
* its entries.
|
|
419
367
|
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
368
|
+
* @spec{Caches `b_1 * \gamma` in @[FIPS203, Algorithm 12, BaseCaseMultiply,
|
|
369
|
+
* L1].}
|
|
422
370
|
*
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
|
|
426
|
-
* Specification:
|
|
427
|
-
* - Caches `b_1 * \gamma` in @[FIPS203, Algorithm 12, BaseCaseMultiply, L1]
|
|
428
|
-
*
|
|
429
|
-
************************************************************/
|
|
371
|
+
* @param[out] x Mulcache to be populated.
|
|
372
|
+
* @param[in] a Input polynomial vector.
|
|
373
|
+
*/
|
|
430
374
|
/*
|
|
431
375
|
* NOTE: The default C implementation of this function populates
|
|
432
376
|
* the mulcache with values in (-q,q), but this is not needed for the
|
|
@@ -441,20 +385,16 @@ __contract__(
|
|
|
441
385
|
);
|
|
442
386
|
|
|
443
387
|
#define mlk_polyvec_reduce MLK_NAMESPACE_K(polyvec_reduce)
|
|
444
|
-
|
|
445
|
-
*
|
|
388
|
+
/**
|
|
389
|
+
* Apply Barrett reduction to each coefficient of each element of a vector
|
|
390
|
+
* of polynomials. For details of the Barrett reduction see comments in
|
|
391
|
+
* poly.c.
|
|
446
392
|
*
|
|
447
|
-
*
|
|
448
|
-
*
|
|
449
|
-
* for details of the Barrett reduction see comments in poly.c
|
|
393
|
+
* @spec{Normalizes on unsigned canonical representatives ahead of calling
|
|
394
|
+
* @[FIPS203, Compress_d, Eq (4.7)]. This is not made explicit in FIPS 203.}
|
|
450
395
|
*
|
|
451
|
-
*
|
|
452
|
-
|
|
453
|
-
* Specification: Normalizes on unsigned canoncial representatives
|
|
454
|
-
* ahead of calling @[FIPS203, Compress_d, Eq (4.7)].
|
|
455
|
-
* This is not made explicit in FIPS 203.
|
|
456
|
-
*
|
|
457
|
-
**************************************************/
|
|
396
|
+
* @param[in,out] r Input/output polynomial vector.
|
|
397
|
+
*/
|
|
458
398
|
/*
|
|
459
399
|
* NOTE: The semantics of mlk_polyvec_reduce() is different in
|
|
460
400
|
* the reference implementation, which requires
|
|
@@ -472,28 +412,22 @@ __contract__(
|
|
|
472
412
|
);
|
|
473
413
|
|
|
474
414
|
#define mlk_polyvec_add MLK_NAMESPACE_K(polyvec_add)
|
|
475
|
-
|
|
476
|
-
*
|
|
415
|
+
/**
|
|
416
|
+
* Add vectors of polynomials.
|
|
477
417
|
*
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
* Arguments: - mlk_polyvec r: pointer to input-output vector of polynomials to
|
|
481
|
-
* be added to
|
|
482
|
-
* - const mlk_polyvec b: pointer to second input vector of
|
|
483
|
-
* polynomials
|
|
484
|
-
*
|
|
485
|
-
* The coefficients of r and b must be so that the addition does
|
|
418
|
+
* The coefficients of @p r and @p b must be such that the addition does
|
|
486
419
|
* not overflow. Otherwise, the behaviour of this function is undefined.
|
|
487
420
|
*
|
|
488
|
-
* The coefficients returned in *r are in int16_t which is sufficient
|
|
489
|
-
*
|
|
490
|
-
*
|
|
421
|
+
* The coefficients returned in @p *r are in int16_t which is sufficient to
|
|
422
|
+
* prove type-safety of calling units. Therefore, no stronger ensures clause
|
|
423
|
+
* is required on this function.
|
|
491
424
|
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
* - Used in @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L19]
|
|
425
|
+
* @spec{@[FIPS203, 2.4.5, Arithmetic With Polynomials and NTT
|
|
426
|
+
* Representations]. Used in @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L19].}
|
|
495
427
|
*
|
|
496
|
-
|
|
428
|
+
* @param[in,out] r Input-output vector of polynomials to be added to.
|
|
429
|
+
* @param[in] b Second input vector of polynomials.
|
|
430
|
+
*/
|
|
497
431
|
MLK_INTERNAL_API
|
|
498
432
|
void mlk_polyvec_add(mlk_polyvec *r, const mlk_polyvec *b)
|
|
499
433
|
__contract__(
|
|
@@ -509,20 +443,18 @@ __contract__(
|
|
|
509
443
|
);
|
|
510
444
|
|
|
511
445
|
#define mlk_polyvec_tomont MLK_NAMESPACE_K(polyvec_tomont)
|
|
512
|
-
|
|
513
|
-
*
|
|
446
|
+
/**
|
|
447
|
+
* In-place conversion of all coefficients of a polynomial vector from the
|
|
448
|
+
* normal domain to the Montgomery domain.
|
|
514
449
|
*
|
|
515
|
-
*
|
|
516
|
-
* vector from normal domain to Montgomery domain
|
|
450
|
+
* Bounds: output < MLKEM_Q in absolute value.
|
|
517
451
|
*
|
|
518
|
-
*
|
|
452
|
+
* @spec{Internal normalization required in `mlk_indcpa_keypair_derand` as
|
|
453
|
+
* part of matrix-vector multiplication @[FIPS203, Algorithm 13, K-PKE.KeyGen,
|
|
454
|
+
* L18].}
|
|
519
455
|
*
|
|
520
|
-
*
|
|
521
|
-
|
|
522
|
-
* as part of matrix-vector multiplication
|
|
523
|
-
* @[FIPS203, Algorithm 13, K-PKE.KeyGen, L18].
|
|
524
|
-
*
|
|
525
|
-
**************************************************/
|
|
456
|
+
* @param[in,out] r Input/output polynomial vector.
|
|
457
|
+
*/
|
|
526
458
|
MLK_INTERNAL_API
|
|
527
459
|
void mlk_polyvec_tomont(mlk_polyvec *r)
|
|
528
460
|
__contract__(
|
|
@@ -533,28 +465,27 @@ __contract__(
|
|
|
533
465
|
);
|
|
534
466
|
|
|
535
467
|
#define mlk_poly_getnoise_eta1_4x MLK_NAMESPACE_K(poly_getnoise_eta1_4x)
|
|
536
|
-
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
* -
|
|
553
|
-
* -
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
|
|
557
|
-
**************************************************/
|
|
468
|
+
/**
|
|
469
|
+
* Batch sample four polynomials deterministically from a seed and nonces,
|
|
470
|
+
* with output polynomials close to centered binomial distribution with
|
|
471
|
+
* parameter MLKEM_ETA1.
|
|
472
|
+
*
|
|
473
|
+
* @spec{Implements 4x `SamplePolyCBD_{eta1} (PRF_{eta1} (sigma, N))`:
|
|
474
|
+
* @[FIPS203, Algorithm 8, SamplePolyCBD_eta] and @[FIPS203, Eq (4.3),
|
|
475
|
+
* PRF_eta]. `SamplePolyCBD_{eta1} (PRF_{eta1} (sigma, N))` appears in
|
|
476
|
+
* @[FIPS203, Algorithm 13, K-PKE.KeyGen, L{9, 13}] and @[FIPS203,
|
|
477
|
+
* Algorithm 14, K-PKE.Encrypt, L10].}
|
|
478
|
+
*
|
|
479
|
+
* @param[out] r0 Output polynomial.
|
|
480
|
+
* @param[out] r1 Output polynomial.
|
|
481
|
+
* @param[out] r2 Output polynomial.
|
|
482
|
+
* @param[out] r3 Output polynomial. May be NULL.
|
|
483
|
+
* @param[in] seed Input seed (of length MLKEM_SYMBYTES bytes).
|
|
484
|
+
* @param nonce0 One-byte input nonce.
|
|
485
|
+
* @param nonce1 One-byte input nonce.
|
|
486
|
+
* @param nonce2 One-byte input nonce.
|
|
487
|
+
* @param nonce3 One-byte input nonce.
|
|
488
|
+
*/
|
|
558
489
|
MLK_INTERNAL_API
|
|
559
490
|
void mlk_poly_getnoise_eta1_4x(mlk_poly *r0, mlk_poly *r1, mlk_poly *r2,
|
|
560
491
|
mlk_poly *r3, const uint8_t seed[MLKEM_SYMBYTES],
|
|
@@ -587,26 +518,20 @@ __contract__(
|
|
|
587
518
|
|
|
588
519
|
#if MLKEM_K == 2 || MLKEM_K == 4
|
|
589
520
|
#define mlk_poly_getnoise_eta2 MLK_NAMESPACE_K(poly_getnoise_eta2)
|
|
590
|
-
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
*
|
|
596
|
-
*
|
|
597
|
-
*
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
*
|
|
602
|
-
*
|
|
603
|
-
|
|
604
|
-
* - @[FIPS203, Algorithm 8, SamplePolyCBD_eta]
|
|
605
|
-
* - @[FIPS203, Eq (4.3), PRF_eta]
|
|
606
|
-
* - `SamplePolyCBD_{eta2} (PRF_{eta2} (sigma, N))` appears in
|
|
607
|
-
* @[FIPS203, Algorithm 14, K-PKE.Encrypt, L14]
|
|
608
|
-
*
|
|
609
|
-
**************************************************/
|
|
521
|
+
/**
|
|
522
|
+
* Sample a polynomial deterministically from a seed and a nonce, with
|
|
523
|
+
* output polynomial close to centered binomial distribution with parameter
|
|
524
|
+
* MLKEM_ETA2.
|
|
525
|
+
*
|
|
526
|
+
* @spec{Implements `SamplePolyCBD_{eta2} (PRF_{eta2} (sigma, N))`:
|
|
527
|
+
* @[FIPS203, Algorithm 8, SamplePolyCBD_eta] and @[FIPS203, Eq (4.3),
|
|
528
|
+
* PRF_eta]. `SamplePolyCBD_{eta2} (PRF_{eta2} (sigma, N))` appears in
|
|
529
|
+
* @[FIPS203, Algorithm 14, K-PKE.Encrypt, L14].}
|
|
530
|
+
*
|
|
531
|
+
* @param[out] r Output polynomial.
|
|
532
|
+
* @param[in] seed Input seed (of length MLKEM_SYMBYTES bytes).
|
|
533
|
+
* @param nonce One-byte input nonce.
|
|
534
|
+
*/
|
|
610
535
|
MLK_INTERNAL_API
|
|
611
536
|
void mlk_poly_getnoise_eta2(mlk_poly *r, const uint8_t seed[MLKEM_SYMBYTES],
|
|
612
537
|
uint8_t nonce)
|
|
@@ -620,28 +545,28 @@ __contract__(
|
|
|
620
545
|
|
|
621
546
|
#if MLKEM_K == 2
|
|
622
547
|
#define mlk_poly_getnoise_eta1122_4x MLK_NAMESPACE_K(poly_getnoise_eta1122_4x)
|
|
623
|
-
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
*
|
|
627
|
-
* and a nonces, with output polynomials close to centered binomial
|
|
628
|
-
* distribution with parameter MLKEM_ETA1 and MLKEM_ETA2
|
|
548
|
+
/**
|
|
549
|
+
* Batch sample four polynomials deterministically from a seed and nonces,
|
|
550
|
+
* with output polynomials close to centered binomial distribution with
|
|
551
|
+
* parameter MLKEM_ETA1 and MLKEM_ETA2.
|
|
629
552
|
*
|
|
630
|
-
*
|
|
631
|
-
* - const uint8_t *seed: pointer to input seed
|
|
632
|
-
* (of length MLKEM_SYMBYTES bytes)
|
|
633
|
-
* - uint8_t nonce{0,1,2,3}: one-byte input nonce
|
|
634
|
-
*
|
|
635
|
-
* Specification:
|
|
636
|
-
* Implements two instances each of
|
|
553
|
+
* @spec{Implements two instances each of
|
|
637
554
|
* `SamplePolyCBD_{eta1} (PRF_{eta1} (sigma, N))` and
|
|
638
555
|
* `SamplePolyCBD_{eta2} (PRF_{eta2} (sigma, N))`:
|
|
639
|
-
*
|
|
640
|
-
*
|
|
641
|
-
*
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
|
|
556
|
+
* @[FIPS203, Algorithm 8, SamplePolyCBD_eta] and @[FIPS203, Eq (4.3),
|
|
557
|
+
* PRF_eta]. `SamplePolyCBD_{eta2} (PRF_{eta2} (sigma, N))` appears in
|
|
558
|
+
* @[FIPS203, Algorithm 14, K-PKE.Encrypt, L14].}
|
|
559
|
+
*
|
|
560
|
+
* @param[out] r0 Output polynomial.
|
|
561
|
+
* @param[out] r1 Output polynomial.
|
|
562
|
+
* @param[out] r2 Output polynomial.
|
|
563
|
+
* @param[out] r3 Output polynomial.
|
|
564
|
+
* @param[in] seed Input seed (of length MLKEM_SYMBYTES bytes).
|
|
565
|
+
* @param nonce0 One-byte input nonce.
|
|
566
|
+
* @param nonce1 One-byte input nonce.
|
|
567
|
+
* @param nonce2 One-byte input nonce.
|
|
568
|
+
* @param nonce3 One-byte input nonce.
|
|
569
|
+
*/
|
|
645
570
|
MLK_INTERNAL_API
|
|
646
571
|
void mlk_poly_getnoise_eta1122_4x(mlk_poly *r0, mlk_poly *r1, mlk_poly *r2,
|
|
647
572
|
mlk_poly *r3,
|