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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#include "pqcrypto_secure.h"
|
|
2
|
+
#include "pqcrypto_version.h"
|
|
2
3
|
|
|
3
4
|
#include <stdio.h>
|
|
4
5
|
#include <sys/types.h>
|
|
@@ -21,12 +22,7 @@
|
|
|
21
22
|
#error "OpenSSL 3.0 or later is required for pq_crypto"
|
|
22
23
|
#endif
|
|
23
24
|
|
|
24
|
-
#
|
|
25
|
-
#error "PQClean-backed algorithms are required. Run: bundle exec rake vendor"
|
|
26
|
-
#endif
|
|
27
|
-
|
|
28
|
-
#include "mlkem_api.h"
|
|
29
|
-
#include "mldsa_api.h"
|
|
25
|
+
#include "pqcrypto_native_api.h"
|
|
30
26
|
|
|
31
27
|
void pq_secure_wipe(void *ptr, size_t len) {
|
|
32
28
|
if (ptr == NULL) {
|
|
@@ -49,15 +45,6 @@ static int pq_size_add(size_t a, size_t b, size_t *out) {
|
|
|
49
45
|
return PQ_SUCCESS;
|
|
50
46
|
}
|
|
51
47
|
|
|
52
|
-
static int pq_size_mul(size_t a, size_t b, size_t *out) {
|
|
53
|
-
if (!out)
|
|
54
|
-
return PQ_ERROR_BUFFER;
|
|
55
|
-
if (a != 0 && SIZE_MAX / a < b)
|
|
56
|
-
return PQ_ERROR_BUFFER;
|
|
57
|
-
*out = a * b;
|
|
58
|
-
return PQ_SUCCESS;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
48
|
static int pq_is_pem_whitespace(char c) {
|
|
62
49
|
return c == '\n' || c == '\r' || c == ' ' || c == '\t';
|
|
63
50
|
}
|
|
@@ -231,8 +218,7 @@ static int xwing_expand_secret_key(hybrid_expanded_secret_key_t *expanded_key,
|
|
|
231
218
|
if (EVP_DigestFinalXOF(ctx, expanded, sizeof(expanded)) != 1)
|
|
232
219
|
goto cleanup;
|
|
233
220
|
|
|
234
|
-
ret =
|
|
235
|
-
expanded_key->mlkem_sk, expanded);
|
|
221
|
+
ret = pqcr_mlkem768_keypair_derand(expanded_key->mlkem_pk, expanded_key->mlkem_sk, expanded);
|
|
236
222
|
if (ret != 0) {
|
|
237
223
|
ret = PQ_ERROR_KEYPAIR;
|
|
238
224
|
goto cleanup;
|
|
@@ -256,99 +242,238 @@ cleanup:
|
|
|
256
242
|
return ret;
|
|
257
243
|
}
|
|
258
244
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
245
|
+
#define PQ_MLKEM_VARIANTS(X) \
|
|
246
|
+
X(mlkem, pqcr_mlkem768) \
|
|
247
|
+
X(mlkem512, pqcr_mlkem512) \
|
|
248
|
+
X(mlkem1024, pqcr_mlkem1024)
|
|
249
|
+
|
|
250
|
+
#define PQ_DEFINE_MLKEM_SHIMS(prefix, native) \
|
|
251
|
+
int pq_##prefix##_keypair(uint8_t *pk, uint8_t *sk) { \
|
|
252
|
+
if (!pk || !sk) { \
|
|
253
|
+
return PQ_ERROR_BUFFER; \
|
|
254
|
+
} \
|
|
255
|
+
return native##_keypair(pk, sk) == 0 ? PQ_SUCCESS : PQ_ERROR_KEYPAIR; \
|
|
256
|
+
} \
|
|
257
|
+
int pq_##prefix##_keypair_from_seed(uint8_t *pk, uint8_t *sk, const uint8_t *seed64) {\
|
|
258
|
+
if (!pk || !sk || !seed64) { \
|
|
259
|
+
return PQ_ERROR_BUFFER; \
|
|
260
|
+
} \
|
|
261
|
+
return native##_keypair_derand(pk, sk, seed64) == 0 ? PQ_SUCCESS \
|
|
262
|
+
: PQ_ERROR_KEYPAIR; \
|
|
263
|
+
} \
|
|
264
|
+
int pq_##prefix##_encapsulate(uint8_t *ct, uint8_t *ss, const uint8_t *pk) { \
|
|
265
|
+
if (!ct || !ss || !pk) { \
|
|
266
|
+
return PQ_ERROR_BUFFER; \
|
|
267
|
+
} \
|
|
268
|
+
return native##_enc(ct, ss, pk) == 0 ? PQ_SUCCESS : PQ_ERROR_ENCAPSULATE; \
|
|
269
|
+
} \
|
|
270
|
+
int pq_##prefix##_decapsulate(uint8_t *ss, const uint8_t *ct, const uint8_t *sk) { \
|
|
271
|
+
if (!ss || !ct || !sk) { \
|
|
272
|
+
return PQ_ERROR_BUFFER; \
|
|
273
|
+
} \
|
|
274
|
+
return native##_dec(ss, ct, sk) == 0 ? PQ_SUCCESS : PQ_ERROR_DECAPSULATE; \
|
|
275
|
+
}
|
|
262
276
|
|
|
263
|
-
|
|
264
|
-
return PQCLEAN_MLKEM768_CLEAN_crypto_kem_enc(ct, ss, pk) == 0 ? PQ_SUCCESS
|
|
265
|
-
: PQ_ERROR_ENCAPSULATE;
|
|
266
|
-
}
|
|
277
|
+
PQ_MLKEM_VARIANTS(PQ_DEFINE_MLKEM_SHIMS)
|
|
267
278
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
279
|
+
#undef PQ_DEFINE_MLKEM_SHIMS
|
|
280
|
+
|
|
281
|
+
static int pq_testing_mlkem_keypair_from_seed_with(uint8_t *public_key, uint8_t *secret_key,
|
|
282
|
+
const uint8_t *seed, size_t seed_len,
|
|
283
|
+
int (*keypair_derand)(uint8_t *, uint8_t *,
|
|
284
|
+
const uint8_t *)) {
|
|
285
|
+
if (!public_key || !secret_key || !seed || seed_len != 64 || !keypair_derand) {
|
|
286
|
+
return PQ_ERROR_BUFFER;
|
|
287
|
+
}
|
|
288
|
+
return keypair_derand(public_key, secret_key, seed) == 0 ? PQ_SUCCESS : PQ_ERROR_KEYPAIR;
|
|
271
289
|
}
|
|
272
290
|
|
|
273
|
-
int
|
|
274
|
-
|
|
275
|
-
|
|
291
|
+
static int pq_testing_mlkem_encapsulate_from_seed_with(
|
|
292
|
+
uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key, const uint8_t *seed,
|
|
293
|
+
size_t seed_len, int (*enc_derand)(uint8_t *, uint8_t *, const uint8_t *, const uint8_t *)) {
|
|
294
|
+
if (!ciphertext || !shared_secret || !public_key || !seed || seed_len != 32 || !enc_derand) {
|
|
276
295
|
return PQ_ERROR_BUFFER;
|
|
277
296
|
}
|
|
278
|
-
return
|
|
279
|
-
|
|
280
|
-
: PQ_ERROR_KEYPAIR;
|
|
297
|
+
return enc_derand(ciphertext, shared_secret, public_key, seed) == 0 ? PQ_SUCCESS
|
|
298
|
+
: PQ_ERROR_ENCAPSULATE;
|
|
281
299
|
}
|
|
282
300
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
301
|
+
#define PQ_DEFINE_MLKEM_TESTING_SHIMS(prefix, native) \
|
|
302
|
+
int pq_testing_##prefix##_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key, \
|
|
303
|
+
const uint8_t *seed, size_t seed_len) { \
|
|
304
|
+
return pq_testing_mlkem_keypair_from_seed_with(public_key, secret_key, seed, seed_len, \
|
|
305
|
+
native##_keypair_derand); \
|
|
306
|
+
} \
|
|
307
|
+
int pq_testing_##prefix##_encapsulate_from_seed(uint8_t *ciphertext, uint8_t *shared_secret,\
|
|
308
|
+
const uint8_t *public_key, \
|
|
309
|
+
const uint8_t *seed, size_t seed_len) { \
|
|
310
|
+
return pq_testing_mlkem_encapsulate_from_seed_with(ciphertext, shared_secret, public_key,\
|
|
311
|
+
seed, seed_len, native##_enc_derand);\
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
PQ_MLKEM_VARIANTS(PQ_DEFINE_MLKEM_TESTING_SHIMS)
|
|
315
|
+
|
|
316
|
+
#undef PQ_DEFINE_MLKEM_TESTING_SHIMS
|
|
317
|
+
|
|
318
|
+
#define PQ_DEFINE_MLDSA_SIGN_KEYPAIR(prefix, native) \
|
|
319
|
+
int pq_##prefix##_keypair(uint8_t *public_key, uint8_t *secret_key) { \
|
|
320
|
+
if (!public_key || !secret_key) { \
|
|
321
|
+
return PQ_ERROR_BUFFER; \
|
|
322
|
+
} \
|
|
323
|
+
return native##_keypair(public_key, secret_key) == 0 ? PQ_SUCCESS \
|
|
324
|
+
: PQ_ERROR_KEYPAIR; \
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
PQ_DEFINE_MLDSA_SIGN_KEYPAIR(sign, pqcr_mldsa65)
|
|
328
|
+
PQ_DEFINE_MLDSA_SIGN_KEYPAIR(mldsa44_sign, pqcr_mldsa44)
|
|
329
|
+
PQ_DEFINE_MLDSA_SIGN_KEYPAIR(mldsa87_sign, pqcr_mldsa87)
|
|
330
|
+
|
|
331
|
+
#undef PQ_DEFINE_MLDSA_SIGN_KEYPAIR
|
|
332
|
+
|
|
333
|
+
#define PQ_DEFINE_MLDSA_SIGN(name, native) \
|
|
334
|
+
int pq_##name(uint8_t *signature, size_t *signature_len, const uint8_t *message, \
|
|
335
|
+
size_t message_len, const uint8_t *secret_key) { \
|
|
336
|
+
if (!signature || !signature_len || !secret_key || (message_len > 0 && !message)) {\
|
|
337
|
+
return PQ_ERROR_BUFFER; \
|
|
338
|
+
} \
|
|
339
|
+
return native##_signature(signature, signature_len, message, message_len, NULL, 0,\
|
|
340
|
+
secret_key) == 0 \
|
|
341
|
+
? PQ_SUCCESS \
|
|
342
|
+
: PQ_ERROR_SIGN; \
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
PQ_DEFINE_MLDSA_SIGN(sign, pqcr_mldsa65)
|
|
346
|
+
PQ_DEFINE_MLDSA_SIGN(mldsa44_sign, pqcr_mldsa44)
|
|
347
|
+
PQ_DEFINE_MLDSA_SIGN(mldsa87_sign, pqcr_mldsa87)
|
|
348
|
+
|
|
349
|
+
#undef PQ_DEFINE_MLDSA_SIGN
|
|
350
|
+
|
|
351
|
+
#define PQ_DEFINE_MLDSA_VERIFY(name, native) \
|
|
352
|
+
int pq_##name(const uint8_t *signature, size_t signature_len, const uint8_t *message, \
|
|
353
|
+
size_t message_len, const uint8_t *public_key) { \
|
|
354
|
+
if (!signature || !public_key || (message_len > 0 && !message)) { \
|
|
355
|
+
return PQ_ERROR_BUFFER; \
|
|
356
|
+
} \
|
|
357
|
+
return native##_verify(signature, signature_len, message, message_len, NULL, 0, \
|
|
358
|
+
public_key) == 0 \
|
|
359
|
+
? PQ_SUCCESS \
|
|
360
|
+
: PQ_ERROR_VERIFY; \
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
PQ_DEFINE_MLDSA_VERIFY(verify, pqcr_mldsa65)
|
|
364
|
+
PQ_DEFINE_MLDSA_VERIFY(mldsa44_verify, pqcr_mldsa44)
|
|
365
|
+
PQ_DEFINE_MLDSA_VERIFY(mldsa87_verify, pqcr_mldsa87)
|
|
366
|
+
|
|
367
|
+
#undef PQ_DEFINE_MLDSA_VERIFY
|
|
368
|
+
|
|
369
|
+
static int pq_testing_mldsa_sign_from_seed_with(
|
|
370
|
+
uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len,
|
|
371
|
+
const uint8_t *secret_key, const uint8_t *seed, size_t seed_len,
|
|
372
|
+
int (*signature_internal)(uint8_t *, size_t *, const uint8_t *, size_t, const uint8_t *, size_t,
|
|
373
|
+
const uint8_t *, const uint8_t *, int),
|
|
374
|
+
size_t (*prepare_prefix)(uint8_t *, const uint8_t *, size_t, const uint8_t *, size_t, int)) {
|
|
375
|
+
uint8_t pre[MLDSA_DOMAIN_SEPARATION_MAX_BYTES];
|
|
376
|
+
size_t pre_len;
|
|
377
|
+
|
|
378
|
+
if (!signature || !signature_len || !secret_key || !seed || seed_len != MLDSA_RNDBYTES ||
|
|
379
|
+
!signature_internal || !prepare_prefix || (message_len > 0 && !message)) {
|
|
287
380
|
return PQ_ERROR_BUFFER;
|
|
288
381
|
}
|
|
289
|
-
|
|
290
|
-
|
|
382
|
+
|
|
383
|
+
/*
|
|
384
|
+
* mldsa-native's signature_internal is lower-level than the public pure
|
|
385
|
+
* ML-DSA signing API. It expects the FIPS 204 domain-separation prefix explicitly. Passing
|
|
386
|
+
* NULL/0 signs CRH(tr, message) instead of CRH(tr, 0x00 || ctxlen || ctx || message),
|
|
387
|
+
* which produces signatures that do not verify through the public pure-ML-DSA API
|
|
388
|
+
* and do not match ACVP/KAT sigGen vectors.
|
|
389
|
+
*/
|
|
390
|
+
pre_len = prepare_prefix(pre, NULL, 0, NULL, 0, MLDSA_PREHASH_NONE);
|
|
391
|
+
if (pre_len == 0) {
|
|
392
|
+
return PQ_ERROR_SIGN;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return signature_internal(signature, signature_len, message, message_len, pre, pre_len, seed,
|
|
396
|
+
secret_key, 0) == 0
|
|
291
397
|
? PQ_SUCCESS
|
|
292
|
-
:
|
|
398
|
+
: PQ_ERROR_SIGN;
|
|
293
399
|
}
|
|
294
400
|
|
|
295
|
-
int
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
401
|
+
int pq_mldsa44_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key, const uint8_t *seed32) {
|
|
402
|
+
if (!public_key || !secret_key || !seed32) {
|
|
403
|
+
return PQ_ERROR_BUFFER;
|
|
404
|
+
}
|
|
405
|
+
return pqcr_mldsa44_keypair_internal(public_key, secret_key, seed32) == 0 ? PQ_SUCCESS
|
|
406
|
+
: PQ_ERROR_KEYPAIR;
|
|
299
407
|
}
|
|
300
408
|
|
|
301
|
-
int
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
409
|
+
int pq_mldsa_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key, const uint8_t *seed32) {
|
|
410
|
+
if (!public_key || !secret_key || !seed32) {
|
|
411
|
+
return PQ_ERROR_BUFFER;
|
|
412
|
+
}
|
|
413
|
+
return pqcr_mldsa65_keypair_internal(public_key, secret_key, seed32) == 0 ? PQ_SUCCESS
|
|
414
|
+
: PQ_ERROR_KEYPAIR;
|
|
307
415
|
}
|
|
308
416
|
|
|
309
|
-
int
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
417
|
+
int pq_mldsa87_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key, const uint8_t *seed32) {
|
|
418
|
+
if (!public_key || !secret_key || !seed32) {
|
|
419
|
+
return PQ_ERROR_BUFFER;
|
|
420
|
+
}
|
|
421
|
+
return pqcr_mldsa87_keypair_internal(public_key, secret_key, seed32) == 0 ? PQ_SUCCESS
|
|
422
|
+
: PQ_ERROR_KEYPAIR;
|
|
315
423
|
}
|
|
316
424
|
|
|
317
425
|
int pq_testing_mldsa_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
|
|
318
426
|
const uint8_t *seed, size_t seed_len) {
|
|
319
|
-
|
|
320
|
-
if (!public_key || !secret_key || !seed) {
|
|
427
|
+
if (seed_len != MLDSA_SEEDBYTES) {
|
|
321
428
|
return PQ_ERROR_BUFFER;
|
|
322
429
|
}
|
|
430
|
+
return pq_mldsa_keypair_from_seed(public_key, secret_key, seed);
|
|
431
|
+
}
|
|
323
432
|
|
|
324
|
-
|
|
433
|
+
int pq_testing_mldsa44_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
|
|
434
|
+
const uint8_t *seed, size_t seed_len) {
|
|
435
|
+
if (seed_len != MLDSA_SEEDBYTES) {
|
|
325
436
|
return PQ_ERROR_BUFFER;
|
|
326
437
|
}
|
|
438
|
+
return pq_mldsa44_keypair_from_seed(public_key, secret_key, seed);
|
|
439
|
+
}
|
|
327
440
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
441
|
+
int pq_testing_mldsa87_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
|
|
442
|
+
const uint8_t *seed, size_t seed_len) {
|
|
443
|
+
if (seed_len != MLDSA_SEEDBYTES) {
|
|
444
|
+
return PQ_ERROR_BUFFER;
|
|
445
|
+
}
|
|
446
|
+
return pq_mldsa87_keypair_from_seed(public_key, secret_key, seed);
|
|
332
447
|
}
|
|
333
448
|
|
|
334
449
|
int pq_testing_mldsa_sign_from_seed(uint8_t *signature, size_t *signature_len,
|
|
335
450
|
const uint8_t *message, size_t message_len,
|
|
336
451
|
const uint8_t *secret_key, const uint8_t *seed,
|
|
337
452
|
size_t seed_len) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
453
|
+
return pq_testing_mldsa_sign_from_seed_with(signature, signature_len, message, message_len,
|
|
454
|
+
secret_key, seed, seed_len,
|
|
455
|
+
pqcr_mldsa65_signature_internal,
|
|
456
|
+
pqcr_mldsa65_prepare_domain_separation_prefix);
|
|
457
|
+
}
|
|
342
458
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
459
|
+
int pq_testing_mldsa44_sign_from_seed(uint8_t *signature, size_t *signature_len,
|
|
460
|
+
const uint8_t *message, size_t message_len,
|
|
461
|
+
const uint8_t *secret_key, const uint8_t *seed,
|
|
462
|
+
size_t seed_len) {
|
|
463
|
+
return pq_testing_mldsa_sign_from_seed_with(signature, signature_len, message, message_len,
|
|
464
|
+
secret_key, seed, seed_len,
|
|
465
|
+
pqcr_mldsa44_signature_internal,
|
|
466
|
+
pqcr_mldsa44_prepare_domain_separation_prefix);
|
|
467
|
+
}
|
|
346
468
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
return
|
|
469
|
+
int pq_testing_mldsa87_sign_from_seed(uint8_t *signature, size_t *signature_len,
|
|
470
|
+
const uint8_t *message, size_t message_len,
|
|
471
|
+
const uint8_t *secret_key, const uint8_t *seed,
|
|
472
|
+
size_t seed_len) {
|
|
473
|
+
return pq_testing_mldsa_sign_from_seed_with(signature, signature_len, message, message_len,
|
|
474
|
+
secret_key, seed, seed_len,
|
|
475
|
+
pqcr_mldsa87_signature_internal,
|
|
476
|
+
pqcr_mldsa87_prepare_domain_separation_prefix);
|
|
352
477
|
}
|
|
353
478
|
|
|
354
479
|
int pq_hybrid_kem_keypair(uint8_t *public_key, uint8_t *secret_key) {
|
|
@@ -405,7 +530,7 @@ int pq_hybrid_kem_encapsulate(uint8_t *ciphertext, uint8_t *shared_secret,
|
|
|
405
530
|
memset(x25519_ss, 0, sizeof(x25519_ss));
|
|
406
531
|
memset(x25519_ephemeral_sk, 0, sizeof(x25519_ephemeral_sk));
|
|
407
532
|
|
|
408
|
-
if (
|
|
533
|
+
if (pqcr_mlkem768_enc(ct.mlkem_ct, mlkem_ss, pk.mlkem_pk) != 0) {
|
|
409
534
|
ret = PQ_ERROR_ENCAPSULATE;
|
|
410
535
|
goto cleanup;
|
|
411
536
|
}
|
|
@@ -459,7 +584,7 @@ int pq_hybrid_kem_decapsulate(uint8_t *shared_secret, const uint8_t *ciphertext,
|
|
|
459
584
|
goto cleanup;
|
|
460
585
|
}
|
|
461
586
|
|
|
462
|
-
if (
|
|
587
|
+
if (pqcr_mlkem768_dec(mlkem_ss, ct.mlkem_ct, expanded.mlkem_sk) != 0) {
|
|
463
588
|
ret = PQ_ERROR_DECAPSULATE;
|
|
464
589
|
goto cleanup;
|
|
465
590
|
}
|
|
@@ -959,5 +1084,5 @@ int pq_secret_key_from_pqc_container_pem(char **algorithm_out, uint8_t **key_out
|
|
|
959
1084
|
}
|
|
960
1085
|
|
|
961
1086
|
const char *pq_version(void) {
|
|
962
|
-
return
|
|
1087
|
+
return PQCRYPTO_VERSION;
|
|
963
1088
|
}
|
|
@@ -5,20 +5,7 @@
|
|
|
5
5
|
#include <stdlib.h>
|
|
6
6
|
#include <string.h>
|
|
7
7
|
|
|
8
|
-
#
|
|
9
|
-
#error "PQClean sources are required to build pq_crypto. Run: bundle exec rake vendor"
|
|
10
|
-
#endif
|
|
11
|
-
|
|
12
|
-
#include "mlkem_api.h"
|
|
13
|
-
#include "mldsa_api.h"
|
|
14
|
-
#define MLKEM_PUBLICKEYBYTES PQCLEAN_MLKEM768_CLEAN_CRYPTO_PUBLICKEYBYTES
|
|
15
|
-
#define MLKEM_SECRETKEYBYTES PQCLEAN_MLKEM768_CLEAN_CRYPTO_SECRETKEYBYTES
|
|
16
|
-
#define MLKEM_CIPHERTEXTBYTES PQCLEAN_MLKEM768_CLEAN_CRYPTO_CIPHERTEXTBYTES
|
|
17
|
-
#define MLKEM_SHAREDSECRETBYTES PQCLEAN_MLKEM768_CLEAN_CRYPTO_BYTES
|
|
18
|
-
|
|
19
|
-
#define MLDSA_PUBLICKEYBYTES 1952
|
|
20
|
-
#define MLDSA_SECRETKEYBYTES 4032
|
|
21
|
-
#define MLDSA_BYTES 3309
|
|
8
|
+
#include "pqcrypto_native_api.h"
|
|
22
9
|
|
|
23
10
|
#define X25519_PUBLICKEYBYTES 32
|
|
24
11
|
#define X25519_SECRETKEYBYTES 32
|
|
@@ -78,15 +65,45 @@ _Static_assert(sizeof(hybrid_ciphertext_t) == HYBRID_CIPHERTEXTBYTES,
|
|
|
78
65
|
void pq_secure_wipe(void *ptr, size_t len);
|
|
79
66
|
|
|
80
67
|
int pq_mlkem_keypair(uint8_t *public_key, uint8_t *secret_key);
|
|
68
|
+
int pq_mlkem512_keypair(uint8_t *public_key, uint8_t *secret_key);
|
|
69
|
+
int pq_mlkem1024_keypair(uint8_t *public_key, uint8_t *secret_key);
|
|
70
|
+
int pq_mlkem_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
|
|
71
|
+
const uint8_t *seed64);
|
|
72
|
+
int pq_mlkem512_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
|
|
73
|
+
const uint8_t *seed64);
|
|
74
|
+
int pq_mlkem1024_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
|
|
75
|
+
const uint8_t *seed64);
|
|
81
76
|
int pq_mlkem_encapsulate(uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key);
|
|
77
|
+
int pq_mlkem512_encapsulate(uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key);
|
|
78
|
+
int pq_mlkem1024_encapsulate(uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key);
|
|
82
79
|
int pq_mlkem_decapsulate(uint8_t *shared_secret, const uint8_t *ciphertext,
|
|
83
80
|
const uint8_t *secret_key);
|
|
81
|
+
int pq_mlkem512_decapsulate(uint8_t *shared_secret, const uint8_t *ciphertext,
|
|
82
|
+
const uint8_t *secret_key);
|
|
83
|
+
int pq_mlkem1024_decapsulate(uint8_t *shared_secret, const uint8_t *ciphertext,
|
|
84
|
+
const uint8_t *secret_key);
|
|
84
85
|
|
|
85
86
|
int pq_sign_keypair(uint8_t *public_key, uint8_t *secret_key);
|
|
87
|
+
int pq_mldsa44_sign_keypair(uint8_t *public_key, uint8_t *secret_key);
|
|
88
|
+
int pq_mldsa87_sign_keypair(uint8_t *public_key, uint8_t *secret_key);
|
|
89
|
+
int pq_mldsa44_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
|
|
90
|
+
const uint8_t *seed32);
|
|
91
|
+
int pq_mldsa_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
|
|
92
|
+
const uint8_t *seed32);
|
|
93
|
+
int pq_mldsa87_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
|
|
94
|
+
const uint8_t *seed32);
|
|
86
95
|
int pq_sign(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len,
|
|
87
96
|
const uint8_t *secret_key);
|
|
97
|
+
int pq_mldsa44_sign(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len,
|
|
98
|
+
const uint8_t *secret_key);
|
|
99
|
+
int pq_mldsa87_sign(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len,
|
|
100
|
+
const uint8_t *secret_key);
|
|
88
101
|
int pq_verify(const uint8_t *signature, size_t signature_len, const uint8_t *message,
|
|
89
102
|
size_t message_len, const uint8_t *public_key);
|
|
103
|
+
int pq_mldsa44_verify(const uint8_t *signature, size_t signature_len, const uint8_t *message,
|
|
104
|
+
size_t message_len, const uint8_t *public_key);
|
|
105
|
+
int pq_mldsa87_verify(const uint8_t *signature, size_t signature_len, const uint8_t *message,
|
|
106
|
+
size_t message_len, const uint8_t *public_key);
|
|
90
107
|
|
|
91
108
|
int pq_public_key_to_pqc_container_der(uint8_t **output, size_t *output_len,
|
|
92
109
|
const uint8_t *public_key,
|
|
@@ -115,15 +132,37 @@ int pq_secret_key_from_pqc_container_pem(char **algorithm_out, uint8_t **key_out
|
|
|
115
132
|
|
|
116
133
|
int pq_testing_mlkem_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
|
|
117
134
|
const uint8_t *seed, size_t seed_len);
|
|
135
|
+
int pq_testing_mlkem512_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
|
|
136
|
+
const uint8_t *seed, size_t seed_len);
|
|
137
|
+
int pq_testing_mlkem1024_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
|
|
138
|
+
const uint8_t *seed, size_t seed_len);
|
|
118
139
|
int pq_testing_mlkem_encapsulate_from_seed(uint8_t *ciphertext, uint8_t *shared_secret,
|
|
119
140
|
const uint8_t *public_key, const uint8_t *seed,
|
|
120
141
|
size_t seed_len);
|
|
142
|
+
int pq_testing_mlkem512_encapsulate_from_seed(uint8_t *ciphertext, uint8_t *shared_secret,
|
|
143
|
+
const uint8_t *public_key, const uint8_t *seed,
|
|
144
|
+
size_t seed_len);
|
|
145
|
+
int pq_testing_mlkem1024_encapsulate_from_seed(uint8_t *ciphertext, uint8_t *shared_secret,
|
|
146
|
+
const uint8_t *public_key, const uint8_t *seed,
|
|
147
|
+
size_t seed_len);
|
|
121
148
|
int pq_testing_mldsa_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
|
|
122
149
|
const uint8_t *seed, size_t seed_len);
|
|
150
|
+
int pq_testing_mldsa44_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
|
|
151
|
+
const uint8_t *seed, size_t seed_len);
|
|
152
|
+
int pq_testing_mldsa87_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
|
|
153
|
+
const uint8_t *seed, size_t seed_len);
|
|
123
154
|
int pq_testing_mldsa_sign_from_seed(uint8_t *signature, size_t *signature_len,
|
|
124
155
|
const uint8_t *message, size_t message_len,
|
|
125
156
|
const uint8_t *secret_key, const uint8_t *seed,
|
|
126
157
|
size_t seed_len);
|
|
158
|
+
int pq_testing_mldsa44_sign_from_seed(uint8_t *signature, size_t *signature_len,
|
|
159
|
+
const uint8_t *message, size_t message_len,
|
|
160
|
+
const uint8_t *secret_key, const uint8_t *seed,
|
|
161
|
+
size_t seed_len);
|
|
162
|
+
int pq_testing_mldsa87_sign_from_seed(uint8_t *signature, size_t *signature_len,
|
|
163
|
+
const uint8_t *message, size_t message_len,
|
|
164
|
+
const uint8_t *secret_key, const uint8_t *seed,
|
|
165
|
+
size_t seed_len);
|
|
127
166
|
|
|
128
167
|
void pq_testing_set_seed(const uint8_t *seed, size_t len);
|
|
129
168
|
void pq_testing_clear_seed(void);
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
backend=PQ Code Package native only
|
|
2
|
+
pqclean=removed
|
|
3
|
+
mlkem_native_repo=https://github.com/pq-code-package/mlkem-native.git
|
|
4
|
+
mlkem_native_ref=v1.1.0
|
|
5
|
+
mlkem_native_commit=d2cae2be522a67bfae26100fdb520576f1b2ef90
|
|
6
|
+
mlkem_native_tree_sha256=368ad66b3a8092dd919d5646eb8507b8336e8f9f09c43b779dbf864700b5b8fb
|
|
7
|
+
mldsa_native_repo=https://github.com/pq-code-package/mldsa-native.git
|
|
8
|
+
mldsa_native_ref=v1.0.0-beta
|
|
9
|
+
mldsa_native_commit=db65535319d9750d75d34c6d170677415f9d2c46
|
|
10
|
+
mldsa_native_tree_sha256=9c73cd6c185bb6885a7cf0ecb56a5282a5657aa5e6c32f68f442d941baa92b3d
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
[//]: # (SPDX-License-Identifier: CC-BY-4.0)
|
|
2
|
+
|
|
3
|
+
# Building mldsa-native
|
|
4
|
+
|
|
5
|
+
### Prerequisites
|
|
6
|
+
|
|
7
|
+
To build **mldsa-native**, you need `make` and a C90 compiler. To use the test scripts, you need Python3 (>= 3.7).
|
|
8
|
+
|
|
9
|
+
### By hand
|
|
10
|
+
|
|
11
|
+
See [mldsa](mldsa).
|
|
12
|
+
|
|
13
|
+
### Using `make`
|
|
14
|
+
|
|
15
|
+
You can build and test **mldsa-native** as follows:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
make test # With native code backend (if available)
|
|
19
|
+
make OPT=0 test # With C backend
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
To merely build test components, use the following `make` targets:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
make func
|
|
26
|
+
make kat
|
|
27
|
+
make acvp
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
To run them, add `run_`:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
make run_func
|
|
34
|
+
make run_kat
|
|
35
|
+
make run_acvp
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The resulting binaries can be found in `test/build` (their full path is printed by `make`).
|
|
39
|
+
|
|
40
|
+
For benchmarking, specify the cycle counting method. Currently, **mldsa-native** is supporting NO, PERF, PMU, and MAC:
|
|
41
|
+
* `NO` means that no cycle counting will be used; this can be used to confirm that benchmarks compile fine.
|
|
42
|
+
* `PERF` uses the `perf` kernel module for cycle counting. Does not work on Apple platforms.
|
|
43
|
+
* `PMU` uses direct PMU access if available. On AArch64, this may require you to load a kernel module first, see [here](https://github.com/mupq/pqax?tab=readme-ov-file#enable-access-to-performance-counters). Does not work on Apple platforms.
|
|
44
|
+
* `MAC` is `perf`-based and works on some Apple platforms, at least Apple M1.
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
# CYCLES has to be one of PERF, PMU, MAC, NO
|
|
48
|
+
sudo make run_bench CYCLES=PERF
|
|
49
|
+
sudo make run_bench_components CYCLES=PERF
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Using `tests` script
|
|
53
|
+
|
|
54
|
+
For convenience, you can also use the [`./scripts/tests`](scripts/tests) script as a wrapper around `make`. For
|
|
55
|
+
example,
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
./scripts/tests func
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
will compile and run functionality tests. Similarly,
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
./scripts/tests bench -c PERF -r
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
will compile and run benchmarks, using PERF for cycle counting (`-c PERF`) and running as root (`-r`).
|
|
68
|
+
|
|
69
|
+
For detailed information on how to use the script, please refer to
|
|
70
|
+
`./scripts/tests --help`.
|
|
71
|
+
|
|
72
|
+
### Windows
|
|
73
|
+
|
|
74
|
+
You can also build **mldsa-native** on Windows using `nmake` and an MSVC compiler.
|
|
75
|
+
|
|
76
|
+
To build and run the tests (only support functional testing for non-opt implementation for now), use the following `nmake` targets:
|
|
77
|
+
```powershell
|
|
78
|
+
nmke /f .\Makefile.Microsoft_nmake quickcheck
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
# Checking the proofs
|
|
82
|
+
|
|
83
|
+
## CBMC
|
|
84
|
+
|
|
85
|
+
### Prerequisites
|
|
86
|
+
|
|
87
|
+
To run the CBMC proofs, you need specific versions of CBMC and the underlying solvers, e.g. as specified in our `nix` environment; see [nix/cbmc](nix/cbmc/).
|
|
88
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how to setup and use `nix`.
|
|
89
|
+
|
|
90
|
+
### Running the CBMC proofs
|
|
91
|
+
|
|
92
|
+
Once you are in the `nix` shell or have all tools setup by hand, use `./scripts/tests cbmc` (or just `tests cbmc` in the `nix` shell) to re-check the CBMC proofs.
|
|
93
|
+
See `tests cbmc --help` for details on the command line options, and [proofs/cbmc](proofs/cbmc) for more details on the CBMC proofs in general.
|
|
94
|
+
|
|
95
|
+
## HOL-Light
|
|
96
|
+
|
|
97
|
+
### Prerequisites
|
|
98
|
+
|
|
99
|
+
To run the HOL-Light proofs, you need recent versions of HOL-Light and s2n-bignum, e.g. as specified in our `nix` environment; see [nix/s2n_bignum](nix/s2n_bignum) and [nix/hol_light](nix/hol_light).
|
|
100
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how to setup and use `nix`.
|
|
101
|
+
|
|
102
|
+
### Running the HOL-Light proofs
|
|
103
|
+
|
|
104
|
+
Once you are in the `nix` shell or have all tools setup by hand, use `./scripts/tests hol_light` (or just `tests hol_light` in the `nix` shell) to re-check the HOL-Light proofs. Note that depending on the function, they will take a long time. See `tests hol_light --help` for details on the command line options, and [proofs/hol_light](proofs/hol_light) for more details on the HOL-Light proofs in general.
|
|
105
|
+
|