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
|
@@ -27,18 +27,6 @@
|
|
|
27
27
|
#include "poly.h"
|
|
28
28
|
#include "verify.h"
|
|
29
29
|
|
|
30
|
-
/************************************************************
|
|
31
|
-
* Name: mlk_scalar_compress_d1
|
|
32
|
-
*
|
|
33
|
-
* Description: Computes round(u * 2 / q)
|
|
34
|
-
*
|
|
35
|
-
* Arguments: - u: Unsigned canonical modulus modulo q
|
|
36
|
-
* to be compressed.
|
|
37
|
-
*
|
|
38
|
-
* Specification: Compress_1 from @[FIPS203, Eq (4.7)].
|
|
39
|
-
*
|
|
40
|
-
************************************************************/
|
|
41
|
-
|
|
42
30
|
/*
|
|
43
31
|
* The multiplication in this routine will exceed UINT32_MAX
|
|
44
32
|
* and wrap around for large values of u. This is expected and required.
|
|
@@ -48,7 +36,17 @@
|
|
|
48
36
|
#pragma CPROVER check disable "unsigned-overflow"
|
|
49
37
|
#endif
|
|
50
38
|
|
|
51
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Compute round(u * 2 / MLKEM_Q).
|
|
41
|
+
*
|
|
42
|
+
* @spec{Compress_1 from @[FIPS203, Eq (4.7)].}
|
|
43
|
+
*
|
|
44
|
+
* @reference{Part of poly_tomsg() in the reference implementation @[REF].}
|
|
45
|
+
*
|
|
46
|
+
* @param u Unsigned canonical modulus modulo MLKEM_Q to be compressed.
|
|
47
|
+
*
|
|
48
|
+
* @return Compressed value.
|
|
49
|
+
*/
|
|
52
50
|
static MLK_INLINE uint8_t mlk_scalar_compress_d1(int16_t u)
|
|
53
51
|
__contract__(
|
|
54
52
|
requires(0 <= u && u <= MLKEM_Q - 1)
|
|
@@ -71,17 +69,6 @@ __contract__(
|
|
|
71
69
|
#pragma CPROVER check pop
|
|
72
70
|
#endif
|
|
73
71
|
|
|
74
|
-
/************************************************************
|
|
75
|
-
* Name: mlk_scalar_compress_d4
|
|
76
|
-
*
|
|
77
|
-
* Description: Computes round(u * 16 / q) % 16
|
|
78
|
-
*
|
|
79
|
-
* Arguments: - u: Unsigned canonical modulus modulo q
|
|
80
|
-
* to be compressed.
|
|
81
|
-
*
|
|
82
|
-
* Specification: Compress_4 from @[FIPS203, Eq (4.7)].
|
|
83
|
-
*
|
|
84
|
-
************************************************************/
|
|
85
72
|
/*
|
|
86
73
|
* The multiplication in this routine will exceed UINT32_MAX
|
|
87
74
|
* and wrap around for large values of u. This is expected and required.
|
|
@@ -91,8 +78,18 @@ __contract__(
|
|
|
91
78
|
#pragma CPROVER check disable "unsigned-overflow"
|
|
92
79
|
#endif
|
|
93
80
|
|
|
94
|
-
|
|
95
|
-
*
|
|
81
|
+
/**
|
|
82
|
+
* Compute round(u * 16 / MLKEM_Q) % 16.
|
|
83
|
+
*
|
|
84
|
+
* @spec{Compress_4 from @[FIPS203, Eq (4.7)].}
|
|
85
|
+
*
|
|
86
|
+
* @reference{Embedded into `poly_compress()` in the reference
|
|
87
|
+
* implementation @[REF].}
|
|
88
|
+
*
|
|
89
|
+
* @param u Unsigned canonical modulus modulo MLKEM_Q to be compressed.
|
|
90
|
+
*
|
|
91
|
+
* @return Compressed value.
|
|
92
|
+
*/
|
|
96
93
|
static MLK_INLINE uint8_t mlk_scalar_compress_d4(int16_t u)
|
|
97
94
|
__contract__(
|
|
98
95
|
requires(0 <= u && u <= MLKEM_Q - 1)
|
|
@@ -115,20 +112,18 @@ __contract__(
|
|
|
115
112
|
#pragma CPROVER check pop
|
|
116
113
|
#endif
|
|
117
114
|
|
|
118
|
-
|
|
119
|
-
*
|
|
115
|
+
/**
|
|
116
|
+
* Compute round(u * MLKEM_Q / 16).
|
|
120
117
|
*
|
|
121
|
-
*
|
|
118
|
+
* @spec{Decompress_4 from @[FIPS203, Eq (4.8)].}
|
|
122
119
|
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
120
|
+
* @reference{Embedded into `poly_decompress()` in the reference
|
|
121
|
+
* implementation @[REF].}
|
|
125
122
|
*
|
|
126
|
-
*
|
|
123
|
+
* @param u Unsigned canonical modulus modulo 16 to be decompressed.
|
|
127
124
|
*
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
/* Reference: Embedded into `poly_decompress()` in the
|
|
131
|
-
* reference implementation @[REF]. */
|
|
125
|
+
* @return Decompressed value.
|
|
126
|
+
*/
|
|
132
127
|
static MLK_INLINE int16_t mlk_scalar_decompress_d4(uint8_t u)
|
|
133
128
|
__contract__(
|
|
134
129
|
requires(0 <= u && u < 16)
|
|
@@ -140,17 +135,6 @@ __contract__(
|
|
|
140
135
|
return (int16_t)((((uint32_t)u * MLKEM_Q) + 8) >> 4);
|
|
141
136
|
}
|
|
142
137
|
|
|
143
|
-
/************************************************************
|
|
144
|
-
* Name: mlk_scalar_compress_d5
|
|
145
|
-
*
|
|
146
|
-
* Description: Computes round(u * 32 / q) % 32
|
|
147
|
-
*
|
|
148
|
-
* Arguments: - u: Unsigned canonical modulus modulo q
|
|
149
|
-
* to be compressed.
|
|
150
|
-
*
|
|
151
|
-
* Specification: Compress_5 from @[FIPS203, Eq (4.7)].
|
|
152
|
-
*
|
|
153
|
-
************************************************************/
|
|
154
138
|
/*
|
|
155
139
|
* The multiplication in this routine will exceed UINT32_MAX
|
|
156
140
|
* and wrap around for large values of u. This is expected and required.
|
|
@@ -160,8 +144,18 @@ __contract__(
|
|
|
160
144
|
#pragma CPROVER check disable "unsigned-overflow"
|
|
161
145
|
#endif
|
|
162
146
|
|
|
163
|
-
|
|
164
|
-
*
|
|
147
|
+
/**
|
|
148
|
+
* Compute round(u * 32 / MLKEM_Q) % 32.
|
|
149
|
+
*
|
|
150
|
+
* @spec{Compress_5 from @[FIPS203, Eq (4.7)].}
|
|
151
|
+
*
|
|
152
|
+
* @reference{Embedded into `poly_compress()` in the reference
|
|
153
|
+
* implementation @[REF].}
|
|
154
|
+
*
|
|
155
|
+
* @param u Unsigned canonical modulus modulo MLKEM_Q to be compressed.
|
|
156
|
+
*
|
|
157
|
+
* @return Compressed value.
|
|
158
|
+
*/
|
|
165
159
|
static MLK_INLINE uint8_t mlk_scalar_compress_d5(int16_t u)
|
|
166
160
|
__contract__(
|
|
167
161
|
requires(0 <= u && u <= MLKEM_Q - 1)
|
|
@@ -184,20 +178,18 @@ __contract__(
|
|
|
184
178
|
#pragma CPROVER check pop
|
|
185
179
|
#endif
|
|
186
180
|
|
|
187
|
-
|
|
188
|
-
*
|
|
181
|
+
/**
|
|
182
|
+
* Compute round(u * MLKEM_Q / 32).
|
|
189
183
|
*
|
|
190
|
-
*
|
|
184
|
+
* @spec{Decompress_5 from @[FIPS203, Eq (4.8)].}
|
|
191
185
|
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
186
|
+
* @reference{Embedded into `poly_decompress()` in the reference
|
|
187
|
+
* implementation @[REF].}
|
|
194
188
|
*
|
|
195
|
-
*
|
|
189
|
+
* @param u Unsigned canonical modulus modulo 32 to be decompressed.
|
|
196
190
|
*
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
/* Reference: Embedded into `poly_decompress()` in the
|
|
200
|
-
* reference implementation @[REF]. */
|
|
191
|
+
* @return Decompressed value.
|
|
192
|
+
*/
|
|
201
193
|
static MLK_INLINE int16_t mlk_scalar_decompress_d5(uint8_t u)
|
|
202
194
|
__contract__(
|
|
203
195
|
requires(0 <= u && u < 32)
|
|
@@ -209,17 +201,6 @@ __contract__(
|
|
|
209
201
|
return (int16_t)((((uint32_t)u * MLKEM_Q) + 16) >> 5);
|
|
210
202
|
}
|
|
211
203
|
|
|
212
|
-
/************************************************************
|
|
213
|
-
* Name: mlk_scalar_compress_d10
|
|
214
|
-
*
|
|
215
|
-
* Description: Computes round(u * 2**10 / q) % 2**10
|
|
216
|
-
*
|
|
217
|
-
* Arguments: - u: Unsigned canonical modulus modulo q
|
|
218
|
-
* to be compressed.
|
|
219
|
-
*
|
|
220
|
-
* Specification: Compress_10 from @[FIPS203, Eq (4.7)].
|
|
221
|
-
*
|
|
222
|
-
************************************************************/
|
|
223
204
|
/*
|
|
224
205
|
* The multiplication in this routine will exceed UINT32_MAX
|
|
225
206
|
* and wrap around for large values of u. This is expected and required.
|
|
@@ -229,8 +210,18 @@ __contract__(
|
|
|
229
210
|
#pragma CPROVER check disable "unsigned-overflow"
|
|
230
211
|
#endif
|
|
231
212
|
|
|
232
|
-
|
|
233
|
-
*
|
|
213
|
+
/**
|
|
214
|
+
* Compute round(u * 2**10 / MLKEM_Q) % 2**10.
|
|
215
|
+
*
|
|
216
|
+
* @spec{Compress_10 from @[FIPS203, Eq (4.7)].}
|
|
217
|
+
*
|
|
218
|
+
* @reference{Embedded into `polyvec_compress()` in the reference
|
|
219
|
+
* implementation @[REF].}
|
|
220
|
+
*
|
|
221
|
+
* @param u Unsigned canonical modulus modulo MLKEM_Q to be compressed.
|
|
222
|
+
*
|
|
223
|
+
* @return Compressed value.
|
|
224
|
+
*/
|
|
234
225
|
static MLK_INLINE uint16_t mlk_scalar_compress_d10(int16_t u)
|
|
235
226
|
__contract__(
|
|
236
227
|
requires(0 <= u && u <= MLKEM_Q - 1)
|
|
@@ -253,20 +244,18 @@ __contract__(
|
|
|
253
244
|
#pragma CPROVER check pop
|
|
254
245
|
#endif
|
|
255
246
|
|
|
256
|
-
|
|
257
|
-
*
|
|
247
|
+
/**
|
|
248
|
+
* Compute round(u * MLKEM_Q / 1024).
|
|
258
249
|
*
|
|
259
|
-
*
|
|
250
|
+
* @spec{Decompress_10 from @[FIPS203, Eq (4.8)].}
|
|
260
251
|
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
252
|
+
* @reference{Embedded into `polyvec_decompress()` in the reference
|
|
253
|
+
* implementation @[REF].}
|
|
263
254
|
*
|
|
264
|
-
*
|
|
255
|
+
* @param u Unsigned canonical modulus modulo 1024 to be decompressed.
|
|
265
256
|
*
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
/* Reference: Embedded into `polyvec_decompress()` in the
|
|
269
|
-
* reference implementation @[REF]. */
|
|
257
|
+
* @return Decompressed value.
|
|
258
|
+
*/
|
|
270
259
|
static MLK_INLINE int16_t mlk_scalar_decompress_d10(uint16_t u)
|
|
271
260
|
__contract__(
|
|
272
261
|
requires(0 <= u && u < 1024)
|
|
@@ -278,17 +267,6 @@ __contract__(
|
|
|
278
267
|
return (int16_t)((((uint32_t)u * MLKEM_Q) + 512) >> 10);
|
|
279
268
|
}
|
|
280
269
|
|
|
281
|
-
/************************************************************
|
|
282
|
-
* Name: mlk_scalar_compress_d11
|
|
283
|
-
*
|
|
284
|
-
* Description: Computes round(u * 2**11 / q) % 2**11
|
|
285
|
-
*
|
|
286
|
-
* Arguments: - u: Unsigned canonical modulus modulo q
|
|
287
|
-
* to be compressed.
|
|
288
|
-
*
|
|
289
|
-
* Specification: Compress_11 from @[FIPS203, Eq (4.7)].
|
|
290
|
-
*
|
|
291
|
-
************************************************************/
|
|
292
270
|
/*
|
|
293
271
|
* The multiplication in this routine will exceed UINT32_MAX
|
|
294
272
|
* and wrap around for large values of u. This is expected and required.
|
|
@@ -298,8 +276,18 @@ __contract__(
|
|
|
298
276
|
#pragma CPROVER check disable "unsigned-overflow"
|
|
299
277
|
#endif
|
|
300
278
|
|
|
301
|
-
|
|
302
|
-
*
|
|
279
|
+
/**
|
|
280
|
+
* Compute round(u * 2**11 / MLKEM_Q) % 2**11.
|
|
281
|
+
*
|
|
282
|
+
* @spec{Compress_11 from @[FIPS203, Eq (4.7)].}
|
|
283
|
+
*
|
|
284
|
+
* @reference{Embedded into `polyvec_compress()` in the reference
|
|
285
|
+
* implementation @[REF].}
|
|
286
|
+
*
|
|
287
|
+
* @param u Unsigned canonical modulus modulo MLKEM_Q to be compressed.
|
|
288
|
+
*
|
|
289
|
+
* @return Compressed value.
|
|
290
|
+
*/
|
|
303
291
|
static MLK_INLINE uint16_t mlk_scalar_compress_d11(int16_t u)
|
|
304
292
|
__contract__(
|
|
305
293
|
requires(0 <= u && u <= MLKEM_Q - 1)
|
|
@@ -322,20 +310,18 @@ __contract__(
|
|
|
322
310
|
#pragma CPROVER check pop
|
|
323
311
|
#endif
|
|
324
312
|
|
|
325
|
-
|
|
326
|
-
*
|
|
313
|
+
/**
|
|
314
|
+
* Compute round(u * MLKEM_Q / 2048).
|
|
327
315
|
*
|
|
328
|
-
*
|
|
316
|
+
* @spec{Decompress_11 from @[FIPS203, Eq (4.8)].}
|
|
329
317
|
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
318
|
+
* @reference{Embedded into `polyvec_decompress()` in the reference
|
|
319
|
+
* implementation @[REF].}
|
|
332
320
|
*
|
|
333
|
-
*
|
|
321
|
+
* @param u Unsigned canonical modulus modulo 2048 to be decompressed.
|
|
334
322
|
*
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
/* Reference: Embedded into `polyvec_decompress()` in the
|
|
338
|
-
* reference implementation @[REF]. */
|
|
323
|
+
* @return Decompressed value.
|
|
324
|
+
*/
|
|
339
325
|
static MLK_INLINE int16_t mlk_scalar_decompress_d11(uint16_t u)
|
|
340
326
|
__contract__(
|
|
341
327
|
requires(0 <= u && u < 2048)
|
|
@@ -349,111 +335,87 @@ __contract__(
|
|
|
349
335
|
|
|
350
336
|
#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || (MLKEM_K == 2 || MLKEM_K == 3)
|
|
351
337
|
#define mlk_poly_compress_d4 MLK_NAMESPACE(poly_compress_d4)
|
|
352
|
-
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
|
|
367
|
-
* Extended to vectors as per
|
|
368
|
-
* @[FIPS203, 2.4.8 Applying Algorithms to Arrays]
|
|
369
|
-
* - `ByteEncode_{d_v} (Compress_{d_v} (v))` appears in
|
|
370
|
-
* @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L23],
|
|
371
|
-
* where `d_v=4` for ML-KEM-{512,768} @[FIPS203, Table 2].
|
|
372
|
-
*
|
|
373
|
-
**************************************************/
|
|
338
|
+
/**
|
|
339
|
+
* Compression (4 bits) and subsequent serialization of a polynomial.
|
|
340
|
+
*
|
|
341
|
+
* @spec{Implements `ByteEncode_4 (Compress_4 (a))`: ByteEncode_d
|
|
342
|
+
* @[FIPS203, Algorithm 5], Compress_d @[FIPS203, Eq (4.7)], extended to
|
|
343
|
+
* vectors as per @[FIPS203, 2.4.8 Applying Algorithms to Arrays].
|
|
344
|
+
* `ByteEncode_{d_v} (Compress_{d_v} (v))` appears in @[FIPS203, Algorithm
|
|
345
|
+
* 14 (K-PKE.Encrypt), L23], where `d_v=4` for ML-KEM-{512,768} @[FIPS203,
|
|
346
|
+
* Table 2].}
|
|
347
|
+
*
|
|
348
|
+
* @param[out] r Output byte array (of length MLKEM_POLYCOMPRESSEDBYTES_D4
|
|
349
|
+
* bytes).
|
|
350
|
+
* @param[in] a Input polynomial. Coefficients must be unsigned canonical,
|
|
351
|
+
* i.e. in [0,1,..,MLKEM_Q-1].
|
|
352
|
+
*/
|
|
374
353
|
MLK_INTERNAL_API
|
|
375
354
|
void mlk_poly_compress_d4(uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D4],
|
|
376
355
|
const mlk_poly *a);
|
|
377
356
|
|
|
378
357
|
#define mlk_poly_compress_d10 MLK_NAMESPACE(poly_compress_d10)
|
|
379
|
-
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
|
|
394
|
-
* Extended to vectors as per
|
|
395
|
-
* @[FIPS203, 2.4.8 Applying Algorithms to Arrays]
|
|
396
|
-
* - `ByteEncode_{d_u} (Compress_{d_u} (u))` appears in
|
|
397
|
-
* @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L22],
|
|
398
|
-
* where `d_u=10` for ML-KEM-{512,768} @[FIPS203, Table 2].
|
|
399
|
-
*
|
|
400
|
-
**************************************************/
|
|
358
|
+
/**
|
|
359
|
+
* Compression (10 bits) and subsequent serialization of a polynomial.
|
|
360
|
+
*
|
|
361
|
+
* @spec{Implements `ByteEncode_10 (Compress_10 (a))`: ByteEncode_d
|
|
362
|
+
* @[FIPS203, Algorithm 5], Compress_d @[FIPS203, Eq (4.7)], extended to
|
|
363
|
+
* vectors as per @[FIPS203, 2.4.8 Applying Algorithms to Arrays].
|
|
364
|
+
* `ByteEncode_{d_u} (Compress_{d_u} (u))` appears in @[FIPS203, Algorithm
|
|
365
|
+
* 14 (K-PKE.Encrypt), L22], where `d_u=10` for ML-KEM-{512,768} @[FIPS203,
|
|
366
|
+
* Table 2].}
|
|
367
|
+
*
|
|
368
|
+
* @param[out] r Output byte array (of length MLKEM_POLYCOMPRESSEDBYTES_D10
|
|
369
|
+
* bytes).
|
|
370
|
+
* @param[in] a Input polynomial. Coefficients must be unsigned canonical,
|
|
371
|
+
* i.e. in [0,1,..,MLKEM_Q-1].
|
|
372
|
+
*/
|
|
401
373
|
MLK_INTERNAL_API
|
|
402
374
|
void mlk_poly_compress_d10(uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D10],
|
|
403
375
|
const mlk_poly *a);
|
|
404
376
|
|
|
405
377
|
#define mlk_poly_decompress_d4 MLK_NAMESPACE(poly_decompress_d4)
|
|
406
|
-
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
* (
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
|
|
424
|
-
* - `Decompress_{d_v} (ByteDecode_{d_v} (v))` appears in
|
|
425
|
-
* @[FIPS203, Algorithm 15 (K-PKE.Decrypt), L4],
|
|
426
|
-
* where `d_v=4` for ML-KEM-{512,768} @[FIPS203, Table 2].
|
|
427
|
-
*
|
|
428
|
-
**************************************************/
|
|
378
|
+
/**
|
|
379
|
+
* De-serialization and subsequent decompression (4 bits) of a polynomial;
|
|
380
|
+
* approximate inverse of mlk_poly_compress_d4.
|
|
381
|
+
*
|
|
382
|
+
* Upon return, the coefficients of the output polynomial are
|
|
383
|
+
* unsigned-canonical (non-negative and smaller than MLKEM_Q).
|
|
384
|
+
*
|
|
385
|
+
* @spec{Implements `Decompress_4 (ByteDecode_4 (a))`: ByteDecode_d
|
|
386
|
+
* @[FIPS203, Algorithm 6], Decompress_d @[FIPS203, Eq (4.8)], extended to
|
|
387
|
+
* vectors as per @[FIPS203, 2.4.8 Applying Algorithms to Arrays].
|
|
388
|
+
* `Decompress_{d_v} (ByteDecode_{d_v} (v))` appears in @[FIPS203, Algorithm
|
|
389
|
+
* 15 (K-PKE.Decrypt), L4], where `d_v=4` for ML-KEM-{512,768} @[FIPS203,
|
|
390
|
+
* Table 2].}
|
|
391
|
+
*
|
|
392
|
+
* @param[out] r Output polynomial.
|
|
393
|
+
* @param[in] a Input byte array (of length MLKEM_POLYCOMPRESSEDBYTES_D4
|
|
394
|
+
* bytes).
|
|
395
|
+
*/
|
|
429
396
|
MLK_INTERNAL_API
|
|
430
397
|
void mlk_poly_decompress_d4(mlk_poly *r,
|
|
431
398
|
const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D4]);
|
|
432
399
|
|
|
433
400
|
#define mlk_poly_decompress_d10 MLK_NAMESPACE(poly_decompress_d10)
|
|
434
|
-
|
|
435
|
-
*
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
* (
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
|
|
452
|
-
* - `Decompress_{d_u} (ByteDecode_{d_u} (u))` appears in
|
|
453
|
-
* @[FIPS203, Algorithm 15 (K-PKE.Decrypt), L3],
|
|
454
|
-
* where `d_u=10` for ML-KEM-{512,768} @[FIPS203, Table 2].
|
|
455
|
-
*
|
|
456
|
-
**************************************************/
|
|
401
|
+
/**
|
|
402
|
+
* De-serialization and subsequent decompression (10 bits) of a polynomial;
|
|
403
|
+
* approximate inverse of mlk_poly_compress_d10.
|
|
404
|
+
*
|
|
405
|
+
* Upon return, the coefficients of the output polynomial are
|
|
406
|
+
* unsigned-canonical (non-negative and smaller than MLKEM_Q).
|
|
407
|
+
*
|
|
408
|
+
* @spec{Implements `Decompress_10 (ByteDecode_10 (a))`: ByteDecode_d
|
|
409
|
+
* @[FIPS203, Algorithm 6], Decompress_d @[FIPS203, Eq (4.8)], extended to
|
|
410
|
+
* vectors as per @[FIPS203, 2.4.8 Applying Algorithms to Arrays].
|
|
411
|
+
* `Decompress_{d_u} (ByteDecode_{d_u} (u))` appears in @[FIPS203, Algorithm
|
|
412
|
+
* 15 (K-PKE.Decrypt), L3], where `d_u=10` for ML-KEM-{512,768} @[FIPS203,
|
|
413
|
+
* Table 2].}
|
|
414
|
+
*
|
|
415
|
+
* @param[out] r Output polynomial.
|
|
416
|
+
* @param[in] a Input byte array (of length MLKEM_POLYCOMPRESSEDBYTES_D10
|
|
417
|
+
* bytes).
|
|
418
|
+
*/
|
|
457
419
|
MLK_INTERNAL_API
|
|
458
420
|
void mlk_poly_decompress_d10(mlk_poly *r,
|
|
459
421
|
const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D10]);
|
|
@@ -461,136 +423,104 @@ void mlk_poly_decompress_d10(mlk_poly *r,
|
|
|
461
423
|
|
|
462
424
|
#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4
|
|
463
425
|
#define mlk_poly_compress_d5 MLK_NAMESPACE(poly_compress_d5)
|
|
464
|
-
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
|
|
479
|
-
* Extended to vectors as per
|
|
480
|
-
* @[FIPS203, 2.4.8 Applying Algorithms to Arrays]
|
|
481
|
-
* - `ByteEncode_{d_v} (Compress_{d_v} (v))` appears in
|
|
482
|
-
* @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L23],
|
|
483
|
-
* where `d_v=5` for ML-KEM-1024 @[FIPS203, Table 2].
|
|
484
|
-
*
|
|
485
|
-
**************************************************/
|
|
426
|
+
/**
|
|
427
|
+
* Compression (5 bits) and subsequent serialization of a polynomial.
|
|
428
|
+
*
|
|
429
|
+
* @spec{Implements `ByteEncode_5 (Compress_5 (a))`: ByteEncode_d
|
|
430
|
+
* @[FIPS203, Algorithm 5], Compress_d @[FIPS203, Eq (4.7)], extended to
|
|
431
|
+
* vectors as per @[FIPS203, 2.4.8 Applying Algorithms to Arrays].
|
|
432
|
+
* `ByteEncode_{d_v} (Compress_{d_v} (v))` appears in @[FIPS203, Algorithm
|
|
433
|
+
* 14 (K-PKE.Encrypt), L23], where `d_v=5` for ML-KEM-1024 @[FIPS203,
|
|
434
|
+
* Table 2].}
|
|
435
|
+
*
|
|
436
|
+
* @param[out] r Output byte array (of length MLKEM_POLYCOMPRESSEDBYTES_D5
|
|
437
|
+
* bytes).
|
|
438
|
+
* @param[in] a Input polynomial. Coefficients must be unsigned canonical,
|
|
439
|
+
* i.e. in [0,1,..,MLKEM_Q-1].
|
|
440
|
+
*/
|
|
486
441
|
MLK_INTERNAL_API
|
|
487
442
|
void mlk_poly_compress_d5(uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D5],
|
|
488
443
|
const mlk_poly *a);
|
|
489
444
|
|
|
490
445
|
#define mlk_poly_compress_d11 MLK_NAMESPACE(poly_compress_d11)
|
|
491
|
-
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
*
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
|
|
506
|
-
* Extended to vectors as per
|
|
507
|
-
* @[FIPS203, 2.4.8 Applying Algorithms to Arrays]
|
|
508
|
-
* - `ByteEncode_{d_u} (Compress_{d_u} (u))` appears in
|
|
509
|
-
* @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L22],
|
|
510
|
-
* where `d_u=11` for ML-KEM-1024 @[FIPS203, Table 2].
|
|
511
|
-
*
|
|
512
|
-
**************************************************/
|
|
446
|
+
/**
|
|
447
|
+
* Compression (11 bits) and subsequent serialization of a polynomial.
|
|
448
|
+
*
|
|
449
|
+
* @spec{`ByteEncode_11 (Compress_11 (a))`: ByteEncode_d @[FIPS203,
|
|
450
|
+
* Algorithm 5], Compress_d @[FIPS203, Eq (4.7)], extended to vectors as
|
|
451
|
+
* per @[FIPS203, 2.4.8 Applying Algorithms to Arrays].
|
|
452
|
+
* `ByteEncode_{d_u} (Compress_{d_u} (u))` appears in @[FIPS203, Algorithm
|
|
453
|
+
* 14 (K-PKE.Encrypt), L22], where `d_u=11` for ML-KEM-1024 @[FIPS203,
|
|
454
|
+
* Table 2].}
|
|
455
|
+
*
|
|
456
|
+
* @param[out] r Output byte array (of length MLKEM_POLYCOMPRESSEDBYTES_D11
|
|
457
|
+
* bytes).
|
|
458
|
+
* @param[in] a Input polynomial. Coefficients must be unsigned canonical,
|
|
459
|
+
* i.e. in [0,1,..,MLKEM_Q-1].
|
|
460
|
+
*/
|
|
513
461
|
MLK_INTERNAL_API
|
|
514
462
|
void mlk_poly_compress_d11(uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D11],
|
|
515
463
|
const mlk_poly *a);
|
|
516
464
|
|
|
517
465
|
#define mlk_poly_decompress_d5 MLK_NAMESPACE(poly_decompress_d5)
|
|
518
|
-
|
|
519
|
-
*
|
|
520
|
-
*
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
* (
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
|
|
536
|
-
* - `Decompress_{d_v} (ByteDecode_{d_v} (v))` appears in
|
|
537
|
-
* @[FIPS203, Algorithm 15 (K-PKE.Decrypt), L4],
|
|
538
|
-
* where `d_v=5` for ML-KEM-1024 @[FIPS203, Table 2].
|
|
539
|
-
*
|
|
540
|
-
**************************************************/
|
|
466
|
+
/**
|
|
467
|
+
* De-serialization and subsequent decompression (5 bits) of a polynomial;
|
|
468
|
+
* approximate inverse of mlk_poly_compress_d5.
|
|
469
|
+
*
|
|
470
|
+
* Upon return, the coefficients of the output polynomial are
|
|
471
|
+
* unsigned-canonical (non-negative and smaller than MLKEM_Q).
|
|
472
|
+
*
|
|
473
|
+
* @spec{Implements `Decompress_5 (ByteDecode_5 (a))`: ByteDecode_d
|
|
474
|
+
* @[FIPS203, Algorithm 6], Decompress_d @[FIPS203, Eq (4.8)], extended to
|
|
475
|
+
* vectors as per @[FIPS203, 2.4.8 Applying Algorithms to Arrays].
|
|
476
|
+
* `Decompress_{d_v} (ByteDecode_{d_v} (v))` appears in @[FIPS203, Algorithm
|
|
477
|
+
* 15 (K-PKE.Decrypt), L4], where `d_v=5` for ML-KEM-1024 @[FIPS203,
|
|
478
|
+
* Table 2].}
|
|
479
|
+
*
|
|
480
|
+
* @param[out] r Output polynomial.
|
|
481
|
+
* @param[in] a Input byte array (of length MLKEM_POLYCOMPRESSEDBYTES_D5
|
|
482
|
+
* bytes).
|
|
483
|
+
*/
|
|
541
484
|
MLK_INTERNAL_API
|
|
542
485
|
void mlk_poly_decompress_d5(mlk_poly *r,
|
|
543
486
|
const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D5]);
|
|
544
487
|
|
|
545
488
|
#define mlk_poly_decompress_d11 MLK_NAMESPACE(poly_decompress_d11)
|
|
546
|
-
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
* (
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
|
|
564
|
-
* - `Decompress_{d_u} (ByteDecode_{d_u} (u))` appears in
|
|
565
|
-
* @[FIPS203, Algorithm 15 (K-PKE.Decrypt), L3],
|
|
566
|
-
* where `d_u=11` for ML-KEM-1024 @[FIPS203, Table 2].
|
|
567
|
-
*
|
|
568
|
-
**************************************************/
|
|
489
|
+
/**
|
|
490
|
+
* De-serialization and subsequent decompression (11 bits) of a polynomial;
|
|
491
|
+
* approximate inverse of mlk_poly_compress_d11.
|
|
492
|
+
*
|
|
493
|
+
* Upon return, the coefficients of the output polynomial are
|
|
494
|
+
* unsigned-canonical (non-negative and smaller than MLKEM_Q).
|
|
495
|
+
*
|
|
496
|
+
* @spec{Implements `Decompress_11 (ByteDecode_11 (a))`: ByteDecode_d
|
|
497
|
+
* @[FIPS203, Algorithm 6], Decompress_d @[FIPS203, Eq (4.8)], extended to
|
|
498
|
+
* vectors as per @[FIPS203, 2.4.8 Applying Algorithms to Arrays].
|
|
499
|
+
* `Decompress_{d_u} (ByteDecode_{d_u} (u))` appears in @[FIPS203, Algorithm
|
|
500
|
+
* 15 (K-PKE.Decrypt), L3], where `d_u=11` for ML-KEM-1024 @[FIPS203,
|
|
501
|
+
* Table 2].}
|
|
502
|
+
*
|
|
503
|
+
* @param[out] r Output polynomial.
|
|
504
|
+
* @param[in] a Input byte array (of length MLKEM_POLYCOMPRESSEDBYTES_D11
|
|
505
|
+
* bytes).
|
|
506
|
+
*/
|
|
569
507
|
MLK_INTERNAL_API
|
|
570
508
|
void mlk_poly_decompress_d11(mlk_poly *r,
|
|
571
509
|
const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D11]);
|
|
572
510
|
#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */
|
|
573
511
|
|
|
574
512
|
#define mlk_poly_tobytes MLK_NAMESPACE(poly_tobytes)
|
|
575
|
-
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
* Description: Serialization of a polynomial.
|
|
579
|
-
* Signed coefficients are converted to
|
|
580
|
-
* unsigned form before serialization.
|
|
513
|
+
/**
|
|
514
|
+
* Serialization of a polynomial. Signed coefficients are converted to
|
|
515
|
+
* unsigned form before serialization.
|
|
581
516
|
*
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
* with each coefficient in the range [0,1,..,Q-1]
|
|
585
|
-
* OUTPUT
|
|
586
|
-
* - r: pointer to output byte array
|
|
587
|
-
* (of MLKEM_POLYBYTES bytes)
|
|
517
|
+
* @spec{Implements ByteEncode_12 @[FIPS203, Algorithm 5]. Extended to
|
|
518
|
+
* vectors as per @[FIPS203, 2.4.8 Applying Algorithms to Arrays].}
|
|
588
519
|
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
|
|
593
|
-
**************************************************/
|
|
520
|
+
* @param[out] r Output byte array (of MLKEM_POLYBYTES bytes).
|
|
521
|
+
* @param[in] a Input polynomial, with each coefficient in the range
|
|
522
|
+
* [0,1,..,MLKEM_Q-1].
|
|
523
|
+
*/
|
|
594
524
|
MLK_INTERNAL_API
|
|
595
525
|
void mlk_poly_tobytes(uint8_t r[MLKEM_POLYBYTES], const mlk_poly *a)
|
|
596
526
|
__contract__(
|
|
@@ -602,24 +532,16 @@ __contract__(
|
|
|
602
532
|
|
|
603
533
|
|
|
604
534
|
#define mlk_poly_frombytes MLK_NAMESPACE(poly_frombytes)
|
|
605
|
-
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
* Description: De-serialization of a polynomial.
|
|
535
|
+
/**
|
|
536
|
+
* De-serialization of a polynomial.
|
|
609
537
|
*
|
|
610
|
-
*
|
|
611
|
-
*
|
|
612
|
-
* (of MLKEM_POLYBYTES bytes)
|
|
613
|
-
* OUTPUT
|
|
614
|
-
* - r: pointer to output polynomial, with
|
|
615
|
-
* each coefficient unsigned and in the range
|
|
616
|
-
* 0 .. 4095
|
|
538
|
+
* @spec{Implements ByteDecode_12 @[FIPS203, Algorithm 6]. Extended to
|
|
539
|
+
* vectors as per @[FIPS203, 2.4.8 Applying Algorithms to Arrays].}
|
|
617
540
|
*
|
|
618
|
-
*
|
|
619
|
-
*
|
|
620
|
-
*
|
|
621
|
-
|
|
622
|
-
**************************************************/
|
|
541
|
+
* @param[out] r Output polynomial, with each coefficient unsigned and in
|
|
542
|
+
* the range 0..4095.
|
|
543
|
+
* @param[in] a Input byte array (of MLKEM_POLYBYTES bytes).
|
|
544
|
+
*/
|
|
623
545
|
MLK_INTERNAL_API
|
|
624
546
|
void mlk_poly_frombytes(mlk_poly *r, const uint8_t a[MLKEM_POLYBYTES])
|
|
625
547
|
__contract__(
|
|
@@ -631,23 +553,18 @@ __contract__(
|
|
|
631
553
|
|
|
632
554
|
|
|
633
555
|
#define mlk_poly_frommsg MLK_NAMESPACE(poly_frommsg)
|
|
634
|
-
|
|
635
|
-
*
|
|
636
|
-
*
|
|
637
|
-
* Description: Convert 32-byte message to polynomial
|
|
556
|
+
/**
|
|
557
|
+
* Convert a 32-byte message to a polynomial.
|
|
638
558
|
*
|
|
639
|
-
*
|
|
640
|
-
*
|
|
559
|
+
* @spec{Implements `Decompress_1 (ByteDecode_1 (a))`: ByteDecode_d
|
|
560
|
+
* @[FIPS203, Algorithm 6], Decompress_d @[FIPS203, Eq (4.8)], extended to
|
|
561
|
+
* vectors as per @[FIPS203, 2.4.8 Applying Algorithms to Arrays].
|
|
562
|
+
* `Decompress_1 (ByteDecode_1 (w))` appears in @[FIPS203, Algorithm 15
|
|
563
|
+
* (K-PKE.Encrypt), L20].}
|
|
641
564
|
*
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
|
|
645
|
-
* Extended to vectors as per
|
|
646
|
-
* @[FIPS203, 2.4.8 Applying Algorithms to Arrays]
|
|
647
|
-
* - `Decompress_1 (ByteDecode_1 (w))` appears in
|
|
648
|
-
* @[FIPS203, Algorithm 15 (K-PKE.Encrypt), L20].
|
|
649
|
-
*
|
|
650
|
-
**************************************************/
|
|
565
|
+
* @param[out] r Output polynomial.
|
|
566
|
+
* @param[in] msg Input message.
|
|
567
|
+
*/
|
|
651
568
|
MLK_INTERNAL_API
|
|
652
569
|
void mlk_poly_frommsg(mlk_poly *r, const uint8_t msg[MLKEM_INDCPA_MSGBYTES])
|
|
653
570
|
__contract__(
|
|
@@ -658,24 +575,18 @@ __contract__(
|
|
|
658
575
|
);
|
|
659
576
|
|
|
660
577
|
#define mlk_poly_tomsg MLK_NAMESPACE(poly_tomsg)
|
|
661
|
-
|
|
662
|
-
*
|
|
663
|
-
*
|
|
664
|
-
* Description: Convert polynomial to 32-byte message
|
|
578
|
+
/**
|
|
579
|
+
* Convert a polynomial to a 32-byte message.
|
|
665
580
|
*
|
|
666
|
-
*
|
|
667
|
-
*
|
|
668
|
-
*
|
|
581
|
+
* @spec{Implements `ByteEncode_1 (Compress_1 (a))`: ByteEncode_d
|
|
582
|
+
* @[FIPS203, Algorithm 5], Compress_d @[FIPS203, Eq (4.7)], extended to
|
|
583
|
+
* vectors as per @[FIPS203, 2.4.8 Applying Algorithms to Arrays].
|
|
584
|
+
* `ByteEncode_1 (Compress_1 (w))` appears in @[FIPS203, Algorithm 14
|
|
585
|
+
* (K-PKE.Decrypt), L7].}
|
|
669
586
|
*
|
|
670
|
-
*
|
|
671
|
-
*
|
|
672
|
-
|
|
673
|
-
* Extended to vectors as per
|
|
674
|
-
* @[FIPS203, 2.4.8 Applying Algorithms to Arrays]
|
|
675
|
-
* - `ByteEncode_1 (Compress_1 (w))` appears in
|
|
676
|
-
* @[FIPS203, Algorithm 14 (K-PKE.Decrypt), L7].
|
|
677
|
-
*
|
|
678
|
-
**************************************************/
|
|
587
|
+
* @param[out] msg Output message.
|
|
588
|
+
* @param[in] r Input polynomial. Coefficients must be unsigned canonical.
|
|
589
|
+
*/
|
|
679
590
|
MLK_INTERNAL_API
|
|
680
591
|
void mlk_poly_tomsg(uint8_t msg[MLKEM_INDCPA_MSGBYTES], const mlk_poly *r)
|
|
681
592
|
__contract__(
|