pq_crypto 0.3.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/.github/workflows/ci.yml +56 -0
- data/CHANGELOG.md +62 -0
- data/GET_STARTED.md +366 -40
- data/README.md +76 -233
- data/SECURITY.md +107 -82
- data/ext/pqcrypto/extconf.rb +169 -87
- data/ext/pqcrypto/mldsa_api.h +1 -48
- data/ext/pqcrypto/mlkem_api.h +1 -18
- data/ext/pqcrypto/pq_externalmu.c +89 -204
- data/ext/pqcrypto/pqcrypto_native_api.h +129 -0
- data/ext/pqcrypto/pqcrypto_ruby_secure.c +484 -84
- data/ext/pqcrypto/pqcrypto_secure.c +203 -78
- data/ext/pqcrypto/pqcrypto_secure.h +53 -14
- data/ext/pqcrypto/pqcrypto_version.h +7 -0
- 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/algorithm_registry.rb +200 -0
- data/lib/pq_crypto/hybrid_kem.rb +1 -12
- data/lib/pq_crypto/kem.rb +104 -13
- data/lib/pq_crypto/pkcs8.rb +387 -0
- data/lib/pq_crypto/serialization.rb +1 -14
- data/lib/pq_crypto/signature.rb +123 -17
- data/lib/pq_crypto/spki.rb +131 -0
- data/lib/pq_crypto/version.rb +1 -1
- data/lib/pq_crypto.rb +79 -20
- data/script/vendor_libs.rb +88 -155
- metadata +241 -73
- 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-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-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
|
@@ -0,0 +1,649 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) The mlkem-native project authors
|
|
3
|
+
* Copyright (c) The mldsa-native project authors
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#ifndef MLD_NATIVE_API_H
|
|
8
|
+
#define MLD_NATIVE_API_H
|
|
9
|
+
/*
|
|
10
|
+
* Native arithmetic interface
|
|
11
|
+
*
|
|
12
|
+
* This header is primarily for documentation purposes.
|
|
13
|
+
* It should not be included by backend implementations.
|
|
14
|
+
*
|
|
15
|
+
* To ensure consistency with backends, the header will be
|
|
16
|
+
* included automatically after inclusion of the active
|
|
17
|
+
* backend, to ensure consistency of function signatures,
|
|
18
|
+
* and run sanity checks.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
#include "../cbmc.h"
|
|
22
|
+
#include "../common.h"
|
|
23
|
+
|
|
24
|
+
/* Backends must return MLD_NATIVE_FUNC_SUCCESS upon success. */
|
|
25
|
+
#define MLD_NATIVE_FUNC_SUCCESS (0)
|
|
26
|
+
/* Backends may return MLD_NATIVE_FUNC_FALLBACK to signal to the frontend that
|
|
27
|
+
* the target/parameters are unsupported; typically, this would be because of
|
|
28
|
+
* dependencies on CPU features not detected on the host CPU. In this case,
|
|
29
|
+
* the frontend falls back to the default C implementation.
|
|
30
|
+
*
|
|
31
|
+
* IMPORTANT: Backend implementations must ensure that the decision of whether
|
|
32
|
+
* to fallback (return MLD_NATIVE_FUNC_FALLBACK) or not must never depend on
|
|
33
|
+
* the input data itself. Fallback decisions may only depend on system
|
|
34
|
+
* capabilities (e.g., CPU features) and, where present, length information.
|
|
35
|
+
* This requirement applies to all backend functions to maintain constant-time
|
|
36
|
+
* properties.
|
|
37
|
+
*/
|
|
38
|
+
#define MLD_NATIVE_FUNC_FALLBACK (-1)
|
|
39
|
+
|
|
40
|
+
/* Bound on absolute value of coefficients after NTT.
|
|
41
|
+
*
|
|
42
|
+
* NOTE: This is the same bound as in poly.h and has to be kept
|
|
43
|
+
* in sync. */
|
|
44
|
+
#define MLD_NTT_BOUND (9 * MLDSA_Q)
|
|
45
|
+
|
|
46
|
+
/* Absolute exclusive upper bound for the output of the inverse NTT
|
|
47
|
+
*
|
|
48
|
+
* NOTE: This is the same bound as in poly.h and has to be kept
|
|
49
|
+
* in sync. */
|
|
50
|
+
#define MLD_INTT_BOUND MLDSA_Q
|
|
51
|
+
|
|
52
|
+
/* Absolute bound for range of mld_reduce32()
|
|
53
|
+
*
|
|
54
|
+
* NOTE: This is the same bound as in reduce.h and has to be kept
|
|
55
|
+
* in sync. */
|
|
56
|
+
/* check-magic: 6283009 == (MLD_REDUCE32_DOMAIN_MAX - 255 * MLDSA_Q + 1) */
|
|
57
|
+
#define MLD_REDUCE32_RANGE_MAX 6283009
|
|
58
|
+
/*
|
|
59
|
+
* This is the C<->native interface allowing for the drop-in of
|
|
60
|
+
* native code for performance critical arithmetic components of ML-DSA.
|
|
61
|
+
*
|
|
62
|
+
* A _backend_ is a specific implementation of (part of) this interface.
|
|
63
|
+
*
|
|
64
|
+
* To add a function to a backend, define MLD_USE_NATIVE_XXX and
|
|
65
|
+
* implement `static inline xxx(...)` in the profile header.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
/*
|
|
69
|
+
* Those functions are meant to be trivial wrappers around the chosen native
|
|
70
|
+
* implementation. The are static inline to avoid unnecessary calls.
|
|
71
|
+
* The macro before each declaration controls whether a native
|
|
72
|
+
* implementation is present.
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
#if defined(MLD_USE_NATIVE_NTT)
|
|
76
|
+
/*************************************************
|
|
77
|
+
* Name: mld_ntt_native
|
|
78
|
+
*
|
|
79
|
+
* Description: Computes negacyclic number-theoretic transform (NTT) of
|
|
80
|
+
* a polynomial in place.
|
|
81
|
+
*
|
|
82
|
+
* The input polynomial is assumed to be in normal order.
|
|
83
|
+
* The output polynomial is in bitreversed order.
|
|
84
|
+
*
|
|
85
|
+
* Arguments: - int32_t p[MLDSA_N]: pointer to in/output polynomial
|
|
86
|
+
**************************************************/
|
|
87
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
88
|
+
static MLD_INLINE int mld_ntt_native(int32_t p[MLDSA_N])
|
|
89
|
+
__contract__(
|
|
90
|
+
requires(memory_no_alias(p, sizeof(int32_t) * MLDSA_N))
|
|
91
|
+
requires(array_abs_bound(p, 0, MLDSA_N, MLDSA_Q))
|
|
92
|
+
assigns(memory_slice(p, sizeof(int32_t) * MLDSA_N))
|
|
93
|
+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
|
|
94
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(p, 0, MLDSA_N, MLD_NTT_BOUND))
|
|
95
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_abs_bound(p, 0, MLDSA_N, MLDSA_Q))
|
|
96
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(p, MLDSA_N))
|
|
97
|
+
);
|
|
98
|
+
#endif /* MLD_USE_NATIVE_NTT */
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
#if defined(MLD_USE_NATIVE_NTT_CUSTOM_ORDER)
|
|
102
|
+
/*
|
|
103
|
+
* This must only be set if NTT and INTT have native implementations
|
|
104
|
+
* that are adapted to the custom order.
|
|
105
|
+
*/
|
|
106
|
+
#if !defined(MLD_USE_NATIVE_NTT) || !defined(MLD_USE_NATIVE_INTT)
|
|
107
|
+
#error \
|
|
108
|
+
"Invalid native profile: MLD_USE_NATIVE_NTT_CUSTOM_ORDER can only be \
|
|
109
|
+
set if there are native implementations for NTT and INTT."
|
|
110
|
+
#endif
|
|
111
|
+
|
|
112
|
+
/*************************************************
|
|
113
|
+
* Name: mlD_poly_permute_bitrev_to_custom
|
|
114
|
+
*
|
|
115
|
+
* Description: When MLD_USE_NATIVE_NTT_CUSTOM_ORDER is defined,
|
|
116
|
+
* convert a polynomial in NTT domain from bitreversed
|
|
117
|
+
* order to the custom order output by the native NTT.
|
|
118
|
+
*
|
|
119
|
+
* This must only be defined if there is native code for
|
|
120
|
+
* both the NTT and INTT.
|
|
121
|
+
*
|
|
122
|
+
* Arguments: - int32_t p[MLDSA_N]: pointer to in/output polynomial
|
|
123
|
+
*
|
|
124
|
+
**************************************************/
|
|
125
|
+
static MLD_INLINE void mld_poly_permute_bitrev_to_custom(int32_t p[MLDSA_N])
|
|
126
|
+
__contract__(
|
|
127
|
+
/* We don't specify that this should be a permutation, but only
|
|
128
|
+
* that it does not change the bound established at the end of
|
|
129
|
+
* mld_polyvec_matrix_expand.
|
|
130
|
+
*/
|
|
131
|
+
requires(memory_no_alias(p, sizeof(int32_t) * MLDSA_N))
|
|
132
|
+
requires(array_bound(p, 0, MLDSA_N, 0, MLDSA_Q))
|
|
133
|
+
assigns(memory_slice(p, sizeof(int32_t) * MLDSA_N))
|
|
134
|
+
ensures(array_bound(p, 0, MLDSA_N, 0, MLDSA_Q)));
|
|
135
|
+
#endif /* MLD_USE_NATIVE_NTT_CUSTOM_ORDER */
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
#if defined(MLD_USE_NATIVE_INTT)
|
|
139
|
+
/*************************************************
|
|
140
|
+
* Name: mld_intt_native
|
|
141
|
+
*
|
|
142
|
+
* Description: Computes inverse of negacyclic number-theoretic transform
|
|
143
|
+
*(NTT) of a polynomial in place.
|
|
144
|
+
*
|
|
145
|
+
* The input polynomial is in bitreversed order.
|
|
146
|
+
* The output polynomial is assumed to be in normal order.
|
|
147
|
+
*
|
|
148
|
+
* Arguments: - uint32_t p[MLDSA_N]: pointer to in/output polynomial
|
|
149
|
+
**************************************************/
|
|
150
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
151
|
+
static MLD_INLINE int mld_intt_native(int32_t p[MLDSA_N])
|
|
152
|
+
__contract__(
|
|
153
|
+
requires(memory_no_alias(p, sizeof(int32_t) * MLDSA_N))
|
|
154
|
+
requires(array_abs_bound(p, 0, MLDSA_N, MLDSA_Q))
|
|
155
|
+
assigns(memory_slice(p, sizeof(int32_t) * MLDSA_N))
|
|
156
|
+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
|
|
157
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(p, 0, MLDSA_N, MLD_INTT_BOUND))
|
|
158
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_abs_bound(p, 0, MLDSA_N, MLDSA_Q))
|
|
159
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(p, MLDSA_N))
|
|
160
|
+
);
|
|
161
|
+
#endif /* MLD_USE_NATIVE_INTT */
|
|
162
|
+
|
|
163
|
+
#if defined(MLD_USE_NATIVE_REJ_UNIFORM)
|
|
164
|
+
/*************************************************
|
|
165
|
+
* Name: mld_rej_uniform_native
|
|
166
|
+
*
|
|
167
|
+
* Description: Run rejection sampling on uniform random bytes to generate
|
|
168
|
+
* uniform random integers in [0, MLDSA_Q-1]
|
|
169
|
+
*
|
|
170
|
+
* Arguments: - int32_t *r: pointer to output buffer
|
|
171
|
+
* - unsigned len: requested number of 32-bit integers
|
|
172
|
+
* (uniform mod q).
|
|
173
|
+
* - const uint8_t *buf: pointer to input buffer
|
|
174
|
+
* (assumed to be uniform random bytes)
|
|
175
|
+
* - unsigned buflen: length of input buffer in bytes.
|
|
176
|
+
*
|
|
177
|
+
* Return -1 if the native implementation does not support the input
|
|
178
|
+
* lengths. Otherwise, returns non-negative number of sampled 32-bit integers
|
|
179
|
+
* (at most len).
|
|
180
|
+
**************************************************/
|
|
181
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
182
|
+
static MLD_INLINE int mld_rej_uniform_native(int32_t *r, unsigned len,
|
|
183
|
+
const uint8_t *buf,
|
|
184
|
+
unsigned buflen)
|
|
185
|
+
__contract__(
|
|
186
|
+
requires(len <= MLDSA_N)
|
|
187
|
+
requires(buflen <= ( 5 * 168) && buflen % 3 == 0)
|
|
188
|
+
requires(memory_no_alias(r, sizeof(int32_t) * len))
|
|
189
|
+
requires(memory_no_alias(buf, buflen))
|
|
190
|
+
assigns(memory_slice(r, sizeof(int32_t) * len))
|
|
191
|
+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || (0 <= return_value && return_value <= len))
|
|
192
|
+
ensures((return_value != MLD_NATIVE_FUNC_FALLBACK) ==> array_bound(r, 0, (unsigned) return_value, 0, MLDSA_Q))
|
|
193
|
+
);
|
|
194
|
+
#endif /* MLD_USE_NATIVE_REJ_UNIFORM */
|
|
195
|
+
|
|
196
|
+
#if defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA2)
|
|
197
|
+
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_ETA == 2
|
|
198
|
+
/*************************************************
|
|
199
|
+
* Name: mld_rej_uniform_eta2_native
|
|
200
|
+
*
|
|
201
|
+
* Description: Run rejection sampling on uniform random bytes to generate
|
|
202
|
+
* uniform random integers in [-2,+2].
|
|
203
|
+
*
|
|
204
|
+
* Arguments: - int32_t *r: pointer to output buffer
|
|
205
|
+
* - unsigned len: requested number of 32-bit integers
|
|
206
|
+
* (uniform in [-2, +2]).
|
|
207
|
+
* - const uint8_t *buf: pointer to input buffer
|
|
208
|
+
* (assumed to be uniform random bytes)
|
|
209
|
+
* - unsigned buflen: length of input buffer in bytes.
|
|
210
|
+
*
|
|
211
|
+
* Return -1 if the native implementation does not support the input
|
|
212
|
+
*lengths. Otherwise, returns non-negative number of sampled 32-bit integers
|
|
213
|
+
*(at most len).
|
|
214
|
+
**************************************************/
|
|
215
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
216
|
+
static MLD_INLINE int mld_rej_uniform_eta2_native(int32_t *r, unsigned len,
|
|
217
|
+
const uint8_t *buf,
|
|
218
|
+
unsigned buflen)
|
|
219
|
+
__contract__(
|
|
220
|
+
requires(len <= MLDSA_N)
|
|
221
|
+
requires(buflen <= (2 * 136))
|
|
222
|
+
requires(memory_no_alias(r, sizeof(int32_t) * len))
|
|
223
|
+
requires(memory_no_alias(buf, buflen))
|
|
224
|
+
assigns(memory_slice(r, sizeof(int32_t) * len))
|
|
225
|
+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || (0 <= return_value && return_value <= len))
|
|
226
|
+
ensures((return_value != MLD_NATIVE_FUNC_FALLBACK) ==> (array_abs_bound(r, 0, return_value, MLDSA_ETA + 1)))
|
|
227
|
+
);
|
|
228
|
+
#endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLDSA_ETA == 2 */
|
|
229
|
+
#endif /* MLD_USE_NATIVE_REJ_UNIFORM_ETA2 */
|
|
230
|
+
|
|
231
|
+
#if defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA4)
|
|
232
|
+
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_ETA == 4
|
|
233
|
+
/*************************************************
|
|
234
|
+
* Name: mld_rej_uniform_eta4_native
|
|
235
|
+
*
|
|
236
|
+
* Description: Run rejection sampling on uniform random bytes to generate
|
|
237
|
+
* uniform random integers in [-4,+4].
|
|
238
|
+
*
|
|
239
|
+
* Arguments: - int32_t *r: pointer to output buffer
|
|
240
|
+
* - unsigned len: requested number of 32-bit integers
|
|
241
|
+
* (uniform in [-4, +4]).
|
|
242
|
+
* - const uint8_t *buf: pointer to input buffer
|
|
243
|
+
* (assumed to be uniform random bytes)
|
|
244
|
+
* - unsigned buflen: length of input buffer in bytes.
|
|
245
|
+
*
|
|
246
|
+
* Return -1 if the native implementation does not support the input
|
|
247
|
+
*lengths. Otherwise, returns non-negative number of sampled 32-bit integers
|
|
248
|
+
*(at most len).
|
|
249
|
+
**************************************************/
|
|
250
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
251
|
+
static MLD_INLINE int mld_rej_uniform_eta4_native(int32_t *r, unsigned len,
|
|
252
|
+
const uint8_t *buf,
|
|
253
|
+
unsigned buflen)
|
|
254
|
+
__contract__(
|
|
255
|
+
requires(len <= MLDSA_N)
|
|
256
|
+
requires(buflen <= (2 * 136))
|
|
257
|
+
requires(memory_no_alias(r, sizeof(int32_t) * len))
|
|
258
|
+
requires(memory_no_alias(buf, buflen))
|
|
259
|
+
assigns(memory_slice(r, sizeof(int32_t) * len))
|
|
260
|
+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || (0 <= return_value && return_value <= len))
|
|
261
|
+
ensures((return_value != MLD_NATIVE_FUNC_FALLBACK) ==> (array_abs_bound(r, 0, return_value, MLDSA_ETA + 1)))
|
|
262
|
+
);
|
|
263
|
+
#endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLDSA_ETA == 4 */
|
|
264
|
+
#endif /* MLD_USE_NATIVE_REJ_UNIFORM_ETA4 */
|
|
265
|
+
|
|
266
|
+
#if defined(MLD_USE_NATIVE_POLY_DECOMPOSE_32)
|
|
267
|
+
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || \
|
|
268
|
+
(MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_PARAMETER_SET == 87)
|
|
269
|
+
/*************************************************
|
|
270
|
+
* Name: mld_poly_decompose_32_native
|
|
271
|
+
*
|
|
272
|
+
* Description: Native implementation of poly_decompose for GAMMA2 = (Q-1)/32.
|
|
273
|
+
* For all coefficients c of the input polynomial,
|
|
274
|
+
* compute high and low bits c0, c1 such
|
|
275
|
+
* c mod MLDSA_Q = c1*(2*GAMMA2) + c0
|
|
276
|
+
* with -(2*GAMMA2)/2 < c0 <= (2*GAMMA2)/2 except
|
|
277
|
+
* c1 = (MLDSA_Q-1)/(2*GAMMA2) where we set
|
|
278
|
+
* c1 = 0 and -(2*GAMMA2)/2 <= c0 = c mod MLDSA_Q - MLDSA_Q < 0.
|
|
279
|
+
* Assumes coefficients to be standard representatives.
|
|
280
|
+
*
|
|
281
|
+
* Arguments: - int32_t *a1: output polynomial with coefficients c1
|
|
282
|
+
* - int32_t *a0: input/output polynomial.
|
|
283
|
+
* Output has coefficients c0
|
|
284
|
+
**************************************************/
|
|
285
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
286
|
+
static MLD_INLINE int mld_poly_decompose_32_native(int32_t *a1, int32_t *a0)
|
|
287
|
+
__contract__(
|
|
288
|
+
requires(memory_no_alias(a1, sizeof(int32_t) * MLDSA_N))
|
|
289
|
+
requires(memory_no_alias(a0, sizeof(int32_t) * MLDSA_N))
|
|
290
|
+
requires(array_bound(a0, 0, MLDSA_N, 0, MLDSA_Q))
|
|
291
|
+
assigns(memory_slice(a1, sizeof(int32_t) * MLDSA_N))
|
|
292
|
+
assigns(memory_slice(a0, sizeof(int32_t) * MLDSA_N))
|
|
293
|
+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
|
|
294
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(a1, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
|
|
295
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(a0, 0, MLDSA_N, MLDSA_GAMMA2+1))
|
|
296
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_bound(a0, 0, MLDSA_N, 0, MLDSA_Q))
|
|
297
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(a0, MLDSA_N))
|
|
298
|
+
);
|
|
299
|
+
#endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 65 \
|
|
300
|
+
|| MLD_CONFIG_PARAMETER_SET == 87 */
|
|
301
|
+
#endif /* MLD_USE_NATIVE_POLY_DECOMPOSE_32 */
|
|
302
|
+
|
|
303
|
+
#if defined(MLD_USE_NATIVE_POLY_DECOMPOSE_88)
|
|
304
|
+
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLD_CONFIG_PARAMETER_SET == 44
|
|
305
|
+
/*************************************************
|
|
306
|
+
* Name: mld_poly_decompose_88_native
|
|
307
|
+
*
|
|
308
|
+
* Description: Native implementation of poly_decompose for GAMMA2 = (Q-1)/88.
|
|
309
|
+
* For all coefficients c of the input polynomial,
|
|
310
|
+
* compute high and low bits c0, c1 such
|
|
311
|
+
* c mod MLDSA_Q = c1*(2*GAMMA2) + c0
|
|
312
|
+
* with -(2*GAMMA2)/2 < c0 <= (2*GAMMA2)/2 except
|
|
313
|
+
* c1 = (MLDSA_Q-1)/(2*GAMMA2) where we set
|
|
314
|
+
* c1 = 0 and -(2*GAMMA2)/2 <= c0 = c mod MLDSA_Q - MLDSA_Q < 0.
|
|
315
|
+
* Assumes coefficients to be standard representatives.
|
|
316
|
+
*
|
|
317
|
+
* Arguments: - int32_t *a1: output polynomial with coefficients c1
|
|
318
|
+
* - int32_t *a0: output polynomial with coefficients c0.
|
|
319
|
+
* Output has coefficients c0
|
|
320
|
+
**************************************************/
|
|
321
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
322
|
+
static MLD_INLINE int mld_poly_decompose_88_native(int32_t *a1, int32_t *a0)
|
|
323
|
+
__contract__(
|
|
324
|
+
requires(memory_no_alias(a1, sizeof(int32_t) * MLDSA_N))
|
|
325
|
+
requires(memory_no_alias(a0, sizeof(int32_t) * MLDSA_N))
|
|
326
|
+
requires(array_bound(a0, 0, MLDSA_N, 0, MLDSA_Q))
|
|
327
|
+
assigns(memory_slice(a1, sizeof(int32_t) * MLDSA_N))
|
|
328
|
+
assigns(memory_slice(a0, sizeof(int32_t) * MLDSA_N))
|
|
329
|
+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
|
|
330
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(a1, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
|
|
331
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(a0, 0, MLDSA_N, MLDSA_GAMMA2+1))
|
|
332
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_bound(a0, 0, MLDSA_N, 0, MLDSA_Q))
|
|
333
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(a0, MLDSA_N))
|
|
334
|
+
);
|
|
335
|
+
#endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 44 \
|
|
336
|
+
*/
|
|
337
|
+
#endif /* MLD_USE_NATIVE_POLY_DECOMPOSE_88 */
|
|
338
|
+
|
|
339
|
+
#if defined(MLD_USE_NATIVE_POLY_CADDQ)
|
|
340
|
+
/*************************************************
|
|
341
|
+
* Name: mld_poly_caddq_native
|
|
342
|
+
*
|
|
343
|
+
* Description: For all coefficients of in/out polynomial add Q if
|
|
344
|
+
* coefficient is negative.
|
|
345
|
+
*
|
|
346
|
+
* Arguments: - int32_t *a: pointer to input/output polynomial
|
|
347
|
+
**************************************************/
|
|
348
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
349
|
+
static MLD_INLINE int mld_poly_caddq_native(int32_t a[MLDSA_N])
|
|
350
|
+
__contract__(
|
|
351
|
+
requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
|
|
352
|
+
requires(array_abs_bound(a, 0, MLDSA_N, MLDSA_Q))
|
|
353
|
+
assigns(memory_slice(a, sizeof(int32_t) * MLDSA_N))
|
|
354
|
+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
|
|
355
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(a, 0, MLDSA_N, 0, MLDSA_Q))
|
|
356
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_abs_bound(a, 0, MLDSA_N, MLDSA_Q))
|
|
357
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(a, MLDSA_N))
|
|
358
|
+
);
|
|
359
|
+
#endif /* MLD_USE_NATIVE_POLY_CADDQ */
|
|
360
|
+
|
|
361
|
+
#if defined(MLD_USE_NATIVE_POLY_USE_HINT_32)
|
|
362
|
+
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || \
|
|
363
|
+
(MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_PARAMETER_SET == 87)
|
|
364
|
+
/*************************************************
|
|
365
|
+
* Name: mld_poly_use_hint_32_native
|
|
366
|
+
*
|
|
367
|
+
* Description: Native implementation of poly_use_hint for GAMMA2 = (Q-1)/32.
|
|
368
|
+
* Use hint polynomial to correct the high bits of a polynomial.
|
|
369
|
+
*
|
|
370
|
+
* Arguments: - int32_t *b: pointer to output polynomial with corrected high
|
|
371
|
+
* bits
|
|
372
|
+
* - const int32_t *a: pointer to input polynomial
|
|
373
|
+
* - const int32_t *h: pointer to input hint polynomial
|
|
374
|
+
**************************************************/
|
|
375
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
376
|
+
static MLD_INLINE int mld_poly_use_hint_32_native(int32_t *b, const int32_t *a,
|
|
377
|
+
const int32_t *h)
|
|
378
|
+
__contract__(
|
|
379
|
+
requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
|
|
380
|
+
requires(memory_no_alias(b, sizeof(int32_t) * MLDSA_N))
|
|
381
|
+
requires(memory_no_alias(h, sizeof(int32_t) * MLDSA_N))
|
|
382
|
+
requires(array_bound(a, 0, MLDSA_N, 0, MLDSA_Q))
|
|
383
|
+
requires(array_bound(h, 0, MLDSA_N, 0, 2))
|
|
384
|
+
assigns(memory_slice(b, sizeof(int32_t) * MLDSA_N))
|
|
385
|
+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
|
|
386
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(b, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
|
|
387
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(b, MLDSA_N))
|
|
388
|
+
);
|
|
389
|
+
#endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 65 \
|
|
390
|
+
|| MLD_CONFIG_PARAMETER_SET == 87 */
|
|
391
|
+
#endif /* MLD_USE_NATIVE_POLY_USE_HINT_32 */
|
|
392
|
+
|
|
393
|
+
#if defined(MLD_USE_NATIVE_POLY_USE_HINT_88)
|
|
394
|
+
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLD_CONFIG_PARAMETER_SET == 44
|
|
395
|
+
/*************************************************
|
|
396
|
+
* Name: mld_poly_use_hint_88_native
|
|
397
|
+
*
|
|
398
|
+
* Description: Native implementation of poly_use_hint for GAMMA2 = (Q-1)/88.
|
|
399
|
+
* Use hint polynomial to correct the high bits of a polynomial.
|
|
400
|
+
*
|
|
401
|
+
* Arguments: - int32_t *b: pointer to output polynomial with corrected high
|
|
402
|
+
* bits
|
|
403
|
+
* - const int32_t *a: pointer to input polynomial
|
|
404
|
+
* - const int32_t *h: pointer to input hint polynomial
|
|
405
|
+
**************************************************/
|
|
406
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
407
|
+
static MLD_INLINE int mld_poly_use_hint_88_native(int32_t *b, const int32_t *a,
|
|
408
|
+
const int32_t *h)
|
|
409
|
+
__contract__(
|
|
410
|
+
requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
|
|
411
|
+
requires(memory_no_alias(b, sizeof(int32_t) * MLDSA_N))
|
|
412
|
+
requires(memory_no_alias(h, sizeof(int32_t) * MLDSA_N))
|
|
413
|
+
requires(array_bound(a, 0, MLDSA_N, 0, MLDSA_Q))
|
|
414
|
+
requires(array_bound(h, 0, MLDSA_N, 0, 2))
|
|
415
|
+
assigns(memory_slice(b, sizeof(int32_t) * MLDSA_N))
|
|
416
|
+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
|
|
417
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(b, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
|
|
418
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(b, MLDSA_N))
|
|
419
|
+
);
|
|
420
|
+
#endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 44 \
|
|
421
|
+
*/
|
|
422
|
+
#endif /* MLD_USE_NATIVE_POLY_USE_HINT_88 */
|
|
423
|
+
|
|
424
|
+
#if defined(MLD_USE_NATIVE_POLY_CHKNORM)
|
|
425
|
+
/*************************************************
|
|
426
|
+
* Name: mld_poly_chknorm_native
|
|
427
|
+
*
|
|
428
|
+
* Description: Check infinity norm of polynomial against given bound.
|
|
429
|
+
* Assumes input coefficients were reduced by mld_reduce32().
|
|
430
|
+
*
|
|
431
|
+
* Arguments: - const int32_t *a: pointer to polynomial
|
|
432
|
+
* - int32_t B: norm bound, which must be in the range
|
|
433
|
+
* 0 .. MLDSA_Q - MLD_REDUCE32_RANGE_MAX inclusive.
|
|
434
|
+
*
|
|
435
|
+
* Returns MLD_NATIVE_FUNC_FALLBACK (-1) if the target CPU cannot
|
|
436
|
+
* support a native implementation of this function.
|
|
437
|
+
*
|
|
438
|
+
* If the target CPU can support this function, then
|
|
439
|
+
* Returns MLD_NATIVE_FUNC_SUCCESS (0) if the infinity norm is strictly
|
|
440
|
+
* smaller than B
|
|
441
|
+
* Returns 1 otherwise
|
|
442
|
+
**************************************************/
|
|
443
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
444
|
+
static MLD_INLINE int mld_poly_chknorm_native(const int32_t *a, int32_t B)
|
|
445
|
+
__contract__(
|
|
446
|
+
requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
|
|
447
|
+
requires(0 <= B && B <= MLDSA_Q - MLD_REDUCE32_RANGE_MAX)
|
|
448
|
+
requires(array_bound(a, 0, MLDSA_N, -MLD_REDUCE32_RANGE_MAX, MLD_REDUCE32_RANGE_MAX))
|
|
449
|
+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == 0 ||
|
|
450
|
+
return_value == 1)
|
|
451
|
+
ensures((return_value != MLD_NATIVE_FUNC_FALLBACK) ==>
|
|
452
|
+
((return_value == 0) == array_abs_bound(a, 0, MLDSA_N, B)))
|
|
453
|
+
);
|
|
454
|
+
#endif /* MLD_USE_NATIVE_POLY_CHKNORM */
|
|
455
|
+
|
|
456
|
+
#if defined(MLD_USE_NATIVE_POLYZ_UNPACK_17)
|
|
457
|
+
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLD_CONFIG_PARAMETER_SET == 44
|
|
458
|
+
/*************************************************
|
|
459
|
+
* Name: mld_polyz_unpack_17_native
|
|
460
|
+
*
|
|
461
|
+
* Description: Native implementation of polyz_unpack for GAMMA1 = 2^17.
|
|
462
|
+
* Unpack polynomial z with coefficients
|
|
463
|
+
* in [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1].
|
|
464
|
+
*
|
|
465
|
+
* Arguments: - int32_t *r: pointer to output polynomial
|
|
466
|
+
* - const uint8_t *a: byte array with bit-packed polynomial
|
|
467
|
+
**************************************************/
|
|
468
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
469
|
+
static MLD_INLINE int mld_polyz_unpack_17_native(int32_t *r, const uint8_t *a)
|
|
470
|
+
__contract__(
|
|
471
|
+
requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
|
|
472
|
+
requires(memory_no_alias(a, MLDSA_POLYZ_PACKEDBYTES))
|
|
473
|
+
assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
|
|
474
|
+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
|
|
475
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(r, 0, MLDSA_N, -(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1 + 1))
|
|
476
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(r, MLDSA_N))
|
|
477
|
+
);
|
|
478
|
+
#endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 44 \
|
|
479
|
+
*/
|
|
480
|
+
#endif /* MLD_USE_NATIVE_POLYZ_UNPACK_17 */
|
|
481
|
+
|
|
482
|
+
#if defined(MLD_USE_NATIVE_POLYZ_UNPACK_19)
|
|
483
|
+
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || \
|
|
484
|
+
(MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_PARAMETER_SET == 87)
|
|
485
|
+
/*************************************************
|
|
486
|
+
* Name: mld_polyz_unpack_19_native
|
|
487
|
+
*
|
|
488
|
+
* Description: Native implementation of polyz_unpack for GAMMA1 = 2^19.
|
|
489
|
+
* Unpack polynomial z with coefficients
|
|
490
|
+
* in [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1].
|
|
491
|
+
*
|
|
492
|
+
* Arguments: - int32_t *r: pointer to output polynomial
|
|
493
|
+
* - const uint8_t *a: byte array with bit-packed polynomial
|
|
494
|
+
**************************************************/
|
|
495
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
496
|
+
static MLD_INLINE int mld_polyz_unpack_19_native(int32_t *r, const uint8_t *a)
|
|
497
|
+
__contract__(
|
|
498
|
+
requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
|
|
499
|
+
requires(memory_no_alias(a, MLDSA_POLYZ_PACKEDBYTES))
|
|
500
|
+
assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
|
|
501
|
+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
|
|
502
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(r, 0, MLDSA_N, -(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1 + 1))
|
|
503
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(r, MLDSA_N))
|
|
504
|
+
);
|
|
505
|
+
#endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 65 \
|
|
506
|
+
|| MLD_CONFIG_PARAMETER_SET == 87 */
|
|
507
|
+
#endif /* MLD_USE_NATIVE_POLYZ_UNPACK_19 */
|
|
508
|
+
|
|
509
|
+
#if defined(MLD_USE_NATIVE_POINTWISE_MONTGOMERY)
|
|
510
|
+
/*************************************************
|
|
511
|
+
* Name: mld_poly_pointwise_montgomery_native
|
|
512
|
+
*
|
|
513
|
+
* Description: Pointwise multiplication of polynomials in NTT domain
|
|
514
|
+
* with Montgomery reduction.
|
|
515
|
+
*
|
|
516
|
+
* Computes c[i] = a[i] * b[i] * R^(-1) mod q for all i,
|
|
517
|
+
* where R = 2^32.
|
|
518
|
+
*
|
|
519
|
+
* Arguments: - int32_t c[MLDSA_N]: output polynomial
|
|
520
|
+
* - const int32_t a[MLDSA_N]: first input polynomial
|
|
521
|
+
* - const int32_t b[MLDSA_N]: second input polynomial
|
|
522
|
+
**************************************************/
|
|
523
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
524
|
+
static MLD_INLINE int mld_poly_pointwise_montgomery_native(
|
|
525
|
+
int32_t c[MLDSA_N], const int32_t a[MLDSA_N], const int32_t b[MLDSA_N])
|
|
526
|
+
__contract__(
|
|
527
|
+
requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
|
|
528
|
+
requires(memory_no_alias(b, sizeof(int32_t) * MLDSA_N))
|
|
529
|
+
requires(memory_no_alias(c, sizeof(int32_t) * MLDSA_N))
|
|
530
|
+
requires(array_abs_bound(a, 0, MLDSA_N, MLD_NTT_BOUND))
|
|
531
|
+
requires(array_abs_bound(b, 0, MLDSA_N, MLD_NTT_BOUND))
|
|
532
|
+
assigns(memory_slice(c, sizeof(int32_t) * MLDSA_N))
|
|
533
|
+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
|
|
534
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(c, 0, MLDSA_N, MLDSA_Q))
|
|
535
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_abs_bound(a, 0, MLDSA_N, MLD_NTT_BOUND))
|
|
536
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_abs_bound(b, 0, MLDSA_N, MLD_NTT_BOUND))
|
|
537
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(c, MLDSA_N))
|
|
538
|
+
);
|
|
539
|
+
#endif /* MLD_USE_NATIVE_POINTWISE_MONTGOMERY */
|
|
540
|
+
|
|
541
|
+
#if defined(MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L4)
|
|
542
|
+
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_L == 4
|
|
543
|
+
/*************************************************
|
|
544
|
+
* Name: mld_polyvecl_pointwise_acc_montgomery_l4_native
|
|
545
|
+
*
|
|
546
|
+
* Description: Native implementation of polyvecl_pointwise_acc_montgomery for
|
|
547
|
+
* MLDSA_L = 4.
|
|
548
|
+
* Pointwise multiply vectors of polynomials of length MLDSA_L,
|
|
549
|
+
* multiply resulting vector by 2^{-32} and add (accumulate)
|
|
550
|
+
* polynomials in it.
|
|
551
|
+
* Input/output vectors are in NTT domain representation.
|
|
552
|
+
*
|
|
553
|
+
* Arguments: - int32_t w[MLDSA_N]: output polynomial
|
|
554
|
+
* - const int32_t u[MLDSA_L][MLDSA_N]: first input vector
|
|
555
|
+
* - const int32_t v[MLDSA_L][MLDSA_N]: second input vector
|
|
556
|
+
**************************************************/
|
|
557
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
558
|
+
static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l4_native(
|
|
559
|
+
int32_t w[MLDSA_N], const int32_t u[4][MLDSA_N],
|
|
560
|
+
const int32_t v[4][MLDSA_N])
|
|
561
|
+
__contract__(
|
|
562
|
+
requires(memory_no_alias(w, sizeof(int32_t) * MLDSA_N))
|
|
563
|
+
requires(memory_no_alias(u, sizeof(int32_t) * 4 * MLDSA_N))
|
|
564
|
+
requires(memory_no_alias(v, sizeof(int32_t) * 4 * MLDSA_N))
|
|
565
|
+
requires(forall(l0, 0, 4,
|
|
566
|
+
array_bound(u[l0], 0, MLDSA_N, 0, MLDSA_Q)))
|
|
567
|
+
requires(forall(l1, 0, 4,
|
|
568
|
+
array_abs_bound(v[l1], 0, MLDSA_N, MLD_NTT_BOUND)))
|
|
569
|
+
assigns(memory_slice(w, sizeof(int32_t) * MLDSA_N))
|
|
570
|
+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
|
|
571
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(w, 0, MLDSA_N, MLDSA_Q))
|
|
572
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(w, MLDSA_N))
|
|
573
|
+
);
|
|
574
|
+
#endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLDSA_L == 4 */
|
|
575
|
+
#endif /* MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L4 */
|
|
576
|
+
|
|
577
|
+
#if defined(MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L5)
|
|
578
|
+
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_L == 5
|
|
579
|
+
/*************************************************
|
|
580
|
+
* Name: mld_polyvecl_pointwise_acc_montgomery_l5_native
|
|
581
|
+
*
|
|
582
|
+
* Description: Native implementation of polyvecl_pointwise_acc_montgomery for
|
|
583
|
+
* MLDSA_L = 5.
|
|
584
|
+
* Pointwise multiply vectors of polynomials of length MLDSA_L,
|
|
585
|
+
* multiply resulting vector by 2^{-32} and add (accumulate)
|
|
586
|
+
* polynomials in it.
|
|
587
|
+
* Input/output vectors are in NTT domain representation.
|
|
588
|
+
*
|
|
589
|
+
* Arguments: - int32_t w[MLDSA_N]: output polynomial
|
|
590
|
+
* - const int32_t u[MLDSA_L][MLDSA_N]: first input vector
|
|
591
|
+
* - const int32_t v[MLDSA_L][MLDSA_N]: second input vector
|
|
592
|
+
**************************************************/
|
|
593
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
594
|
+
static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l5_native(
|
|
595
|
+
int32_t w[MLDSA_N], const int32_t u[5][MLDSA_N],
|
|
596
|
+
const int32_t v[5][MLDSA_N])
|
|
597
|
+
__contract__(
|
|
598
|
+
requires(memory_no_alias(w, sizeof(int32_t) * MLDSA_N))
|
|
599
|
+
requires(memory_no_alias(u, sizeof(int32_t) * 5 * MLDSA_N))
|
|
600
|
+
requires(memory_no_alias(v, sizeof(int32_t) * 5 * MLDSA_N))
|
|
601
|
+
requires(forall(l0, 0, 5,
|
|
602
|
+
array_bound(u[l0], 0, MLDSA_N, 0, MLDSA_Q)))
|
|
603
|
+
requires(forall(l1, 0, 5,
|
|
604
|
+
array_abs_bound(v[l1], 0, MLDSA_N, MLD_NTT_BOUND)))
|
|
605
|
+
assigns(memory_slice(w, sizeof(int32_t) * MLDSA_N))
|
|
606
|
+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
|
|
607
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(w, 0, MLDSA_N, MLDSA_Q))
|
|
608
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(w, MLDSA_N))
|
|
609
|
+
);
|
|
610
|
+
#endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLDSA_L == 5 */
|
|
611
|
+
#endif /* MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L5 */
|
|
612
|
+
|
|
613
|
+
#if defined(MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L7)
|
|
614
|
+
#if defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_L == 7
|
|
615
|
+
/*************************************************
|
|
616
|
+
* Name: mld_polyvecl_pointwise_acc_montgomery_l7_native
|
|
617
|
+
*
|
|
618
|
+
* Description: Native implementation of polyvecl_pointwise_acc_montgomery for
|
|
619
|
+
* MLDSA_L = 7.
|
|
620
|
+
* Pointwise multiply vectors of polynomials of length MLDSA_L,
|
|
621
|
+
* multiply resulting vector by 2^{-32} and add (accumulate)
|
|
622
|
+
* polynomials in it.
|
|
623
|
+
* Input/output vectors are in NTT domain representation.
|
|
624
|
+
*
|
|
625
|
+
* Arguments: - int32_t w[MLDSA_N]: output polynomial
|
|
626
|
+
* - const int32_t u[MLDSA_L][MLDSA_N]: first input vector
|
|
627
|
+
* - const int32_t v[MLDSA_L][MLDSA_N]: second input vector
|
|
628
|
+
**************************************************/
|
|
629
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
630
|
+
static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l7_native(
|
|
631
|
+
int32_t w[MLDSA_N], const int32_t u[7][MLDSA_N],
|
|
632
|
+
const int32_t v[7][MLDSA_N])
|
|
633
|
+
__contract__(
|
|
634
|
+
requires(memory_no_alias(w, sizeof(int32_t) * MLDSA_N))
|
|
635
|
+
requires(memory_no_alias(u, sizeof(int32_t) * 7 * MLDSA_N))
|
|
636
|
+
requires(memory_no_alias(v, sizeof(int32_t) * 7 * MLDSA_N))
|
|
637
|
+
requires(forall(l0, 0, 7,
|
|
638
|
+
array_bound(u[l0], 0, MLDSA_N, 0, MLDSA_Q)))
|
|
639
|
+
requires(forall(l1, 0, 7,
|
|
640
|
+
array_abs_bound(v[l1], 0, MLDSA_N, MLD_NTT_BOUND)))
|
|
641
|
+
assigns(memory_slice(w, sizeof(int32_t) * MLDSA_N))
|
|
642
|
+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
|
|
643
|
+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(w, 0, MLDSA_N, MLDSA_Q))
|
|
644
|
+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(w, MLDSA_N))
|
|
645
|
+
);
|
|
646
|
+
#endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLDSA_L == 7 */
|
|
647
|
+
#endif /* MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L7 */
|
|
648
|
+
|
|
649
|
+
#endif /* !MLD_NATIVE_API_H */
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) The mlkem-native project authors
|
|
3
|
+
* Copyright (c) The mldsa-native project authors
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#ifndef MLD_NATIVE_META_H
|
|
8
|
+
#define MLD_NATIVE_META_H
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Default arithmetic backend
|
|
12
|
+
*/
|
|
13
|
+
#include "../sys.h"
|
|
14
|
+
|
|
15
|
+
#ifdef MLD_SYS_AARCH64
|
|
16
|
+
#include "aarch64/meta.h"
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
#ifdef MLD_SYS_X86_64_AVX2
|
|
20
|
+
#include "x86_64/meta.h"
|
|
21
|
+
#endif
|
|
22
|
+
|
|
23
|
+
#endif /* !MLD_NATIVE_META_H */
|