pq_crypto 0.3.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +56 -0
- data/CHANGELOG.md +62 -0
- data/GET_STARTED.md +366 -40
- data/README.md +76 -233
- data/SECURITY.md +107 -82
- data/ext/pqcrypto/extconf.rb +169 -87
- data/ext/pqcrypto/mldsa_api.h +1 -48
- data/ext/pqcrypto/mlkem_api.h +1 -18
- data/ext/pqcrypto/pq_externalmu.c +89 -204
- data/ext/pqcrypto/pqcrypto_native_api.h +129 -0
- data/ext/pqcrypto/pqcrypto_ruby_secure.c +484 -84
- data/ext/pqcrypto/pqcrypto_secure.c +203 -78
- data/ext/pqcrypto/pqcrypto_secure.h +53 -14
- data/ext/pqcrypto/pqcrypto_version.h +7 -0
- data/ext/pqcrypto/randombytes.h +9 -0
- data/ext/pqcrypto/vendor/.vendored +10 -5
- data/ext/pqcrypto/vendor/mldsa-native/BUILDING.md +105 -0
- data/ext/pqcrypto/vendor/mldsa-native/LICENSE +286 -0
- data/ext/pqcrypto/vendor/mldsa-native/META.yml +24 -0
- data/ext/pqcrypto/vendor/mldsa-native/README.md +221 -0
- data/ext/pqcrypto/vendor/mldsa-native/SECURITY.md +8 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +721 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +975 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +724 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +723 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +166 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +321 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.c +21 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +385 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c +73 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +130 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.c +277 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +244 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +182 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +117 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +438 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +105 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +71 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +62 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +376 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +204 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +259 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +1077 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +987 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +41 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +26 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +35 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +37 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +27 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +36 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +69 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/README.md +10 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +32 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +20 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +638 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +136 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +52 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +29 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +488 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +16 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/xkcp.h +31 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +247 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +231 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +150 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +753 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +129 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +145 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +177 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +653 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +79 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +53 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +55 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +85 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +85 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +102 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +110 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +72 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +69 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +40 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +189 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +135 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +128 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +543 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +62 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +649 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/meta.h +23 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +315 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +124 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +157 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +27 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +2311 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +2383 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +239 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +131 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +187 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +61 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_chknorm_avx2.c +52 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +102 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +104 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +91 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +93 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_avx2.c +126 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +160 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +293 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +224 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/params.h +77 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +991 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +393 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +946 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +360 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +877 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +725 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/randombytes.h +26 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +249 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +1511 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +806 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/symmetric.h +68 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sys.h +268 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/zetas.inc +55 -0
- data/ext/pqcrypto/vendor/mlkem-native/BUILDING.md +104 -0
- data/ext/pqcrypto/vendor/mlkem-native/LICENSE +294 -0
- data/ext/pqcrypto/vendor/mlkem-native/META.yml +30 -0
- data/ext/pqcrypto/vendor/mlkem-native/README.md +223 -0
- data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +86 -0
- data/ext/pqcrypto/vendor/mlkem-native/SECURITY.md +8 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/README.md +23 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +660 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +538 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +681 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +709 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +174 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +274 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +717 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +688 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.c +64 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.h +128 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +251 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +158 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +208 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +80 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +463 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.h +98 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/auto.h +70 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/fips202_native_aarch64.h +69 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +375 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +203 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +258 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +1076 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +986 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +46 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +25 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +34 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +35 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +26 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +35 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/api.h +117 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/README.md +10 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/mve.h +79 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/fips202_native_armv81m.h +35 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +667 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +40 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +51 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +290 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +314 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +28 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +33 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +41 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2.S +451 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +51 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +622 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +156 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +446 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +326 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/README.md +16 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +122 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +174 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +177 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/intt.S +628 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/ntt.S +562 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_mulcache_compute_asm.S +127 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_reduce_asm.S +150 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_tobytes_asm.S +117 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_tomont_asm.S +98 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k2.S +261 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k3.S +314 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k4.S +368 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_asm.S +226 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_table.c +542 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +637 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +25 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/README.md +11 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +128 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/arith_native_riscv64.h +45 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +81 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +145 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_izetas.inc +27 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +805 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_zetas.inc +27 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_zetas_basemul.inc +39 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/README.md +4 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +304 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +309 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +94 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +45 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.c +102 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.h +25 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/intt.S +719 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mulcache_compute.S +90 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/ntt.S +639 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/nttfrombytes.S +193 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/ntttobytes.S +181 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/nttunpack.S +174 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d10.S +382 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d11.S +448 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d4.S +163 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d5.S +220 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d10.S +228 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d11.S +277 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d4.S +180 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d5.S +192 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k2.S +502 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k3.S +750 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k4.S +998 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/reduce.S +218 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_asm.S +103 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_table.c +544 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/tomont.S +155 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/params.h +76 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +572 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +317 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +502 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +668 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/randombytes.h +60 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +362 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +118 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/symmetric.h +70 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +260 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.c +20 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +464 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/zetas.inc +30 -0
- data/lib/pq_crypto/algorithm_registry.rb +200 -0
- data/lib/pq_crypto/hybrid_kem.rb +1 -12
- data/lib/pq_crypto/kem.rb +104 -13
- data/lib/pq_crypto/pkcs8.rb +387 -0
- data/lib/pq_crypto/serialization.rb +1 -14
- data/lib/pq_crypto/signature.rb +123 -17
- data/lib/pq_crypto/spki.rb +131 -0
- data/lib/pq_crypto/version.rb +1 -1
- data/lib/pq_crypto.rb +79 -20
- data/script/vendor_libs.rb +88 -155
- metadata +241 -73
- data/ext/pqcrypto/vendor/pqclean/common/aes.c +0 -639
- data/ext/pqcrypto/vendor/pqclean/common/aes.h +0 -64
- data/ext/pqcrypto/vendor/pqclean/common/compat.h +0 -73
- data/ext/pqcrypto/vendor/pqclean/common/crypto_declassify.h +0 -7
- data/ext/pqcrypto/vendor/pqclean/common/fips202.c +0 -928
- data/ext/pqcrypto/vendor/pqclean/common/fips202.h +0 -166
- data/ext/pqcrypto/vendor/pqclean/common/keccak2x/feat.S +0 -168
- data/ext/pqcrypto/vendor/pqclean/common/keccak2x/fips202x2.c +0 -684
- data/ext/pqcrypto/vendor/pqclean/common/keccak2x/fips202x2.h +0 -60
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-times4-SIMD256.c +0 -1028
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-times4-SnP.h +0 -50
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-unrolling.macros +0 -198
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/Makefile +0 -8
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/Makefile.Microsoft_nmake +0 -8
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/SIMD256-config.h +0 -3
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/align.h +0 -34
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/brg_endian.h +0 -142
- data/ext/pqcrypto/vendor/pqclean/common/nistseedexpander.c +0 -101
- data/ext/pqcrypto/vendor/pqclean/common/nistseedexpander.h +0 -39
- data/ext/pqcrypto/vendor/pqclean/common/randombytes.c +0 -355
- data/ext/pqcrypto/vendor/pqclean/common/randombytes.h +0 -27
- data/ext/pqcrypto/vendor/pqclean/common/sha2.c +0 -769
- data/ext/pqcrypto/vendor/pqclean/common/sha2.h +0 -173
- data/ext/pqcrypto/vendor/pqclean/common/sp800-185.c +0 -156
- data/ext/pqcrypto/vendor/pqclean/common/sp800-185.h +0 -27
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/LICENSE +0 -5
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/Makefile +0 -19
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/Makefile.Microsoft_nmake +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/api.h +0 -18
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/cbd.c +0 -83
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/cbd.h +0 -11
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/indcpa.c +0 -327
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/indcpa.h +0 -22
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/kem.c +0 -164
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/kem.h +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/ntt.c +0 -146
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/ntt.h +0 -14
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/params.h +0 -36
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/poly.c +0 -299
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/poly.h +0 -37
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/polyvec.c +0 -188
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/polyvec.h +0 -26
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/reduce.c +0 -41
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/reduce.h +0 -13
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/symmetric-shake.c +0 -71
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/symmetric.h +0 -30
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/verify.c +0 -67
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/verify.h +0 -13
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/LICENSE +0 -5
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/Makefile +0 -19
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/Makefile.Microsoft_nmake +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/api.h +0 -50
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/ntt.c +0 -98
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/ntt.h +0 -10
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.c +0 -261
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.h +0 -31
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/params.h +0 -44
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.c +0 -799
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.h +0 -52
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.c +0 -415
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.h +0 -65
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/reduce.c +0 -69
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/reduce.h +0 -17
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/rounding.c +0 -92
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/rounding.h +0 -14
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/sign.c +0 -407
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/sign.h +0 -47
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric-shake.c +0 -26
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric.h +0 -34
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) The mlkem-native project authors
|
|
3
|
+
* Copyright (c) The mldsa-native project authors
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* References
|
|
8
|
+
* ==========
|
|
9
|
+
*
|
|
10
|
+
* - [FIPS204]
|
|
11
|
+
* FIPS 204 Module-Lattice-Based Digital Signature Standard
|
|
12
|
+
* National Institute of Standards and Technology
|
|
13
|
+
* https://csrc.nist.gov/pubs/fips/204/final
|
|
14
|
+
*
|
|
15
|
+
* - [libmceliece]
|
|
16
|
+
* libmceliece implementation of Classic McEliece
|
|
17
|
+
* Bernstein, Chou
|
|
18
|
+
* https://lib.mceliece.org/
|
|
19
|
+
*
|
|
20
|
+
* - [optblocker]
|
|
21
|
+
* PQC forum post on opt-blockers using volatile globals
|
|
22
|
+
* Daniel J. Bernstein
|
|
23
|
+
* https://groups.google.com/a/list.nist.gov/g/pqc-forum/c/hqbtIGFKIpU/m/H14H0wOlBgAJ
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#ifndef MLD_CT_H
|
|
27
|
+
#define MLD_CT_H
|
|
28
|
+
|
|
29
|
+
#include "cbmc.h"
|
|
30
|
+
#include "common.h"
|
|
31
|
+
|
|
32
|
+
/* Constant-time comparisons and conditional operations
|
|
33
|
+
|
|
34
|
+
We reduce the risk for compilation into variable-time code
|
|
35
|
+
through the use of 'value barriers'.
|
|
36
|
+
|
|
37
|
+
Functionally, a value barrier is a no-op. To the compiler, however,
|
|
38
|
+
it constitutes an arbitrary modification of its input, and therefore
|
|
39
|
+
harden's value propagation and range analysis.
|
|
40
|
+
|
|
41
|
+
We consider two approaches to implement a value barrier:
|
|
42
|
+
- An empty inline asm block which marks the target value as clobbered.
|
|
43
|
+
- XOR'ing with the value of a volatile global that's set to 0;
|
|
44
|
+
see @[optblocker] for a discussion of this idea, and
|
|
45
|
+
@[libmceliece, inttypes/crypto_intN.h] for an implementation.
|
|
46
|
+
|
|
47
|
+
The first approach is cheap because it only prevents the compiler
|
|
48
|
+
from reasoning about the value of the variable past the barrier,
|
|
49
|
+
but does not directly generate additional instructions.
|
|
50
|
+
|
|
51
|
+
The second approach generates redundant loads and XOR operations
|
|
52
|
+
and therefore comes at a higher runtime cost. However, it appears
|
|
53
|
+
more robust towards optimization, as compilers should never drop
|
|
54
|
+
a volatile load.
|
|
55
|
+
|
|
56
|
+
We use the empty-ASM value barrier for GCC and clang, and fall
|
|
57
|
+
back to the global volatile barrier otherwise.
|
|
58
|
+
|
|
59
|
+
The global value barrier can be forced by setting
|
|
60
|
+
MLD_CONFIG_NO_ASM_VALUE_BARRIER.
|
|
61
|
+
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
#if defined(MLD_HAVE_INLINE_ASM) && !defined(MLD_CONFIG_NO_ASM_VALUE_BARRIER)
|
|
65
|
+
#define MLD_USE_ASM_VALUE_BARRIER
|
|
66
|
+
#endif
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
#if !defined(MLD_USE_ASM_VALUE_BARRIER)
|
|
70
|
+
/*
|
|
71
|
+
* Declaration of global volatile that the global value barrier
|
|
72
|
+
* is loading from and masking with.
|
|
73
|
+
*/
|
|
74
|
+
#define mld_ct_opt_blocker_u64 MLD_NAMESPACE(ct_opt_blocker_u64)
|
|
75
|
+
extern volatile uint64_t mld_ct_opt_blocker_u64;
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
/* Helper functions for obtaining global masks of various sizes */
|
|
79
|
+
|
|
80
|
+
/* This contract is not proved but treated as an axiom.
|
|
81
|
+
*
|
|
82
|
+
* Its validity relies on the assumption that the global opt-blocker
|
|
83
|
+
* constant mld_ct_opt_blocker_u64 is not modified.
|
|
84
|
+
*/
|
|
85
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
86
|
+
static MLD_INLINE uint64_t mld_ct_get_optblocker_u64(void)
|
|
87
|
+
__contract__(ensures(return_value == 0)) { return mld_ct_opt_blocker_u64; }
|
|
88
|
+
|
|
89
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
90
|
+
static MLD_INLINE int64_t mld_ct_get_optblocker_i64(void)
|
|
91
|
+
__contract__(ensures(return_value == 0)) { return (int64_t)mld_ct_get_optblocker_u64(); }
|
|
92
|
+
|
|
93
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
94
|
+
static MLD_INLINE uint32_t mld_ct_get_optblocker_u32(void)
|
|
95
|
+
__contract__(ensures(return_value == 0)) { return (uint32_t)mld_ct_get_optblocker_u64(); }
|
|
96
|
+
|
|
97
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
98
|
+
static MLD_INLINE uint8_t mld_ct_get_optblocker_u8(void)
|
|
99
|
+
__contract__(ensures(return_value == 0)) { return (uint8_t)mld_ct_get_optblocker_u64(); }
|
|
100
|
+
|
|
101
|
+
/* Opt-blocker based implementation of value barriers */
|
|
102
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
103
|
+
static MLD_INLINE int64_t mld_value_barrier_i64(int64_t b)
|
|
104
|
+
__contract__(ensures(return_value == b)) { return (b ^ mld_ct_get_optblocker_i64()); }
|
|
105
|
+
|
|
106
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
107
|
+
static MLD_INLINE uint32_t mld_value_barrier_u32(uint32_t b)
|
|
108
|
+
__contract__(ensures(return_value == b)) { return (b ^ mld_ct_get_optblocker_u32()); }
|
|
109
|
+
|
|
110
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
111
|
+
static MLD_INLINE uint8_t mld_value_barrier_u8(uint8_t b)
|
|
112
|
+
__contract__(ensures(return_value == b)) { return (b ^ mld_ct_get_optblocker_u8()); }
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
#else /* !MLD_USE_ASM_VALUE_BARRIER */
|
|
116
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
117
|
+
static MLD_INLINE int64_t mld_value_barrier_i64(int64_t b)
|
|
118
|
+
__contract__(ensures(return_value == b))
|
|
119
|
+
{
|
|
120
|
+
__asm__ volatile("" : "+r"(b));
|
|
121
|
+
return b;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
125
|
+
static MLD_INLINE uint32_t mld_value_barrier_u32(uint32_t b)
|
|
126
|
+
__contract__(ensures(return_value == b))
|
|
127
|
+
{
|
|
128
|
+
__asm__ volatile("" : "+r"(b));
|
|
129
|
+
return b;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
133
|
+
static MLD_INLINE uint8_t mld_value_barrier_u8(uint8_t b)
|
|
134
|
+
__contract__(ensures(return_value == b))
|
|
135
|
+
{
|
|
136
|
+
__asm__ volatile("" : "+r"(b));
|
|
137
|
+
return b;
|
|
138
|
+
}
|
|
139
|
+
#endif /* MLD_USE_ASM_VALUE_BARRIER */
|
|
140
|
+
|
|
141
|
+
#ifdef CBMC
|
|
142
|
+
#pragma CPROVER check push
|
|
143
|
+
#pragma CPROVER check disable "conversion"
|
|
144
|
+
#endif
|
|
145
|
+
|
|
146
|
+
/*************************************************
|
|
147
|
+
* Name: mld_cast_uint32_to_int32
|
|
148
|
+
*
|
|
149
|
+
* Description: Cast uint32 value to int32
|
|
150
|
+
*
|
|
151
|
+
* Returns: For uint32_t x, the unique y in int32_t
|
|
152
|
+
* so that x == y mod 2^32.
|
|
153
|
+
*
|
|
154
|
+
* Concretely:
|
|
155
|
+
* - x < 2^31: returns x
|
|
156
|
+
* - x >= 2^31: returns x - 2^31
|
|
157
|
+
*
|
|
158
|
+
**************************************************/
|
|
159
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
160
|
+
static MLD_ALWAYS_INLINE int32_t mld_cast_uint32_to_int32(uint32_t x)
|
|
161
|
+
{
|
|
162
|
+
/*
|
|
163
|
+
* PORTABILITY: This relies on uint32_t -> int32_t
|
|
164
|
+
* being implemented as the inverse of int32_t -> uint32_t,
|
|
165
|
+
* which is implementation-defined (C99 6.3.1.3 (3))
|
|
166
|
+
* CBMC (correctly) fails to prove this conversion is OK,
|
|
167
|
+
* so we have to suppress that check here
|
|
168
|
+
*/
|
|
169
|
+
return (int32_t)x;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
#ifdef CBMC
|
|
173
|
+
#pragma CPROVER check pop
|
|
174
|
+
#endif
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
/*************************************************
|
|
178
|
+
* Name: mld_cast_int64_to_uint32
|
|
179
|
+
*
|
|
180
|
+
* Description: Cast int64 value to uint32 as per C standard.
|
|
181
|
+
*
|
|
182
|
+
* Returns: For int64_t x, the unique y in uint32_t
|
|
183
|
+
* so that x == y mod 2^32.
|
|
184
|
+
**************************************************/
|
|
185
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
186
|
+
static MLD_ALWAYS_INLINE uint32_t mld_cast_int64_to_uint32(int64_t x)
|
|
187
|
+
{
|
|
188
|
+
return (uint32_t)(x & (int64_t)UINT32_MAX);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/*************************************************
|
|
192
|
+
* Name: mld_cast_int32_to_uint32
|
|
193
|
+
*
|
|
194
|
+
* Description: Cast int32 value to uint32 as per C standard.
|
|
195
|
+
*
|
|
196
|
+
* Returns: For int32_t x, the unique y in uint32_t
|
|
197
|
+
* so that x == y mod 2^32.
|
|
198
|
+
**************************************************/
|
|
199
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
200
|
+
static MLD_ALWAYS_INLINE uint32_t mld_cast_int32_to_uint32(int32_t x)
|
|
201
|
+
{
|
|
202
|
+
return mld_cast_int64_to_uint32((int64_t)x);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/*************************************************
|
|
206
|
+
* Name: mld_ct_sel_int32
|
|
207
|
+
*
|
|
208
|
+
* Description: Functionally equivalent to cond ? a : b,
|
|
209
|
+
* but implemented with guards against
|
|
210
|
+
* compiler-introduced branches.
|
|
211
|
+
*
|
|
212
|
+
* Arguments: int32_t a: First alternative
|
|
213
|
+
* int32_t b: Second alternative
|
|
214
|
+
* uint32_t cond: Condition variable.
|
|
215
|
+
*
|
|
216
|
+
*
|
|
217
|
+
**************************************************/
|
|
218
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
219
|
+
static MLD_INLINE int32_t mld_ct_sel_int32(int32_t a, int32_t b, uint32_t cond)
|
|
220
|
+
__contract__(
|
|
221
|
+
requires(cond == 0x0 || cond == 0xFFFFFFFF)
|
|
222
|
+
ensures(return_value == (cond ? a : b))
|
|
223
|
+
)
|
|
224
|
+
{
|
|
225
|
+
uint32_t au = mld_cast_int32_to_uint32(a);
|
|
226
|
+
uint32_t bu = mld_cast_int32_to_uint32(b);
|
|
227
|
+
uint32_t res = bu ^ (mld_value_barrier_u32(cond) & (au ^ bu));
|
|
228
|
+
return mld_cast_uint32_to_int32(res);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/*************************************************
|
|
232
|
+
* Name: mld_ct_cmask_nonzero_u32
|
|
233
|
+
*
|
|
234
|
+
* Description: Return 0 if input is zero, and -1 otherwise.
|
|
235
|
+
*
|
|
236
|
+
* Arguments: uint32_t x: Value to be converted into a mask
|
|
237
|
+
*
|
|
238
|
+
**************************************************/
|
|
239
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
240
|
+
static MLD_INLINE uint32_t mld_ct_cmask_nonzero_u32(uint32_t x)
|
|
241
|
+
__contract__(ensures(return_value == ((x == 0) ? 0 : 0xFFFFFFFF)))
|
|
242
|
+
{
|
|
243
|
+
int64_t tmp = mld_value_barrier_i64(-((int64_t)x));
|
|
244
|
+
tmp >>= 32;
|
|
245
|
+
return mld_cast_int64_to_uint32(tmp);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/*************************************************
|
|
249
|
+
* Name: mld_ct_cmask_nonzero_u8
|
|
250
|
+
*
|
|
251
|
+
* Description: Return 0 if input is zero, and -1 otherwise.
|
|
252
|
+
*
|
|
253
|
+
* Arguments: uint8_t x: Value to be converted into a mask
|
|
254
|
+
*
|
|
255
|
+
**************************************************/
|
|
256
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
257
|
+
static MLD_INLINE uint8_t mld_ct_cmask_nonzero_u8(uint8_t x)
|
|
258
|
+
__contract__(ensures(return_value == ((x == 0) ? 0 : 0xFF)))
|
|
259
|
+
{
|
|
260
|
+
uint32_t mask = mld_ct_cmask_nonzero_u32((uint32_t)x);
|
|
261
|
+
return (uint8_t)(mask & 0xFF);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/*************************************************
|
|
265
|
+
* Name: mld_ct_cmask_neg_i32
|
|
266
|
+
*
|
|
267
|
+
* Description: Return 0 if input is non-negative, and -1 otherwise.
|
|
268
|
+
*
|
|
269
|
+
* Arguments: int32_t x: Value to be converted into a mask
|
|
270
|
+
*
|
|
271
|
+
**************************************************/
|
|
272
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
273
|
+
static MLD_INLINE uint32_t mld_ct_cmask_neg_i32(int32_t x)
|
|
274
|
+
__contract__(
|
|
275
|
+
ensures(return_value == ((x < 0) ? 0xFFFFFFFF : 0))
|
|
276
|
+
)
|
|
277
|
+
{
|
|
278
|
+
int64_t tmp = mld_value_barrier_i64((int64_t)x);
|
|
279
|
+
tmp >>= 31;
|
|
280
|
+
return mld_cast_int64_to_uint32(tmp);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/*************************************************
|
|
284
|
+
* Name: mld_ct_abs_i32
|
|
285
|
+
*
|
|
286
|
+
* Description: Return -x if x<0, x otherwise
|
|
287
|
+
*
|
|
288
|
+
* Arguments: int32_t x: Input value
|
|
289
|
+
*
|
|
290
|
+
**************************************************/
|
|
291
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
292
|
+
static MLD_INLINE int32_t mld_ct_abs_i32(int32_t x)
|
|
293
|
+
__contract__(
|
|
294
|
+
requires(x >= -INT32_MAX)
|
|
295
|
+
ensures(return_value == ((x < 0) ? -x : x))
|
|
296
|
+
)
|
|
297
|
+
{
|
|
298
|
+
return mld_ct_sel_int32(-x, x, mld_ct_cmask_neg_i32(x));
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/*************************************************
|
|
302
|
+
* Name: mld_ct_memcmp
|
|
303
|
+
*
|
|
304
|
+
* Description: Compare two arrays for equality in constant time.
|
|
305
|
+
*
|
|
306
|
+
* Arguments: const uint8_t *a: pointer to first byte array
|
|
307
|
+
* const uint8_t *b: pointer to second byte array
|
|
308
|
+
* size_t len: length of the byte arrays, upper-bounded
|
|
309
|
+
* to UINT16_MAX to control proof complexity
|
|
310
|
+
* only.
|
|
311
|
+
*
|
|
312
|
+
* Returns 0 if the byte arrays are equal, 0xFF otherwise.
|
|
313
|
+
**************************************************/
|
|
314
|
+
MLD_MUST_CHECK_RETURN_VALUE
|
|
315
|
+
static MLD_INLINE uint8_t mld_ct_memcmp(const uint8_t *a, const uint8_t *b,
|
|
316
|
+
const size_t len)
|
|
317
|
+
__contract__(
|
|
318
|
+
requires(len <= UINT16_MAX)
|
|
319
|
+
requires(memory_no_alias(a, len))
|
|
320
|
+
requires(memory_no_alias(b, len))
|
|
321
|
+
ensures((return_value == 0) || (return_value == 0xFF))
|
|
322
|
+
ensures((return_value == 0) == forall(i, 0, len, (a[i] == b[i]))))
|
|
323
|
+
{
|
|
324
|
+
uint8_t r = 0, s = 0;
|
|
325
|
+
unsigned i;
|
|
326
|
+
|
|
327
|
+
for (i = 0; i < len; i++)
|
|
328
|
+
__loop__(
|
|
329
|
+
invariant(i <= len)
|
|
330
|
+
invariant((r == 0) == (forall(k, 0, i, (a[k] == b[k]))))
|
|
331
|
+
decreases(len - i))
|
|
332
|
+
{
|
|
333
|
+
r |= a[i] ^ b[i];
|
|
334
|
+
/* s is useless, but prevents the loop from being aborted once r=0xff. */
|
|
335
|
+
s ^= a[i] ^ b[i];
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/*
|
|
339
|
+
* - Convert r into a mask; this may not be necessary, but is an additional
|
|
340
|
+
* safeguard
|
|
341
|
+
* towards leaking information about a and b.
|
|
342
|
+
* - XOR twice with s, separated by a value barrier, to prevent the compile
|
|
343
|
+
* from dropping the s computation in the loop.
|
|
344
|
+
*/
|
|
345
|
+
return (mld_value_barrier_u8(mld_ct_cmask_nonzero_u8(r) ^ s) ^ s);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/*************************************************
|
|
349
|
+
* Name: mld_zeroize
|
|
350
|
+
*
|
|
351
|
+
* Description: Force-zeroize a buffer.
|
|
352
|
+
* @[FIPS204, Section 3.6.3] Destruction of intermediate
|
|
353
|
+
* values.
|
|
354
|
+
*
|
|
355
|
+
* Arguments: void *ptr: pointer to buffer to be zeroed
|
|
356
|
+
* size_t len: Amount of bytes to be zeroed
|
|
357
|
+
**************************************************/
|
|
358
|
+
#if !defined(MLD_CONFIG_CUSTOM_ZEROIZE)
|
|
359
|
+
#if defined(MLD_SYS_WINDOWS)
|
|
360
|
+
#include <windows.h>
|
|
361
|
+
static MLD_INLINE void mld_zeroize(void *ptr, size_t len)
|
|
362
|
+
__contract__(
|
|
363
|
+
requires(memory_no_alias(ptr, len))
|
|
364
|
+
assigns(memory_slice(ptr, len))) { SecureZeroMemory(ptr, len); }
|
|
365
|
+
#elif defined(MLD_HAVE_INLINE_ASM)
|
|
366
|
+
#include <string.h>
|
|
367
|
+
static MLD_INLINE void mld_zeroize(void *ptr, size_t len)
|
|
368
|
+
__contract__(
|
|
369
|
+
requires(memory_no_alias(ptr, len))
|
|
370
|
+
assigns(memory_slice(ptr, len)))
|
|
371
|
+
{
|
|
372
|
+
memset(ptr, 0, len);
|
|
373
|
+
/* This follows OpenSSL and seems sufficient to prevent the compiler
|
|
374
|
+
* from optimizing away the memset.
|
|
375
|
+
*
|
|
376
|
+
* If there was a reliable way to detect availability of memset_s(),
|
|
377
|
+
* that would be preferred. */
|
|
378
|
+
__asm__ __volatile__("" : : "r"(ptr) : "memory");
|
|
379
|
+
}
|
|
380
|
+
#else /* !MLD_SYS_WINDOWS && MLD_HAVE_INLINE_ASM */
|
|
381
|
+
#error No plausibly-secure implementation of mld_zeroize available. Please provide your own using MLD_CONFIG_CUSTOM_ZEROIZE.
|
|
382
|
+
#endif /* !MLD_SYS_WINDOWS && !MLD_HAVE_INLINE_ASM */
|
|
383
|
+
#endif /* !MLD_CONFIG_CUSTOM_ZEROIZE */
|
|
384
|
+
|
|
385
|
+
#endif /* !MLD_CT_H */
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) The mlkem-native project authors
|
|
3
|
+
* Copyright (c) The mldsa-native project authors
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* NOTE: You can remove this file unless you compile with MLDSA_DEBUG. */
|
|
8
|
+
|
|
9
|
+
#include "common.h"
|
|
10
|
+
|
|
11
|
+
#if !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
|
|
12
|
+
|
|
13
|
+
#if defined(MLDSA_DEBUG)
|
|
14
|
+
|
|
15
|
+
#include <inttypes.h>
|
|
16
|
+
#include <stdio.h>
|
|
17
|
+
#include <stdlib.h>
|
|
18
|
+
#include "debug.h"
|
|
19
|
+
|
|
20
|
+
#define MLD_DEBUG_ERROR_HEADER "[ERROR:%s:%04d] "
|
|
21
|
+
|
|
22
|
+
void mld_debug_check_assert(const char *file, int line, const int val)
|
|
23
|
+
{
|
|
24
|
+
if (val == 0)
|
|
25
|
+
{
|
|
26
|
+
fprintf(stderr, MLD_DEBUG_ERROR_HEADER "Assertion failed (value %d)\n",
|
|
27
|
+
file, line, val);
|
|
28
|
+
exit(1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
void mld_debug_check_bounds(const char *file, int line, const int32_t *ptr,
|
|
33
|
+
unsigned len, int64_t lower_bound_exclusive,
|
|
34
|
+
int64_t upper_bound_exclusive)
|
|
35
|
+
{
|
|
36
|
+
int err = 0;
|
|
37
|
+
unsigned i;
|
|
38
|
+
for (i = 0; i < len; i++)
|
|
39
|
+
{
|
|
40
|
+
int32_t val = ptr[i];
|
|
41
|
+
if (!(val > lower_bound_exclusive && val < upper_bound_exclusive))
|
|
42
|
+
{
|
|
43
|
+
fprintf(stderr,
|
|
44
|
+
MLD_DEBUG_ERROR_HEADER
|
|
45
|
+
"Bounds assertion failed: Index %u, value %d out of bounds "
|
|
46
|
+
"(%" PRId64 ",%" PRId64 ")\n",
|
|
47
|
+
file, line, i, (int)val, lower_bound_exclusive,
|
|
48
|
+
upper_bound_exclusive);
|
|
49
|
+
err = 1;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (err == 1)
|
|
54
|
+
{
|
|
55
|
+
exit(1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#else /* MLDSA_DEBUG */
|
|
60
|
+
|
|
61
|
+
MLD_EMPTY_CU(debug)
|
|
62
|
+
|
|
63
|
+
#endif /* !MLDSA_DEBUG */
|
|
64
|
+
|
|
65
|
+
#else /* !MLD_CONFIG_MULTILEVEL_NO_SHARED */
|
|
66
|
+
|
|
67
|
+
MLD_EMPTY_CU(debug)
|
|
68
|
+
|
|
69
|
+
#endif /* MLD_CONFIG_MULTILEVEL_NO_SHARED */
|
|
70
|
+
|
|
71
|
+
/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
|
|
72
|
+
* Don't modify by hand -- this is auto-generated by scripts/autogen. */
|
|
73
|
+
#undef MLD_DEBUG_ERROR_HEADER
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) The mlkem-native project authors
|
|
3
|
+
* Copyright (c) The mldsa-native project authors
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
5
|
+
*/
|
|
6
|
+
#ifndef MLD_DEBUG_H
|
|
7
|
+
#define MLD_DEBUG_H
|
|
8
|
+
#include "common.h"
|
|
9
|
+
|
|
10
|
+
#if defined(MLDSA_DEBUG)
|
|
11
|
+
|
|
12
|
+
/*************************************************
|
|
13
|
+
* Name: mld_assert
|
|
14
|
+
*
|
|
15
|
+
* Description: Check debug assertion
|
|
16
|
+
*
|
|
17
|
+
* Prints an error message to stderr and calls
|
|
18
|
+
* exit(1) if not.
|
|
19
|
+
*
|
|
20
|
+
* Arguments: - file: filename
|
|
21
|
+
* - line: line number
|
|
22
|
+
* - val: Value asserted to be non-zero
|
|
23
|
+
**************************************************/
|
|
24
|
+
#define mld_debug_check_assert MLD_NAMESPACE(mldsa_debug_assert)
|
|
25
|
+
void mld_debug_check_assert(const char *file, int line, const int val);
|
|
26
|
+
|
|
27
|
+
/*************************************************
|
|
28
|
+
* Name: mld_debug_check_bounds
|
|
29
|
+
*
|
|
30
|
+
* Description: Check whether values in an array of int32_t
|
|
31
|
+
* are within specified bounds.
|
|
32
|
+
*
|
|
33
|
+
* Prints an error message to stderr and calls
|
|
34
|
+
* exit(1) if not.
|
|
35
|
+
*
|
|
36
|
+
* Arguments: - file: filename
|
|
37
|
+
* - line: line number
|
|
38
|
+
* - ptr: Base of array to be checked
|
|
39
|
+
* - len: Number of int32_t in ptr
|
|
40
|
+
* - lower_bound_exclusive: Exclusive lower bound
|
|
41
|
+
* - upper_bound_exclusive: Exclusive upper bound
|
|
42
|
+
**************************************************/
|
|
43
|
+
#define mld_debug_check_bounds MLD_NAMESPACE(mldsa_debug_check_bounds)
|
|
44
|
+
void mld_debug_check_bounds(const char *file, int line, const int32_t *ptr,
|
|
45
|
+
unsigned len, int64_t lower_bound_exclusive,
|
|
46
|
+
int64_t upper_bound_exclusive);
|
|
47
|
+
|
|
48
|
+
/* Check assertion, calling exit() upon failure
|
|
49
|
+
*
|
|
50
|
+
* val: Value that's asserted to be non-zero
|
|
51
|
+
*/
|
|
52
|
+
#define mld_assert(val) mld_debug_check_assert(__FILE__, __LINE__, (val))
|
|
53
|
+
|
|
54
|
+
/* Check bounds in array of int32_t's
|
|
55
|
+
* ptr: Base of int32_t array; will be explicitly cast to int32_t*,
|
|
56
|
+
* so you may pass a byte-compatible type such as mld_poly or mld_polyvec.
|
|
57
|
+
* len: Number of int32_t in array
|
|
58
|
+
* value_lb: Inclusive lower value bound
|
|
59
|
+
* value_ub: Exclusive upper value bound */
|
|
60
|
+
#define mld_assert_bound(ptr, len, value_lb, value_ub) \
|
|
61
|
+
mld_debug_check_bounds(__FILE__, __LINE__, (const int32_t *)(ptr), (len), \
|
|
62
|
+
((int64_t)(value_lb)) - 1, (value_ub))
|
|
63
|
+
|
|
64
|
+
/* Check absolute bounds in array of int32_t's
|
|
65
|
+
* ptr: Base of array, expression of type int32_t*
|
|
66
|
+
* len: Number of int32_t in array
|
|
67
|
+
* value_abs_bd: Exclusive absolute upper bound */
|
|
68
|
+
#define mld_assert_abs_bound(ptr, len, value_abs_bd) \
|
|
69
|
+
mld_assert_bound((ptr), (len), (-((int64_t)(value_abs_bd)) + 1), \
|
|
70
|
+
(value_abs_bd))
|
|
71
|
+
|
|
72
|
+
/* Version of bounds assertions for 2-dimensional arrays */
|
|
73
|
+
#define mld_assert_bound_2d(ptr, len0, len1, value_lb, value_ub) \
|
|
74
|
+
mld_assert_bound((ptr), ((len0) * (len1)), (value_lb), (value_ub))
|
|
75
|
+
|
|
76
|
+
#define mld_assert_abs_bound_2d(ptr, len0, len1, value_abs_bd) \
|
|
77
|
+
mld_assert_abs_bound((ptr), ((len0) * (len1)), (value_abs_bd))
|
|
78
|
+
|
|
79
|
+
/* When running CBMC, convert debug assertions into proof obligations */
|
|
80
|
+
#elif defined(CBMC)
|
|
81
|
+
#include "cbmc.h"
|
|
82
|
+
|
|
83
|
+
#define mld_assert(val) cassert(val)
|
|
84
|
+
|
|
85
|
+
#define mld_assert_bound(ptr, len, value_lb, value_ub) \
|
|
86
|
+
cassert(array_bound(((int32_t *)(ptr)), 0, (len), (value_lb), (value_ub)))
|
|
87
|
+
|
|
88
|
+
#define mld_assert_abs_bound(ptr, len, value_abs_bd) \
|
|
89
|
+
cassert(array_abs_bound(((int32_t *)(ptr)), 0, (len), (value_abs_bd)))
|
|
90
|
+
|
|
91
|
+
/* Because of https://github.com/diffblue/cbmc/issues/8570, we can't
|
|
92
|
+
* just use a single flattened array_bound(...) here. */
|
|
93
|
+
#define mld_assert_bound_2d(ptr, M, N, value_lb, value_ub) \
|
|
94
|
+
cassert(forall(kN, 0, (M), \
|
|
95
|
+
array_bound(&((int32_t (*)[(N)])(ptr))[kN][0], 0, (N), \
|
|
96
|
+
(value_lb), (value_ub))))
|
|
97
|
+
|
|
98
|
+
#define mld_assert_abs_bound_2d(ptr, M, N, value_abs_bd) \
|
|
99
|
+
cassert(forall(kN, 0, (M), \
|
|
100
|
+
array_abs_bound(&((int32_t (*)[(N)])(ptr))[kN][0], 0, (N), \
|
|
101
|
+
(value_abs_bd))))
|
|
102
|
+
|
|
103
|
+
#else /* !MLDSA_DEBUG && CBMC */
|
|
104
|
+
|
|
105
|
+
#define mld_assert(val) \
|
|
106
|
+
do \
|
|
107
|
+
{ \
|
|
108
|
+
} while (0)
|
|
109
|
+
#define mld_assert_bound(ptr, len, value_lb, value_ub) \
|
|
110
|
+
do \
|
|
111
|
+
{ \
|
|
112
|
+
} while (0)
|
|
113
|
+
#define mld_assert_abs_bound(ptr, len, value_abs_bd) \
|
|
114
|
+
do \
|
|
115
|
+
{ \
|
|
116
|
+
} while (0)
|
|
117
|
+
|
|
118
|
+
#define mld_assert_bound_2d(ptr, len0, len1, value_lb, value_ub) \
|
|
119
|
+
do \
|
|
120
|
+
{ \
|
|
121
|
+
} while (0)
|
|
122
|
+
|
|
123
|
+
#define mld_assert_abs_bound_2d(ptr, len0, len1, value_abs_bd) \
|
|
124
|
+
do \
|
|
125
|
+
{ \
|
|
126
|
+
} while (0)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
#endif /* !MLDSA_DEBUG && !CBMC */
|
|
130
|
+
#endif /* !MLD_DEBUG_H */
|