pq_crypto 0.6.3 → 0.6.5
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/.github/workflows/ci.yml +149 -17
- data/CHANGELOG.md +73 -0
- data/GET_STARTED.md +1 -1
- data/README.md +7 -2
- data/ext/pqcrypto/extconf.rb +264 -24
- data/ext/pqcrypto/pqcrypto_version.h +1 -1
- data/ext/pqcrypto/vendor/.vendored +4 -4
- data/ext/pqcrypto/vendor/mlkem-native/README.md +2 -4
- data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +98 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +8 -7
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +21 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +45 -44
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +36 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +13 -30
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +25 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +14 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/context.h +42 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/auto.h +20 -12
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +5 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +5 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +5 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +10 -7
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +10 -7
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +2 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +2 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +5 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +2 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/mve.h +5 -19
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +8 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/{state_extract_bytes_x4_mve.S → keccak_f1600_x4_state_extract_bytes_mve.S} +14 -14
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/{state_xor_bytes_x4_mve.S → keccak_f1600_x4_state_xor_bytes_mve.S} +12 -12
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +36 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +22 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +6 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +11 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +25 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +44 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +2 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +11 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{intt_aarch64_asm.S → mlkem_intt_aarch64_asm.S} +16 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{ntt_aarch64_asm.S → mlkem_ntt_aarch64_asm.S} +10 -7
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_mulcache_compute_aarch64_asm.S → mlkem_poly_mulcache_compute_aarch64_asm.S} +6 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_reduce_aarch64_asm.S → mlkem_poly_reduce_aarch64_asm.S} +6 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tobytes_aarch64_asm.S → mlkem_poly_tobytes_aarch64_asm.S} +12 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tomont_aarch64_asm.S → mlkem_poly_tomont_aarch64_asm.S} +11 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S} +6 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S} +6 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S} +6 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{rej_uniform_aarch64_asm.S → mlkem_rej_uniform_aarch64_asm.S} +17 -17
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +21 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +1 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/meta.h +4 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{intt_ppc_asm.S → mlkem_intt_ppc_asm.S} +29 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{ntt_ppc_asm.S → mlkem_ntt_ppc_asm.S} +22 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{poly_tomont_ppc_asm.S → mlkem_poly_tomont_ppc_asm.S} +25 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{reduce_ppc_asm.S → mlkem_reduce_ppc_asm.S} +22 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +4 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/arith_native_riscv64.h +4 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +6 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +25 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +20 -20
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +14 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +8 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{intt_avx2_asm.S → mlkem_intt_avx2_asm.S} +27 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntt_avx2_asm.S → mlkem_ntt_avx2_asm.S} +23 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttfrombytes_avx2_asm.S → mlkem_nttfrombytes_avx2_asm.S} +27 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntttobytes_avx2_asm.S → mlkem_ntttobytes_avx2_asm.S} +27 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttunpack_avx2_asm.S → mlkem_nttunpack_avx2_asm.S} +17 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d10_avx2_asm.S → mlkem_poly_compress_d10_avx2_asm.S} +34 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d11_avx2_asm.S → mlkem_poly_compress_d11_avx2_asm.S} +33 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d4_avx2_asm.S → mlkem_poly_compress_d4_avx2_asm.S} +34 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d5_avx2_asm.S → mlkem_poly_compress_d5_avx2_asm.S} +33 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d10_avx2_asm.S → mlkem_poly_decompress_d10_avx2_asm.S} +32 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d11_avx2_asm.S → mlkem_poly_decompress_d11_avx2_asm.S} +32 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d4_avx2_asm.S → mlkem_poly_decompress_d4_avx2_asm.S} +32 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d5_avx2_asm.S → mlkem_poly_decompress_d5_avx2_asm.S} +32 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_mulcache_compute_avx2_asm.S → mlkem_poly_mulcache_compute_avx2_asm.S} +29 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S} +35 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S} +35 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S} +35 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{reduce_avx2_asm.S → mlkem_reduce_avx2_asm.S} +17 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{rej_uniform_avx2_asm.S → mlkem_rej_uniform_avx2_asm.S} +40 -7
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{tomont_avx2_asm.S → mlkem_tomont_avx2_asm.S} +20 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +7 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +6 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +25 -4
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +33 -4
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +4 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +4 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +19 -1
- data/lib/pq_crypto/version.rb +1 -1
- data/script/vendor_libs.rb +3 -3
- metadata +41 -43
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* levels, you should include this file once with
|
|
23
23
|
* MLK_CONFIG_MULTILEVEL_WITH_SHARED set.
|
|
24
24
|
*
|
|
25
|
-
* (You could also follow the same pattern as for
|
|
25
|
+
* (You could also follow the same pattern as for mlkem_native.c
|
|
26
26
|
* and include it for every level, setting MLK_CONFIG_MULTILEVEL_NO_SHARED
|
|
27
27
|
* for all but one. For builds with MLK_CONFIG_MULTILEVEL_NO_SHARED, this
|
|
28
28
|
* file will then be ignored.)
|
|
@@ -60,46 +60,46 @@
|
|
|
60
60
|
|
|
61
61
|
#if defined(MLK_CONFIG_USE_NATIVE_BACKEND_ARITH)
|
|
62
62
|
#if defined(MLK_SYS_AARCH64)
|
|
63
|
-
#include "src/native/aarch64/src/
|
|
64
|
-
#include "src/native/aarch64/src/
|
|
65
|
-
#include "src/native/aarch64/src/
|
|
66
|
-
#include "src/native/aarch64/src/
|
|
67
|
-
#include "src/native/aarch64/src/
|
|
68
|
-
#include "src/native/aarch64/src/
|
|
69
|
-
#include "src/native/aarch64/src/
|
|
70
|
-
#include "src/native/aarch64/src/
|
|
71
|
-
#include "src/native/aarch64/src/
|
|
72
|
-
#include "src/native/aarch64/src/
|
|
63
|
+
#include "src/native/aarch64/src/mlkem_intt_aarch64_asm.S"
|
|
64
|
+
#include "src/native/aarch64/src/mlkem_ntt_aarch64_asm.S"
|
|
65
|
+
#include "src/native/aarch64/src/mlkem_poly_mulcache_compute_aarch64_asm.S"
|
|
66
|
+
#include "src/native/aarch64/src/mlkem_poly_reduce_aarch64_asm.S"
|
|
67
|
+
#include "src/native/aarch64/src/mlkem_poly_tobytes_aarch64_asm.S"
|
|
68
|
+
#include "src/native/aarch64/src/mlkem_poly_tomont_aarch64_asm.S"
|
|
69
|
+
#include "src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S"
|
|
70
|
+
#include "src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S"
|
|
71
|
+
#include "src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S"
|
|
72
|
+
#include "src/native/aarch64/src/mlkem_rej_uniform_aarch64_asm.S"
|
|
73
73
|
#endif /* MLK_SYS_AARCH64 */
|
|
74
74
|
#if defined(MLK_SYS_X86_64)
|
|
75
|
-
#include "src/native/x86_64/src/
|
|
76
|
-
#include "src/native/x86_64/src/
|
|
77
|
-
#include "src/native/x86_64/src/
|
|
78
|
-
#include "src/native/x86_64/src/
|
|
79
|
-
#include "src/native/x86_64/src/
|
|
80
|
-
#include "src/native/x86_64/src/
|
|
81
|
-
#include "src/native/x86_64/src/
|
|
82
|
-
#include "src/native/x86_64/src/
|
|
83
|
-
#include "src/native/x86_64/src/
|
|
84
|
-
#include "src/native/x86_64/src/
|
|
85
|
-
#include "src/native/x86_64/src/
|
|
86
|
-
#include "src/native/x86_64/src/
|
|
87
|
-
#include "src/native/x86_64/src/
|
|
88
|
-
#include "src/native/x86_64/src/
|
|
89
|
-
#include "src/native/x86_64/src/
|
|
90
|
-
#include "src/native/x86_64/src/
|
|
91
|
-
#include "src/native/x86_64/src/
|
|
92
|
-
#include "src/native/x86_64/src/
|
|
93
|
-
#include "src/native/x86_64/src/
|
|
94
|
-
#include "src/native/x86_64/src/
|
|
75
|
+
#include "src/native/x86_64/src/mlkem_intt_avx2_asm.S"
|
|
76
|
+
#include "src/native/x86_64/src/mlkem_ntt_avx2_asm.S"
|
|
77
|
+
#include "src/native/x86_64/src/mlkem_nttfrombytes_avx2_asm.S"
|
|
78
|
+
#include "src/native/x86_64/src/mlkem_ntttobytes_avx2_asm.S"
|
|
79
|
+
#include "src/native/x86_64/src/mlkem_nttunpack_avx2_asm.S"
|
|
80
|
+
#include "src/native/x86_64/src/mlkem_poly_compress_d10_avx2_asm.S"
|
|
81
|
+
#include "src/native/x86_64/src/mlkem_poly_compress_d11_avx2_asm.S"
|
|
82
|
+
#include "src/native/x86_64/src/mlkem_poly_compress_d4_avx2_asm.S"
|
|
83
|
+
#include "src/native/x86_64/src/mlkem_poly_compress_d5_avx2_asm.S"
|
|
84
|
+
#include "src/native/x86_64/src/mlkem_poly_decompress_d10_avx2_asm.S"
|
|
85
|
+
#include "src/native/x86_64/src/mlkem_poly_decompress_d11_avx2_asm.S"
|
|
86
|
+
#include "src/native/x86_64/src/mlkem_poly_decompress_d4_avx2_asm.S"
|
|
87
|
+
#include "src/native/x86_64/src/mlkem_poly_decompress_d5_avx2_asm.S"
|
|
88
|
+
#include "src/native/x86_64/src/mlkem_poly_mulcache_compute_avx2_asm.S"
|
|
89
|
+
#include "src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S"
|
|
90
|
+
#include "src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S"
|
|
91
|
+
#include "src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S"
|
|
92
|
+
#include "src/native/x86_64/src/mlkem_reduce_avx2_asm.S"
|
|
93
|
+
#include "src/native/x86_64/src/mlkem_rej_uniform_avx2_asm.S"
|
|
94
|
+
#include "src/native/x86_64/src/mlkem_tomont_avx2_asm.S"
|
|
95
95
|
#endif /* MLK_SYS_X86_64 */
|
|
96
96
|
#if defined(MLK_SYS_RISCV64)
|
|
97
97
|
#endif
|
|
98
98
|
#if defined(MLK_SYS_PPC64LE)
|
|
99
|
-
#include "src/native/ppc64le/src/
|
|
100
|
-
#include "src/native/ppc64le/src/
|
|
101
|
-
#include "src/native/ppc64le/src/
|
|
102
|
-
#include "src/native/ppc64le/src/
|
|
99
|
+
#include "src/native/ppc64le/src/mlkem_intt_ppc_asm.S"
|
|
100
|
+
#include "src/native/ppc64le/src/mlkem_ntt_ppc_asm.S"
|
|
101
|
+
#include "src/native/ppc64le/src/mlkem_poly_tomont_ppc_asm.S"
|
|
102
|
+
#include "src/native/ppc64le/src/mlkem_reduce_ppc_asm.S"
|
|
103
103
|
#endif /* MLK_SYS_PPC64LE */
|
|
104
104
|
#endif /* MLK_CONFIG_USE_NATIVE_BACKEND_ARITH */
|
|
105
105
|
|
|
@@ -116,8 +116,8 @@
|
|
|
116
116
|
#endif
|
|
117
117
|
#if defined(MLK_SYS_ARMV81M_MVE)
|
|
118
118
|
#include "src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S"
|
|
119
|
-
#include "src/fips202/native/armv81m/src/
|
|
120
|
-
#include "src/fips202/native/armv81m/src/
|
|
119
|
+
#include "src/fips202/native/armv81m/src/keccak_f1600_x4_state_extract_bytes_mve.S"
|
|
120
|
+
#include "src/fips202/native/armv81m/src/keccak_f1600_x4_state_xor_bytes_mve.S"
|
|
121
121
|
#endif
|
|
122
122
|
#endif /* MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202 */
|
|
123
123
|
|
|
@@ -226,11 +226,6 @@
|
|
|
226
226
|
#undef MLK_COMMON_H
|
|
227
227
|
#undef MLK_CONCAT
|
|
228
228
|
#undef MLK_CONCAT_
|
|
229
|
-
#undef MLK_CONTEXT_PARAMETERS_0
|
|
230
|
-
#undef MLK_CONTEXT_PARAMETERS_1
|
|
231
|
-
#undef MLK_CONTEXT_PARAMETERS_2
|
|
232
|
-
#undef MLK_CONTEXT_PARAMETERS_3
|
|
233
|
-
#undef MLK_CONTEXT_PARAMETERS_4
|
|
234
229
|
#undef MLK_EMPTY_CU
|
|
235
230
|
#undef MLK_ERR_FAIL
|
|
236
231
|
#undef MLK_ERR_OUT_OF_MEMORY
|
|
@@ -335,6 +330,13 @@
|
|
|
335
330
|
#undef mlk_poly_frommsg
|
|
336
331
|
#undef mlk_poly_tobytes
|
|
337
332
|
#undef mlk_poly_tomsg
|
|
333
|
+
/* mlkem/src/context.h */
|
|
334
|
+
#undef MLK_CONTEXT_H
|
|
335
|
+
#undef MLK_CONTEXT_PARAMETERS_0
|
|
336
|
+
#undef MLK_CONTEXT_PARAMETERS_1
|
|
337
|
+
#undef MLK_CONTEXT_PARAMETERS_2
|
|
338
|
+
#undef MLK_CONTEXT_PARAMETERS_3
|
|
339
|
+
#undef MLK_CONTEXT_PARAMETERS_4
|
|
338
340
|
/* mlkem/src/debug.h */
|
|
339
341
|
#undef MLK_DEBUG_H
|
|
340
342
|
#undef mlk_assert
|
|
@@ -401,6 +403,7 @@
|
|
|
401
403
|
#undef MLK_SYSV_ABI_SUPPORTED
|
|
402
404
|
#undef MLK_SYS_AARCH64
|
|
403
405
|
#undef MLK_SYS_AARCH64_EB
|
|
406
|
+
#undef MLK_SYS_AARCH64_NEON
|
|
404
407
|
#undef MLK_SYS_APPLE
|
|
405
408
|
#undef MLK_SYS_ARMV81M_MVE
|
|
406
409
|
#undef MLK_SYS_BIG_ENDIAN
|
|
@@ -532,8 +535,6 @@
|
|
|
532
535
|
#undef MLK_USE_FIPS202_X4_NATIVE
|
|
533
536
|
#undef MLK_USE_FIPS202_X4_XOR_BYTES_NATIVE
|
|
534
537
|
#undef mlk_keccak_f1600_x4_native_impl
|
|
535
|
-
#undef mlk_keccak_f1600_x4_state_extract_bytes
|
|
536
|
-
#undef mlk_keccak_f1600_x4_state_xor_bytes
|
|
537
538
|
/* mlkem/src/fips202/native/armv81m/src/fips202_native_armv81m.h */
|
|
538
539
|
#undef MLK_FIPS202_NATIVE_ARMV81M_SRC_FIPS202_NATIVE_ARMV81M_H
|
|
539
540
|
#undef mlk_keccak_f1600_x4_mve_asm
|
|
@@ -99,6 +99,42 @@
|
|
|
99
99
|
*/
|
|
100
100
|
/* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */
|
|
101
101
|
|
|
102
|
+
/**
|
|
103
|
+
* MLK_CONFIG_NO_KEYPAIR_API
|
|
104
|
+
*
|
|
105
|
+
* By default, mlkem-native includes support for generating key pairs.
|
|
106
|
+
* If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude
|
|
107
|
+
* crypto_kem_keypair and crypto_kem_keypair_derand, and all internal
|
|
108
|
+
* APIs only needed by those functions.
|
|
109
|
+
*/
|
|
110
|
+
/* #define MLK_CONFIG_NO_KEYPAIR_API */
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* MLK_CONFIG_NO_ENCAPS_API
|
|
114
|
+
*
|
|
115
|
+
* By default, mlkem-native includes support for encapsulation. If you
|
|
116
|
+
* don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude
|
|
117
|
+
* crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and
|
|
118
|
+
* all internal APIs only needed by those functions.
|
|
119
|
+
*
|
|
120
|
+
* @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT
|
|
121
|
+
* as the current PCT implementation requires crypto_kem_enc().
|
|
122
|
+
*/
|
|
123
|
+
/* #define MLK_CONFIG_NO_ENCAPS_API */
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* MLK_CONFIG_NO_DECAPS_API
|
|
127
|
+
*
|
|
128
|
+
* By default, mlkem-native includes support for decapsulation. If you
|
|
129
|
+
* don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude
|
|
130
|
+
* crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only
|
|
131
|
+
* needed by those functions.
|
|
132
|
+
*
|
|
133
|
+
* @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT
|
|
134
|
+
* as the current PCT implementation requires crypto_kem_dec().
|
|
135
|
+
*/
|
|
136
|
+
/* #define MLK_CONFIG_NO_DECAPS_API */
|
|
137
|
+
|
|
102
138
|
/**
|
|
103
139
|
* MLK_CONFIG_NO_RANDOMIZED_API
|
|
104
140
|
*
|
|
@@ -125,6 +125,14 @@
|
|
|
125
125
|
#error Bad configuration: MLK_CONFIG_NO_RANDOMIZED_API is incompatible with MLK_CONFIG_KEYGEN_PCT as the current PCT implementation requires crypto_kem_enc()
|
|
126
126
|
#endif
|
|
127
127
|
|
|
128
|
+
#if defined(MLK_CONFIG_NO_ENCAPS_API) && defined(MLK_CONFIG_KEYGEN_PCT)
|
|
129
|
+
#error Bad configuration: MLK_CONFIG_NO_ENCAPS_API is incompatible with MLK_CONFIG_KEYGEN_PCT as the current PCT implementation requires crypto_kem_enc()
|
|
130
|
+
#endif
|
|
131
|
+
|
|
132
|
+
#if defined(MLK_CONFIG_NO_DECAPS_API) && defined(MLK_CONFIG_KEYGEN_PCT)
|
|
133
|
+
#error Bad configuration: MLK_CONFIG_NO_DECAPS_API is incompatible with MLK_CONFIG_KEYGEN_PCT as the current PCT implementation requires crypto_kem_dec()
|
|
134
|
+
#endif
|
|
135
|
+
|
|
128
136
|
#if defined(MLK_CONFIG_USE_NATIVE_BACKEND_ARITH)
|
|
129
137
|
#include MLK_CONFIG_ARITH_BACKEND_FILE
|
|
130
138
|
/* Include to enforce consistency of API and implementation,
|
|
@@ -188,36 +196,11 @@
|
|
|
188
196
|
#error Bad configuration: MLK_CONFIG_CUSTOM_ALLOC_FREE must be set together with MLK_CUSTOM_ALLOC and MLK_CUSTOM_FREE
|
|
189
197
|
#endif
|
|
190
198
|
|
|
191
|
-
/*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
|
|
196
|
-
* defining the function names and expand to either pass or discard the context
|
|
197
|
-
* argument as required by the current build. If there is no context parameter
|
|
198
|
-
* requested then these are removed from the prototypes and from all calls.
|
|
199
|
-
*/
|
|
200
|
-
#ifdef MLK_CONFIG_CONTEXT_PARAMETER
|
|
201
|
-
#define MLK_CONTEXT_PARAMETERS_0(context) (context)
|
|
202
|
-
#define MLK_CONTEXT_PARAMETERS_1(arg0, context) (arg0, context)
|
|
203
|
-
#define MLK_CONTEXT_PARAMETERS_2(arg0, arg1, context) (arg0, arg1, context)
|
|
204
|
-
#define MLK_CONTEXT_PARAMETERS_3(arg0, arg1, arg2, context) \
|
|
205
|
-
(arg0, arg1, arg2, context)
|
|
206
|
-
#define MLK_CONTEXT_PARAMETERS_4(arg0, arg1, arg2, arg3, context) \
|
|
207
|
-
(arg0, arg1, arg2, arg3, context)
|
|
208
|
-
#else /* MLK_CONFIG_CONTEXT_PARAMETER */
|
|
209
|
-
#define MLK_CONTEXT_PARAMETERS_0(context) ()
|
|
210
|
-
#define MLK_CONTEXT_PARAMETERS_1(arg0, context) (arg0)
|
|
211
|
-
#define MLK_CONTEXT_PARAMETERS_2(arg0, arg1, context) (arg0, arg1)
|
|
212
|
-
#define MLK_CONTEXT_PARAMETERS_3(arg0, arg1, arg2, context) (arg0, arg1, arg2)
|
|
213
|
-
#define MLK_CONTEXT_PARAMETERS_4(arg0, arg1, arg2, arg3, context) \
|
|
214
|
-
(arg0, arg1, arg2, arg3)
|
|
215
|
-
#endif /* !MLK_CONFIG_CONTEXT_PARAMETER */
|
|
216
|
-
|
|
217
|
-
#if defined(MLK_CONFIG_CONTEXT_PARAMETER_TYPE) != \
|
|
218
|
-
defined(MLK_CONFIG_CONTEXT_PARAMETER)
|
|
219
|
-
#error MLK_CONFIG_CONTEXT_PARAMETER_TYPE must be defined if and only if MLK_CONFIG_CONTEXT_PARAMETER is defined
|
|
220
|
-
#endif
|
|
199
|
+
/* Context-parameter machinery (MLK_CONTEXT_PARAMETERS_n and related config
|
|
200
|
+
* checks). Kept in a separate, level-generic header for readability; included
|
|
201
|
+
* here so it is available to the allocation macros below and to all consumers
|
|
202
|
+
* of common.h. */
|
|
203
|
+
#include "context.h"
|
|
221
204
|
|
|
222
205
|
#if !defined(MLK_CONFIG_CUSTOM_ALLOC_FREE)
|
|
223
206
|
/* Default: stack allocation */
|
|
@@ -26,7 +26,10 @@
|
|
|
26
26
|
#include "debug.h"
|
|
27
27
|
#include "verify.h"
|
|
28
28
|
|
|
29
|
-
#if defined(
|
|
29
|
+
#if (!defined(MLK_CONFIG_NO_ENCAPS_API) || \
|
|
30
|
+
!defined(MLK_CONFIG_NO_DECAPS_API)) && \
|
|
31
|
+
(defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 2 || \
|
|
32
|
+
MLKEM_K == 3)
|
|
30
33
|
/* Reference: `poly_compress()` in the reference implementation @[REF],
|
|
31
34
|
* for ML-KEM-{512,768}.
|
|
32
35
|
* - In contrast to the reference implementation, we assume
|
|
@@ -158,6 +161,7 @@ __contract__(
|
|
|
158
161
|
mlk_poly_compress_d10_c(r, a);
|
|
159
162
|
}
|
|
160
163
|
|
|
164
|
+
#if !defined(MLK_CONFIG_NO_DECAPS_API)
|
|
161
165
|
/* Reference: `poly_decompress()` in the reference implementation @[REF],
|
|
162
166
|
* for ML-KEM-{512,768}. */
|
|
163
167
|
MLK_STATIC_TESTABLE void mlk_poly_decompress_d4_c(
|
|
@@ -268,9 +272,14 @@ __contract__(
|
|
|
268
272
|
|
|
269
273
|
mlk_poly_decompress_d10_c(r, a);
|
|
270
274
|
}
|
|
271
|
-
#endif /*
|
|
272
|
-
|
|
273
|
-
|
|
275
|
+
#endif /* !MLK_CONFIG_NO_DECAPS_API */
|
|
276
|
+
#endif /* (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) && \
|
|
277
|
+
(MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3) \
|
|
278
|
+
*/
|
|
279
|
+
|
|
280
|
+
#if (!defined(MLK_CONFIG_NO_ENCAPS_API) || \
|
|
281
|
+
!defined(MLK_CONFIG_NO_DECAPS_API)) && \
|
|
282
|
+
(defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4)
|
|
274
283
|
/* Reference: `poly_compress()` in the reference implementation @[REF],
|
|
275
284
|
* for ML-KEM-1024.
|
|
276
285
|
* - In contrast to the reference implementation, we assume
|
|
@@ -409,6 +418,7 @@ __contract__(
|
|
|
409
418
|
mlk_poly_compress_d11_c(r, a);
|
|
410
419
|
}
|
|
411
420
|
|
|
421
|
+
#if !defined(MLK_CONFIG_NO_DECAPS_API)
|
|
412
422
|
/* Reference: `poly_decompress()` in the reference implementation @[REF],
|
|
413
423
|
* for ML-KEM-1024. */
|
|
414
424
|
MLK_STATIC_TESTABLE void mlk_poly_decompress_d5_c(
|
|
@@ -554,8 +564,11 @@ __contract__(
|
|
|
554
564
|
mlk_poly_decompress_d11_c(r, a);
|
|
555
565
|
}
|
|
556
566
|
|
|
557
|
-
#endif /*
|
|
567
|
+
#endif /* !MLK_CONFIG_NO_DECAPS_API */
|
|
568
|
+
#endif /* (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) && \
|
|
569
|
+
(MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */
|
|
558
570
|
|
|
571
|
+
#if !defined(MLK_CONFIG_NO_KEYPAIR_API) || !defined(MLK_CONFIG_NO_ENCAPS_API)
|
|
559
572
|
/* Reference: `poly_tobytes()` in the reference implementation @[REF].
|
|
560
573
|
* - In contrast to the reference implementation, we assume
|
|
561
574
|
* unsigned canonical coefficients here.
|
|
@@ -620,7 +633,9 @@ void mlk_poly_tobytes(uint8_t r[MLKEM_POLYBYTES], const mlk_poly *a)
|
|
|
620
633
|
|
|
621
634
|
mlk_poly_tobytes_c(r, a);
|
|
622
635
|
}
|
|
636
|
+
#endif /* !MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API */
|
|
623
637
|
|
|
638
|
+
#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
|
|
624
639
|
/* Reference: `poly_frombytes()` in the reference implementation @[REF]. */
|
|
625
640
|
MLK_STATIC_TESTABLE void mlk_poly_frombytes_c(mlk_poly *r,
|
|
626
641
|
const uint8_t a[MLKEM_POLYBYTES])
|
|
@@ -668,7 +683,9 @@ void mlk_poly_frombytes(mlk_poly *r, const uint8_t a[MLKEM_POLYBYTES])
|
|
|
668
683
|
|
|
669
684
|
mlk_poly_frombytes_c(r, a);
|
|
670
685
|
}
|
|
686
|
+
#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
|
|
671
687
|
|
|
688
|
+
#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
|
|
672
689
|
/* Reference: `poly_frommsg()` in the reference implementation @[REF].
|
|
673
690
|
* - We use a value barrier around the bit-selection mask to
|
|
674
691
|
* reduce the risk of compiler-introduced branches.
|
|
@@ -706,7 +723,9 @@ void mlk_poly_frommsg(mlk_poly *r, const uint8_t msg[MLKEM_INDCPA_MSGBYTES])
|
|
|
706
723
|
}
|
|
707
724
|
mlk_assert_abs_bound(r, MLKEM_N, MLKEM_Q);
|
|
708
725
|
}
|
|
726
|
+
#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
|
|
709
727
|
|
|
728
|
+
#if !defined(MLK_CONFIG_NO_DECAPS_API)
|
|
710
729
|
/* Reference: `poly_tomsg()` in the reference implementation @[REF].
|
|
711
730
|
* - In contrast to the reference implementation, we assume
|
|
712
731
|
* unsigned canonical coefficients here.
|
|
@@ -735,6 +754,7 @@ void mlk_poly_tomsg(uint8_t msg[MLKEM_INDCPA_MSGBYTES], const mlk_poly *r)
|
|
|
735
754
|
}
|
|
736
755
|
}
|
|
737
756
|
}
|
|
757
|
+
#endif /* !MLK_CONFIG_NO_DECAPS_API */
|
|
738
758
|
|
|
739
759
|
#else /* !MLK_CONFIG_MULTILEVEL_NO_SHARED */
|
|
740
760
|
|
|
@@ -333,6 +333,7 @@ __contract__(
|
|
|
333
333
|
return (int16_t)((((uint32_t)u * MLKEM_Q) + 1024) >> 11);
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
+
#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
|
|
336
337
|
#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || (MLKEM_K == 2 || MLKEM_K == 3)
|
|
337
338
|
#define mlk_poly_compress_d4 MLK_NAMESPACE(poly_compress_d4)
|
|
338
339
|
/**
|
|
@@ -374,6 +375,7 @@ MLK_INTERNAL_API
|
|
|
374
375
|
void mlk_poly_compress_d10(uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D10],
|
|
375
376
|
const mlk_poly *a);
|
|
376
377
|
|
|
378
|
+
#if !defined(MLK_CONFIG_NO_DECAPS_API)
|
|
377
379
|
#define mlk_poly_decompress_d4 MLK_NAMESPACE(poly_decompress_d4)
|
|
378
380
|
/**
|
|
379
381
|
* De-serialization and subsequent decompression (4 bits) of a polynomial;
|
|
@@ -419,6 +421,7 @@ void mlk_poly_decompress_d4(mlk_poly *r,
|
|
|
419
421
|
MLK_INTERNAL_API
|
|
420
422
|
void mlk_poly_decompress_d10(mlk_poly *r,
|
|
421
423
|
const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D10]);
|
|
424
|
+
#endif /* !MLK_CONFIG_NO_DECAPS_API */
|
|
422
425
|
#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3 */
|
|
423
426
|
|
|
424
427
|
#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4
|
|
@@ -462,6 +465,7 @@ MLK_INTERNAL_API
|
|
|
462
465
|
void mlk_poly_compress_d11(uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D11],
|
|
463
466
|
const mlk_poly *a);
|
|
464
467
|
|
|
468
|
+
#if !defined(MLK_CONFIG_NO_DECAPS_API)
|
|
465
469
|
#define mlk_poly_decompress_d5 MLK_NAMESPACE(poly_decompress_d5)
|
|
466
470
|
/**
|
|
467
471
|
* De-serialization and subsequent decompression (5 bits) of a polynomial;
|
|
@@ -507,8 +511,11 @@ void mlk_poly_decompress_d5(mlk_poly *r,
|
|
|
507
511
|
MLK_INTERNAL_API
|
|
508
512
|
void mlk_poly_decompress_d11(mlk_poly *r,
|
|
509
513
|
const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D11]);
|
|
514
|
+
#endif /* !MLK_CONFIG_NO_DECAPS_API */
|
|
510
515
|
#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */
|
|
516
|
+
#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
|
|
511
517
|
|
|
518
|
+
#if !defined(MLK_CONFIG_NO_KEYPAIR_API) || !defined(MLK_CONFIG_NO_ENCAPS_API)
|
|
512
519
|
#define mlk_poly_tobytes MLK_NAMESPACE(poly_tobytes)
|
|
513
520
|
/**
|
|
514
521
|
* Serialization of a polynomial. Signed coefficients are converted to
|
|
@@ -529,8 +536,10 @@ __contract__(
|
|
|
529
536
|
requires(array_bound(a->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
|
|
530
537
|
assigns(memory_slice(r, MLKEM_POLYBYTES))
|
|
531
538
|
);
|
|
539
|
+
#endif /* !MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API */
|
|
532
540
|
|
|
533
541
|
|
|
542
|
+
#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
|
|
534
543
|
#define mlk_poly_frombytes MLK_NAMESPACE(poly_frombytes)
|
|
535
544
|
/**
|
|
536
545
|
* De-serialization of a polynomial.
|
|
@@ -550,8 +559,10 @@ __contract__(
|
|
|
550
559
|
assigns(memory_slice(r, sizeof(mlk_poly)))
|
|
551
560
|
ensures(array_bound(r->coeffs, 0, MLKEM_N, 0, MLKEM_UINT12_LIMIT))
|
|
552
561
|
);
|
|
562
|
+
#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
|
|
553
563
|
|
|
554
564
|
|
|
565
|
+
#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
|
|
555
566
|
#define mlk_poly_frommsg MLK_NAMESPACE(poly_frommsg)
|
|
556
567
|
/**
|
|
557
568
|
* Convert a 32-byte message to a polynomial.
|
|
@@ -573,7 +584,9 @@ __contract__(
|
|
|
573
584
|
assigns(memory_slice(r, sizeof(mlk_poly)))
|
|
574
585
|
ensures(array_bound(r->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
|
|
575
586
|
);
|
|
587
|
+
#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
|
|
576
588
|
|
|
589
|
+
#if !defined(MLK_CONFIG_NO_DECAPS_API)
|
|
577
590
|
#define mlk_poly_tomsg MLK_NAMESPACE(poly_tomsg)
|
|
578
591
|
/**
|
|
579
592
|
* Convert a polynomial to a 32-byte message.
|
|
@@ -595,5 +608,6 @@ __contract__(
|
|
|
595
608
|
requires(array_bound(r->coeffs, 0, MLKEM_N, 0, MLKEM_Q))
|
|
596
609
|
assigns(memory_slice(msg, MLKEM_INDCPA_MSGBYTES))
|
|
597
610
|
);
|
|
611
|
+
#endif /* !MLK_CONFIG_NO_DECAPS_API */
|
|
598
612
|
|
|
599
613
|
#endif /* !MLK_COMPRESS_H */
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) The mlkem-native project authors
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
4
|
+
*/
|
|
5
|
+
#ifndef MLK_CONTEXT_H
|
|
6
|
+
#define MLK_CONTEXT_H
|
|
7
|
+
|
|
8
|
+
/* This header is included by common.h once the configuration has been pulled
|
|
9
|
+
* in; it is not meant to be included directly. */
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
* If the integration wants to provide a context parameter for use in
|
|
13
|
+
* platform-specific hooks, then it should define this parameter.
|
|
14
|
+
*
|
|
15
|
+
* The MLK_CONTEXT_PARAMETERS_n macros are intended to be used with macros
|
|
16
|
+
* defining the function names and expand to either pass or discard the context
|
|
17
|
+
* argument as required by the current build. If there is no context parameter
|
|
18
|
+
* requested then these are removed from the prototypes and from all calls.
|
|
19
|
+
*/
|
|
20
|
+
#ifdef MLK_CONFIG_CONTEXT_PARAMETER
|
|
21
|
+
#define MLK_CONTEXT_PARAMETERS_0(context) (context)
|
|
22
|
+
#define MLK_CONTEXT_PARAMETERS_1(arg0, context) (arg0, context)
|
|
23
|
+
#define MLK_CONTEXT_PARAMETERS_2(arg0, arg1, context) (arg0, arg1, context)
|
|
24
|
+
#define MLK_CONTEXT_PARAMETERS_3(arg0, arg1, arg2, context) \
|
|
25
|
+
(arg0, arg1, arg2, context)
|
|
26
|
+
#define MLK_CONTEXT_PARAMETERS_4(arg0, arg1, arg2, arg3, context) \
|
|
27
|
+
(arg0, arg1, arg2, arg3, context)
|
|
28
|
+
#else /* MLK_CONFIG_CONTEXT_PARAMETER */
|
|
29
|
+
#define MLK_CONTEXT_PARAMETERS_0(context) ()
|
|
30
|
+
#define MLK_CONTEXT_PARAMETERS_1(arg0, context) (arg0)
|
|
31
|
+
#define MLK_CONTEXT_PARAMETERS_2(arg0, arg1, context) (arg0, arg1)
|
|
32
|
+
#define MLK_CONTEXT_PARAMETERS_3(arg0, arg1, arg2, context) (arg0, arg1, arg2)
|
|
33
|
+
#define MLK_CONTEXT_PARAMETERS_4(arg0, arg1, arg2, arg3, context) \
|
|
34
|
+
(arg0, arg1, arg2, arg3)
|
|
35
|
+
#endif /* !MLK_CONFIG_CONTEXT_PARAMETER */
|
|
36
|
+
|
|
37
|
+
#if defined(MLK_CONFIG_CONTEXT_PARAMETER_TYPE) != \
|
|
38
|
+
defined(MLK_CONFIG_CONTEXT_PARAMETER)
|
|
39
|
+
#error MLK_CONFIG_CONTEXT_PARAMETER_TYPE must be defined if and only if MLK_CONFIG_CONTEXT_PARAMETER is defined
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
#endif /* !MLK_CONTEXT_H */
|
|
@@ -24,38 +24,44 @@
|
|
|
24
24
|
/*
|
|
25
25
|
* Keccak-f1600
|
|
26
26
|
*
|
|
27
|
-
* - On Arm-based Apple CPUs,
|
|
27
|
+
* - On Arm-based Apple CPUs, or if MLK_SYS_AARCH64_FAST_SHA3 is set,
|
|
28
|
+
* we pick a pure Neon implementation.
|
|
28
29
|
* - Otherwise, unless MLK_SYS_AARCH64_SLOW_BARREL_SHIFTER is set,
|
|
29
30
|
* we use lazy-rotation scalar assembly from @[HYBRID].
|
|
30
31
|
* - Otherwise, if MLK_SYS_AARCH64_SLOW_BARREL_SHIFTER is set, we
|
|
31
32
|
* fall back to the standard C implementation.
|
|
32
33
|
*/
|
|
33
|
-
#if defined(__ARM_FEATURE_SHA3) &&
|
|
34
|
+
#if defined(__ARM_FEATURE_SHA3) && \
|
|
35
|
+
(defined(__APPLE__) || defined(MLK_SYS_AARCH64_FAST_SHA3))
|
|
34
36
|
#include "x1_v84a.h"
|
|
35
37
|
#elif !defined(MLK_SYS_AARCH64_SLOW_BARREL_SHIFTER)
|
|
36
38
|
#include "x1_scalar.h"
|
|
37
39
|
#endif
|
|
38
40
|
|
|
41
|
+
/* Batched, SIMD-based Keccak-f1600 implementations. */
|
|
42
|
+
#if defined(MLK_SYS_AARCH64_NEON)
|
|
43
|
+
|
|
39
44
|
/*
|
|
40
45
|
* Keccak-f1600x2/x4
|
|
41
46
|
*
|
|
42
47
|
* The optimal implementation is highly CPU-specific; see @[HYBRID].
|
|
43
48
|
*
|
|
44
49
|
* For now, if v8.4-A is not implemented, we fall back to Keccak-f1600.
|
|
45
|
-
* If v8.4-A is implemented and we are on an Apple CPU
|
|
46
|
-
* Neon-based
|
|
47
|
-
*
|
|
48
|
-
* scalar/Neon/Neon hybrid.
|
|
49
|
-
* The reason for this distinction is that Apple CPUs
|
|
50
|
-
* the SHA3 instructions on all SIMD
|
|
51
|
-
* don't, and ordinary Neon
|
|
50
|
+
* If v8.4-A is implemented and we are on an Apple CPU or
|
|
51
|
+
* MLK_SYS_AARCH64_FAST_SHA3 is set, we use a plain Neon-based
|
|
52
|
+
* implementation.
|
|
53
|
+
* Otherwise, if v8.4-A is implemented, we use a scalar/Neon/Neon hybrid.
|
|
54
|
+
* The reason for this distinction is that Apple CPUs (and CPUs flagged with
|
|
55
|
+
* MLK_SYS_AARCH64_FAST_SHA3) implement the SHA3 instructions on all SIMD
|
|
56
|
+
* units, while Arm CPUs prior to Cortex-X4 don't, and ordinary Neon
|
|
57
|
+
* instructions are still needed.
|
|
52
58
|
*/
|
|
53
59
|
#if defined(__ARM_FEATURE_SHA3)
|
|
54
60
|
/*
|
|
55
|
-
* For Apple-M cores
|
|
56
|
-
* instructions only.
|
|
61
|
+
* For Apple-M cores (and CPUs flagged with MLK_SYS_AARCH64_FAST_SHA3), we
|
|
62
|
+
* use a plain implementation leveraging SHA3 instructions only.
|
|
57
63
|
*/
|
|
58
|
-
#if defined(__APPLE__)
|
|
64
|
+
#if defined(__APPLE__) || defined(MLK_SYS_AARCH64_FAST_SHA3)
|
|
59
65
|
#include "x2_v84a.h"
|
|
60
66
|
#else
|
|
61
67
|
#include "x4_v8a_v84a_scalar.h"
|
|
@@ -67,4 +73,6 @@
|
|
|
67
73
|
|
|
68
74
|
#endif /* !__ARM_FEATURE_SHA3 */
|
|
69
75
|
|
|
76
|
+
#endif /* MLK_SYS_AARCH64_NEON */
|
|
77
|
+
|
|
70
78
|
#endif /* !MLK_FIPS202_NATIVE_AARCH64_AUTO_H */
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
Description: AArch64 scalar implementation of Keccak-f[1600] permutation for single state
|
|
14
14
|
Signature: void mlk_keccak_f1600_x1_scalar_aarch64_asm(uint64_t state[25], const uint64_t rc[24])
|
|
15
15
|
ABI:
|
|
16
|
+
Architecture: aarch64
|
|
17
|
+
CallingConvention: AAPCS64
|
|
16
18
|
x0:
|
|
17
19
|
type: buffer
|
|
18
20
|
size_bytes: 200
|
|
@@ -66,7 +68,7 @@ MLK_ASM_FN_SYMBOL(keccak_f1600_x1_scalar_aarch64_asm)
|
|
|
66
68
|
.cfi_rel_offset x29, 0x70
|
|
67
69
|
.cfi_rel_offset x30, 0x78
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
Lmlk_keccak_f1600_x1_scalar_initial:
|
|
70
72
|
mov x26, x1
|
|
71
73
|
str x1, [sp, #0x8]
|
|
72
74
|
ldp x1, x6, [x0]
|
|
@@ -191,7 +193,7 @@ Lkeccak_f1600_x1_scalar_initial:
|
|
|
191
193
|
eor x14, x26, x6, ror #46
|
|
192
194
|
eor x6, x27, x29, ror #41
|
|
193
195
|
|
|
194
|
-
|
|
196
|
+
Lmlk_keccak_f1600_x1_scalar_loop:
|
|
195
197
|
eor x0, x15, x11, ror #52
|
|
196
198
|
eor x0, x0, x13, ror #48
|
|
197
199
|
eor x26, x8, x9, ror #57
|
|
@@ -304,7 +306,7 @@ Lkeccak_f1600_x1_scalar_loop:
|
|
|
304
306
|
bic x3, x0, x30, ror #5
|
|
305
307
|
eor x23, x3, x26, ror #52
|
|
306
308
|
eor x3, x29, x30, ror #24
|
|
307
|
-
b.le
|
|
309
|
+
b.le Lmlk_keccak_f1600_x1_scalar_loop
|
|
308
310
|
ror x6, x6, #0x2b
|
|
309
311
|
ror x11, x11, #0x32
|
|
310
312
|
ror x21, x21, #0x14
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
Description: AArch64 ARMv8.4-A implementation of Keccak-f[1600] permutation for single state
|
|
20
20
|
Signature: void mlk_keccak_f1600_x1_v84a_aarch64_asm(uint64_t state[25], const uint64_t rc[24])
|
|
21
21
|
ABI:
|
|
22
|
+
Architecture: aarch64
|
|
23
|
+
CallingConvention: AAPCS64
|
|
24
|
+
Features: [NEON, SHA3]
|
|
22
25
|
x0:
|
|
23
26
|
type: buffer
|
|
24
27
|
size_bytes: 200
|
|
@@ -91,7 +94,7 @@ MLK_ASM_FN_SYMBOL(keccak_f1600_x1_v84a_aarch64_asm)
|
|
|
91
94
|
ldr d24, [x0, #0xc0]
|
|
92
95
|
mov x2, #0x18 // =24
|
|
93
96
|
|
|
94
|
-
|
|
97
|
+
Lmlk_keccak_f1600_x1_v84a_loop:
|
|
95
98
|
eor3 v30.16b, v0.16b, v5.16b, v10.16b
|
|
96
99
|
eor3 v29.16b, v1.16b, v6.16b, v11.16b
|
|
97
100
|
eor3 v28.16b, v2.16b, v7.16b, v12.16b
|
|
@@ -160,7 +163,7 @@ Lkeccak_f1600_x1_v84a_loop:
|
|
|
160
163
|
bcax v4.16b, v4.16b, v27.16b, v30.16b
|
|
161
164
|
eor v0.16b, v0.16b, v31.16b
|
|
162
165
|
sub x2, x2, #0x1
|
|
163
|
-
cbnz x2,
|
|
166
|
+
cbnz x2, Lmlk_keccak_f1600_x1_v84a_loop
|
|
164
167
|
stp d0, d1, [x0]
|
|
165
168
|
stp d2, d3, [x0, #0x10]
|
|
166
169
|
stp d4, d5, [x0, #0x20]
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
Description: AArch64 ARMv8.4-A implementation of Keccak-f[1600] permutation for two sequential states
|
|
20
20
|
Signature: void mlk_keccak_f1600_x2_v84a_aarch64_asm(uint64_t state[50], const uint64_t rc[24])
|
|
21
21
|
ABI:
|
|
22
|
+
Architecture: aarch64
|
|
23
|
+
CallingConvention: AAPCS64
|
|
24
|
+
Features: [NEON, SHA3]
|
|
22
25
|
x0:
|
|
23
26
|
type: buffer
|
|
24
27
|
size_bytes: 400
|
|
@@ -118,7 +121,7 @@ MLK_ASM_FN_SYMBOL(keccak_f1600_x2_v84a_aarch64_asm)
|
|
|
118
121
|
trn1 v24.2d, v25.2d, v27.2d
|
|
119
122
|
mov x2, #0x18 // =24
|
|
120
123
|
|
|
121
|
-
|
|
124
|
+
Lmlk_keccak_f1600_x2_v84a_loop:
|
|
122
125
|
eor3 v30.16b, v0.16b, v5.16b, v10.16b
|
|
123
126
|
eor3 v29.16b, v1.16b, v6.16b, v11.16b
|
|
124
127
|
eor3 v28.16b, v2.16b, v7.16b, v12.16b
|
|
@@ -187,7 +190,7 @@ Lkeccak_f1600_x2_v84a_loop:
|
|
|
187
190
|
bcax v4.16b, v4.16b, v27.16b, v30.16b
|
|
188
191
|
eor v0.16b, v0.16b, v31.16b
|
|
189
192
|
sub x2, x2, #0x1
|
|
190
|
-
cbnz x2,
|
|
193
|
+
cbnz x2, Lmlk_keccak_f1600_x2_v84a_loop
|
|
191
194
|
sub x0, x0, #0xc0
|
|
192
195
|
add x2, x0, #0xc8
|
|
193
196
|
trn1 v25.2d, v0.2d, v1.2d
|