pq_crypto 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/GET_STARTED.md +21 -16
- data/README.md +26 -0
- data/SECURITY.md +22 -16
- data/ext/pqcrypto/extconf.rb +148 -99
- data/ext/pqcrypto/mldsa_api.h +1 -118
- data/ext/pqcrypto/mlkem_api.h +1 -42
- data/ext/pqcrypto/pq_externalmu.c +88 -216
- data/ext/pqcrypto/pqcrypto_native_api.h +129 -0
- data/ext/pqcrypto/pqcrypto_ruby_secure.c +0 -3
- data/ext/pqcrypto/pqcrypto_secure.c +135 -117
- data/ext/pqcrypto/pqcrypto_secure.h +1 -42
- data/ext/pqcrypto/pqcrypto_version.h +1 -1
- data/ext/pqcrypto/randombytes.h +9 -0
- data/ext/pqcrypto/vendor/.vendored +10 -5
- data/ext/pqcrypto/vendor/mldsa-native/BUILDING.md +105 -0
- data/ext/pqcrypto/vendor/mldsa-native/LICENSE +286 -0
- data/ext/pqcrypto/vendor/mldsa-native/META.yml +24 -0
- data/ext/pqcrypto/vendor/mldsa-native/README.md +221 -0
- data/ext/pqcrypto/vendor/mldsa-native/SECURITY.md +8 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +721 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +975 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +724 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +723 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +166 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +321 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.c +21 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +385 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c +73 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +130 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.c +277 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +244 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +182 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +117 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +438 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +105 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +71 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +62 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +376 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +204 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +259 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +1077 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +987 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +41 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +26 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +35 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +37 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +27 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +36 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +69 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/README.md +10 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +32 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +20 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +638 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +136 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +52 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +29 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +488 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +16 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/xkcp.h +31 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +247 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +231 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +150 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +753 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +129 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +145 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +177 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +653 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +79 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +53 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +55 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +85 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +85 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +102 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +110 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +72 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +69 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +40 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +189 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +135 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +128 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +543 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +62 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +649 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/meta.h +23 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +315 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +124 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +157 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +27 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +2311 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +2383 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +239 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +131 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +187 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +61 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_chknorm_avx2.c +52 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +102 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +104 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +91 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +93 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_avx2.c +126 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +160 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +293 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +224 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/params.h +77 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +991 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +393 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +946 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +360 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +877 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +725 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/randombytes.h +26 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +249 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +1511 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +806 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/symmetric.h +68 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sys.h +268 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/zetas.inc +55 -0
- data/ext/pqcrypto/vendor/mlkem-native/BUILDING.md +104 -0
- data/ext/pqcrypto/vendor/mlkem-native/LICENSE +294 -0
- data/ext/pqcrypto/vendor/mlkem-native/META.yml +30 -0
- data/ext/pqcrypto/vendor/mlkem-native/README.md +223 -0
- data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +86 -0
- data/ext/pqcrypto/vendor/mlkem-native/SECURITY.md +8 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/README.md +23 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +660 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +538 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +681 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +709 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +174 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +274 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +717 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +688 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.c +64 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.h +128 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +251 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +158 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +208 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +80 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +463 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.h +98 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/auto.h +70 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/fips202_native_aarch64.h +69 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +375 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +203 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +258 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +1076 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +986 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +46 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +25 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +34 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +35 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +26 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +35 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/api.h +117 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/README.md +10 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/mve.h +79 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/fips202_native_armv81m.h +35 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +667 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +40 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +51 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +290 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +314 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +28 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +33 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +41 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2.S +451 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +51 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +622 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +156 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +446 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +326 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/README.md +16 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +122 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +174 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +177 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/intt.S +628 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/ntt.S +562 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_mulcache_compute_asm.S +127 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_reduce_asm.S +150 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_tobytes_asm.S +117 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_tomont_asm.S +98 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k2.S +261 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k3.S +314 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k4.S +368 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_asm.S +226 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_table.c +542 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +637 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +25 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/README.md +11 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +128 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/arith_native_riscv64.h +45 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +81 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +145 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_izetas.inc +27 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +805 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_zetas.inc +27 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_zetas_basemul.inc +39 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/README.md +4 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +304 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +309 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +94 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +45 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.c +102 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.h +25 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/intt.S +719 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mulcache_compute.S +90 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/ntt.S +639 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/nttfrombytes.S +193 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/ntttobytes.S +181 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/nttunpack.S +174 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d10.S +382 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d11.S +448 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d4.S +163 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d5.S +220 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d10.S +228 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d11.S +277 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d4.S +180 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d5.S +192 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k2.S +502 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k3.S +750 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k4.S +998 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/reduce.S +218 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_asm.S +103 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_table.c +544 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/tomont.S +155 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/params.h +76 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +572 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +317 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +502 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +668 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/randombytes.h +60 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +362 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +118 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/symmetric.h +70 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +260 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.c +20 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +464 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/zetas.inc +30 -0
- data/lib/pq_crypto/version.rb +1 -1
- data/lib/pq_crypto.rb +1 -1
- data/script/vendor_libs.rb +88 -159
- metadata +236 -160
- data/ext/pqcrypto/vendor/pqclean/common/aes.c +0 -639
- data/ext/pqcrypto/vendor/pqclean/common/aes.h +0 -64
- data/ext/pqcrypto/vendor/pqclean/common/compat.h +0 -73
- data/ext/pqcrypto/vendor/pqclean/common/crypto_declassify.h +0 -7
- data/ext/pqcrypto/vendor/pqclean/common/fips202.c +0 -928
- data/ext/pqcrypto/vendor/pqclean/common/fips202.h +0 -166
- data/ext/pqcrypto/vendor/pqclean/common/keccak2x/feat.S +0 -168
- data/ext/pqcrypto/vendor/pqclean/common/keccak2x/fips202x2.c +0 -684
- data/ext/pqcrypto/vendor/pqclean/common/keccak2x/fips202x2.h +0 -60
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-times4-SIMD256.c +0 -1028
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-times4-SnP.h +0 -50
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-unrolling.macros +0 -198
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/Makefile +0 -8
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/Makefile.Microsoft_nmake +0 -8
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/SIMD256-config.h +0 -3
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/align.h +0 -34
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/brg_endian.h +0 -142
- data/ext/pqcrypto/vendor/pqclean/common/nistseedexpander.c +0 -101
- data/ext/pqcrypto/vendor/pqclean/common/nistseedexpander.h +0 -39
- data/ext/pqcrypto/vendor/pqclean/common/randombytes.c +0 -355
- data/ext/pqcrypto/vendor/pqclean/common/randombytes.h +0 -27
- data/ext/pqcrypto/vendor/pqclean/common/sha2.c +0 -769
- data/ext/pqcrypto/vendor/pqclean/common/sha2.h +0 -173
- data/ext/pqcrypto/vendor/pqclean/common/sp800-185.c +0 -156
- data/ext/pqcrypto/vendor/pqclean/common/sp800-185.h +0 -27
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/LICENSE +0 -5
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/Makefile +0 -19
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/Makefile.Microsoft_nmake +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/api.h +0 -18
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/cbd.c +0 -83
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/cbd.h +0 -11
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/indcpa.c +0 -327
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/indcpa.h +0 -22
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/kem.c +0 -164
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/kem.h +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/ntt.c +0 -146
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/ntt.h +0 -14
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/params.h +0 -36
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/poly.c +0 -311
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/poly.h +0 -37
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/polyvec.c +0 -198
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/polyvec.h +0 -26
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/reduce.c +0 -41
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/reduce.h +0 -13
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/symmetric-shake.c +0 -71
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/symmetric.h +0 -30
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/verify.c +0 -67
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/verify.h +0 -13
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/LICENSE +0 -5
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/Makefile +0 -19
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/Makefile.Microsoft_nmake +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/api.h +0 -18
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/cbd.c +0 -108
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/cbd.h +0 -11
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/indcpa.c +0 -327
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/indcpa.h +0 -22
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/kem.c +0 -164
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/kem.h +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/ntt.c +0 -146
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/ntt.h +0 -14
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/params.h +0 -36
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/poly.c +0 -299
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/poly.h +0 -37
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/polyvec.c +0 -188
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/polyvec.h +0 -26
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/reduce.c +0 -41
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/reduce.h +0 -13
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/symmetric-shake.c +0 -71
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/symmetric.h +0 -30
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/verify.c +0 -67
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/verify.h +0 -13
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/LICENSE +0 -5
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/Makefile +0 -19
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/Makefile.Microsoft_nmake +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/api.h +0 -18
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/cbd.c +0 -83
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/cbd.h +0 -11
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/indcpa.c +0 -327
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/indcpa.h +0 -22
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/kem.c +0 -164
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/kem.h +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/ntt.c +0 -146
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/ntt.h +0 -14
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/params.h +0 -36
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/poly.c +0 -299
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/poly.h +0 -37
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/polyvec.c +0 -188
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/polyvec.h +0 -26
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/reduce.c +0 -41
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/reduce.h +0 -13
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/symmetric-shake.c +0 -71
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/symmetric.h +0 -30
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/verify.c +0 -67
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/verify.h +0 -13
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/LICENSE +0 -5
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/Makefile +0 -19
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/Makefile.Microsoft_nmake +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/api.h +0 -50
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/ntt.c +0 -98
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/ntt.h +0 -10
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/packing.c +0 -261
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/packing.h +0 -31
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/params.h +0 -44
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/poly.c +0 -848
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/poly.h +0 -52
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/polyvec.c +0 -415
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/polyvec.h +0 -65
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/reduce.c +0 -69
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/reduce.h +0 -17
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/rounding.c +0 -98
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/rounding.h +0 -14
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/sign.c +0 -407
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/sign.h +0 -47
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/symmetric-shake.c +0 -26
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/symmetric.h +0 -34
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/LICENSE +0 -5
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/Makefile +0 -19
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/Makefile.Microsoft_nmake +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/api.h +0 -50
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/ntt.c +0 -98
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/ntt.h +0 -10
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.c +0 -261
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.h +0 -31
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/params.h +0 -44
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.c +0 -799
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.h +0 -52
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.c +0 -415
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.h +0 -65
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/reduce.c +0 -69
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/reduce.h +0 -17
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/rounding.c +0 -92
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/rounding.h +0 -14
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/sign.c +0 -407
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/sign.h +0 -47
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric-shake.c +0 -26
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric.h +0 -34
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/LICENSE +0 -5
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/Makefile +0 -19
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/Makefile.Microsoft_nmake +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/api.h +0 -50
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/ntt.c +0 -98
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/ntt.h +0 -10
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/packing.c +0 -261
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/packing.h +0 -31
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/params.h +0 -44
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/poly.c +0 -823
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/poly.h +0 -52
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/polyvec.c +0 -415
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/polyvec.h +0 -65
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/reduce.c +0 -69
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/reduce.h +0 -17
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/rounding.c +0 -92
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/rounding.h +0 -14
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/sign.c +0 -407
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/sign.h +0 -47
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/symmetric-shake.c +0 -26
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/symmetric.h +0 -34
|
@@ -0,0 +1,877 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) The mldsa-native project authors
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/* References
|
|
7
|
+
* ==========
|
|
8
|
+
*
|
|
9
|
+
* - [FIPS204]
|
|
10
|
+
* FIPS 204 Module-Lattice-Based Digital Signature Standard
|
|
11
|
+
* National Institute of Standards and Technology
|
|
12
|
+
* https://csrc.nist.gov/pubs/fips/204/final
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
#include "polyvec.h"
|
|
16
|
+
|
|
17
|
+
#include "debug.h"
|
|
18
|
+
|
|
19
|
+
/* This namespacing is not done at the top to avoid a naming conflict
|
|
20
|
+
* with native backends, which are currently not yet namespaced. */
|
|
21
|
+
#define mld_polymat_permute_bitrev_to_custom \
|
|
22
|
+
MLD_ADD_PARAM_SET(mld_polymat_permute_bitrev_to_custom)
|
|
23
|
+
#define mld_polyvecl_permute_bitrev_to_custom \
|
|
24
|
+
MLD_ADD_PARAM_SET(mld_polyvecl_permute_bitrev_to_custom)
|
|
25
|
+
#define mld_polyvecl_pointwise_acc_montgomery_c \
|
|
26
|
+
MLD_ADD_PARAM_SET(mld_polyvecl_pointwise_acc_montgomery_c)
|
|
27
|
+
|
|
28
|
+
#if !defined(MLD_CONFIG_REDUCE_RAM)
|
|
29
|
+
/* Helper function to ensure that the polynomial entries in the output
|
|
30
|
+
* of mld_polyvec_matrix_expand use the standard (bitreversed) ordering
|
|
31
|
+
* of coefficients.
|
|
32
|
+
* No-op unless a native backend with a custom ordering is used.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
static void mld_polyvecl_permute_bitrev_to_custom(mld_polyvecl *v)
|
|
36
|
+
__contract__(
|
|
37
|
+
/* We don't specify that this should be a permutation, but only
|
|
38
|
+
* that it does not change the bound established at the end of
|
|
39
|
+
* mld_polyvec_matrix_expand.
|
|
40
|
+
*/
|
|
41
|
+
requires(memory_no_alias(v, sizeof(mld_polyvecl)))
|
|
42
|
+
requires(forall(x, 0, MLDSA_L,
|
|
43
|
+
array_bound(v->vec[x].coeffs, 0, MLDSA_N, 0, MLDSA_Q)))
|
|
44
|
+
assigns(memory_slice(v, sizeof(mld_polyvecl)))
|
|
45
|
+
ensures(forall(x, 0, MLDSA_L,
|
|
46
|
+
array_bound(v->vec[x].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
|
|
47
|
+
{
|
|
48
|
+
#if defined(MLD_USE_NATIVE_NTT_CUSTOM_ORDER)
|
|
49
|
+
unsigned i;
|
|
50
|
+
for (i = 0; i < MLDSA_L; i++)
|
|
51
|
+
__loop__(
|
|
52
|
+
assigns(i, memory_slice(v, sizeof(mld_polyvecl)))
|
|
53
|
+
invariant(i <= MLDSA_L)
|
|
54
|
+
invariant(forall(x, 0, MLDSA_L,
|
|
55
|
+
array_bound(v->vec[x].coeffs, 0, MLDSA_N, 0, MLDSA_Q)))
|
|
56
|
+
decreases(MLDSA_L - i))
|
|
57
|
+
{
|
|
58
|
+
mld_poly_permute_bitrev_to_custom(v->vec[i].coeffs);
|
|
59
|
+
}
|
|
60
|
+
#else /* MLD_USE_NATIVE_NTT_CUSTOM_ORDER */
|
|
61
|
+
/* Nothing to do */
|
|
62
|
+
(void)v;
|
|
63
|
+
#endif /* !MLD_USE_NATIVE_NTT_CUSTOM_ORDER */
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static void mld_polymat_permute_bitrev_to_custom(mld_polymat *mat)
|
|
67
|
+
__contract__(
|
|
68
|
+
/* We don't specify that this should be a permutation, but only
|
|
69
|
+
* that it does not change the bound established at the end of
|
|
70
|
+
* mld_polyvec_matrix_expand.
|
|
71
|
+
*/
|
|
72
|
+
requires(memory_no_alias(mat, sizeof(mld_polymat)))
|
|
73
|
+
requires(forall(k1, 0, MLDSA_K, forall(l1, 0, MLDSA_L,
|
|
74
|
+
array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
|
|
75
|
+
assigns(memory_slice(mat, sizeof(mld_polymat)))
|
|
76
|
+
ensures(forall(k1, 0, MLDSA_K, forall(l1, 0, MLDSA_L,
|
|
77
|
+
array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
|
|
78
|
+
)
|
|
79
|
+
{
|
|
80
|
+
unsigned int i;
|
|
81
|
+
for (i = 0; i < MLDSA_K; i++)
|
|
82
|
+
__loop__(
|
|
83
|
+
assigns(i, memory_slice(mat, sizeof(mld_polymat)))
|
|
84
|
+
invariant(i <= MLDSA_K)
|
|
85
|
+
invariant(forall(k1, 0, MLDSA_K, forall(l1, 0, MLDSA_L,
|
|
86
|
+
array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
|
|
87
|
+
decreases(MLDSA_K - i))
|
|
88
|
+
{
|
|
89
|
+
mld_polyvecl_permute_bitrev_to_custom(&mat->vec[i]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
#endif /* !MLD_CONFIG_REDUCE_RAM */
|
|
93
|
+
|
|
94
|
+
MLD_INTERNAL_API
|
|
95
|
+
const mld_polyvecl *mld_polymat_get_row(mld_polymat *mat, unsigned int row)
|
|
96
|
+
{
|
|
97
|
+
#if defined(MLD_CONFIG_REDUCE_RAM)
|
|
98
|
+
unsigned int i;
|
|
99
|
+
MLD_ALIGN uint8_t seed_ext[MLD_ALIGN_UP(MLDSA_SEEDBYTES + 2)];
|
|
100
|
+
|
|
101
|
+
mld_memcpy(seed_ext, mat->rho, MLDSA_SEEDBYTES);
|
|
102
|
+
|
|
103
|
+
/* Generate row on-demand */
|
|
104
|
+
for (i = 0; i < MLDSA_L; i++)
|
|
105
|
+
{
|
|
106
|
+
uint8_t x = (uint8_t)row;
|
|
107
|
+
uint8_t y = (uint8_t)i;
|
|
108
|
+
|
|
109
|
+
seed_ext[MLDSA_SEEDBYTES + 0] = y;
|
|
110
|
+
seed_ext[MLDSA_SEEDBYTES + 1] = x;
|
|
111
|
+
|
|
112
|
+
mld_poly_uniform(&mat->row_buffer.vec[i], seed_ext);
|
|
113
|
+
|
|
114
|
+
#if defined(MLD_USE_NATIVE_NTT_CUSTOM_ORDER)
|
|
115
|
+
mld_poly_permute_bitrev_to_custom(mat->row_buffer.vec[i].coeffs);
|
|
116
|
+
#endif
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* @[FIPS204, Section 3.6.3] Destruction of intermediate values. */
|
|
120
|
+
mld_zeroize(seed_ext, sizeof(seed_ext));
|
|
121
|
+
|
|
122
|
+
return &mat->row_buffer;
|
|
123
|
+
#else /* MLD_CONFIG_REDUCE_RAM */
|
|
124
|
+
return &mat->vec[row];
|
|
125
|
+
#endif /* !MLD_CONFIG_REDUCE_RAM */
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
MLD_INTERNAL_API
|
|
129
|
+
void mld_polyvec_matrix_expand(mld_polymat *mat,
|
|
130
|
+
const uint8_t rho[MLDSA_SEEDBYTES])
|
|
131
|
+
{
|
|
132
|
+
#if defined(MLD_CONFIG_REDUCE_RAM)
|
|
133
|
+
/* In REDUCE_RAM mode, just copy the seed for later on-demand generation */
|
|
134
|
+
mld_memcpy(mat->rho, rho, MLDSA_SEEDBYTES);
|
|
135
|
+
#else
|
|
136
|
+
unsigned int i, j;
|
|
137
|
+
/*
|
|
138
|
+
* We generate four separate seed arrays rather than a single one to work
|
|
139
|
+
* around limitations in CBMC function contracts dealing with disjoint slices
|
|
140
|
+
* of the same parent object.
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
MLD_ALIGN uint8_t seed_ext[4][MLD_ALIGN_UP(MLDSA_SEEDBYTES + 2)];
|
|
144
|
+
|
|
145
|
+
for (j = 0; j < 4; j++)
|
|
146
|
+
__loop__(
|
|
147
|
+
assigns(j, object_whole(seed_ext))
|
|
148
|
+
invariant(j <= 4)
|
|
149
|
+
decreases(4 - j)
|
|
150
|
+
)
|
|
151
|
+
{
|
|
152
|
+
mld_memcpy(seed_ext[j], rho, MLDSA_SEEDBYTES);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
#if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
|
|
156
|
+
/* Sample 4 matrix entries a time. */
|
|
157
|
+
for (i = 0; i < (MLDSA_K * MLDSA_L / 4) * 4; i += 4)
|
|
158
|
+
__loop__(
|
|
159
|
+
assigns(i, j, object_whole(seed_ext), memory_slice(mat, sizeof(mld_polymat)))
|
|
160
|
+
invariant(i <= (MLDSA_K * MLDSA_L / 4) * 4 && i % 4 == 0)
|
|
161
|
+
/* vectors 0 .. i / MLDSA_L are completely sampled */
|
|
162
|
+
invariant(forall(k1, 0, i / MLDSA_L, forall(l1, 0, MLDSA_L,
|
|
163
|
+
array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
|
|
164
|
+
/* last vector is sampled up to i % MLDSA_L */
|
|
165
|
+
invariant(forall(k2, i / MLDSA_L, i / MLDSA_L + 1, forall(l2, 0, i % MLDSA_L,
|
|
166
|
+
array_bound(mat->vec[k2].vec[l2].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
|
|
167
|
+
decreases((MLDSA_K * MLDSA_L / 4) * 4 - i)
|
|
168
|
+
)
|
|
169
|
+
{
|
|
170
|
+
for (j = 0; j < 4; j++)
|
|
171
|
+
__loop__(
|
|
172
|
+
assigns(j, object_whole(seed_ext))
|
|
173
|
+
invariant(j <= 4)
|
|
174
|
+
decreases(4 - j)
|
|
175
|
+
)
|
|
176
|
+
{
|
|
177
|
+
uint8_t x = (uint8_t)((i + j) / MLDSA_L);
|
|
178
|
+
uint8_t y = (uint8_t)((i + j) % MLDSA_L);
|
|
179
|
+
|
|
180
|
+
seed_ext[j][MLDSA_SEEDBYTES + 0] = y;
|
|
181
|
+
seed_ext[j][MLDSA_SEEDBYTES + 1] = x;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
mld_poly_uniform_4x(&mat->vec[i / MLDSA_L].vec[i % MLDSA_L],
|
|
185
|
+
&mat->vec[(i + 1) / MLDSA_L].vec[(i + 1) % MLDSA_L],
|
|
186
|
+
&mat->vec[(i + 2) / MLDSA_L].vec[(i + 2) % MLDSA_L],
|
|
187
|
+
&mat->vec[(i + 3) / MLDSA_L].vec[(i + 3) % MLDSA_L],
|
|
188
|
+
seed_ext);
|
|
189
|
+
}
|
|
190
|
+
#else /* !MLD_CONFIG_SERIAL_FIPS202_ONLY */
|
|
191
|
+
i = 0;
|
|
192
|
+
#endif /* MLD_CONFIG_SERIAL_FIPS202_ONLY */
|
|
193
|
+
|
|
194
|
+
/* Entries omitted by the batch-sampling are sampled individually. */
|
|
195
|
+
while (i < MLDSA_K * MLDSA_L)
|
|
196
|
+
__loop__(
|
|
197
|
+
assigns(i, object_whole(seed_ext), memory_slice(mat, sizeof(mld_polymat)))
|
|
198
|
+
invariant(i <= MLDSA_K * MLDSA_L)
|
|
199
|
+
/* vectors 0 .. i / MLDSA_L are completely sampled */
|
|
200
|
+
invariant(forall(k1, 0, i / MLDSA_L, forall(l1, 0, MLDSA_L,
|
|
201
|
+
array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
|
|
202
|
+
/* last vector is sampled up to i % MLDSA_L */
|
|
203
|
+
invariant(forall(k2, i / MLDSA_L, i / MLDSA_L + 1, forall(l2, 0, i % MLDSA_L,
|
|
204
|
+
array_bound(mat->vec[k2].vec[l2].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
|
|
205
|
+
decreases(MLDSA_K * MLDSA_L - i)
|
|
206
|
+
)
|
|
207
|
+
{
|
|
208
|
+
uint8_t x = (uint8_t)(i / MLDSA_L);
|
|
209
|
+
uint8_t y = (uint8_t)(i % MLDSA_L);
|
|
210
|
+
mld_poly *this_poly = &mat->vec[i / MLDSA_L].vec[i % MLDSA_L];
|
|
211
|
+
|
|
212
|
+
seed_ext[0][MLDSA_SEEDBYTES + 0] = y;
|
|
213
|
+
seed_ext[0][MLDSA_SEEDBYTES + 1] = x;
|
|
214
|
+
|
|
215
|
+
mld_poly_uniform(this_poly, seed_ext[0]);
|
|
216
|
+
i++;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
mld_polymat_permute_bitrev_to_custom(mat);
|
|
220
|
+
|
|
221
|
+
/* @[FIPS204, Section 3.6.3] Destruction of intermediate values. */
|
|
222
|
+
mld_zeroize(seed_ext, sizeof(seed_ext));
|
|
223
|
+
#endif /* !MLD_CONFIG_REDUCE_RAM */
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
MLD_INTERNAL_API
|
|
227
|
+
void mld_polyvec_matrix_pointwise_montgomery(mld_polyveck *t, mld_polymat *mat,
|
|
228
|
+
const mld_polyvecl *v)
|
|
229
|
+
{
|
|
230
|
+
unsigned int i;
|
|
231
|
+
mld_assert_abs_bound_2d(v->vec, MLDSA_L, MLDSA_N, MLD_NTT_BOUND);
|
|
232
|
+
|
|
233
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
234
|
+
__loop__(
|
|
235
|
+
assigns(i, memory_slice(t, sizeof(mld_polyveck)))
|
|
236
|
+
invariant(i <= MLDSA_K)
|
|
237
|
+
invariant(forall(k0, 0, i,
|
|
238
|
+
array_abs_bound(t->vec[k0].coeffs, 0, MLDSA_N, MLDSA_Q)))
|
|
239
|
+
decreases(MLDSA_K - i)
|
|
240
|
+
)
|
|
241
|
+
{
|
|
242
|
+
const mld_polyvecl *row = mld_polymat_get_row(mat, i);
|
|
243
|
+
mld_polyvecl_pointwise_acc_montgomery(&t->vec[i], row, v);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
mld_assert_abs_bound_2d(t->vec, MLDSA_K, MLDSA_N, MLDSA_Q);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**************************************************************/
|
|
250
|
+
/************ Vectors of polynomials of length MLDSA_L **************/
|
|
251
|
+
/**************************************************************/
|
|
252
|
+
MLD_INTERNAL_API
|
|
253
|
+
void mld_polyvecl_uniform_gamma1(mld_polyvecl *v,
|
|
254
|
+
const uint8_t seed[MLDSA_CRHBYTES],
|
|
255
|
+
uint16_t nonce)
|
|
256
|
+
{
|
|
257
|
+
#if defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
|
|
258
|
+
int i;
|
|
259
|
+
#endif
|
|
260
|
+
|
|
261
|
+
/* Safety: nonce is at most ((UINT16_MAX - MLDSA_L) / MLDSA_L), and, hence,
|
|
262
|
+
* this cast is safe. See MLD_NONCE_UB comment in sign.c. */
|
|
263
|
+
nonce = (uint16_t)(MLDSA_L * nonce);
|
|
264
|
+
/* Now, nonce <= UINT16_MAX - (MLDSA_L - 1), so the casts below are safe. */
|
|
265
|
+
#if defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
|
|
266
|
+
for (i = 0; i < MLDSA_L; i++)
|
|
267
|
+
{
|
|
268
|
+
mld_poly_uniform_gamma1(&v->vec[i], seed, (uint16_t)(nonce + i));
|
|
269
|
+
}
|
|
270
|
+
#else /* MLD_CONFIG_SERIAL_FIPS202_ONLY */
|
|
271
|
+
#if MLDSA_L == 4
|
|
272
|
+
mld_poly_uniform_gamma1_4x(&v->vec[0], &v->vec[1], &v->vec[2], &v->vec[3],
|
|
273
|
+
seed, nonce, (uint16_t)(nonce + 1),
|
|
274
|
+
(uint16_t)(nonce + 2), (uint16_t)(nonce + 3));
|
|
275
|
+
#elif MLDSA_L == 5
|
|
276
|
+
mld_poly_uniform_gamma1_4x(&v->vec[0], &v->vec[1], &v->vec[2], &v->vec[3],
|
|
277
|
+
seed, nonce, (uint16_t)(nonce + 1),
|
|
278
|
+
(uint16_t)(nonce + 2), (uint16_t)(nonce + 3));
|
|
279
|
+
mld_poly_uniform_gamma1(&v->vec[4], seed, (uint16_t)(nonce + 4));
|
|
280
|
+
#elif MLDSA_L == 7
|
|
281
|
+
mld_poly_uniform_gamma1_4x(&v->vec[0], &v->vec[1], &v->vec[2],
|
|
282
|
+
&v->vec[3 /* irrelevant */], seed, nonce,
|
|
283
|
+
(uint16_t)(nonce + 1), (uint16_t)(nonce + 2),
|
|
284
|
+
0xFF /* irrelevant */);
|
|
285
|
+
mld_poly_uniform_gamma1_4x(&v->vec[3], &v->vec[4], &v->vec[5], &v->vec[6],
|
|
286
|
+
seed, (uint16_t)(nonce + 3), (uint16_t)(nonce + 4),
|
|
287
|
+
(uint16_t)(nonce + 5), (uint16_t)(nonce + 6));
|
|
288
|
+
#endif /* MLDSA_L == 7 */
|
|
289
|
+
#endif /* !MLD_CONFIG_SERIAL_FIPS202_ONLY */
|
|
290
|
+
|
|
291
|
+
mld_assert_bound_2d(v->vec, MLDSA_L, MLDSA_N, -(MLDSA_GAMMA1 - 1),
|
|
292
|
+
MLDSA_GAMMA1 + 1);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
MLD_INTERNAL_API
|
|
296
|
+
void mld_polyvecl_ntt(mld_polyvecl *v)
|
|
297
|
+
{
|
|
298
|
+
unsigned int i;
|
|
299
|
+
mld_assert_abs_bound_2d(v->vec, MLDSA_L, MLDSA_N, MLDSA_Q);
|
|
300
|
+
|
|
301
|
+
for (i = 0; i < MLDSA_L; ++i)
|
|
302
|
+
__loop__(
|
|
303
|
+
assigns(i, memory_slice(v, sizeof(mld_polyvecl)))
|
|
304
|
+
invariant(i <= MLDSA_L)
|
|
305
|
+
invariant(forall(k0, i, MLDSA_L, forall(k1, 0, MLDSA_N, v->vec[k0].coeffs[k1] == loop_entry(*v).vec[k0].coeffs[k1])))
|
|
306
|
+
invariant(forall(k1, 0, i, array_abs_bound(v->vec[k1].coeffs, 0, MLDSA_N, MLD_NTT_BOUND)))
|
|
307
|
+
decreases(MLDSA_L - i))
|
|
308
|
+
{
|
|
309
|
+
mld_poly_ntt(&v->vec[i]);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
mld_assert_abs_bound_2d(v->vec, MLDSA_L, MLDSA_N, MLD_NTT_BOUND);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
MLD_STATIC_TESTABLE void mld_polyvecl_pointwise_acc_montgomery_c(
|
|
316
|
+
mld_poly *w, const mld_polyvecl *u, const mld_polyvecl *v)
|
|
317
|
+
__contract__(
|
|
318
|
+
requires(memory_no_alias(w, sizeof(mld_poly)))
|
|
319
|
+
requires(memory_no_alias(u, sizeof(mld_polyvecl)))
|
|
320
|
+
requires(memory_no_alias(v, sizeof(mld_polyvecl)))
|
|
321
|
+
requires(forall(l0, 0, MLDSA_L,
|
|
322
|
+
array_bound(u->vec[l0].coeffs, 0, MLDSA_N, 0, MLDSA_Q)))
|
|
323
|
+
requires(forall(l1, 0, MLDSA_L,
|
|
324
|
+
array_abs_bound(v->vec[l1].coeffs, 0, MLDSA_N, MLD_NTT_BOUND)))
|
|
325
|
+
assigns(memory_slice(w, sizeof(mld_poly)))
|
|
326
|
+
ensures(array_abs_bound(w->coeffs, 0, MLDSA_N, MLDSA_Q))
|
|
327
|
+
)
|
|
328
|
+
{
|
|
329
|
+
unsigned int i, j;
|
|
330
|
+
mld_assert_bound_2d(u->vec, MLDSA_L, MLDSA_N, 0, MLDSA_Q);
|
|
331
|
+
mld_assert_abs_bound_2d(v->vec, MLDSA_L, MLDSA_N, MLD_NTT_BOUND);
|
|
332
|
+
for (i = 0; i < MLDSA_N; i++)
|
|
333
|
+
__loop__(
|
|
334
|
+
assigns(i, j, memory_slice(w, sizeof(mld_poly)))
|
|
335
|
+
invariant(i <= MLDSA_N)
|
|
336
|
+
invariant(array_abs_bound(w->coeffs, 0, i, MLDSA_Q))
|
|
337
|
+
decreases(MLDSA_N - i)
|
|
338
|
+
)
|
|
339
|
+
{
|
|
340
|
+
int64_t t = 0;
|
|
341
|
+
int32_t r;
|
|
342
|
+
for (j = 0; j < MLDSA_L; j++)
|
|
343
|
+
__loop__(
|
|
344
|
+
assigns(j, t)
|
|
345
|
+
invariant(j <= MLDSA_L)
|
|
346
|
+
invariant(t >= -(int64_t)j*(MLDSA_Q - 1)*(MLD_NTT_BOUND - 1))
|
|
347
|
+
invariant(t <= (int64_t)j*(MLDSA_Q - 1)*(MLD_NTT_BOUND - 1))
|
|
348
|
+
decreases(MLDSA_L - j)
|
|
349
|
+
)
|
|
350
|
+
{
|
|
351
|
+
t += (int64_t)u->vec[j].coeffs[i] * v->vec[j].coeffs[i];
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
r = mld_montgomery_reduce(t);
|
|
355
|
+
w->coeffs[i] = r;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
mld_assert_abs_bound(w->coeffs, MLDSA_N, MLDSA_Q);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
MLD_INTERNAL_API
|
|
362
|
+
void mld_polyvecl_pointwise_acc_montgomery(mld_poly *w, const mld_polyvecl *u,
|
|
363
|
+
const mld_polyvecl *v)
|
|
364
|
+
{
|
|
365
|
+
#if defined(MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L4) && \
|
|
366
|
+
MLD_CONFIG_PARAMETER_SET == 44
|
|
367
|
+
int ret;
|
|
368
|
+
mld_assert_bound_2d(u->vec, MLDSA_L, MLDSA_N, 0, MLDSA_Q);
|
|
369
|
+
mld_assert_abs_bound_2d(v->vec, MLDSA_L, MLDSA_N, MLD_NTT_BOUND);
|
|
370
|
+
ret = mld_polyvecl_pointwise_acc_montgomery_l4_native(
|
|
371
|
+
w->coeffs, (const int32_t (*)[MLDSA_N])u->vec,
|
|
372
|
+
(const int32_t (*)[MLDSA_N])v->vec);
|
|
373
|
+
if (ret == MLD_NATIVE_FUNC_SUCCESS)
|
|
374
|
+
{
|
|
375
|
+
mld_assert_abs_bound(w->coeffs, MLDSA_N, MLDSA_Q);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
#elif defined(MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L5) && \
|
|
379
|
+
MLD_CONFIG_PARAMETER_SET == 65
|
|
380
|
+
int ret;
|
|
381
|
+
mld_assert_bound_2d(u->vec, MLDSA_L, MLDSA_N, 0, MLDSA_Q);
|
|
382
|
+
mld_assert_abs_bound_2d(v->vec, MLDSA_L, MLDSA_N, MLD_NTT_BOUND);
|
|
383
|
+
ret = mld_polyvecl_pointwise_acc_montgomery_l5_native(
|
|
384
|
+
w->coeffs, (const int32_t (*)[MLDSA_N])u->vec,
|
|
385
|
+
(const int32_t (*)[MLDSA_N])v->vec);
|
|
386
|
+
if (ret == MLD_NATIVE_FUNC_SUCCESS)
|
|
387
|
+
{
|
|
388
|
+
mld_assert_abs_bound(w->coeffs, MLDSA_N, MLDSA_Q);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
#elif defined(MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L7) && \
|
|
392
|
+
MLD_CONFIG_PARAMETER_SET == 87
|
|
393
|
+
int ret;
|
|
394
|
+
mld_assert_bound_2d(u->vec, MLDSA_L, MLDSA_N, 0, MLDSA_Q);
|
|
395
|
+
mld_assert_abs_bound_2d(v->vec, MLDSA_L, MLDSA_N, MLD_NTT_BOUND);
|
|
396
|
+
ret = mld_polyvecl_pointwise_acc_montgomery_l7_native(
|
|
397
|
+
w->coeffs, (const int32_t (*)[MLDSA_N])u->vec,
|
|
398
|
+
(const int32_t (*)[MLDSA_N])v->vec);
|
|
399
|
+
if (ret == MLD_NATIVE_FUNC_SUCCESS)
|
|
400
|
+
{
|
|
401
|
+
mld_assert_abs_bound(w->coeffs, MLDSA_N, MLDSA_Q);
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
#endif /* !(MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L4 && \
|
|
405
|
+
MLD_CONFIG_PARAMETER_SET == 44) && \
|
|
406
|
+
!(MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L5 && \
|
|
407
|
+
MLD_CONFIG_PARAMETER_SET == 65) && \
|
|
408
|
+
MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L7 && \
|
|
409
|
+
MLD_CONFIG_PARAMETER_SET == 87 */
|
|
410
|
+
/* The first input is bounded by [0, Q-1] inclusive
|
|
411
|
+
* The second input is bounded by [-9Q+1, 9Q-1] inclusive . Hence, we can
|
|
412
|
+
* safely accumulate in 64-bits without intermediate reductions as
|
|
413
|
+
* MLDSA_L * (MLD_NTT_BOUND-1) * (Q-1) < INT64_MAX
|
|
414
|
+
*
|
|
415
|
+
* The worst case is ML-DSA-87: 7 * (9Q-1) * (Q-1) < 2**52
|
|
416
|
+
* (and likewise for negative values)
|
|
417
|
+
*/
|
|
418
|
+
mld_polyvecl_pointwise_acc_montgomery_c(w, u, v);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
MLD_INTERNAL_API
|
|
422
|
+
uint32_t mld_polyvecl_chknorm(const mld_polyvecl *v, int32_t bound)
|
|
423
|
+
{
|
|
424
|
+
unsigned int i;
|
|
425
|
+
uint32_t t = 0;
|
|
426
|
+
mld_assert_bound_2d(v->vec, MLDSA_L, MLDSA_N, -MLD_REDUCE32_RANGE_MAX,
|
|
427
|
+
MLD_REDUCE32_RANGE_MAX);
|
|
428
|
+
|
|
429
|
+
for (i = 0; i < MLDSA_L; ++i)
|
|
430
|
+
__loop__(
|
|
431
|
+
invariant(i <= MLDSA_L)
|
|
432
|
+
invariant(t == 0 || t == 0xFFFFFFFF)
|
|
433
|
+
invariant((t == 0) == forall(k1, 0, i, array_abs_bound(v->vec[k1].coeffs, 0, MLDSA_N, bound)))
|
|
434
|
+
decreases(MLDSA_L - i)
|
|
435
|
+
)
|
|
436
|
+
{
|
|
437
|
+
/* Reference: Leaks which polynomial violates the bound via a conditional.
|
|
438
|
+
* We are more conservative to reduce the number of declassifications in
|
|
439
|
+
* constant-time testing.
|
|
440
|
+
*/
|
|
441
|
+
t |= mld_poly_chknorm(&v->vec[i], bound);
|
|
442
|
+
}
|
|
443
|
+
return t;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**************************************************************/
|
|
447
|
+
/************ Vectors of polynomials of length MLDSA_K **************/
|
|
448
|
+
/**************************************************************/
|
|
449
|
+
MLD_INTERNAL_API
|
|
450
|
+
void mld_polyveck_reduce(mld_polyveck *v)
|
|
451
|
+
{
|
|
452
|
+
unsigned int i;
|
|
453
|
+
mld_assert_bound_2d(v->vec, MLDSA_K, MLDSA_N, INT32_MIN,
|
|
454
|
+
MLD_REDUCE32_DOMAIN_MAX);
|
|
455
|
+
|
|
456
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
457
|
+
__loop__(
|
|
458
|
+
assigns(i, memory_slice(v, sizeof(mld_polyveck)))
|
|
459
|
+
invariant(i <= MLDSA_K)
|
|
460
|
+
invariant(forall(k0, i, MLDSA_K, forall(k1, 0, MLDSA_N, v->vec[k0].coeffs[k1] == loop_entry(*v).vec[k0].coeffs[k1])))
|
|
461
|
+
invariant(forall(k2, 0, i,
|
|
462
|
+
array_bound(v->vec[k2].coeffs, 0, MLDSA_N, -MLD_REDUCE32_RANGE_MAX, MLD_REDUCE32_RANGE_MAX)))
|
|
463
|
+
decreases(MLDSA_K - i)
|
|
464
|
+
)
|
|
465
|
+
{
|
|
466
|
+
mld_poly_reduce(&v->vec[i]);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
mld_assert_bound_2d(v->vec, MLDSA_K, MLDSA_N, -MLD_REDUCE32_RANGE_MAX,
|
|
470
|
+
MLD_REDUCE32_RANGE_MAX);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
MLD_INTERNAL_API
|
|
474
|
+
void mld_polyveck_caddq(mld_polyveck *v)
|
|
475
|
+
{
|
|
476
|
+
unsigned int i;
|
|
477
|
+
mld_assert_abs_bound_2d(v->vec, MLDSA_K, MLDSA_N, MLDSA_Q);
|
|
478
|
+
|
|
479
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
480
|
+
__loop__(
|
|
481
|
+
assigns(i, memory_slice(v, sizeof(mld_polyveck)))
|
|
482
|
+
invariant(i <= MLDSA_K)
|
|
483
|
+
invariant(forall(k0, i, MLDSA_K, forall(k1, 0, MLDSA_N, v->vec[k0].coeffs[k1] == loop_entry(*v).vec[k0].coeffs[k1])))
|
|
484
|
+
invariant(forall(k1, 0, i, array_bound(v->vec[k1].coeffs, 0, MLDSA_N, 0, MLDSA_Q)))
|
|
485
|
+
decreases(MLDSA_K - i))
|
|
486
|
+
{
|
|
487
|
+
mld_poly_caddq(&v->vec[i]);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
mld_assert_bound_2d(v->vec, MLDSA_K, MLDSA_N, 0, MLDSA_Q);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/* Reference: We use destructive version (output=first input) to avoid
|
|
494
|
+
* reasoning about aliasing in the CBMC specification */
|
|
495
|
+
MLD_INTERNAL_API
|
|
496
|
+
void mld_polyveck_add(mld_polyveck *u, const mld_polyveck *v)
|
|
497
|
+
{
|
|
498
|
+
unsigned int i;
|
|
499
|
+
|
|
500
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
501
|
+
__loop__(
|
|
502
|
+
assigns(i, memory_slice(u, sizeof(mld_polyveck)))
|
|
503
|
+
invariant(i <= MLDSA_K)
|
|
504
|
+
invariant(forall(k0, i, MLDSA_K,
|
|
505
|
+
forall(k1, 0, MLDSA_N, u->vec[k0].coeffs[k1] == loop_entry(*u).vec[k0].coeffs[k1])))
|
|
506
|
+
invariant(forall(k6, 0, i, array_bound(u->vec[k6].coeffs, 0, MLDSA_N, INT32_MIN, MLD_REDUCE32_DOMAIN_MAX)))
|
|
507
|
+
decreases(MLDSA_K - i)
|
|
508
|
+
)
|
|
509
|
+
{
|
|
510
|
+
mld_poly_add(&u->vec[i], &v->vec[i]);
|
|
511
|
+
}
|
|
512
|
+
mld_assert_bound_2d(u->vec, MLDSA_K, MLDSA_N, INT32_MIN,
|
|
513
|
+
MLD_REDUCE32_DOMAIN_MAX);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
MLD_INTERNAL_API
|
|
517
|
+
void mld_polyveck_sub(mld_polyveck *u, const mld_polyveck *v)
|
|
518
|
+
{
|
|
519
|
+
unsigned int i;
|
|
520
|
+
mld_assert_abs_bound_2d(u->vec, MLDSA_K, MLDSA_N, MLDSA_Q);
|
|
521
|
+
mld_assert_abs_bound_2d(v->vec, MLDSA_K, MLDSA_N, MLDSA_Q);
|
|
522
|
+
|
|
523
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
524
|
+
__loop__(
|
|
525
|
+
assigns(i, memory_slice(u, sizeof(mld_polyveck)))
|
|
526
|
+
invariant(i <= MLDSA_K)
|
|
527
|
+
invariant(forall(k0, 0, i,
|
|
528
|
+
array_bound(u->vec[k0].coeffs, 0, MLDSA_N, INT32_MIN, MLD_REDUCE32_DOMAIN_MAX)))
|
|
529
|
+
invariant(forall(k1, i, MLDSA_K,
|
|
530
|
+
forall(n1, 0, MLDSA_N, u->vec[k1].coeffs[n1] == loop_entry(*u).vec[k1].coeffs[n1])))
|
|
531
|
+
decreases(MLDSA_K - i))
|
|
532
|
+
{
|
|
533
|
+
mld_poly_sub(&u->vec[i], &v->vec[i]);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
mld_assert_bound_2d(u->vec, MLDSA_K, MLDSA_N, INT32_MIN,
|
|
537
|
+
MLD_REDUCE32_DOMAIN_MAX);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
MLD_INTERNAL_API
|
|
541
|
+
void mld_polyveck_shiftl(mld_polyveck *v)
|
|
542
|
+
{
|
|
543
|
+
unsigned int i;
|
|
544
|
+
mld_assert_bound_2d(v->vec, MLDSA_K, MLDSA_N, 0, 1 << 10);
|
|
545
|
+
|
|
546
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
547
|
+
__loop__(
|
|
548
|
+
assigns(i, memory_slice(v, sizeof(mld_polyveck)))
|
|
549
|
+
invariant(i <= MLDSA_K)
|
|
550
|
+
invariant(forall(k1, 0, i, array_bound(v->vec[k1].coeffs, 0, MLDSA_N, 0, MLDSA_Q)))
|
|
551
|
+
invariant(forall(k1, i, MLDSA_K,
|
|
552
|
+
forall(n1, 0, MLDSA_N, v->vec[k1].coeffs[n1] == loop_entry(*v).vec[k1].coeffs[n1])))
|
|
553
|
+
decreases(MLDSA_K - i)
|
|
554
|
+
)
|
|
555
|
+
{
|
|
556
|
+
mld_poly_shiftl(&v->vec[i]);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
mld_assert_bound_2d(v->vec, MLDSA_K, MLDSA_N, 0, MLDSA_Q);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
MLD_INTERNAL_API
|
|
563
|
+
void mld_polyveck_ntt(mld_polyveck *v)
|
|
564
|
+
{
|
|
565
|
+
unsigned int i;
|
|
566
|
+
mld_assert_abs_bound_2d(v->vec, MLDSA_K, MLDSA_N, MLDSA_Q);
|
|
567
|
+
|
|
568
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
569
|
+
__loop__(
|
|
570
|
+
assigns(i, memory_slice(v, sizeof(mld_polyveck)))
|
|
571
|
+
invariant(i <= MLDSA_K)
|
|
572
|
+
invariant(forall(k0, i, MLDSA_K, forall(k1, 0, MLDSA_N, v->vec[k0].coeffs[k1] == loop_entry(*v).vec[k0].coeffs[k1])))
|
|
573
|
+
invariant(forall(k1, 0, i, array_abs_bound(v->vec[k1].coeffs, 0, MLDSA_N, MLD_NTT_BOUND)))
|
|
574
|
+
decreases(MLDSA_K - i))
|
|
575
|
+
{
|
|
576
|
+
mld_poly_ntt(&v->vec[i]);
|
|
577
|
+
}
|
|
578
|
+
mld_assert_abs_bound_2d(v->vec, MLDSA_K, MLDSA_N, MLD_NTT_BOUND);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
MLD_INTERNAL_API
|
|
582
|
+
void mld_polyveck_invntt_tomont(mld_polyveck *v)
|
|
583
|
+
{
|
|
584
|
+
unsigned int i;
|
|
585
|
+
mld_assert_abs_bound_2d(v->vec, MLDSA_K, MLDSA_N, MLDSA_Q);
|
|
586
|
+
|
|
587
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
588
|
+
__loop__(
|
|
589
|
+
assigns(i, memory_slice(v, sizeof(mld_polyveck)))
|
|
590
|
+
invariant(i <= MLDSA_K)
|
|
591
|
+
invariant(forall(k0, i, MLDSA_K, forall(k1, 0, MLDSA_N, v->vec[k0].coeffs[k1] == loop_entry(*v).vec[k0].coeffs[k1])))
|
|
592
|
+
invariant(forall(k1, 0, i, array_abs_bound(v->vec[k1].coeffs, 0, MLDSA_N, MLD_INTT_BOUND)))
|
|
593
|
+
decreases(MLDSA_K - i))
|
|
594
|
+
{
|
|
595
|
+
mld_poly_invntt_tomont(&v->vec[i]);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
mld_assert_abs_bound_2d(v->vec, MLDSA_K, MLDSA_N, MLD_INTT_BOUND);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
MLD_INTERNAL_API
|
|
602
|
+
void mld_polyveck_pointwise_poly_montgomery(mld_polyveck *r, const mld_poly *a,
|
|
603
|
+
const mld_polyveck *v)
|
|
604
|
+
{
|
|
605
|
+
unsigned int i;
|
|
606
|
+
mld_assert_abs_bound_2d(v->vec, MLDSA_K, MLDSA_N, MLD_NTT_BOUND);
|
|
607
|
+
|
|
608
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
609
|
+
__loop__(
|
|
610
|
+
assigns(i, memory_slice(r, sizeof(mld_polyveck)))
|
|
611
|
+
invariant(i <= MLDSA_K)
|
|
612
|
+
invariant(forall(k2, 0, i, array_abs_bound(r->vec[k2].coeffs, 0, MLDSA_N, MLDSA_Q)))
|
|
613
|
+
decreases(MLDSA_K - i)
|
|
614
|
+
)
|
|
615
|
+
{
|
|
616
|
+
mld_poly_pointwise_montgomery(&r->vec[i], a, &v->vec[i]);
|
|
617
|
+
}
|
|
618
|
+
mld_assert_abs_bound_2d(r->vec, MLDSA_K, MLDSA_N, MLDSA_Q);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
MLD_INTERNAL_API
|
|
622
|
+
uint32_t mld_polyveck_chknorm(const mld_polyveck *v, int32_t bound)
|
|
623
|
+
{
|
|
624
|
+
unsigned int i;
|
|
625
|
+
uint32_t t = 0;
|
|
626
|
+
mld_assert_bound_2d(v->vec, MLDSA_K, MLDSA_N, -MLD_REDUCE32_RANGE_MAX,
|
|
627
|
+
MLD_REDUCE32_RANGE_MAX);
|
|
628
|
+
|
|
629
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
630
|
+
__loop__(
|
|
631
|
+
invariant(i <= MLDSA_K)
|
|
632
|
+
invariant(t == 0 || t == 0xFFFFFFFF)
|
|
633
|
+
invariant((t == 0) == forall(k1, 0, i, array_abs_bound(v->vec[k1].coeffs, 0, MLDSA_N, bound)))
|
|
634
|
+
decreases(MLDSA_K - i)
|
|
635
|
+
)
|
|
636
|
+
{
|
|
637
|
+
/* Reference: Leaks which polynomial violates the bound via a conditional.
|
|
638
|
+
* We are more conservative to reduce the number of declassifications in
|
|
639
|
+
* constant-time testing.
|
|
640
|
+
*/
|
|
641
|
+
t |= mld_poly_chknorm(&v->vec[i], bound);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
return t;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
MLD_INTERNAL_API
|
|
648
|
+
void mld_polyveck_power2round(mld_polyveck *v1, mld_polyveck *v0,
|
|
649
|
+
const mld_polyveck *v)
|
|
650
|
+
{
|
|
651
|
+
unsigned int i;
|
|
652
|
+
mld_assert_bound_2d(v->vec, MLDSA_K, MLDSA_N, 0, MLDSA_Q);
|
|
653
|
+
|
|
654
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
655
|
+
__loop__(
|
|
656
|
+
assigns(i, memory_slice(v0, sizeof(mld_polyveck)), memory_slice(v1, sizeof(mld_polyveck)))
|
|
657
|
+
invariant(i <= MLDSA_K)
|
|
658
|
+
invariant(forall(k1, 0, i, array_bound(v0->vec[k1].coeffs, 0, MLDSA_N, -(MLD_2_POW_D/2)+1, (MLD_2_POW_D/2)+1)))
|
|
659
|
+
invariant(forall(k2, 0, i, array_bound(v1->vec[k2].coeffs, 0, MLDSA_N, 0, ((MLDSA_Q - 1) / MLD_2_POW_D) + 1)))
|
|
660
|
+
decreases(MLDSA_K - i)
|
|
661
|
+
)
|
|
662
|
+
{
|
|
663
|
+
mld_poly_power2round(&v1->vec[i], &v0->vec[i], &v->vec[i]);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
mld_assert_bound_2d(v0->vec, MLDSA_K, MLDSA_N, -(MLD_2_POW_D / 2) + 1,
|
|
667
|
+
(MLD_2_POW_D / 2) + 1);
|
|
668
|
+
mld_assert_bound_2d(v1->vec, MLDSA_K, MLDSA_N, 0,
|
|
669
|
+
((MLDSA_Q - 1) / MLD_2_POW_D) + 1);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
MLD_INTERNAL_API
|
|
673
|
+
void mld_polyveck_decompose(mld_polyveck *v1, mld_polyveck *v0)
|
|
674
|
+
{
|
|
675
|
+
unsigned int i;
|
|
676
|
+
mld_assert_bound_2d(v0->vec, MLDSA_K, MLDSA_N, 0, MLDSA_Q);
|
|
677
|
+
|
|
678
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
679
|
+
__loop__(
|
|
680
|
+
assigns(i, memory_slice(v0, sizeof(mld_polyveck)), memory_slice(v1, sizeof(mld_polyveck)))
|
|
681
|
+
invariant(i <= MLDSA_K)
|
|
682
|
+
invariant(forall(k1, 0, i,
|
|
683
|
+
array_bound(v1->vec[k1].coeffs, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2))))
|
|
684
|
+
invariant(forall(k2, 0, i,
|
|
685
|
+
array_abs_bound(v0->vec[k2].coeffs, 0, MLDSA_N, MLDSA_GAMMA2+1)))
|
|
686
|
+
invariant(forall(k3, i, MLDSA_K,
|
|
687
|
+
array_bound(v0->vec[k3].coeffs, 0, MLDSA_N, 0, MLDSA_Q)))
|
|
688
|
+
decreases(MLDSA_K - i)
|
|
689
|
+
)
|
|
690
|
+
{
|
|
691
|
+
mld_poly_decompose(&v1->vec[i], &v0->vec[i]);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
mld_assert_bound_2d(v1->vec, MLDSA_K, MLDSA_N, 0,
|
|
695
|
+
(MLDSA_Q - 1) / (2 * MLDSA_GAMMA2));
|
|
696
|
+
mld_assert_abs_bound_2d(v0->vec, MLDSA_K, MLDSA_N, MLDSA_GAMMA2 + 1);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
MLD_INTERNAL_API
|
|
700
|
+
unsigned int mld_polyveck_make_hint(mld_polyveck *h, const mld_polyveck *v0,
|
|
701
|
+
const mld_polyveck *v1)
|
|
702
|
+
{
|
|
703
|
+
unsigned int i, s = 0;
|
|
704
|
+
|
|
705
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
706
|
+
__loop__(
|
|
707
|
+
assigns(i, s, memory_slice(h, sizeof(mld_polyveck)))
|
|
708
|
+
invariant(i <= MLDSA_K)
|
|
709
|
+
invariant(s <= i * MLDSA_N)
|
|
710
|
+
invariant(forall(k1, 0, i, array_bound(h->vec[k1].coeffs, 0, MLDSA_N, 0, 2)))
|
|
711
|
+
decreases(MLDSA_K - i)
|
|
712
|
+
)
|
|
713
|
+
{
|
|
714
|
+
s += mld_poly_make_hint(&h->vec[i], &v0->vec[i], &v1->vec[i]);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
mld_assert_bound_2d(h->vec, MLDSA_K, MLDSA_N, 0, 2);
|
|
718
|
+
return s;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
MLD_INTERNAL_API
|
|
722
|
+
void mld_polyveck_use_hint(mld_polyveck *w, const mld_polyveck *u,
|
|
723
|
+
const mld_polyveck *h)
|
|
724
|
+
{
|
|
725
|
+
unsigned int i;
|
|
726
|
+
mld_assert_bound_2d(u->vec, MLDSA_K, MLDSA_N, 0, MLDSA_Q);
|
|
727
|
+
mld_assert_bound_2d(h->vec, MLDSA_K, MLDSA_N, 0, 2);
|
|
728
|
+
|
|
729
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
730
|
+
__loop__(
|
|
731
|
+
assigns(i, memory_slice(w, sizeof(mld_polyveck)))
|
|
732
|
+
invariant(i <= MLDSA_K)
|
|
733
|
+
invariant(forall(k2, 0, i,
|
|
734
|
+
array_bound(w->vec[k2].coeffs, 0, MLDSA_N, 0,
|
|
735
|
+
(MLDSA_Q - 1) / (2 * MLDSA_GAMMA2))))
|
|
736
|
+
decreases(MLDSA_K - i)
|
|
737
|
+
)
|
|
738
|
+
{
|
|
739
|
+
mld_poly_use_hint(&w->vec[i], &u->vec[i], &h->vec[i]);
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
mld_assert_bound_2d(w->vec, MLDSA_K, MLDSA_N, 0,
|
|
743
|
+
(MLDSA_Q - 1) / (2 * MLDSA_GAMMA2));
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
MLD_INTERNAL_API
|
|
747
|
+
void mld_polyveck_pack_w1(uint8_t r[MLDSA_K * MLDSA_POLYW1_PACKEDBYTES],
|
|
748
|
+
const mld_polyveck *w1)
|
|
749
|
+
{
|
|
750
|
+
unsigned int i;
|
|
751
|
+
mld_assert_bound_2d(w1->vec, MLDSA_K, MLDSA_N, 0,
|
|
752
|
+
(MLDSA_Q - 1) / (2 * MLDSA_GAMMA2));
|
|
753
|
+
|
|
754
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
755
|
+
__loop__(
|
|
756
|
+
assigns(i, memory_slice(r, MLDSA_K * MLDSA_POLYW1_PACKEDBYTES))
|
|
757
|
+
invariant(i <= MLDSA_K)
|
|
758
|
+
decreases(MLDSA_K - i)
|
|
759
|
+
)
|
|
760
|
+
{
|
|
761
|
+
mld_polyw1_pack(&r[i * MLDSA_POLYW1_PACKEDBYTES], &w1->vec[i]);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
MLD_INTERNAL_API
|
|
766
|
+
void mld_polyveck_pack_eta(uint8_t r[MLDSA_K * MLDSA_POLYETA_PACKEDBYTES],
|
|
767
|
+
const mld_polyveck *p)
|
|
768
|
+
{
|
|
769
|
+
unsigned int i;
|
|
770
|
+
mld_assert_abs_bound_2d(p->vec, MLDSA_K, MLDSA_N, MLDSA_ETA + 1);
|
|
771
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
772
|
+
__loop__(
|
|
773
|
+
assigns(i, memory_slice(r, MLDSA_K * MLDSA_POLYETA_PACKEDBYTES))
|
|
774
|
+
invariant(i <= MLDSA_K)
|
|
775
|
+
decreases(MLDSA_K - i)
|
|
776
|
+
)
|
|
777
|
+
{
|
|
778
|
+
mld_polyeta_pack(&r[i * MLDSA_POLYETA_PACKEDBYTES], &p->vec[i]);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
MLD_INTERNAL_API
|
|
783
|
+
void mld_polyvecl_pack_eta(uint8_t r[MLDSA_L * MLDSA_POLYETA_PACKEDBYTES],
|
|
784
|
+
const mld_polyvecl *p)
|
|
785
|
+
{
|
|
786
|
+
unsigned int i;
|
|
787
|
+
mld_assert_abs_bound_2d(p->vec, MLDSA_L, MLDSA_N, MLDSA_ETA + 1);
|
|
788
|
+
for (i = 0; i < MLDSA_L; ++i)
|
|
789
|
+
__loop__(
|
|
790
|
+
assigns(i, memory_slice(r, MLDSA_L * MLDSA_POLYETA_PACKEDBYTES))
|
|
791
|
+
invariant(i <= MLDSA_L)
|
|
792
|
+
decreases(MLDSA_L - i)
|
|
793
|
+
)
|
|
794
|
+
{
|
|
795
|
+
mld_polyeta_pack(&r[i * MLDSA_POLYETA_PACKEDBYTES], &p->vec[i]);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
MLD_INTERNAL_API
|
|
800
|
+
void mld_polyveck_pack_t0(uint8_t r[MLDSA_K * MLDSA_POLYT0_PACKEDBYTES],
|
|
801
|
+
const mld_polyveck *p)
|
|
802
|
+
{
|
|
803
|
+
unsigned int i;
|
|
804
|
+
mld_assert_bound_2d(p->vec, MLDSA_K, MLDSA_N, -(1 << (MLDSA_D - 1)) + 1,
|
|
805
|
+
(1 << (MLDSA_D - 1)) + 1);
|
|
806
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
807
|
+
__loop__(
|
|
808
|
+
assigns(i, memory_slice(r, MLDSA_K * MLDSA_POLYT0_PACKEDBYTES))
|
|
809
|
+
invariant(i <= MLDSA_K)
|
|
810
|
+
decreases(MLDSA_K - i)
|
|
811
|
+
)
|
|
812
|
+
{
|
|
813
|
+
mld_polyt0_pack(&r[i * MLDSA_POLYT0_PACKEDBYTES], &p->vec[i]);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
MLD_INTERNAL_API
|
|
818
|
+
void mld_polyvecl_unpack_eta(
|
|
819
|
+
mld_polyvecl *p, const uint8_t r[MLDSA_L * MLDSA_POLYETA_PACKEDBYTES])
|
|
820
|
+
{
|
|
821
|
+
unsigned int i;
|
|
822
|
+
for (i = 0; i < MLDSA_L; ++i)
|
|
823
|
+
{
|
|
824
|
+
mld_polyeta_unpack(&p->vec[i], r + i * MLDSA_POLYETA_PACKEDBYTES);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
mld_assert_bound_2d(p->vec, MLDSA_L, MLDSA_N, MLD_POLYETA_UNPACK_LOWER_BOUND,
|
|
828
|
+
MLDSA_ETA + 1);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
MLD_INTERNAL_API
|
|
832
|
+
void mld_polyvecl_unpack_z(mld_polyvecl *z,
|
|
833
|
+
const uint8_t r[MLDSA_L * MLDSA_POLYZ_PACKEDBYTES])
|
|
834
|
+
{
|
|
835
|
+
unsigned int i;
|
|
836
|
+
for (i = 0; i < MLDSA_L; ++i)
|
|
837
|
+
{
|
|
838
|
+
mld_polyz_unpack(&z->vec[i], r + i * MLDSA_POLYZ_PACKEDBYTES);
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
mld_assert_bound_2d(z->vec, MLDSA_L, MLDSA_N, -(MLDSA_GAMMA1 - 1),
|
|
842
|
+
MLDSA_GAMMA1 + 1);
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
MLD_INTERNAL_API
|
|
846
|
+
void mld_polyveck_unpack_eta(
|
|
847
|
+
mld_polyveck *p, const uint8_t r[MLDSA_K * MLDSA_POLYETA_PACKEDBYTES])
|
|
848
|
+
{
|
|
849
|
+
unsigned int i;
|
|
850
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
851
|
+
{
|
|
852
|
+
mld_polyeta_unpack(&p->vec[i], r + i * MLDSA_POLYETA_PACKEDBYTES);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
mld_assert_bound_2d(p->vec, MLDSA_K, MLDSA_N, MLD_POLYETA_UNPACK_LOWER_BOUND,
|
|
856
|
+
MLDSA_ETA + 1);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
MLD_INTERNAL_API
|
|
860
|
+
void mld_polyveck_unpack_t0(mld_polyveck *p,
|
|
861
|
+
const uint8_t r[MLDSA_K * MLDSA_POLYT0_PACKEDBYTES])
|
|
862
|
+
{
|
|
863
|
+
unsigned int i;
|
|
864
|
+
for (i = 0; i < MLDSA_K; ++i)
|
|
865
|
+
{
|
|
866
|
+
mld_polyt0_unpack(&p->vec[i], r + i * MLDSA_POLYT0_PACKEDBYTES);
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
mld_assert_bound_2d(p->vec, MLDSA_K, MLDSA_N, -(1 << (MLDSA_D - 1)) + 1,
|
|
870
|
+
(1 << (MLDSA_D - 1)) + 1);
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
|
|
874
|
+
* Don't modify by hand -- this is auto-generated by scripts/autogen. */
|
|
875
|
+
#undef mld_polymat_permute_bitrev_to_custom
|
|
876
|
+
#undef mld_polyvecl_permute_bitrev_to_custom
|
|
877
|
+
#undef mld_polyvecl_pointwise_acc_montgomery_c
|