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
data/ext/pqcrypto/extconf.rb
CHANGED
|
@@ -2,20 +2,36 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require "mkmf"
|
|
5
|
+
require "rbconfig"
|
|
6
|
+
require_relative "../../lib/pq_crypto/version"
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
def generate_version_header!
|
|
9
|
+
version = PQCrypto::VERSION
|
|
10
|
+
unless version.match?(/\A[0-9A-Za-z][0-9A-Za-z._+-]*\z/)
|
|
11
|
+
abort "Invalid PQCrypto::VERSION for C header: #{version.inspect}"
|
|
12
|
+
end
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
header = File.join(__dir__, "pqcrypto_version.h")
|
|
15
|
+
File.write(header, <<~C)
|
|
16
|
+
/* Generated by extconf.rb from lib/pq_crypto/version.rb. Do not edit. */
|
|
17
|
+
#ifndef PQCRYPTO_VERSION_H
|
|
18
|
+
#define PQCRYPTO_VERSION_H
|
|
11
19
|
|
|
12
|
-
|
|
20
|
+
#define PQCRYPTO_VERSION #{version.dump}
|
|
13
21
|
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
#endif
|
|
23
|
+
C
|
|
24
|
+
end
|
|
16
25
|
|
|
17
|
-
|
|
26
|
+
generate_version_header!
|
|
27
|
+
|
|
28
|
+
$CFLAGS << " -std=c11 -Wall -Wextra -O3"
|
|
29
|
+
$CFLAGS << " -fstack-protector-strong -D_FORTIFY_SOURCE=2"
|
|
30
|
+
$LDFLAGS << " -Wl,-no_warn_duplicate_libraries" if RbConfig::CONFIG["host_os"] =~ /darwin/
|
|
31
|
+
|
|
32
|
+
VENDOR_ONLY_CFLAGS = "-Wno-unused-parameter -Wno-unused-function -Wno-strict-prototypes -Wno-pedantic -Wno-c23-extensions -Wno-undef"
|
|
18
33
|
|
|
34
|
+
SANITIZE = ENV["PQCRYPTO_SANITIZE"]
|
|
19
35
|
if SANITIZE && !SANITIZE.strip.empty?
|
|
20
36
|
sanitize = SANITIZE.strip
|
|
21
37
|
$CFLAGS.gsub!(/\s-D_FORTIFY_SOURCE=\d+/, "")
|
|
@@ -23,6 +39,8 @@ if SANITIZE && !SANITIZE.strip.empty?
|
|
|
23
39
|
$LDFLAGS << " -fsanitize=#{sanitize}"
|
|
24
40
|
end
|
|
25
41
|
|
|
42
|
+
NATIVE_ASM = (ENV["PQCRYPTO_NATIVE_ASM"] || "0") == "1"
|
|
43
|
+
|
|
26
44
|
def configure_compiler_environment
|
|
27
45
|
return unless RUBY_PLATFORM.include?("darwin")
|
|
28
46
|
|
|
@@ -31,6 +49,54 @@ def configure_compiler_environment
|
|
|
31
49
|
$LDFLAGS << " -L/opt/homebrew/lib"
|
|
32
50
|
end
|
|
33
51
|
|
|
52
|
+
def native_vendor_sources_for(vendor_dir)
|
|
53
|
+
[
|
|
54
|
+
File.join(vendor_dir, "mlkem-native", "mlkem", "mlkem_native.c"),
|
|
55
|
+
File.join(vendor_dir, "mldsa-native", "mldsa", "mldsa_native.c")
|
|
56
|
+
]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def native_vendor_ready?(vendor_dir)
|
|
60
|
+
File.exist?(File.join(vendor_dir, ".vendored")) &&
|
|
61
|
+
native_vendor_sources_for(vendor_dir).all? { |path| File.exist?(path) }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def vendor_script_path
|
|
65
|
+
File.expand_path("../../script/vendor_libs.rb", __dir__)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def run_vendor_script!(vendor_dir)
|
|
69
|
+
script = vendor_script_path
|
|
70
|
+
abort <<~MSG unless File.exist?(script)
|
|
71
|
+
PQ Code Package vendored sources are missing and script/vendor_libs.rb was not packaged.
|
|
72
|
+
|
|
73
|
+
Expected:
|
|
74
|
+
#{native_vendor_sources_for(vendor_dir).join("\n ")}
|
|
75
|
+
|
|
76
|
+
Rebuild the gem from a repository that includes script/vendor_libs.rb, or run
|
|
77
|
+
script/vendor_libs.rb before building the gem package.
|
|
78
|
+
MSG
|
|
79
|
+
|
|
80
|
+
abort <<~MSG if ENV["PQCRYPTO_AUTO_VENDOR"] == "0"
|
|
81
|
+
PQ Code Package vendored sources are missing and PQCRYPTO_AUTO_VENDOR=0 was set.
|
|
82
|
+
|
|
83
|
+
Expected:
|
|
84
|
+
#{native_vendor_sources_for(vendor_dir).join("\n ")}
|
|
85
|
+
|
|
86
|
+
Run:
|
|
87
|
+
ruby script/vendor_libs.rb
|
|
88
|
+
MSG
|
|
89
|
+
|
|
90
|
+
puts "PQ Code Package native sources are missing; vendoring now..."
|
|
91
|
+
ok = system(RbConfig.ruby, script)
|
|
92
|
+
abort <<~MSG unless ok
|
|
93
|
+
Failed to vendor PQ Code Package native sources.
|
|
94
|
+
|
|
95
|
+
This build intentionally has no PQClean fallback. Install git/network access or
|
|
96
|
+
vendor mlkem-native and mldsa-native before installing the gem.
|
|
97
|
+
MSG
|
|
98
|
+
end
|
|
99
|
+
|
|
34
100
|
def find_vendor_dir
|
|
35
101
|
candidates = [
|
|
36
102
|
File.join(__dir__, "vendor"),
|
|
@@ -44,8 +110,13 @@ def find_vendor_dir
|
|
|
44
110
|
dir = File.dirname(dir)
|
|
45
111
|
end
|
|
46
112
|
|
|
47
|
-
candidates.
|
|
48
|
-
|
|
113
|
+
candidates.map! { |path| File.expand_path(path) }
|
|
114
|
+
candidates.uniq!
|
|
115
|
+
|
|
116
|
+
primary = File.expand_path(File.join(__dir__, "vendor"))
|
|
117
|
+
run_vendor_script!(primary) unless native_vendor_ready?(primary)
|
|
118
|
+
|
|
119
|
+
candidates.find { |path| native_vendor_ready?(path) }
|
|
49
120
|
end
|
|
50
121
|
|
|
51
122
|
def configure_openssl!
|
|
@@ -64,7 +135,6 @@ def configure_openssl!
|
|
|
64
135
|
#endif
|
|
65
136
|
int main(void) { return 0; }
|
|
66
137
|
SRC
|
|
67
|
-
|
|
68
138
|
abort "OpenSSL 3.0 or later is required" unless try_compile(version_check)
|
|
69
139
|
|
|
70
140
|
sha3_check = <<~SRC
|
|
@@ -83,101 +153,112 @@ def configure_openssl!
|
|
|
83
153
|
return md == NULL ? 1 : 0;
|
|
84
154
|
}
|
|
85
155
|
SRC
|
|
86
|
-
abort "OpenSSL SHAKE256 is required (X-Wing key expansion)" unless try_compile(shake_check)
|
|
156
|
+
abort "OpenSSL SHAKE256 is required (X-Wing key expansion / ML-DSA streaming mu)" unless try_compile(shake_check)
|
|
87
157
|
|
|
88
158
|
$CFLAGS << " -DHAVE_OPENSSL_EVP_H -DHAVE_OPENSSL_RAND_H"
|
|
89
159
|
end
|
|
90
160
|
|
|
91
|
-
def
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
case KECCAK_BACKEND
|
|
95
|
-
when "clean"
|
|
96
|
-
{
|
|
97
|
-
name: "clean",
|
|
98
|
-
include_dirs: [],
|
|
99
|
-
source_group: ["pqclean_common", [File.join(common_dir, "fips202.c")]]
|
|
100
|
-
}
|
|
101
|
-
when "xkcp"
|
|
102
|
-
# The optimized backend must provide the same fips202.h-compatible API as
|
|
103
|
-
# PQClean's common/fips202.c. Do not substitute OpenSSL EVP SHAKE here: the
|
|
104
|
-
# PQClean SHAKE state layout is part of the ML-KEM/ML-DSA call graph.
|
|
105
|
-
xkcp_dir = File.join(vendor_dir, "xkcp")
|
|
106
|
-
adapter_source = File.join(xkcp_dir, "pqclean_fips202_xkcp.c")
|
|
107
|
-
|
|
108
|
-
abort <<~MSG unless File.exist?(adapter_source)
|
|
109
|
-
PQCRYPTO_KECCAK_BACKEND=xkcp was requested, but no reviewed XKCP adapter was found.
|
|
110
|
-
|
|
111
|
-
Expected:
|
|
112
|
-
#{adapter_source}
|
|
113
|
-
|
|
114
|
-
Refusing to fall back silently to the clean backend. Vendor a fips202.h-compatible
|
|
115
|
-
XKCP adapter first, then run the full SHAKE-dependent KAT/regression test matrix.
|
|
116
|
-
MSG
|
|
117
|
-
|
|
118
|
-
{
|
|
119
|
-
name: "xkcp",
|
|
120
|
-
include_dirs: [xkcp_dir],
|
|
121
|
-
source_group: ["xkcp_keccak", [adapter_source]]
|
|
122
|
-
}
|
|
123
|
-
end
|
|
161
|
+
def recursive_include_dirs(root)
|
|
162
|
+
Dir.glob(File.join(root, "**", "*")).select { |p| File.directory?(p) }.map { |p| File.expand_path(p) }
|
|
124
163
|
end
|
|
125
164
|
|
|
126
|
-
def
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
pqclean_dir = File.join(vendor_dir, "pqclean")
|
|
130
|
-
return nil unless Dir.exist?(pqclean_dir)
|
|
165
|
+
def native_vendor_config(vendor_dir)
|
|
166
|
+
abort <<~MSG unless vendor_dir
|
|
167
|
+
PQ Code Package vendored sources are required.
|
|
131
168
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
169
|
+
Expected:
|
|
170
|
+
ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c
|
|
171
|
+
ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c
|
|
135
172
|
|
|
136
|
-
|
|
173
|
+
Run:
|
|
174
|
+
bundle exec rake vendor
|
|
175
|
+
MSG
|
|
137
176
|
|
|
138
|
-
|
|
139
|
-
|
|
177
|
+
mlkem_dir = File.join(vendor_dir, "mlkem-native", "mlkem")
|
|
178
|
+
mldsa_dir = File.join(vendor_dir, "mldsa-native", "mldsa")
|
|
179
|
+
mlkem_c = File.join(mlkem_dir, "mlkem_native.c")
|
|
180
|
+
mldsa_c = File.join(mldsa_dir, "mldsa_native.c")
|
|
140
181
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
182
|
+
missing = [mlkem_c, mldsa_c].reject { |path| File.exist?(path) }
|
|
183
|
+
abort <<~MSG unless missing.empty?
|
|
184
|
+
Missing PQ Code Package native source files:
|
|
185
|
+
#{missing.join("\n ")}
|
|
144
186
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
["pqclean_common", common_sources],
|
|
149
|
-
keccak_config[:source_group]
|
|
150
|
-
]
|
|
187
|
+
This build intentionally has no PQClean fallback. Auto-vendoring did not
|
|
188
|
+
produce the required files. Vendor mlkem-native and mldsa-native, then rebuild.
|
|
189
|
+
MSG
|
|
151
190
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
$CFLAGS << " -DHAVE_PQCLEAN"
|
|
191
|
+
include_dirs = [__dir__, mlkem_dir, mldsa_dir, *recursive_include_dirs(mlkem_dir), *recursive_include_dirs(mldsa_dir)].uniq
|
|
155
192
|
include_dirs.each { |dir| $CPPFLAGS << " -I#{dir}" }
|
|
156
193
|
|
|
157
194
|
{
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
195
|
+
mlkem_dir: mlkem_dir,
|
|
196
|
+
mldsa_dir: mldsa_dir,
|
|
197
|
+
mlkem_c: mlkem_c,
|
|
198
|
+
mldsa_c: mldsa_c,
|
|
199
|
+
mlkem_asm: File.join(mlkem_dir, "mlkem_native_asm.S"),
|
|
200
|
+
mldsa_asm: File.join(mldsa_dir, "mldsa_native_asm.S")
|
|
161
201
|
}
|
|
162
202
|
end
|
|
163
203
|
|
|
164
|
-
def
|
|
165
|
-
|
|
204
|
+
def native_flags(kind, level, shared:)
|
|
205
|
+
prefix = kind == :mlkem ? "MLK" : "MLD"
|
|
206
|
+
ns = kind == :mlkem ? "pqcr_mlkem" : "pqcr_mldsa"
|
|
207
|
+
flags = []
|
|
208
|
+
flags << "-D#{prefix}_CONFIG_MULTILEVEL_BUILD"
|
|
209
|
+
flags << "-D#{prefix}_CONFIG_PARAMETER_SET=#{level}"
|
|
210
|
+
flags << "-D#{prefix}_CONFIG_NAMESPACE_PREFIX=#{ns}"
|
|
211
|
+
flags << "-D#{prefix}_CONFIG_NO_SUPERCOP"
|
|
212
|
+
flags << (shared ? "-D#{prefix}_CONFIG_MULTILEVEL_WITH_SHARED" : "-D#{prefix}_CONFIG_MULTILEVEL_NO_SHARED")
|
|
213
|
+
if NATIVE_ASM
|
|
214
|
+
flags << "-D#{prefix}_CONFIG_USE_NATIVE_BACKEND_ARITH"
|
|
215
|
+
flags << "-D#{prefix}_CONFIG_USE_NATIVE_BACKEND_FIPS202"
|
|
216
|
+
end
|
|
217
|
+
flags.join(" ")
|
|
218
|
+
end
|
|
166
219
|
|
|
220
|
+
def inject_native_sources!(config)
|
|
167
221
|
makefile = File.read("Makefile")
|
|
168
222
|
|
|
169
223
|
vendor_objects = []
|
|
170
224
|
build_rules = []
|
|
171
225
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
226
|
+
[
|
|
227
|
+
[:mlkem, "512", config[:mlkem_c], true],
|
|
228
|
+
[:mlkem, "768", config[:mlkem_c], false],
|
|
229
|
+
[:mlkem, "1024", config[:mlkem_c], false],
|
|
230
|
+
[:mldsa, "44", config[:mldsa_c], true],
|
|
231
|
+
[:mldsa, "65", config[:mldsa_c], false],
|
|
232
|
+
[:mldsa, "87", config[:mldsa_c], false]
|
|
233
|
+
].each do |kind, level, source, shared|
|
|
234
|
+
object = "pqnative_#{kind}_#{level}.o"
|
|
235
|
+
flags = native_flags(kind, level, shared: shared)
|
|
236
|
+
vendor_objects << object
|
|
237
|
+
build_rules << <<~RULE
|
|
238
|
+
#{object}: #{source}
|
|
239
|
+
$(ECHO) compiling #{source} [#{kind}-#{level}]
|
|
240
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) #{VENDOR_ONLY_CFLAGS} #{flags} $(COUTFLAG)$@ -c $(CSRCFLAG)$<
|
|
241
|
+
RULE
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
if NATIVE_ASM
|
|
245
|
+
[
|
|
246
|
+
[:mlkem, "512", config[:mlkem_asm], true],
|
|
247
|
+
[:mlkem, "768", config[:mlkem_asm], false],
|
|
248
|
+
[:mlkem, "1024", config[:mlkem_asm], false],
|
|
249
|
+
[:mldsa, "44", config[:mldsa_asm], true],
|
|
250
|
+
[:mldsa, "65", config[:mldsa_asm], false],
|
|
251
|
+
[:mldsa, "87", config[:mldsa_asm], false]
|
|
252
|
+
].each do |kind, level, source, shared|
|
|
253
|
+
next unless File.exist?(source)
|
|
254
|
+
|
|
255
|
+
object = "pqnative_#{kind}_#{level}_asm.o"
|
|
256
|
+
flags = native_flags(kind, level, shared: shared)
|
|
176
257
|
vendor_objects << object
|
|
177
258
|
build_rules << <<~RULE
|
|
178
259
|
#{object}: #{source}
|
|
179
|
-
$(ECHO)
|
|
180
|
-
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) #{VENDOR_ONLY_CFLAGS} $(COUTFLAG)$@ -c $(CSRCFLAG)$<
|
|
260
|
+
$(ECHO) assembling #{source} [#{kind}-#{level}]
|
|
261
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) #{VENDOR_ONLY_CFLAGS} #{flags} $(COUTFLAG)$@ -c $(CSRCFLAG)$<
|
|
181
262
|
RULE
|
|
182
263
|
end
|
|
183
264
|
end
|
|
@@ -187,8 +268,8 @@ def inject_pqclean_sources!(pqclean_config)
|
|
|
187
268
|
|
|
188
269
|
makefile.sub!(objects_line, objects_line.chomp + " #{vendor_objects.join(' ')}\n")
|
|
189
270
|
|
|
190
|
-
unless makefile.include?("# vendored
|
|
191
|
-
rules_block = "\n# vendored
|
|
271
|
+
unless makefile.include?("# vendored pq-code-package objects")
|
|
272
|
+
rules_block = "\n# vendored pq-code-package objects\n" + build_rules.join("\n") + "\n"
|
|
192
273
|
anchor = "$(OBJS): $(HDRS) $(ruby_headers)\n"
|
|
193
274
|
raise "Could not find OBJS dependency anchor in generated Makefile" unless makefile.include?(anchor)
|
|
194
275
|
|
|
@@ -198,18 +279,19 @@ def inject_pqclean_sources!(pqclean_config)
|
|
|
198
279
|
File.write("Makefile", makefile)
|
|
199
280
|
end
|
|
200
281
|
|
|
201
|
-
vendor_dir =
|
|
282
|
+
vendor_dir = find_vendor_dir
|
|
202
283
|
|
|
203
284
|
puts
|
|
204
285
|
puts "=== PQCrypto build configuration ==="
|
|
205
286
|
configure_openssl!
|
|
206
|
-
|
|
287
|
+
native_config = native_vendor_config(vendor_dir)
|
|
207
288
|
puts "OpenSSL: system"
|
|
208
|
-
|
|
209
|
-
puts "
|
|
210
|
-
puts "
|
|
289
|
+
puts "ML-KEM: mlkem-native vendored"
|
|
290
|
+
puts "ML-DSA: mldsa-native vendored"
|
|
291
|
+
puts "Native asm backends: #{NATIVE_ASM ? 'enabled' : 'disabled'}"
|
|
292
|
+
puts "PQClean fallback: removed"
|
|
211
293
|
puts "Output: pqcrypto/pqcrypto_secure"
|
|
212
294
|
puts "===================================="
|
|
213
295
|
|
|
214
296
|
create_makefile("pqcrypto/pqcrypto_secure")
|
|
215
|
-
|
|
297
|
+
inject_native_sources!(native_config)
|
data/ext/pqcrypto/mldsa_api.h
CHANGED
|
@@ -1,51 +1,4 @@
|
|
|
1
1
|
#ifndef MLDSA_API_H
|
|
2
2
|
#define MLDSA_API_H
|
|
3
|
-
|
|
4
|
-
#ifdef HAVE_PQCLEAN
|
|
5
|
-
#include <stddef.h>
|
|
6
|
-
#include <stdint.h>
|
|
7
|
-
|
|
8
|
-
#define PQCLEAN_MLDSA65_CLEAN_CRYPTO_ALGNAME "ML-DSA-65"
|
|
9
|
-
|
|
10
|
-
int PQCLEAN_MLDSA65_CLEAN_crypto_sign_keypair(uint8_t *pk, uint8_t *sk);
|
|
11
|
-
|
|
12
|
-
int PQCLEAN_MLDSA65_CLEAN_crypto_sign_signature_ctx(uint8_t *sig, size_t *siglen,
|
|
13
|
-
const uint8_t *m, size_t mlen,
|
|
14
|
-
const uint8_t *ctx, size_t ctxlen,
|
|
15
|
-
const uint8_t *sk);
|
|
16
|
-
|
|
17
|
-
int PQCLEAN_MLDSA65_CLEAN_crypto_sign_ctx(uint8_t *sm, size_t *smlen,
|
|
18
|
-
const uint8_t *m, size_t mlen,
|
|
19
|
-
const uint8_t *ctx, size_t ctxlen,
|
|
20
|
-
const uint8_t *sk);
|
|
21
|
-
|
|
22
|
-
int PQCLEAN_MLDSA65_CLEAN_crypto_sign_verify_ctx(const uint8_t *sig, size_t siglen,
|
|
23
|
-
const uint8_t *m, size_t mlen,
|
|
24
|
-
const uint8_t *ctx, size_t ctxlen,
|
|
25
|
-
const uint8_t *pk);
|
|
26
|
-
|
|
27
|
-
int PQCLEAN_MLDSA65_CLEAN_crypto_sign_open_ctx(uint8_t *m, size_t *mlen,
|
|
28
|
-
const uint8_t *sm, size_t smlen,
|
|
29
|
-
const uint8_t *ctx, size_t ctxlen,
|
|
30
|
-
const uint8_t *pk);
|
|
31
|
-
|
|
32
|
-
int PQCLEAN_MLDSA65_CLEAN_crypto_sign_signature(uint8_t *sig, size_t *siglen,
|
|
33
|
-
const uint8_t *m, size_t mlen,
|
|
34
|
-
const uint8_t *sk);
|
|
35
|
-
|
|
36
|
-
int PQCLEAN_MLDSA65_CLEAN_crypto_sign(uint8_t *sm, size_t *smlen,
|
|
37
|
-
const uint8_t *m, size_t mlen,
|
|
38
|
-
const uint8_t *sk);
|
|
39
|
-
|
|
40
|
-
int PQCLEAN_MLDSA65_CLEAN_crypto_sign_verify(const uint8_t *sig, size_t siglen,
|
|
41
|
-
const uint8_t *m, size_t mlen,
|
|
42
|
-
const uint8_t *pk);
|
|
43
|
-
|
|
44
|
-
int PQCLEAN_MLDSA65_CLEAN_crypto_sign_open(uint8_t *m, size_t *mlen,
|
|
45
|
-
const uint8_t *sm, size_t smlen,
|
|
46
|
-
const uint8_t *pk);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
#endif
|
|
50
|
-
|
|
3
|
+
#include "pqcrypto_native_api.h"
|
|
51
4
|
#endif
|
data/ext/pqcrypto/mlkem_api.h
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
1
|
#ifndef MLKEM_API_H
|
|
2
2
|
#define MLKEM_API_H
|
|
3
|
-
|
|
4
|
-
#ifdef HAVE_PQCLEAN
|
|
5
|
-
#include <stdint.h>
|
|
6
|
-
|
|
7
|
-
#define PQCLEAN_MLKEM768_CLEAN_CRYPTO_SECRETKEYBYTES 2400
|
|
8
|
-
#define PQCLEAN_MLKEM768_CLEAN_CRYPTO_PUBLICKEYBYTES 1184
|
|
9
|
-
#define PQCLEAN_MLKEM768_CLEAN_CRYPTO_CIPHERTEXTBYTES 1088
|
|
10
|
-
#define PQCLEAN_MLKEM768_CLEAN_CRYPTO_BYTES 32
|
|
11
|
-
#define PQCLEAN_MLKEM768_CLEAN_CRYPTO_ALGNAME "ML-KEM-768"
|
|
12
|
-
|
|
13
|
-
int PQCLEAN_MLKEM768_CLEAN_crypto_kem_keypair(uint8_t *pk, uint8_t *sk);
|
|
14
|
-
int PQCLEAN_MLKEM768_CLEAN_crypto_kem_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk);
|
|
15
|
-
int PQCLEAN_MLKEM768_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);
|
|
16
|
-
int PQCLEAN_MLKEM768_CLEAN_crypto_kem_keypair_derand(uint8_t *pk, uint8_t *sk, const uint8_t *coins);
|
|
17
|
-
int PQCLEAN_MLKEM768_CLEAN_crypto_kem_enc_derand(uint8_t *ct, uint8_t *ss, const uint8_t *pk, const uint8_t *coins);
|
|
18
|
-
|
|
19
|
-
#endif
|
|
20
|
-
|
|
3
|
+
#include "pqcrypto_native_api.h"
|
|
21
4
|
#endif
|