pq_crypto 0.6.1 → 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 +10 -0
- data/SECURITY.md +7 -0
- data/ext/pqcrypto/pqcrypto_version.h +1 -1
- data/ext/pqcrypto/vendor/.vendored +7 -7
- data/ext/pqcrypto/vendor/mldsa-native/README.md +23 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/README.md +23 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +114 -58
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +498 -461
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +145 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +456 -422
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +47 -25
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +26 -14
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +56 -81
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +17 -24
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.c +33 -40
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +67 -87
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +19 -14
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +13 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +84 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +10 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +6 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +22 -15
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +376 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +204 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +259 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +1077 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +987 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +16 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +2 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +4 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +60 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +48 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +18 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +658 -582
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +5 -100
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +26 -25
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +334 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +355 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +8 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/{xkcp.h → keccak_f1600_x4_avx2.h} +11 -8
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +44 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +454 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +52 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +37 -28
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +213 -196
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +248 -64
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt_aarch64_asm.S +753 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +129 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +145 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +177 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt_aarch64_asm.S +653 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery_aarch64_asm.S +84 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_aarch64_asm.S +53 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_aarch64_asm.S +55 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_aarch64_asm.S +86 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_aarch64_asm.S +86 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_aarch64_asm.S +103 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_aarch64_asm.S +111 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_aarch64_asm.S +75 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_aarch64_asm.S +72 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +23 -11
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_aarch64_asm.S +189 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_aarch64_asm.S +137 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_aarch64_asm.S +130 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +520 -516
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +34 -33
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +202 -242
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +25 -17
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +112 -28
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt_avx2_asm.S +2311 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt_avx2_asm.S +2383 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack_avx2_asm.S +238 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4_avx2_asm.S +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5_avx2_asm.S +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7_avx2_asm.S +187 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_avx2_asm.S +130 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2_asm.S +190 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +9 -8
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +10 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +8 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +8 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +130 -129
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +109 -180
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +169 -150
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +56 -40
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +149 -164
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +52 -57
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +132 -167
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +57 -424
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +167 -474
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +308 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +653 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +22 -29
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +37 -43
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +511 -367
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +456 -417
- data/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 +6 -6
- metadata +86 -71
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +0 -376
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +0 -204
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +0 -259
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +0 -1077
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +0 -987
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +0 -488
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +0 -16
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +0 -753
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +0 -129
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +0 -145
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +0 -177
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +0 -653
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +0 -79
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +0 -53
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +0 -55
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +0 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +0 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +0 -102
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +0 -110
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +0 -72
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +0 -69
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +0 -189
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +0 -135
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +0 -128
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +0 -2311
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +0 -2383
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +0 -239
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +0 -131
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +0 -139
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +0 -155
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +0 -187
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +0 -61
data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{tomont.S → tomont_avx2_asm.S}
RENAMED
|
@@ -28,17 +28,13 @@
|
|
|
28
28
|
|
|
29
29
|
/*
|
|
30
30
|
* WARNING: This file is auto-derived from the mlkem-native source file
|
|
31
|
-
* dev/x86_64/src/
|
|
31
|
+
* dev/x86_64/src/tomont_avx2_asm.S using scripts/simpasm. Do not modify it directly.
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
-
#if defined(__ELF__)
|
|
35
|
-
.section .note.GNU-stack,"",@progbits
|
|
36
|
-
#endif
|
|
37
|
-
|
|
38
34
|
.text
|
|
39
35
|
.balign 4
|
|
40
|
-
.global MLK_ASM_NAMESPACE(
|
|
41
|
-
MLK_ASM_FN_SYMBOL(
|
|
36
|
+
.global MLK_ASM_NAMESPACE(tomont_avx2_asm)
|
|
37
|
+
MLK_ASM_FN_SYMBOL(tomont_avx2_asm)
|
|
42
38
|
|
|
43
39
|
.cfi_startproc
|
|
44
40
|
movl $0xd010d01, %eax # imm = 0xD010D01
|
|
@@ -149,7 +145,11 @@ MLK_ASM_FN_SYMBOL(tomont_avx2)
|
|
|
149
145
|
retq
|
|
150
146
|
.cfi_endproc
|
|
151
147
|
|
|
152
|
-
MLK_ASM_FN_SIZE(
|
|
148
|
+
MLK_ASM_FN_SIZE(tomont_avx2_asm)
|
|
153
149
|
|
|
154
150
|
#endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \
|
|
155
151
|
*/
|
|
152
|
+
|
|
153
|
+
#if defined(__ELF__)
|
|
154
|
+
.section .note.GNU-stack,"",%progbits
|
|
155
|
+
#endif
|
|
@@ -28,22 +28,18 @@
|
|
|
28
28
|
#include "symmetric.h"
|
|
29
29
|
#include "verify.h"
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
*
|
|
31
|
+
/**
|
|
32
|
+
* Montgomery multiplication modulo MLKEM_Q.
|
|
33
33
|
*
|
|
34
|
-
*
|
|
34
|
+
* @reference{`fqmul()` in the reference implementation @[REF].}
|
|
35
35
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* Must be signed canonical (abs value <(MLKEM_Q+1)/2)
|
|
36
|
+
* @param a First factor. Can be any int16_t.
|
|
37
|
+
* @param b Second factor. Must be signed canonical
|
|
38
|
+
* (abs value < (MLKEM_Q+1)/2).
|
|
40
39
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
**************************************************/
|
|
45
|
-
|
|
46
|
-
/* Reference: `fqmul()` in the reference implementation @[REF]. */
|
|
40
|
+
* @return 16-bit integer congruent to a*b*R^{-1} mod MLKEM_Q, and
|
|
41
|
+
* smaller than MLKEM_Q in absolute value.
|
|
42
|
+
*/
|
|
47
43
|
static MLK_INLINE int16_t mlk_fqmul(int16_t a, int16_t b)
|
|
48
44
|
__contract__(
|
|
49
45
|
requires(b > -MLKEM_Q_HALF && b < MLKEM_Q_HALF)
|
|
@@ -65,20 +61,17 @@ __contract__(
|
|
|
65
61
|
return res;
|
|
66
62
|
}
|
|
67
63
|
|
|
68
|
-
|
|
69
|
-
*
|
|
64
|
+
/**
|
|
65
|
+
* Barrett reduction; given a 16-bit integer a, computes the centered
|
|
66
|
+
* representative congruent to a mod MLKEM_Q in [-(MLKEM_Q-1)/2, (MLKEM_Q-1)/2].
|
|
70
67
|
*
|
|
71
|
-
*
|
|
72
|
-
* centered representative congruent to a mod q in
|
|
73
|
-
* {-(q-1)/2,...,(q-1)/2}
|
|
68
|
+
* @reference{`barrett_reduce()` in the reference implementation @[REF].}
|
|
74
69
|
*
|
|
75
|
-
*
|
|
70
|
+
* @param a Input integer to be reduced.
|
|
76
71
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
/* Reference: `barrett_reduce()` in the reference implementation @[REF]. */
|
|
72
|
+
* @return Integer in [-(MLKEM_Q-1)/2, (MLKEM_Q-1)/2] congruent to @p a modulo
|
|
73
|
+
* MLKEM_Q.
|
|
74
|
+
*/
|
|
82
75
|
static MLK_INLINE int16_t mlk_barrett_reduce(int16_t a)
|
|
83
76
|
__contract__(
|
|
84
77
|
ensures(return_value > -MLKEM_Q_HALF && return_value < MLKEM_Q_HALF)
|
|
@@ -125,7 +118,8 @@ __contract__(
|
|
|
125
118
|
for (i = 0; i < MLKEM_N; i++)
|
|
126
119
|
__loop__(
|
|
127
120
|
invariant(i <= MLKEM_N)
|
|
128
|
-
invariant(array_abs_bound(r->coeffs, 0, i, MLKEM_Q))
|
|
121
|
+
invariant(array_abs_bound(r->coeffs, 0, i, MLKEM_Q))
|
|
122
|
+
decreases(MLKEM_N - i))
|
|
129
123
|
{
|
|
130
124
|
r->coeffs[i] = mlk_fqmul(r->coeffs[i], f);
|
|
131
125
|
}
|
|
@@ -149,21 +143,20 @@ void mlk_poly_tomont(mlk_poly *r)
|
|
|
149
143
|
mlk_poly_tomont_c(r);
|
|
150
144
|
}
|
|
151
145
|
|
|
152
|
-
|
|
153
|
-
*
|
|
146
|
+
/**
|
|
147
|
+
* Constant-time conversion of signed representatives modulo MLKEM_Q within
|
|
148
|
+
* range [-(MLKEM_Q-1), MLKEM_Q-1] into unsigned representatives within
|
|
149
|
+
* range [0, MLKEM_Q-1].
|
|
154
150
|
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
151
|
+
* @reference{Not present in the reference implementation @[REF]. Used here
|
|
152
|
+
* to implement different semantics of `poly_reduce()`; see below. In the
|
|
153
|
+
* reference implementation @[REF] this logic is part of all compression
|
|
154
|
+
* functions (see `compress.c`).}
|
|
158
155
|
*
|
|
159
|
-
*
|
|
156
|
+
* @param c Signed coefficient to be converted.
|
|
160
157
|
*
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
/* Reference: Not present in the reference implementation @[REF].
|
|
164
|
-
* - Used here to implement different semantics of `poly_reduce()`;
|
|
165
|
-
* see below. in the reference implementation @[REF], this logic is
|
|
166
|
-
* part of all compression functions (see `compress.c`). */
|
|
158
|
+
* @return Unsigned representative in [0, MLKEM_Q).
|
|
159
|
+
*/
|
|
167
160
|
static MLK_INLINE int16_t mlk_scalar_signed_to_unsigned_q(int16_t c)
|
|
168
161
|
__contract__(
|
|
169
162
|
requires(c > -MLKEM_Q && c < MLKEM_Q)
|
|
@@ -201,7 +194,8 @@ __contract__(
|
|
|
201
194
|
for (i = 0; i < MLKEM_N; i++)
|
|
202
195
|
__loop__(
|
|
203
196
|
invariant(i <= MLKEM_N)
|
|
204
|
-
invariant(array_bound(r->coeffs, 0, i, 0, MLKEM_Q))
|
|
197
|
+
invariant(array_bound(r->coeffs, 0, i, 0, MLKEM_Q))
|
|
198
|
+
decreases(MLKEM_N - i))
|
|
205
199
|
{
|
|
206
200
|
/* Barrett reduction, giving signed canonical representative */
|
|
207
201
|
int16_t t = mlk_barrett_reduce(r->coeffs[i]);
|
|
@@ -239,7 +233,8 @@ void mlk_poly_add(mlk_poly *r, const mlk_poly *b)
|
|
|
239
233
|
__loop__(
|
|
240
234
|
invariant(i <= MLKEM_N)
|
|
241
235
|
invariant(forall(k0, i, MLKEM_N, r->coeffs[k0] == loop_entry(*r).coeffs[k0]))
|
|
242
|
-
invariant(forall(k1, 0, i, r->coeffs[k1] == loop_entry(*r).coeffs[k1] + b->coeffs[k1]))
|
|
236
|
+
invariant(forall(k1, 0, i, r->coeffs[k1] == loop_entry(*r).coeffs[k1] + b->coeffs[k1]))
|
|
237
|
+
decreases(MLKEM_N - i))
|
|
243
238
|
{
|
|
244
239
|
/* The preconditions imply that the addition stays within int16_t. */
|
|
245
240
|
r->coeffs[i] = (int16_t)(r->coeffs[i] + b->coeffs[i]);
|
|
@@ -257,7 +252,8 @@ void mlk_poly_sub(mlk_poly *r, const mlk_poly *b)
|
|
|
257
252
|
__loop__(
|
|
258
253
|
invariant(i <= MLKEM_N)
|
|
259
254
|
invariant(forall(k0, i, MLKEM_N, r->coeffs[k0] == loop_entry(*r).coeffs[k0]))
|
|
260
|
-
invariant(forall(k1, 0, i, r->coeffs[k1] == loop_entry(*r).coeffs[k1] - b->coeffs[k1]))
|
|
255
|
+
invariant(forall(k1, 0, i, r->coeffs[k1] == loop_entry(*r).coeffs[k1] - b->coeffs[k1]))
|
|
256
|
+
decreases(MLKEM_N - i))
|
|
261
257
|
{
|
|
262
258
|
/* The preconditions imply that the subtraction stays within int16_t. */
|
|
263
259
|
r->coeffs[i] = (int16_t)(r->coeffs[i] - b->coeffs[i]);
|
|
@@ -282,7 +278,8 @@ __contract__(
|
|
|
282
278
|
for (i = 0; i < MLKEM_N / 4; i++)
|
|
283
279
|
__loop__(
|
|
284
280
|
invariant(i <= MLKEM_N / 4)
|
|
285
|
-
invariant(array_abs_bound(x->coeffs, 0, 2 * i, MLKEM_Q))
|
|
281
|
+
invariant(array_abs_bound(x->coeffs, 0, 2 * i, MLKEM_Q))
|
|
282
|
+
decreases(MLKEM_N / 4 - i))
|
|
286
283
|
{
|
|
287
284
|
x->coeffs[2 * i + 0] = mlk_fqmul(a->coeffs[4 * i + 1], mlk_zetas[64 + i]);
|
|
288
285
|
/* The values in zeta table are <= MLKEM_Q in absolute value,
|
|
@@ -371,7 +368,8 @@ __contract__(
|
|
|
371
368
|
invariant(array_abs_bound(r, 0, j, bound + MLKEM_Q))
|
|
372
369
|
invariant(array_abs_bound(r, j, start + len, bound))
|
|
373
370
|
invariant(array_abs_bound(r, start + len, j + len, bound + MLKEM_Q))
|
|
374
|
-
invariant(array_abs_bound(r, j + len, MLKEM_N, bound))
|
|
371
|
+
invariant(array_abs_bound(r, j + len, MLKEM_N, bound))
|
|
372
|
+
decreases(start + len - j))
|
|
375
373
|
{
|
|
376
374
|
int16_t t;
|
|
377
375
|
t = mlk_fqmul(r[j + len], zeta);
|
|
@@ -406,7 +404,8 @@ __contract__(
|
|
|
406
404
|
invariant(start < MLKEM_N + 2 * len)
|
|
407
405
|
invariant(k <= MLKEM_N / 2 && 2 * len * k == start + MLKEM_N)
|
|
408
406
|
invariant(array_abs_bound(r, 0, start, layer * MLKEM_Q + MLKEM_Q))
|
|
409
|
-
invariant(array_abs_bound(r, start, MLKEM_N, layer * MLKEM_Q))
|
|
407
|
+
invariant(array_abs_bound(r, start, MLKEM_N, layer * MLKEM_Q))
|
|
408
|
+
decreases(MLKEM_N - start))
|
|
410
409
|
{
|
|
411
410
|
int16_t zeta = mlk_zetas[k++];
|
|
412
411
|
mlk_ntt_butterfly_block(r, zeta, start, len, layer * MLKEM_Q);
|
|
@@ -443,7 +442,8 @@ __contract__(
|
|
|
443
442
|
for (layer = 1; layer <= 7; layer++)
|
|
444
443
|
__loop__(
|
|
445
444
|
invariant(1 <= layer && layer <= 8)
|
|
446
|
-
invariant(array_abs_bound(r, 0, MLKEM_N, layer * MLKEM_Q))
|
|
445
|
+
invariant(array_abs_bound(r, 0, MLKEM_N, layer * MLKEM_Q))
|
|
446
|
+
decreases(8 - layer))
|
|
447
447
|
{
|
|
448
448
|
mlk_ntt_layer(r, layer);
|
|
449
449
|
}
|
|
@@ -453,20 +453,20 @@ __contract__(
|
|
|
453
453
|
}
|
|
454
454
|
|
|
455
455
|
MLK_INTERNAL_API
|
|
456
|
-
void mlk_poly_ntt(mlk_poly *
|
|
456
|
+
void mlk_poly_ntt(mlk_poly *r)
|
|
457
457
|
{
|
|
458
458
|
#if defined(MLK_USE_NATIVE_NTT)
|
|
459
459
|
int ret;
|
|
460
|
-
mlk_assert_abs_bound(
|
|
461
|
-
ret = mlk_ntt_native(
|
|
460
|
+
mlk_assert_abs_bound(r, MLKEM_N, MLKEM_Q);
|
|
461
|
+
ret = mlk_ntt_native(r->coeffs);
|
|
462
462
|
if (ret == MLK_NATIVE_FUNC_SUCCESS)
|
|
463
463
|
{
|
|
464
|
-
mlk_assert_abs_bound(
|
|
464
|
+
mlk_assert_abs_bound(r, MLKEM_N, MLK_NTT_BOUND);
|
|
465
465
|
return;
|
|
466
466
|
}
|
|
467
467
|
#endif /* MLK_USE_NATIVE_NTT */
|
|
468
468
|
|
|
469
|
-
mlk_poly_ntt_c(
|
|
469
|
+
mlk_poly_ntt_c(r);
|
|
470
470
|
}
|
|
471
471
|
|
|
472
472
|
|
|
@@ -489,7 +489,8 @@ __contract__(
|
|
|
489
489
|
invariant(array_abs_bound(r, 0, MLKEM_N, MLKEM_Q))
|
|
490
490
|
invariant(start <= MLKEM_N && k <= 127)
|
|
491
491
|
/* Normalised form of k == MLKEM_N / len - 1 - start / (2 * len) */
|
|
492
|
-
invariant(2 * len * k + start == 2 * MLKEM_N - 2 * len)
|
|
492
|
+
invariant(2 * len * k + start == 2 * MLKEM_N - 2 * len)
|
|
493
|
+
decreases(MLKEM_N - start))
|
|
493
494
|
{
|
|
494
495
|
unsigned j;
|
|
495
496
|
int16_t zeta = mlk_zetas[k--];
|
|
@@ -497,7 +498,8 @@ __contract__(
|
|
|
497
498
|
__loop__(
|
|
498
499
|
invariant(start <= j && j <= start + len)
|
|
499
500
|
invariant(start <= MLKEM_N && k <= 127)
|
|
500
|
-
invariant(array_abs_bound(r, 0, MLKEM_N, MLKEM_Q))
|
|
501
|
+
invariant(array_abs_bound(r, 0, MLKEM_N, MLKEM_Q))
|
|
502
|
+
decreases(start + len - j))
|
|
501
503
|
{
|
|
502
504
|
int16_t t = r[j];
|
|
503
505
|
/* The preconditions imply that the arithmetic does not overflow. */
|
|
@@ -532,7 +534,8 @@ __contract__(
|
|
|
532
534
|
for (j = 0; j < MLKEM_N; j++)
|
|
533
535
|
__loop__(
|
|
534
536
|
invariant(j <= MLKEM_N)
|
|
535
|
-
invariant(array_abs_bound(r, 0, j, MLKEM_Q))
|
|
537
|
+
invariant(array_abs_bound(r, 0, j, MLKEM_Q))
|
|
538
|
+
decreases(MLKEM_N - j))
|
|
536
539
|
{
|
|
537
540
|
r[j] = mlk_fqmul(r[j], f);
|
|
538
541
|
}
|
|
@@ -541,7 +544,8 @@ __contract__(
|
|
|
541
544
|
for (layer = 7; layer > 0; layer--)
|
|
542
545
|
__loop__(
|
|
543
546
|
invariant(0 <= layer && layer < 8)
|
|
544
|
-
invariant(array_abs_bound(r, 0, MLKEM_N, MLKEM_Q))
|
|
547
|
+
invariant(array_abs_bound(r, 0, MLKEM_N, MLKEM_Q))
|
|
548
|
+
decreases(layer))
|
|
545
549
|
{
|
|
546
550
|
mlk_invntt_layer(r, layer);
|
|
547
551
|
}
|
|
@@ -550,19 +554,19 @@ __contract__(
|
|
|
550
554
|
}
|
|
551
555
|
|
|
552
556
|
MLK_INTERNAL_API
|
|
553
|
-
void mlk_poly_invntt_tomont(mlk_poly *
|
|
557
|
+
void mlk_poly_invntt_tomont(mlk_poly *r)
|
|
554
558
|
{
|
|
555
559
|
#if defined(MLK_USE_NATIVE_INTT)
|
|
556
560
|
int ret;
|
|
557
|
-
ret = mlk_intt_native(
|
|
561
|
+
ret = mlk_intt_native(r->coeffs);
|
|
558
562
|
if (ret == MLK_NATIVE_FUNC_SUCCESS)
|
|
559
563
|
{
|
|
560
|
-
mlk_assert_abs_bound(
|
|
564
|
+
mlk_assert_abs_bound(r, MLKEM_N, MLK_INVNTT_BOUND);
|
|
561
565
|
return;
|
|
562
566
|
}
|
|
563
567
|
#endif /* MLK_USE_NATIVE_INTT */
|
|
564
568
|
|
|
565
|
-
mlk_poly_invntt_tomont_c(
|
|
569
|
+
mlk_poly_invntt_tomont_c(r);
|
|
566
570
|
}
|
|
567
571
|
|
|
568
572
|
#else /* !MLK_CONFIG_MULTILEVEL_NO_SHARED */
|
|
@@ -27,37 +27,34 @@
|
|
|
27
27
|
/* Absolute exclusive upper bound for the output of the forward NTT */
|
|
28
28
|
#define MLK_NTT_BOUND (8 * MLKEM_Q)
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
*
|
|
32
|
-
* coeffs[0] + X*coeffs[1] + X^2*coeffs[2] + ... + X^{n-1}*coeffs[n-1]
|
|
30
|
+
/**
|
|
31
|
+
* Element of R_q = Z_q[X]/(X^n + 1). Represents polynomial
|
|
32
|
+
* coeffs[0] + X*coeffs[1] + X^2*coeffs[2] + ... + X^{n-1}*coeffs[n-1].
|
|
33
33
|
*/
|
|
34
34
|
typedef struct
|
|
35
35
|
{
|
|
36
|
-
int16_t coeffs[MLKEM_N];
|
|
36
|
+
int16_t coeffs[MLKEM_N]; /**< Polynomial coefficients. */
|
|
37
37
|
} MLK_ALIGN mlk_poly;
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
* INTERNAL
|
|
39
|
+
/**
|
|
40
|
+
* INTERNAL representation of precomputed data speeding up
|
|
41
41
|
* the base multiplication of two polynomials in NTT domain.
|
|
42
42
|
*/
|
|
43
43
|
typedef struct
|
|
44
44
|
{
|
|
45
|
-
int16_t coeffs[MLKEM_N >> 1];
|
|
45
|
+
int16_t coeffs[MLKEM_N >> 1]; /**< Cached coefficients. */
|
|
46
46
|
} MLK_ALIGN mlk_poly_mulcache;
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* Description: Generic Montgomery reduction; given a 32-bit integer a, computes
|
|
52
|
-
* 16-bit integer congruent to a * R^-1 mod q, where R=2^16
|
|
53
|
-
*
|
|
54
|
-
* Arguments: - int32_t a: input integer to be reduced, of absolute value
|
|
55
|
-
* smaller or equal to INT32_MAX - 2^15 * MLKEM_Q.
|
|
48
|
+
/**
|
|
49
|
+
* Generic Montgomery reduction; given a 32-bit integer a, computes a 16-bit
|
|
50
|
+
* integer congruent to a * R^-1 mod MLKEM_Q, where R=2^16.
|
|
56
51
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
52
|
+
* @param a Input integer to be reduced, of absolute value smaller or equal
|
|
53
|
+
* to INT32_MAX - 2^15 * MLKEM_Q.
|
|
59
54
|
*
|
|
60
|
-
|
|
55
|
+
* @return Integer congruent to a * R^-1 modulo MLKEM_Q, with absolute value
|
|
56
|
+
* <= ceil(|a| / 2^16) + (MLKEM_Q + 1)/2.
|
|
57
|
+
*/
|
|
61
58
|
static MLK_ALWAYS_INLINE int16_t mlk_montgomery_reduce(int32_t a)
|
|
62
59
|
__contract__(
|
|
63
60
|
requires(a < +(INT32_MAX - (((int32_t)1 << 15) * MLKEM_Q)) &&
|
|
@@ -103,21 +100,18 @@ __contract__(
|
|
|
103
100
|
}
|
|
104
101
|
|
|
105
102
|
#define mlk_poly_tomont MLK_NAMESPACE(poly_tomont)
|
|
106
|
-
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* Description: Inplace conversion of all coefficients of a polynomial
|
|
110
|
-
* from normal domain to Montgomery domain
|
|
111
|
-
*
|
|
112
|
-
* Bounds: Output < q in absolute value.
|
|
103
|
+
/**
|
|
104
|
+
* In-place conversion of all coefficients of a polynomial from the normal
|
|
105
|
+
* domain to the Montgomery domain.
|
|
113
106
|
*
|
|
114
|
-
*
|
|
107
|
+
* Bounds: output < MLKEM_Q in absolute value.
|
|
115
108
|
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
109
|
+
* @spec{Internal normalization required in `mlk_indcpa_keypair_derand` as
|
|
110
|
+
* part of matrix-vector multiplication @[FIPS203, Algorithm 13, K-PKE.KeyGen,
|
|
111
|
+
* L18].}
|
|
119
112
|
*
|
|
120
|
-
|
|
113
|
+
* @param[in,out] r Input/output polynomial.
|
|
114
|
+
*/
|
|
121
115
|
MLK_INTERNAL_API
|
|
122
116
|
void mlk_poly_tomont(mlk_poly *r)
|
|
123
117
|
__contract__(
|
|
@@ -127,27 +121,23 @@ __contract__(
|
|
|
127
121
|
);
|
|
128
122
|
|
|
129
123
|
#define mlk_poly_mulcache_compute MLK_NAMESPACE(poly_mulcache_compute)
|
|
130
|
-
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* Description: Computes the mulcache for a polynomial in NTT domain
|
|
134
|
-
*
|
|
135
|
-
* The mulcache of a degree-2 polynomial b := b0 + b1*X
|
|
136
|
-
* in Fq[X]/(X^2-zeta) is the value b1*zeta, needed when
|
|
137
|
-
* computing products of b in Fq[X]/(X^2-zeta).
|
|
124
|
+
/**
|
|
125
|
+
* Compute the mulcache for a polynomial in NTT domain.
|
|
138
126
|
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* polynomials.
|
|
127
|
+
* The mulcache of a degree-2 polynomial b := b0 + b1*X in Fq[X]/(X^2-zeta)
|
|
128
|
+
* is the value b1*zeta, needed when computing products of b in
|
|
129
|
+
* Fq[X]/(X^2-zeta).
|
|
143
130
|
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
131
|
+
* The mulcache of a polynomial in NTT domain -- which is a 128-tuple of
|
|
132
|
+
* degree-2 polynomials in Fq[X]/(X^2-zeta), for varying zeta, is the
|
|
133
|
+
* 128-tuple of mulcaches of those polynomials.
|
|
146
134
|
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
135
|
+
* @spec{Caches `b_1 * \gamma` in @[FIPS203, Algorithm 12, BaseCaseMultiply,
|
|
136
|
+
* L1].}
|
|
149
137
|
*
|
|
150
|
-
|
|
138
|
+
* @param[out] x Mulcache to be populated.
|
|
139
|
+
* @param[in] a Input polynomial.
|
|
140
|
+
*/
|
|
151
141
|
/*
|
|
152
142
|
* NOTE: The default C implementation of this function populates
|
|
153
143
|
* the mulcache with values in (-q,q), but this is not needed for the
|
|
@@ -162,21 +152,17 @@ __contract__(
|
|
|
162
152
|
);
|
|
163
153
|
|
|
164
154
|
#define mlk_poly_reduce MLK_NAMESPACE(poly_reduce)
|
|
165
|
-
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* Description: Converts polynomial to _unsigned canonical_ representatives.
|
|
169
|
-
*
|
|
170
|
-
* The input coefficients can be arbitrary integers in int16_t.
|
|
171
|
-
* The output coefficients are in [0,1,...,MLKEM_Q-1].
|
|
155
|
+
/**
|
|
156
|
+
* Convert a polynomial to unsigned canonical representatives.
|
|
172
157
|
*
|
|
173
|
-
*
|
|
158
|
+
* The input coefficients can be arbitrary integers in int16_t. The output
|
|
159
|
+
* coefficients are in [0,1,..,MLKEM_Q-1].
|
|
174
160
|
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* This is not made explicit in FIPS 203.
|
|
161
|
+
* @spec{Normalizes on unsigned canonical representatives ahead of calling
|
|
162
|
+
* @[FIPS203, Compress_d, Eq (4.7)]. This is not made explicit in FIPS 203.}
|
|
178
163
|
*
|
|
179
|
-
|
|
164
|
+
* @param[in,out] r Input/output polynomial.
|
|
165
|
+
*/
|
|
180
166
|
/*
|
|
181
167
|
* NOTE: The semantics of mlk_poly_reduce() is different in
|
|
182
168
|
* the reference implementation, which requires
|
|
@@ -193,23 +179,19 @@ __contract__(
|
|
|
193
179
|
);
|
|
194
180
|
|
|
195
181
|
#define mlk_poly_add MLK_NAMESPACE(poly_add)
|
|
196
|
-
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
* Description: Adds two polynomials in place
|
|
182
|
+
/**
|
|
183
|
+
* Add two polynomials in place.
|
|
200
184
|
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* to r. Must be disjoint from r.
|
|
185
|
+
* The coefficients of @p r and @p b must be such that the addition does not
|
|
186
|
+
* overflow. Otherwise, the behaviour of this function is undefined.
|
|
204
187
|
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
188
|
+
* @spec{@[FIPS203, 2.4.5, Arithmetic With Polynomials and NTT
|
|
189
|
+
* Representations]. Used in @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L21].}
|
|
207
190
|
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
|
|
212
|
-
************************************************************/
|
|
191
|
+
* @param[in,out] r Input-output polynomial to be added to.
|
|
192
|
+
* @param[in] b Input polynomial that should be added to @p r. Must be
|
|
193
|
+
* disjoint from @p r.
|
|
194
|
+
*/
|
|
213
195
|
/*
|
|
214
196
|
* NOTE: The reference implementation uses a 3-argument mlk_poly_add.
|
|
215
197
|
* We specialize to the accumulator form to avoid reasoning about aliasing.
|
|
@@ -226,19 +208,15 @@ __contract__(
|
|
|
226
208
|
);
|
|
227
209
|
|
|
228
210
|
#define mlk_poly_sub MLK_NAMESPACE(poly_sub)
|
|
229
|
-
|
|
230
|
-
*
|
|
211
|
+
/**
|
|
212
|
+
* Subtract two polynomials; no modular reduction is performed.
|
|
231
213
|
*
|
|
232
|
-
*
|
|
214
|
+
* @spec{@[FIPS203, 2.4.5, Arithmetic With Polynomials and NTT
|
|
215
|
+
* Representations]. Used in @[FIPS203, Algorithm 15, K-PKE.Decrypt, L6].}
|
|
233
216
|
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
|
|
237
|
-
* Specification:
|
|
238
|
-
* - @[FIPS203, 2.4.5, Arithmetic With Polynomials and NTT Representations]
|
|
239
|
-
* - Used in @[FIPS203, Algorithm 15, K-PKE.Decrypt, L6]
|
|
240
|
-
*
|
|
241
|
-
**************************************************/
|
|
217
|
+
* @param[in,out] r Input-output polynomial to be subtracted from.
|
|
218
|
+
* @param[in] b Second input polynomial.
|
|
219
|
+
*/
|
|
242
220
|
/*
|
|
243
221
|
* NOTE: The reference implementation uses a 3-argument mlk_poly_sub.
|
|
244
222
|
* We specialize to the accumulator form to avoid reasoning about aliasing.
|
|
@@ -255,26 +233,24 @@ __contract__(
|
|
|
255
233
|
);
|
|
256
234
|
|
|
257
235
|
#define mlk_poly_ntt MLK_NAMESPACE(poly_ntt)
|
|
258
|
-
|
|
259
|
-
*
|
|
236
|
+
/**
|
|
237
|
+
* Compute the negacyclic number-theoretic transform (NTT) of a polynomial
|
|
238
|
+
* in place.
|
|
260
239
|
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
240
|
+
* The input is assumed to be in normal order and coefficient-wise bound by
|
|
241
|
+
* MLKEM_Q in absolute value.
|
|
263
242
|
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
243
|
+
* The output polynomial is in bitreversed order, or of a custom order if
|
|
244
|
+
* MLK_USE_NATIVE_NTT_CUSTOM_ORDER is set, and coefficient-wise bound
|
|
245
|
+
* by MLK_NTT_BOUND in absolute value.
|
|
266
246
|
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
247
|
+
* (NOTE: Sometimes the input to the NTT is actually smaller, which gives
|
|
248
|
+
* better bounds.)
|
|
269
249
|
*
|
|
270
|
-
*
|
|
271
|
-
* which gives better bounds.)
|
|
250
|
+
* @spec{Implements @[FIPS203, Algorithm 9, NTT].}
|
|
272
251
|
*
|
|
273
|
-
*
|
|
274
|
-
|
|
275
|
-
* Specification: Implements @[FIPS203, Algorithm 9, NTT]
|
|
276
|
-
*
|
|
277
|
-
**************************************************/
|
|
252
|
+
* @param[in,out] r Input/output polynomial.
|
|
253
|
+
*/
|
|
278
254
|
MLK_INTERNAL_API
|
|
279
255
|
void mlk_poly_ntt(mlk_poly *r)
|
|
280
256
|
__contract__(
|
|
@@ -285,27 +261,24 @@ __contract__(
|
|
|
285
261
|
);
|
|
286
262
|
|
|
287
263
|
#define mlk_poly_invntt_tomont MLK_NAMESPACE(poly_invntt_tomont)
|
|
288
|
-
|
|
289
|
-
*
|
|
264
|
+
/**
|
|
265
|
+
* Compute the inverse negacyclic number-theoretic transform (NTT) of a
|
|
266
|
+
* polynomial in place; input assumed to be in bitreversed order, output in
|
|
267
|
+
* normal order.
|
|
290
268
|
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
* order
|
|
269
|
+
* The input is assumed to be in bitreversed order, or of a custom order if
|
|
270
|
+
* MLK_USE_NATIVE_NTT_CUSTOM_ORDER is set, and can have arbitrary
|
|
271
|
+
* coefficients in int16_t.
|
|
295
272
|
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
273
|
+
* The output polynomial is in normal order, and coefficient-wise bound by
|
|
274
|
+
* MLK_INVNTT_BOUND in absolute value.
|
|
298
275
|
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
276
|
+
* @spec{Implements composition of @[FIPS203, Algorithm 10, NTT^{-1}] and
|
|
277
|
+
* elementwise modular multiplication with a suitable Montgomery factor
|
|
278
|
+
* introduced during the base multiplication.}
|
|
301
279
|
*
|
|
302
|
-
*
|
|
303
|
-
|
|
304
|
-
* Specification: Implements composition of @[FIPS203, Algorithm 10, NTT^{-1}]
|
|
305
|
-
* and elementwise modular multiplication with a suitable
|
|
306
|
-
* Montgomery factor introduced during the base multiplication.
|
|
307
|
-
*
|
|
308
|
-
**************************************************/
|
|
280
|
+
* @param[in,out] r Input/output polynomial.
|
|
281
|
+
*/
|
|
309
282
|
MLK_INTERNAL_API
|
|
310
283
|
void mlk_poly_invntt_tomont(mlk_poly *r)
|
|
311
284
|
__contract__(
|