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,128 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) The mlkem-native project authors
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#ifndef MLK_NATIVE_RISCV64_META_H
|
|
7
|
+
#define MLK_NATIVE_RISCV64_META_H
|
|
8
|
+
|
|
9
|
+
/* Identifier for this backend so that source and assembly files
|
|
10
|
+
* in the build can be appropriately guarded. */
|
|
11
|
+
#define MLK_ARITH_BACKEND_RISCV64
|
|
12
|
+
|
|
13
|
+
/* Set of primitives that this backend replaces */
|
|
14
|
+
#define MLK_USE_NATIVE_NTT
|
|
15
|
+
#define MLK_USE_NATIVE_INTT
|
|
16
|
+
#define MLK_USE_NATIVE_POLY_TOMONT
|
|
17
|
+
#define MLK_USE_NATIVE_REJ_UNIFORM
|
|
18
|
+
#define MLK_USE_NATIVE_POLY_REDUCE
|
|
19
|
+
#define MLK_USE_NATIVE_POLY_MULCACHE_COMPUTE
|
|
20
|
+
#define MLK_USE_NATIVE_POLYVEC_BASEMUL_ACC_MONTGOMERY_CACHED
|
|
21
|
+
|
|
22
|
+
#include "../../common.h"
|
|
23
|
+
|
|
24
|
+
#if !defined(__ASSEMBLER__)
|
|
25
|
+
#include <riscv_vector.h>
|
|
26
|
+
|
|
27
|
+
#include "../api.h"
|
|
28
|
+
#include "src/arith_native_riscv64.h"
|
|
29
|
+
|
|
30
|
+
MLK_MUST_CHECK_RETURN_VALUE
|
|
31
|
+
static MLK_INLINE int mlk_ntt_native(int16_t data[MLKEM_N])
|
|
32
|
+
{
|
|
33
|
+
/* VLEN = 256 only for now */
|
|
34
|
+
if (__riscv_vsetvlmax_e16m1() != 16)
|
|
35
|
+
{
|
|
36
|
+
return MLK_NATIVE_FUNC_FALLBACK;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
mlk_rv64v_poly_ntt(data);
|
|
40
|
+
return MLK_NATIVE_FUNC_SUCCESS;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
MLK_MUST_CHECK_RETURN_VALUE
|
|
44
|
+
static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N])
|
|
45
|
+
{
|
|
46
|
+
/* VLEN = 256 only for now */
|
|
47
|
+
if (__riscv_vsetvlmax_e16m1() != 16)
|
|
48
|
+
{
|
|
49
|
+
return MLK_NATIVE_FUNC_FALLBACK;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
mlk_rv64v_poly_invntt_tomont(data);
|
|
53
|
+
return MLK_NATIVE_FUNC_SUCCESS;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
MLK_MUST_CHECK_RETURN_VALUE
|
|
57
|
+
static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N])
|
|
58
|
+
{
|
|
59
|
+
mlk_rv64v_poly_tomont(data);
|
|
60
|
+
return MLK_NATIVE_FUNC_SUCCESS;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
MLK_MUST_CHECK_RETURN_VALUE
|
|
64
|
+
static MLK_INLINE int mlk_rej_uniform_native(int16_t *r, unsigned len,
|
|
65
|
+
const uint8_t *buf,
|
|
66
|
+
unsigned buflen)
|
|
67
|
+
{
|
|
68
|
+
/* The cast from unsigned to signed integer is safe
|
|
69
|
+
* because the return value is <= len, which we asssume
|
|
70
|
+
* to be bound by 4096 and hence <= INT_MAX. */
|
|
71
|
+
return (int)mlk_rv64v_rej_uniform(r, len, buf, buflen);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
MLK_MUST_CHECK_RETURN_VALUE
|
|
75
|
+
static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N])
|
|
76
|
+
{
|
|
77
|
+
mlk_rv64v_poly_reduce(data);
|
|
78
|
+
return MLK_NATIVE_FUNC_SUCCESS;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
MLK_MUST_CHECK_RETURN_VALUE
|
|
82
|
+
static MLK_INLINE int mlk_poly_mulcache_compute_native(int16_t x[MLKEM_N / 2],
|
|
83
|
+
const int16_t y[MLKEM_N])
|
|
84
|
+
{
|
|
85
|
+
(void)x; /* not using the cache at the moment */
|
|
86
|
+
(void)y;
|
|
87
|
+
return MLK_NATIVE_FUNC_SUCCESS;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 2
|
|
91
|
+
MLK_MUST_CHECK_RETURN_VALUE
|
|
92
|
+
static MLK_INLINE int mlk_polyvec_basemul_acc_montgomery_cached_k2_native(
|
|
93
|
+
int16_t r[MLKEM_N], const int16_t a[2 * MLKEM_N],
|
|
94
|
+
const int16_t b[2 * MLKEM_N], const int16_t b_cache[2 * (MLKEM_N / 2)])
|
|
95
|
+
{
|
|
96
|
+
(void)b_cache;
|
|
97
|
+
mlk_rv64v_poly_basemul_mont_add_k2(r, a, b);
|
|
98
|
+
return MLK_NATIVE_FUNC_SUCCESS;
|
|
99
|
+
}
|
|
100
|
+
#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 */
|
|
101
|
+
|
|
102
|
+
#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 3
|
|
103
|
+
MLK_MUST_CHECK_RETURN_VALUE
|
|
104
|
+
static MLK_INLINE int mlk_polyvec_basemul_acc_montgomery_cached_k3_native(
|
|
105
|
+
int16_t r[MLKEM_N], const int16_t a[3 * MLKEM_N],
|
|
106
|
+
const int16_t b[3 * MLKEM_N], const int16_t b_cache[3 * (MLKEM_N / 2)])
|
|
107
|
+
{
|
|
108
|
+
(void)b_cache;
|
|
109
|
+
mlk_rv64v_poly_basemul_mont_add_k3(r, a, b);
|
|
110
|
+
return MLK_NATIVE_FUNC_SUCCESS;
|
|
111
|
+
}
|
|
112
|
+
#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 3 */
|
|
113
|
+
|
|
114
|
+
#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4
|
|
115
|
+
MLK_MUST_CHECK_RETURN_VALUE
|
|
116
|
+
static MLK_INLINE int mlk_polyvec_basemul_acc_montgomery_cached_k4_native(
|
|
117
|
+
int16_t r[MLKEM_N], const int16_t a[4 * MLKEM_N],
|
|
118
|
+
const int16_t b[4 * MLKEM_N], const int16_t b_cache[4 * (MLKEM_N / 2)])
|
|
119
|
+
{
|
|
120
|
+
(void)b_cache;
|
|
121
|
+
mlk_rv64v_poly_basemul_mont_add_k4(r, a, b);
|
|
122
|
+
return MLK_NATIVE_FUNC_SUCCESS;
|
|
123
|
+
}
|
|
124
|
+
#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */
|
|
125
|
+
|
|
126
|
+
#endif /* !__ASSEMBLER__ */
|
|
127
|
+
|
|
128
|
+
#endif /* !MLK_NATIVE_RISCV64_META_H */
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) The mlkem-native project authors
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
4
|
+
*/
|
|
5
|
+
#ifndef MLK_NATIVE_RISCV64_SRC_ARITH_NATIVE_RISCV64_H
|
|
6
|
+
#define MLK_NATIVE_RISCV64_SRC_ARITH_NATIVE_RISCV64_H
|
|
7
|
+
|
|
8
|
+
#include "../../../common.h"
|
|
9
|
+
|
|
10
|
+
#define mlk_rv64v_poly_ntt MLK_NAMESPACE(ntt_riscv64)
|
|
11
|
+
void mlk_rv64v_poly_ntt(int16_t *);
|
|
12
|
+
|
|
13
|
+
#define mlk_rv64v_poly_invntt_tomont MLK_NAMESPACE(intt_riscv64)
|
|
14
|
+
void mlk_rv64v_poly_invntt_tomont(int16_t *r);
|
|
15
|
+
|
|
16
|
+
#define mlk_rv64v_poly_basemul_mont_add_k2 MLK_NAMESPACE(basemul_add_k2_riscv64)
|
|
17
|
+
void mlk_rv64v_poly_basemul_mont_add_k2(int16_t *r, const int16_t *a,
|
|
18
|
+
const int16_t *b);
|
|
19
|
+
|
|
20
|
+
#define mlk_rv64v_poly_basemul_mont_add_k3 MLK_NAMESPACE(basemul_add_k3_riscv64)
|
|
21
|
+
void mlk_rv64v_poly_basemul_mont_add_k3(int16_t *r, const int16_t *a,
|
|
22
|
+
const int16_t *b);
|
|
23
|
+
|
|
24
|
+
#define mlk_rv64v_poly_basemul_mont_add_k4 MLK_NAMESPACE(basemul_add_k4_riscv64)
|
|
25
|
+
void mlk_rv64v_poly_basemul_mont_add_k4(int16_t *r, const int16_t *a,
|
|
26
|
+
const int16_t *b);
|
|
27
|
+
|
|
28
|
+
#define mlk_rv64v_poly_tomont MLK_NAMESPACE(tomont_riscv64)
|
|
29
|
+
void mlk_rv64v_poly_tomont(int16_t *r);
|
|
30
|
+
|
|
31
|
+
#define mlk_rv64v_poly_reduce MLK_NAMESPACE(reduce_riscv64)
|
|
32
|
+
void mlk_rv64v_poly_reduce(int16_t *r);
|
|
33
|
+
|
|
34
|
+
#define mlk_rv64v_poly_add MLK_NAMESPACE(poly_add_riscv64)
|
|
35
|
+
void mlk_rv64v_poly_add(int16_t *r, const int16_t *a, const int16_t *b);
|
|
36
|
+
|
|
37
|
+
#define mlk_rv64v_poly_sub MLK_NAMESPACE(poly_sub_riscv64)
|
|
38
|
+
void mlk_rv64v_poly_sub(int16_t *r, const int16_t *a, const int16_t *b);
|
|
39
|
+
|
|
40
|
+
#define mlk_rv64v_rej_uniform MLK_NAMESPACE(rj_uniform_riscv64)
|
|
41
|
+
MLK_MUST_CHECK_RETURN_VALUE
|
|
42
|
+
unsigned int mlk_rv64v_rej_uniform(int16_t *r, unsigned int len,
|
|
43
|
+
const uint8_t *buf, unsigned int buflen);
|
|
44
|
+
|
|
45
|
+
#endif /* !MLK_NATIVE_RISCV64_SRC_ARITH_NATIVE_RISCV64_H */
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) The mlkem-native project authors
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/* NOTE: You can remove this file unless you compile with MLKEM_DEBUG. */
|
|
7
|
+
|
|
8
|
+
#include "../../../common.h"
|
|
9
|
+
|
|
10
|
+
#if defined(MLK_ARITH_BACKEND_RISCV64) && \
|
|
11
|
+
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && defined(MLKEM_DEBUG)
|
|
12
|
+
|
|
13
|
+
#include <stdio.h>
|
|
14
|
+
#include <stdlib.h>
|
|
15
|
+
|
|
16
|
+
#include "../../../debug.h"
|
|
17
|
+
#include "rv64v_debug.h"
|
|
18
|
+
|
|
19
|
+
#define MLK_DEBUG_ERROR_HEADER "[ERROR:%s:%04d] "
|
|
20
|
+
|
|
21
|
+
/*************************************************
|
|
22
|
+
* Name: mlk_debug_check_bounds_int16m1
|
|
23
|
+
*
|
|
24
|
+
* Description: Check whether values in a vint16m1_t vector
|
|
25
|
+
* are within specified bounds.
|
|
26
|
+
*
|
|
27
|
+
* Implementation: Extract vector elements to a temporary array
|
|
28
|
+
* and reuse existing array bounds checking.
|
|
29
|
+
**************************************************/
|
|
30
|
+
void mlk_debug_check_bounds_int16m1(const char *file, int line, vint16m1_t vec,
|
|
31
|
+
size_t vl, int lower_bound_exclusive,
|
|
32
|
+
int upper_bound_exclusive)
|
|
33
|
+
{
|
|
34
|
+
/* Allocate temporary array to store vector elements
|
|
35
|
+
* We use the maximum possible vector length to be safe */
|
|
36
|
+
int16_t temp_array[64];
|
|
37
|
+
|
|
38
|
+
/* Store vector elements to temporary array for inspection */
|
|
39
|
+
__riscv_vse16_v_i16m1(temp_array, vec, vl);
|
|
40
|
+
|
|
41
|
+
/* Reuse existing array bounds checking function */
|
|
42
|
+
mlk_debug_check_bounds(file, line, temp_array, (unsigned)vl,
|
|
43
|
+
lower_bound_exclusive, upper_bound_exclusive);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/*************************************************
|
|
47
|
+
* Name: mlk_debug_check_bounds_int16m2
|
|
48
|
+
*
|
|
49
|
+
* Description: Check whether values in a vint16m2_t vector
|
|
50
|
+
* are within specified bounds.
|
|
51
|
+
*
|
|
52
|
+
* Implementation: Extract vector elements to a temporary array
|
|
53
|
+
* and reuse existing array bounds checking.
|
|
54
|
+
**************************************************/
|
|
55
|
+
void mlk_debug_check_bounds_int16m2(const char *file, int line, vint16m2_t vec,
|
|
56
|
+
size_t vl, int lower_bound_exclusive,
|
|
57
|
+
int upper_bound_exclusive)
|
|
58
|
+
{
|
|
59
|
+
/* Allocate temporary array to store vector elements
|
|
60
|
+
* m2 vectors hold 2x the elements of m1 vectors */
|
|
61
|
+
int16_t temp_array[2 * 64];
|
|
62
|
+
|
|
63
|
+
/* Store vector elements to temporary array for inspection */
|
|
64
|
+
__riscv_vse16_v_i16m2(temp_array, vec, 2 * vl);
|
|
65
|
+
|
|
66
|
+
/* Reuse existing array bounds checking function for all elements */
|
|
67
|
+
mlk_debug_check_bounds(file, line, temp_array, (unsigned)(2 * vl),
|
|
68
|
+
lower_bound_exclusive, upper_bound_exclusive);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#else /* MLK_ARITH_BACKEND_RISCV64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED && \
|
|
72
|
+
MLKEM_DEBUG */
|
|
73
|
+
|
|
74
|
+
MLK_EMPTY_CU(rv64v_debug)
|
|
75
|
+
|
|
76
|
+
#endif /* !(MLK_ARITH_BACKEND_RISCV64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED && \
|
|
77
|
+
MLKEM_DEBUG) */
|
|
78
|
+
|
|
79
|
+
/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
|
|
80
|
+
* Don't modify by hand -- this is auto-generated by scripts/autogen. */
|
|
81
|
+
#undef MLK_DEBUG_ERROR_HEADER
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) The mlkem-native project authors
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
4
|
+
*/
|
|
5
|
+
#ifndef MLK_NATIVE_RISCV64_SRC_RV64V_DEBUG_H
|
|
6
|
+
#define MLK_NATIVE_RISCV64_SRC_RV64V_DEBUG_H
|
|
7
|
+
|
|
8
|
+
#include "../../../debug.h"
|
|
9
|
+
|
|
10
|
+
#include <riscv_vector.h>
|
|
11
|
+
|
|
12
|
+
/*************************************************
|
|
13
|
+
* RISC-V Vector Bounds Assertion Macros
|
|
14
|
+
*
|
|
15
|
+
* These macros provide runtime bounds checking for RISC-V vector types
|
|
16
|
+
* vint16m1_t and vint16m2_t, following the same pattern as the scalar
|
|
17
|
+
* bounds assertions in debug.h
|
|
18
|
+
*
|
|
19
|
+
* The macros are only active when MLKEM_DEBUG is defined, otherwise they
|
|
20
|
+
* compile to no-ops for zero runtime overhead in release builds.
|
|
21
|
+
**************************************************/
|
|
22
|
+
|
|
23
|
+
#if defined(MLKEM_DEBUG)
|
|
24
|
+
|
|
25
|
+
/*************************************************
|
|
26
|
+
* Name: mlk_debug_check_bounds_int16m1
|
|
27
|
+
*
|
|
28
|
+
* Description: Check whether values in a vint16m1_t vector
|
|
29
|
+
* are within specified bounds.
|
|
30
|
+
*
|
|
31
|
+
* Arguments: - file: filename
|
|
32
|
+
* - line: line number
|
|
33
|
+
* - vec: RISC-V vector to be checked
|
|
34
|
+
* - vl: vector length (number of active elements)
|
|
35
|
+
* - lower_bound_exclusive: Exclusive lower bound
|
|
36
|
+
* - upper_bound_exclusive: Exclusive upper bound
|
|
37
|
+
**************************************************/
|
|
38
|
+
#define mlk_debug_check_bounds_int16m1 \
|
|
39
|
+
MLK_NAMESPACE(mlkem_debug_check_bounds_int16m1)
|
|
40
|
+
void mlk_debug_check_bounds_int16m1(const char *file, int line, vint16m1_t vec,
|
|
41
|
+
size_t vl, int lower_bound_exclusive,
|
|
42
|
+
int upper_bound_exclusive);
|
|
43
|
+
|
|
44
|
+
/*************************************************
|
|
45
|
+
* Name: mlk_debug_check_bounds_int16m2
|
|
46
|
+
*
|
|
47
|
+
* Description: Check whether values in a vint16m2_t vector
|
|
48
|
+
* are within specified bounds by splitting into m1 vectors.
|
|
49
|
+
*
|
|
50
|
+
* Arguments: - file: filename
|
|
51
|
+
* - line: line number
|
|
52
|
+
* - vec: RISC-V vector to be checked
|
|
53
|
+
* - vl: vector length (number of active elements per m1 half)
|
|
54
|
+
* - lower_bound_exclusive: Exclusive lower bound
|
|
55
|
+
* - upper_bound_exclusive: Exclusive upper bound
|
|
56
|
+
**************************************************/
|
|
57
|
+
#define mlk_debug_check_bounds_int16m2 \
|
|
58
|
+
MLK_NAMESPACE(mlkem_debug_check_bounds_int16m2)
|
|
59
|
+
void mlk_debug_check_bounds_int16m2(const char *file, int line, vint16m2_t vec,
|
|
60
|
+
size_t vl, int lower_bound_exclusive,
|
|
61
|
+
int upper_bound_exclusive);
|
|
62
|
+
|
|
63
|
+
/* Check bounds in vint16m1_t vector
|
|
64
|
+
* vec: RISC-V vector of type vint16m1_t
|
|
65
|
+
* vl: Vector length (number of active elements)
|
|
66
|
+
* value_lb: Inclusive lower value bound
|
|
67
|
+
* value_ub: Exclusive upper value bound */
|
|
68
|
+
#define mlk_assert_bound_int16m1(vec, vl, value_lb, value_ub) \
|
|
69
|
+
mlk_debug_check_bounds_int16m1(__FILE__, __LINE__, (vec), (vl), \
|
|
70
|
+
(value_lb) - 1, (value_ub))
|
|
71
|
+
|
|
72
|
+
/* Check absolute bounds in vint16m1_t vector
|
|
73
|
+
* vec: RISC-V vector of type vint16m1_t
|
|
74
|
+
* vl: Vector length (number of active elements)
|
|
75
|
+
* value_abs_bd: Exclusive absolute upper bound */
|
|
76
|
+
#define mlk_assert_abs_bound_int16m1(vec, vl, value_abs_bd) \
|
|
77
|
+
mlk_assert_bound_int16m1((vec), (vl), (-(value_abs_bd) + 1), (value_abs_bd))
|
|
78
|
+
|
|
79
|
+
/* Check bounds in vint16m2_t vector
|
|
80
|
+
* vec: RISC-V vector of type vint16m2_t
|
|
81
|
+
* vl: Vector length (number of active elements per m1 half)
|
|
82
|
+
* value_lb: Inclusive lower value bound
|
|
83
|
+
* value_ub: Exclusive upper value bound */
|
|
84
|
+
#define mlk_assert_bound_int16m2(vec, vl, value_lb, value_ub) \
|
|
85
|
+
mlk_debug_check_bounds_int16m2(__FILE__, __LINE__, (vec), (vl), \
|
|
86
|
+
(value_lb) - 1, (value_ub))
|
|
87
|
+
|
|
88
|
+
/* Check absolute bounds in vint16m2_t vector
|
|
89
|
+
* vec: RISC-V vector of type vint16m2_t
|
|
90
|
+
* vl: Vector length (number of active elements per m1 half)
|
|
91
|
+
* value_abs_bd: Exclusive absolute upper bound */
|
|
92
|
+
#define mlk_assert_abs_bound_int16m2(vec, vl, value_abs_bd) \
|
|
93
|
+
mlk_assert_bound_int16m2((vec), (vl), (-(value_abs_bd) + 1), (value_abs_bd))
|
|
94
|
+
|
|
95
|
+
#elif defined(CBMC)
|
|
96
|
+
|
|
97
|
+
/* For CBMC, we would need to implement vector bounds checking using CBMC
|
|
98
|
+
* primitives This is complex and would require extracting vector elements, so
|
|
99
|
+
* for now we provide empty implementations that could be extended later */
|
|
100
|
+
#define mlk_assert_bound_int16m1(vec, vl, value_lb, value_ub) \
|
|
101
|
+
do \
|
|
102
|
+
{ \
|
|
103
|
+
} while (0)
|
|
104
|
+
|
|
105
|
+
#define mlk_assert_abs_bound_int16m1(vec, vl, value_abs_bd) \
|
|
106
|
+
do \
|
|
107
|
+
{ \
|
|
108
|
+
} while (0)
|
|
109
|
+
|
|
110
|
+
#define mlk_assert_bound_int16m2(vec, vl, value_lb, value_ub) \
|
|
111
|
+
do \
|
|
112
|
+
{ \
|
|
113
|
+
} while (0)
|
|
114
|
+
|
|
115
|
+
#define mlk_assert_abs_bound_int16m2(vec, vl, value_abs_bd) \
|
|
116
|
+
do \
|
|
117
|
+
{ \
|
|
118
|
+
} while (0)
|
|
119
|
+
|
|
120
|
+
#else /* !MLKEM_DEBUG && CBMC */
|
|
121
|
+
|
|
122
|
+
/* When debugging is disabled, all assertions become no-ops */
|
|
123
|
+
#define mlk_assert_bound_int16m1(vec, vl, value_lb, value_ub) \
|
|
124
|
+
do \
|
|
125
|
+
{ \
|
|
126
|
+
} while (0)
|
|
127
|
+
|
|
128
|
+
#define mlk_assert_abs_bound_int16m1(vec, vl, value_abs_bd) \
|
|
129
|
+
do \
|
|
130
|
+
{ \
|
|
131
|
+
} while (0)
|
|
132
|
+
|
|
133
|
+
#define mlk_assert_bound_int16m2(vec, vl, value_lb, value_ub) \
|
|
134
|
+
do \
|
|
135
|
+
{ \
|
|
136
|
+
} while (0)
|
|
137
|
+
|
|
138
|
+
#define mlk_assert_abs_bound_int16m2(vec, vl, value_abs_bd) \
|
|
139
|
+
do \
|
|
140
|
+
{ \
|
|
141
|
+
} while (0)
|
|
142
|
+
|
|
143
|
+
#endif /* !MLKEM_DEBUG && !CBMC */
|
|
144
|
+
|
|
145
|
+
#endif /* !MLK_NATIVE_RISCV64_SRC_RV64V_DEBUG_H */
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) The mlkem-native project authors
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* WARNING: This file is auto-generated from scripts/autogen
|
|
8
|
+
* in the mlkem-native repository.
|
|
9
|
+
* Do not modify it directly.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
#include "arith_native_riscv64.h"
|
|
13
|
+
|
|
14
|
+
const int16_t izeta[] = {
|
|
15
|
+
-1044, 758, 1571, 205, 1275, -677, 1065, -448, -1628, -1522, 1460,
|
|
16
|
+
-958, -991, -996, 308, 108, 1517, 359, -411, 1542, 725, 1508,
|
|
17
|
+
-961, 398, -478, 870, 854, 1510, -794, 1278, 1530, 1185, -202,
|
|
18
|
+
-287, -608, -732, 951, 247, 1421, -107, 1659, 1187, -220, 874,
|
|
19
|
+
1335, -1218, 136, 1215, -1422, -1493, -1017, 681, -830, 271, 90,
|
|
20
|
+
853, -384, 1465, 1285, -1322, -610, -603, -1097, -817, -1468, 1474,
|
|
21
|
+
130, 1602, -1469, -126, 1162, 1618, 75, 156, -329, -418, -349,
|
|
22
|
+
872, -644, 1590, 1202, -962, -1458, 829, 666, 320, 8, -516,
|
|
23
|
+
-1119, 602, -1483, 777, 147, -1159, -778, 246, -182, -1577, -383,
|
|
24
|
+
-264, 1544, 282, -1491, 1293, -1653, -1574, 460, 291, 235, -177,
|
|
25
|
+
-587, -422, -622, 171, 1325, -573, -1015, 552, -652, -1223, -105,
|
|
26
|
+
-1550, -871, 1251, -843, -555, -430, 1103,
|
|
27
|
+
};
|