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,174 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) The mlkem-native project authors
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#ifndef MLK_CBMC_H
|
|
7
|
+
#define MLK_CBMC_H
|
|
8
|
+
/***************************************************
|
|
9
|
+
* Basic replacements for __CPROVER_XXX contracts
|
|
10
|
+
***************************************************/
|
|
11
|
+
#ifndef CBMC
|
|
12
|
+
|
|
13
|
+
#define __contract__(x)
|
|
14
|
+
#define __loop__(x)
|
|
15
|
+
|
|
16
|
+
#else /* !CBMC */
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
#define __contract__(x) x
|
|
20
|
+
#define __loop__(x) x
|
|
21
|
+
|
|
22
|
+
/* https://diffblue.github.io/cbmc/contracts-assigns.html */
|
|
23
|
+
#define assigns(...) __CPROVER_assigns(__VA_ARGS__)
|
|
24
|
+
|
|
25
|
+
/* https://diffblue.github.io/cbmc/contracts-requires-ensures.html */
|
|
26
|
+
#define requires(...) __CPROVER_requires(__VA_ARGS__)
|
|
27
|
+
#define ensures(...) __CPROVER_ensures(__VA_ARGS__)
|
|
28
|
+
/* https://diffblue.github.io/cbmc/contracts-loops.html */
|
|
29
|
+
#define invariant(...) __CPROVER_loop_invariant(__VA_ARGS__)
|
|
30
|
+
#define decreases(...) __CPROVER_decreases(__VA_ARGS__)
|
|
31
|
+
/* cassert to avoid confusion with in-built assert */
|
|
32
|
+
#define cassert(x) __CPROVER_assert(x, "cbmc assertion failed")
|
|
33
|
+
#define assume(...) __CPROVER_assume(__VA_ARGS__)
|
|
34
|
+
|
|
35
|
+
/***************************************************
|
|
36
|
+
* Macros for "expression" forms that may appear
|
|
37
|
+
* _inside_ top-level contracts.
|
|
38
|
+
***************************************************/
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
* function return value - useful inside ensures
|
|
42
|
+
* https://diffblue.github.io/cbmc/contracts-functions.html
|
|
43
|
+
*/
|
|
44
|
+
#define return_value (__CPROVER_return_value)
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
* assigns l-value targets
|
|
48
|
+
* https://diffblue.github.io/cbmc/contracts-assigns.html
|
|
49
|
+
*/
|
|
50
|
+
#define object_whole(...) __CPROVER_object_whole(__VA_ARGS__)
|
|
51
|
+
#define memory_slice(...) __CPROVER_object_upto(__VA_ARGS__)
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
* Pointer-related predicates
|
|
55
|
+
* https://diffblue.github.io/cbmc/contracts-memory-predicates.html
|
|
56
|
+
*/
|
|
57
|
+
#define memory_no_alias(...) __CPROVER_is_fresh(__VA_ARGS__)
|
|
58
|
+
#define readable(...) __CPROVER_r_ok(__VA_ARGS__)
|
|
59
|
+
#define writeable(...) __CPROVER_w_ok(__VA_ARGS__)
|
|
60
|
+
|
|
61
|
+
/* Maximum supported buffer size
|
|
62
|
+
*
|
|
63
|
+
* Larger buffers may be supported, but due to internal modeling constraints
|
|
64
|
+
* in CBMC, the proofs of memory- and type-safety won't be able to run.
|
|
65
|
+
*
|
|
66
|
+
* If you find yourself in need for a buffer size larger than this,
|
|
67
|
+
* please contact the maintainers, so we can prioritize work to relax
|
|
68
|
+
* this somewhat artificial bound.
|
|
69
|
+
*/
|
|
70
|
+
#define MLK_MAX_BUFFER_SIZE (SIZE_MAX >> 12)
|
|
71
|
+
|
|
72
|
+
/*
|
|
73
|
+
* History variables
|
|
74
|
+
* https://diffblue.github.io/cbmc/contracts-history-variables.html
|
|
75
|
+
*/
|
|
76
|
+
#define old(...) __CPROVER_old(__VA_ARGS__)
|
|
77
|
+
#define loop_entry(...) __CPROVER_loop_entry(__VA_ARGS__)
|
|
78
|
+
|
|
79
|
+
/*
|
|
80
|
+
* Quantifiers
|
|
81
|
+
* Note that the range on qvar is _exclusive_ between qvar_lb .. qvar_ub
|
|
82
|
+
* https://diffblue.github.io/cbmc/contracts-quantifiers.html
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
* Prevent clang-format from corrupting CBMC's special ==> operator
|
|
87
|
+
*/
|
|
88
|
+
/* clang-format off */
|
|
89
|
+
#define forall(qvar, qvar_lb, qvar_ub, predicate) \
|
|
90
|
+
__CPROVER_forall \
|
|
91
|
+
{ \
|
|
92
|
+
unsigned qvar; \
|
|
93
|
+
((qvar_lb) <= (qvar) && (qvar) < (qvar_ub)) ==> (predicate) \
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
#define exists(qvar, qvar_lb, qvar_ub, predicate) \
|
|
97
|
+
__CPROVER_exists \
|
|
98
|
+
{ \
|
|
99
|
+
unsigned qvar; \
|
|
100
|
+
((qvar_lb) <= (qvar) && (qvar) < (qvar_ub)) && (predicate) \
|
|
101
|
+
}
|
|
102
|
+
/* clang-format on */
|
|
103
|
+
|
|
104
|
+
/***************************************************
|
|
105
|
+
* Convenience macros for common contract patterns
|
|
106
|
+
***************************************************/
|
|
107
|
+
|
|
108
|
+
/*
|
|
109
|
+
* Boolean-value predidate that asserts that "all values of array_var are in
|
|
110
|
+
* range value_lb (inclusive) .. value_ub (exclusive)"
|
|
111
|
+
* Example:
|
|
112
|
+
* array_bound(a->coeffs, 0, MLKEM_N, 0, MLKEM_Q)
|
|
113
|
+
* expands to
|
|
114
|
+
* __CPROVER_forall { int k; (0 <= k && k <= MLKEM_N-1) ==> (
|
|
115
|
+
* 0 <= a->coeffs[k]) && a->coeffs[k] < MLKEM_Q)) }
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
/*
|
|
119
|
+
* Prevent clang-format from corrupting CBMC's special ==> operator
|
|
120
|
+
*/
|
|
121
|
+
/* clang-format off */
|
|
122
|
+
#define CBMC_CONCAT_(left, right) left##right
|
|
123
|
+
#define CBMC_CONCAT(left, right) CBMC_CONCAT_(left, right)
|
|
124
|
+
|
|
125
|
+
#define array_bound_core(qvar, qvar_lb, qvar_ub, array_var, \
|
|
126
|
+
value_lb, value_ub) \
|
|
127
|
+
__CPROVER_forall \
|
|
128
|
+
{ \
|
|
129
|
+
unsigned qvar; \
|
|
130
|
+
((qvar_lb) <= (qvar) && (qvar) < (qvar_ub)) ==> \
|
|
131
|
+
(((int)(value_lb) <= ((array_var)[(qvar)])) && \
|
|
132
|
+
(((array_var)[(qvar)]) < (int)(value_ub))) \
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
#define array_bound(array_var, qvar_lb, qvar_ub, value_lb, value_ub) \
|
|
136
|
+
array_bound_core(CBMC_CONCAT(_cbmc_idx, __COUNTER__), (qvar_lb), \
|
|
137
|
+
(qvar_ub), (array_var), (value_lb), (value_ub))
|
|
138
|
+
|
|
139
|
+
#define array_unchanged_core(qvar, qvar_lb, qvar_ub, array_var) \
|
|
140
|
+
__CPROVER_forall \
|
|
141
|
+
{ \
|
|
142
|
+
unsigned qvar; \
|
|
143
|
+
((qvar_lb) <= (qvar) && (qvar) < (qvar_ub)) ==> \
|
|
144
|
+
((array_var)[(qvar)]) == (old(* (int16_t (*)[(qvar_ub)])(array_var)))[(qvar)] \
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
#define array_unchanged(array_var, N) \
|
|
148
|
+
array_unchanged_core(CBMC_CONCAT(_cbmc_idx, __COUNTER__), 0, (N), (array_var))
|
|
149
|
+
|
|
150
|
+
#define array_unchanged_u64_core(qvar, qvar_lb, qvar_ub, array_var) \
|
|
151
|
+
__CPROVER_forall \
|
|
152
|
+
{ \
|
|
153
|
+
unsigned qvar; \
|
|
154
|
+
((qvar_lb) <= (qvar) && (qvar) < (qvar_ub)) ==> \
|
|
155
|
+
((array_var)[(qvar)]) == (old(* (uint64_t (*)[(qvar_ub)])(array_var)))[(qvar)] \
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
#define array_unchanged_u64(array_var, N) \
|
|
159
|
+
array_unchanged_u64_core(CBMC_CONCAT(_cbmc_idx, __COUNTER__), 0, (N), (array_var))
|
|
160
|
+
/* clang-format on */
|
|
161
|
+
|
|
162
|
+
/* Wrapper around array_bound operating on absolute values.
|
|
163
|
+
*
|
|
164
|
+
* The absolute value bound `k` is exclusive.
|
|
165
|
+
*
|
|
166
|
+
* Note that since the lower bound in array_bound is inclusive, we have to
|
|
167
|
+
* raise it by 1 here.
|
|
168
|
+
*/
|
|
169
|
+
#define array_abs_bound(arr, lb, ub, k) \
|
|
170
|
+
array_bound((arr), (lb), (ub), -((int)(k)) + 1, (k))
|
|
171
|
+
|
|
172
|
+
#endif /* CBMC */
|
|
173
|
+
|
|
174
|
+
#endif /* !MLK_CBMC_H */
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) The mlkem-native project authors
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
4
|
+
*/
|
|
5
|
+
#ifndef MLK_COMMON_H
|
|
6
|
+
#define MLK_COMMON_H
|
|
7
|
+
|
|
8
|
+
#ifndef __ASSEMBLER__
|
|
9
|
+
#include <stdint.h>
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#define MLK_BUILD_INTERNAL
|
|
13
|
+
|
|
14
|
+
#if defined(MLK_CONFIG_FILE)
|
|
15
|
+
#include MLK_CONFIG_FILE
|
|
16
|
+
#else
|
|
17
|
+
#include "mlkem_native_config.h"
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
#include "params.h"
|
|
21
|
+
#include "sys.h"
|
|
22
|
+
|
|
23
|
+
/* Internal and public API have external linkage by default, but
|
|
24
|
+
* this can be overwritten by the user, e.g. for single-CU builds. */
|
|
25
|
+
#if !defined(MLK_CONFIG_INTERNAL_API_QUALIFIER)
|
|
26
|
+
#define MLK_INTERNAL_API
|
|
27
|
+
#else
|
|
28
|
+
#define MLK_INTERNAL_API MLK_CONFIG_INTERNAL_API_QUALIFIER
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
#if !defined(MLK_CONFIG_EXTERNAL_API_QUALIFIER)
|
|
32
|
+
#define MLK_EXTERNAL_API
|
|
33
|
+
#else
|
|
34
|
+
#define MLK_EXTERNAL_API MLK_CONFIG_EXTERNAL_API_QUALIFIER
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
#define MLK_CONCAT_(x1, x2) x1##x2
|
|
38
|
+
#define MLK_CONCAT(x1, x2) MLK_CONCAT_(x1, x2)
|
|
39
|
+
|
|
40
|
+
#if (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || \
|
|
41
|
+
defined(MLK_CONFIG_MULTILEVEL_NO_SHARED))
|
|
42
|
+
#define MLK_ADD_PARAM_SET(s) MLK_CONCAT(s, MLK_CONFIG_PARAMETER_SET)
|
|
43
|
+
#else
|
|
44
|
+
#define MLK_ADD_PARAM_SET(s) s
|
|
45
|
+
#endif
|
|
46
|
+
|
|
47
|
+
#define MLK_NAMESPACE_PREFIX MLK_CONCAT(MLK_CONFIG_NAMESPACE_PREFIX, _)
|
|
48
|
+
#define MLK_NAMESPACE_PREFIX_K \
|
|
49
|
+
MLK_CONCAT(MLK_ADD_PARAM_SET(MLK_CONFIG_NAMESPACE_PREFIX), _)
|
|
50
|
+
|
|
51
|
+
/* Functions are prefixed by MLK_CONFIG_NAMESPACE_PREFIX.
|
|
52
|
+
*
|
|
53
|
+
* If multiple parameter sets are used, functions depending on the parameter
|
|
54
|
+
* set are additionally prefixed with 512/768/1024. See mlkem_native_config.h.
|
|
55
|
+
*
|
|
56
|
+
* Example: If MLK_CONFIG_NAMESPACE_PREFIX is mlkem, then
|
|
57
|
+
* MLK_NAMESPACE_K(enc) becomes mlkem512_enc/mlkem768_enc/mlkem1024_enc.
|
|
58
|
+
*/
|
|
59
|
+
#define MLK_NAMESPACE(s) MLK_CONCAT(MLK_NAMESPACE_PREFIX, s)
|
|
60
|
+
#define MLK_NAMESPACE_K(s) MLK_CONCAT(MLK_NAMESPACE_PREFIX_K, s)
|
|
61
|
+
|
|
62
|
+
/* On Apple platforms, we need to emit leading underscore
|
|
63
|
+
* in front of assembly symbols. We thus introducee a separate
|
|
64
|
+
* namespace wrapper for ASM symbols. */
|
|
65
|
+
#if !defined(__APPLE__)
|
|
66
|
+
#define MLK_ASM_NAMESPACE(sym) MLK_NAMESPACE(sym)
|
|
67
|
+
#else
|
|
68
|
+
#define MLK_ASM_NAMESPACE(sym) MLK_CONCAT(_, MLK_NAMESPACE(sym))
|
|
69
|
+
#endif
|
|
70
|
+
|
|
71
|
+
/*
|
|
72
|
+
* On X86_64 if control-flow protections (CET) are enabled (through
|
|
73
|
+
* -fcf-protection=), we add an endbr64 instruction at every global function
|
|
74
|
+
* label. See sys.h for more details
|
|
75
|
+
*/
|
|
76
|
+
#if defined(MLK_SYS_X86_64)
|
|
77
|
+
#define MLK_ASM_FN_SYMBOL(sym) MLK_ASM_NAMESPACE(sym) : MLK_CET_ENDBR
|
|
78
|
+
#elif defined(MLK_SYS_ARMV81M_MVE)
|
|
79
|
+
/* clang-format off */
|
|
80
|
+
#define MLK_ASM_FN_SYMBOL(sym) \
|
|
81
|
+
.type MLK_ASM_NAMESPACE(sym), %function; \
|
|
82
|
+
MLK_ASM_NAMESPACE(sym) :
|
|
83
|
+
/* clang-format on */
|
|
84
|
+
#else /* !MLK_SYS_X86_64 && MLK_SYS_ARMV81M_MVE */
|
|
85
|
+
#define MLK_ASM_FN_SYMBOL(sym) MLK_ASM_NAMESPACE(sym) :
|
|
86
|
+
#endif /* !MLK_SYS_X86_64 && !MLK_SYS_ARMV81M_MVE */
|
|
87
|
+
|
|
88
|
+
/*
|
|
89
|
+
* Output the size of an assembly function.
|
|
90
|
+
*/
|
|
91
|
+
#if defined(__ELF__)
|
|
92
|
+
#define MLK_ASM_FN_SIZE(sym) \
|
|
93
|
+
.size MLK_ASM_NAMESPACE(sym), .- MLK_ASM_NAMESPACE(sym)
|
|
94
|
+
#else
|
|
95
|
+
#define MLK_ASM_FN_SIZE(sym)
|
|
96
|
+
#endif
|
|
97
|
+
|
|
98
|
+
/* We aim to simplify the user's life by supporting builds where
|
|
99
|
+
* all source files are included, even those that are not needed.
|
|
100
|
+
* Those files are appropriately guarded and will be empty when unneeded.
|
|
101
|
+
* The following is to avoid compilers complaining about this. */
|
|
102
|
+
#define MLK_EMPTY_CU(s) extern int MLK_NAMESPACE_K(empty_cu_##s);
|
|
103
|
+
|
|
104
|
+
/* MLK_CONFIG_NO_ASM takes precedence over MLK_USE_NATIVE_XXX */
|
|
105
|
+
#if defined(MLK_CONFIG_NO_ASM)
|
|
106
|
+
#undef MLK_CONFIG_USE_NATIVE_BACKEND_ARITH
|
|
107
|
+
#undef MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202
|
|
108
|
+
#endif
|
|
109
|
+
|
|
110
|
+
#if defined(MLK_CONFIG_USE_NATIVE_BACKEND_ARITH) && \
|
|
111
|
+
!defined(MLK_CONFIG_ARITH_BACKEND_FILE)
|
|
112
|
+
#error Bad configuration: MLK_CONFIG_USE_NATIVE_BACKEND_ARITH is set, but MLK_CONFIG_ARITH_BACKEND_FILE is not.
|
|
113
|
+
#endif
|
|
114
|
+
|
|
115
|
+
#if defined(MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202) && \
|
|
116
|
+
!defined(MLK_CONFIG_FIPS202_BACKEND_FILE)
|
|
117
|
+
#error Bad configuration: MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202 is set, but MLK_CONFIG_FIPS202_BACKEND_FILE is not.
|
|
118
|
+
#endif
|
|
119
|
+
|
|
120
|
+
#if defined(MLK_CONFIG_NO_RANDOMIZED_API) && defined(MLK_CONFIG_KEYGEN_PCT)
|
|
121
|
+
#error Bad configuration: MLK_CONFIG_NO_RANDOMIZED_API is incompatible with MLK_CONFIG_KEYGEN_PCT as the current PCT implementation requires crypto_kem_enc()
|
|
122
|
+
#endif
|
|
123
|
+
|
|
124
|
+
#if defined(MLK_CONFIG_USE_NATIVE_BACKEND_ARITH)
|
|
125
|
+
#include MLK_CONFIG_ARITH_BACKEND_FILE
|
|
126
|
+
/* Include to enforce consistency of API and implementation,
|
|
127
|
+
* and conduct sanity checks on the backend.
|
|
128
|
+
*
|
|
129
|
+
* Keep this _after_ the inclusion of the backend; otherwise,
|
|
130
|
+
* the sanity checks won't have an effect. */
|
|
131
|
+
#if defined(MLK_CHECK_APIS) && !defined(__ASSEMBLER__)
|
|
132
|
+
#include "native/api.h"
|
|
133
|
+
#endif
|
|
134
|
+
#endif /* MLK_CONFIG_USE_NATIVE_BACKEND_ARITH */
|
|
135
|
+
|
|
136
|
+
#if defined(MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202)
|
|
137
|
+
#include MLK_CONFIG_FIPS202_BACKEND_FILE
|
|
138
|
+
/* Include to enforce consistency of API and implementation,
|
|
139
|
+
* and conduct sanity checks on the backend.
|
|
140
|
+
*
|
|
141
|
+
* Keep this _after_ the inclusion of the backend; otherwise,
|
|
142
|
+
* the sanity checks won't have an effect. */
|
|
143
|
+
#if defined(MLK_CHECK_APIS) && !defined(__ASSEMBLER__)
|
|
144
|
+
#include "fips202/native/api.h"
|
|
145
|
+
#endif
|
|
146
|
+
#endif /* MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202 */
|
|
147
|
+
|
|
148
|
+
#if !defined(MLK_CONFIG_FIPS202_CUSTOM_HEADER)
|
|
149
|
+
#define MLK_FIPS202_HEADER_FILE "fips202/fips202.h"
|
|
150
|
+
#else
|
|
151
|
+
#define MLK_FIPS202_HEADER_FILE MLK_CONFIG_FIPS202_CUSTOM_HEADER
|
|
152
|
+
#endif
|
|
153
|
+
|
|
154
|
+
#if !defined(MLK_CONFIG_FIPS202X4_CUSTOM_HEADER)
|
|
155
|
+
#define MLK_FIPS202X4_HEADER_FILE "fips202/fips202x4.h"
|
|
156
|
+
#else
|
|
157
|
+
#define MLK_FIPS202X4_HEADER_FILE MLK_CONFIG_FIPS202X4_CUSTOM_HEADER
|
|
158
|
+
#endif
|
|
159
|
+
|
|
160
|
+
/* Standard library function replacements */
|
|
161
|
+
#if !defined(__ASSEMBLER__)
|
|
162
|
+
#if !defined(MLK_CONFIG_CUSTOM_MEMCPY)
|
|
163
|
+
#include <string.h>
|
|
164
|
+
#define mlk_memcpy memcpy
|
|
165
|
+
#endif
|
|
166
|
+
|
|
167
|
+
#if !defined(MLK_CONFIG_CUSTOM_MEMSET)
|
|
168
|
+
#include <string.h>
|
|
169
|
+
#define mlk_memset memset
|
|
170
|
+
#endif
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
/* Allocation macros for large local structures
|
|
174
|
+
*
|
|
175
|
+
* MLK_ALLOC(v, T, N) declares T *v and attempts to point it to an T[N]
|
|
176
|
+
* MLK_FREE(v, T, N) zeroizes and frees the allocation
|
|
177
|
+
*
|
|
178
|
+
* Default implementation uses stack allocation.
|
|
179
|
+
* Can be overridden by setting the config option MLK_CONFIG_CUSTOM_ALLOC_FREE
|
|
180
|
+
* and defining MLK_CUSTOM_ALLOC and MLK_CUSTOM_FREE.
|
|
181
|
+
*/
|
|
182
|
+
#if defined(MLK_CONFIG_CUSTOM_ALLOC_FREE) != \
|
|
183
|
+
(defined(MLK_CUSTOM_ALLOC) && defined(MLK_CUSTOM_FREE))
|
|
184
|
+
#error Bad configuration: MLK_CONFIG_CUSTOM_ALLOC_FREE must be set together with MLK_CUSTOM_ALLOC and MLK_CUSTOM_FREE
|
|
185
|
+
#endif
|
|
186
|
+
|
|
187
|
+
/*
|
|
188
|
+
* If the integration wants to provide a context parameter for use in
|
|
189
|
+
* platform-specific hooks, then it should define this parameter.
|
|
190
|
+
*
|
|
191
|
+
* The MLK_CONTEXT_PARAMETERS_n macros are intended to be used with macros
|
|
192
|
+
* defining the function names and expand to either pass or discard the context
|
|
193
|
+
* argument as required by the current build. If there is no context parameter
|
|
194
|
+
* requested then these are removed from the prototypes and from all calls.
|
|
195
|
+
*/
|
|
196
|
+
#ifdef MLK_CONFIG_CONTEXT_PARAMETER
|
|
197
|
+
#define MLK_CONTEXT_PARAMETERS_0(context) (context)
|
|
198
|
+
#define MLK_CONTEXT_PARAMETERS_1(arg0, context) (arg0, context)
|
|
199
|
+
#define MLK_CONTEXT_PARAMETERS_2(arg0, arg1, context) (arg0, arg1, context)
|
|
200
|
+
#define MLK_CONTEXT_PARAMETERS_3(arg0, arg1, arg2, context) \
|
|
201
|
+
(arg0, arg1, arg2, context)
|
|
202
|
+
#define MLK_CONTEXT_PARAMETERS_4(arg0, arg1, arg2, arg3, context) \
|
|
203
|
+
(arg0, arg1, arg2, arg3, context)
|
|
204
|
+
#else /* MLK_CONFIG_CONTEXT_PARAMETER */
|
|
205
|
+
#define MLK_CONTEXT_PARAMETERS_0(context) ()
|
|
206
|
+
#define MLK_CONTEXT_PARAMETERS_1(arg0, context) (arg0)
|
|
207
|
+
#define MLK_CONTEXT_PARAMETERS_2(arg0, arg1, context) (arg0, arg1)
|
|
208
|
+
#define MLK_CONTEXT_PARAMETERS_3(arg0, arg1, arg2, context) (arg0, arg1, arg2)
|
|
209
|
+
#define MLK_CONTEXT_PARAMETERS_4(arg0, arg1, arg2, arg3, context) \
|
|
210
|
+
(arg0, arg1, arg2, arg3)
|
|
211
|
+
#endif /* !MLK_CONFIG_CONTEXT_PARAMETER */
|
|
212
|
+
|
|
213
|
+
#if defined(MLK_CONFIG_CONTEXT_PARAMETER_TYPE) != \
|
|
214
|
+
defined(MLK_CONFIG_CONTEXT_PARAMETER)
|
|
215
|
+
#error MLK_CONFIG_CONTEXT_PARAMETER_TYPE must be defined if and only if MLK_CONFIG_CONTEXT_PARAMETER is defined
|
|
216
|
+
#endif
|
|
217
|
+
|
|
218
|
+
#if !defined(MLK_CONFIG_CUSTOM_ALLOC_FREE)
|
|
219
|
+
/* Default: stack allocation */
|
|
220
|
+
|
|
221
|
+
#define MLK_ALLOC(v, T, N, context) \
|
|
222
|
+
MLK_ALIGN T mlk_alloc_##v[N]; \
|
|
223
|
+
T *v = mlk_alloc_##v
|
|
224
|
+
|
|
225
|
+
/* TODO: This leads to a circular dependency between common and verify.h
|
|
226
|
+
* It just works out before we're at the end of the file, but it's still
|
|
227
|
+
* prone to issues in the future. */
|
|
228
|
+
#include "verify.h"
|
|
229
|
+
#define MLK_FREE(v, T, N, context) \
|
|
230
|
+
do \
|
|
231
|
+
{ \
|
|
232
|
+
mlk_zeroize(mlk_alloc_##v, sizeof(mlk_alloc_##v)); \
|
|
233
|
+
(v) = NULL; \
|
|
234
|
+
} while (0)
|
|
235
|
+
|
|
236
|
+
#else /* !MLK_CONFIG_CUSTOM_ALLOC_FREE */
|
|
237
|
+
|
|
238
|
+
/* Custom allocation */
|
|
239
|
+
|
|
240
|
+
/*
|
|
241
|
+
* The indirection here is necessary to use MLK_CONTEXT_PARAMETERS_3 here.
|
|
242
|
+
*/
|
|
243
|
+
#define MLK_APPLY(f, args) f args
|
|
244
|
+
|
|
245
|
+
#define MLK_ALLOC(v, T, N, context) \
|
|
246
|
+
MLK_APPLY(MLK_CUSTOM_ALLOC, MLK_CONTEXT_PARAMETERS_3(v, T, N, context))
|
|
247
|
+
|
|
248
|
+
#define MLK_FREE(v, T, N, context) \
|
|
249
|
+
do \
|
|
250
|
+
{ \
|
|
251
|
+
if (v != NULL) \
|
|
252
|
+
{ \
|
|
253
|
+
mlk_zeroize(v, sizeof(T) * (N)); \
|
|
254
|
+
MLK_APPLY(MLK_CUSTOM_FREE, MLK_CONTEXT_PARAMETERS_3(v, T, N, context)); \
|
|
255
|
+
v = NULL; \
|
|
256
|
+
} \
|
|
257
|
+
} while (0)
|
|
258
|
+
|
|
259
|
+
#endif /* MLK_CONFIG_CUSTOM_ALLOC_FREE */
|
|
260
|
+
|
|
261
|
+
/****************************** Error codes ***********************************/
|
|
262
|
+
|
|
263
|
+
/* Generic failure condition */
|
|
264
|
+
#define MLK_ERR_FAIL -1
|
|
265
|
+
/* An allocation failed. This can only happen if MLK_CONFIG_CUSTOM_ALLOC_FREE
|
|
266
|
+
* is defined and the provided MLK_CUSTOM_ALLOC can fail. */
|
|
267
|
+
#define MLK_ERR_OUT_OF_MEMORY -2
|
|
268
|
+
/* An rng failure occured. Might be due to insufficient entropy or
|
|
269
|
+
* system misconfiguration. */
|
|
270
|
+
#define MLK_ERR_RNG_FAIL -3
|
|
271
|
+
|
|
272
|
+
#endif /* !__ASSEMBLER__ */
|
|
273
|
+
|
|
274
|
+
#endif /* !MLK_COMMON_H */
|