pq_crypto 0.6.7 → 0.6.9
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/CHANGELOG.md +20 -0
- data/README.md +1 -3
- data/ext/pqcrypto/pqcrypto_ruby_secure.c +41 -11
- data/ext/pqcrypto/pqcrypto_secure.c +501 -296
- data/ext/pqcrypto/pqcrypto_version.h +1 -1
- data/ext/pqcrypto/vendor/.vendored +7 -7
- data/ext/pqcrypto/vendor/mldsa-native/BUILDING.md +71 -0
- data/ext/pqcrypto/vendor/mldsa-native/README.md +26 -11
- data/ext/pqcrypto/vendor/mldsa-native/RELEASE.md +77 -150
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +93 -40
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +74 -59
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +106 -40
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +94 -92
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/capability.h +31 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +55 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +30 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/context.h +1 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c +1 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +1 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +5 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +4 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +4 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +8 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +8 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +12 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +4 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_extract_bytes_mve.S +37 -19
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_xor_bytes_mve.S +37 -19
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +3 -8
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/auto.h +53 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x1_avx512.h +38 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx512.h +38 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +24 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x1_avx512_asm.S +574 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +46 -18
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx512_asm.S +679 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +13 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +5 -6
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_intt_aarch64_asm.S +4 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_ntt_aarch64_asm.S +4 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_pointwise_montgomery_aarch64_asm.S +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_caddq_aarch64_asm.S +4 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_chknorm_aarch64_asm.S +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_32_aarch64_asm.S +4 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_88_aarch64_asm.S +4 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_32_aarch64_asm.S +4 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_88_aarch64_asm.S +4 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +4 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +4 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +4 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_17_aarch64_asm.S +5 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_19_aarch64_asm.S +5 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_aarch64_asm.S +110 -120
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta2_aarch64_asm.S +109 -101
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta4_aarch64_asm.S +97 -93
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +1 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/meta.h +4 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/fastmul.h +74 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/slowmul.h +77 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/arith_native_rv32im.h +124 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_intt_rv32im_asm.S +331 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_intt_rv32im_slowmul_asm.S +381 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_ntt_rv32im_asm.S +304 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_ntt_rv32im_slowmul_asm.S +351 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_poly_pointwise_montgomery_rv32im_asm.S +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/rv32im_zetas.c +118 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +6 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +2 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_intt_avx2_asm.S +5 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_ntt_avx2_asm.S +5 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_nttunpack_avx2_asm.S +5 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l4_avx2_asm.S +6 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l5_avx2_asm.S +6 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l7_avx2_asm.S +6 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_avx2_asm.S +5 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_caddq_avx2_asm.S +5 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_chknorm_avx2_asm.S +7 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_32_avx2_asm.S +69 -67
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_88_avx2_asm.S +69 -67
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_32_avx2_asm.S +12 -16
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_88_avx2_asm.S +14 -18
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_17_avx2_asm.S +6 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_19_avx2_asm.S +6 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_avx2_asm.S +5 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta2_avx2_asm.S +5 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S +5 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +23 -27
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +21 -42
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/params.h +28 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +87 -28
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +61 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +23 -19
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +30 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +55 -107
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +67 -107
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +16 -24
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +27 -21
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +8 -8
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +191 -119
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +6 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sys.h +16 -42
- data/ext/pqcrypto/vendor/mlkem-native/BUILDING.md +72 -0
- data/ext/pqcrypto/vendor/mlkem-native/README.md +9 -5
- data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +64 -312
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +77 -34
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +41 -13
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +89 -33
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +50 -46
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/capability.h +30 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +30 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +1 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +4 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.c +1 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +15 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +23 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +11 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +7 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +8 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.h +8 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +5 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +4 -4
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +4 -4
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +8 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +8 -4
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +4 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_state_extract_bytes_mve.S +37 -19
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_state_xor_bytes_mve.S +37 -19
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +2 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/auto.h +47 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x1_avx512.h +37 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx512.h +37 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +24 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x1_avx512_asm.S +573 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +46 -18
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx512_asm.S +678 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +13 -4
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +1 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +7 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +29 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +156 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +137 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/compress_d5_table.c +43 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d10_table.c +50 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d11_table.c +53 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d4_table.c +44 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d5_table.c +53 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_intt_aarch64_asm.S +5 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_ntt_aarch64_asm.S +4 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d10_aarch64_asm.S +439 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d11_aarch64_asm.S +452 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d4_aarch64_asm.S +106 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d5_aarch64_asm.S +124 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d10_aarch64_asm.S +108 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d11_aarch64_asm.S +116 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d4_aarch64_asm.S +93 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d5_aarch64_asm.S +104 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_frombytes_aarch64_asm.S +84 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_mulcache_compute_aarch64_asm.S +4 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_reduce_aarch64_asm.S +4 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_tobytes_aarch64_asm.S +5 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_tomont_aarch64_asm.S +4 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S +4 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S +4 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S +4 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_rej_uniform_aarch64_asm.S +112 -104
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +0 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +2 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/README.md +2 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/meta.h +16 -21
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/arith_native_ppc64le.h +1 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/consts.c +2 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_intt_ppc_asm.S +6 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_ntt_ppc_asm.S +6 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_poly_tomont_ppc_asm.S +6 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_reduce_ppc_asm.S +6 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +5 -4
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +2 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +1 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +5 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_intt_avx2_asm.S +36 -33
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_ntt_avx2_asm.S +67 -65
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_nttfrombytes_avx2_asm.S +8 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_ntttobytes_avx2_asm.S +6 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_nttunpack_avx2_asm.S +5 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d10_avx2_asm.S +7 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d11_avx2_asm.S +7 -4
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d4_avx2_asm.S +7 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d5_avx2_asm.S +7 -4
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d10_avx2_asm.S +7 -4
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d11_avx2_asm.S +6 -4
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d4_avx2_asm.S +7 -4
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d5_avx2_asm.S +6 -4
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_mulcache_compute_avx2_asm.S +5 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S +118 -115
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S +174 -171
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S +230 -227
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_reduce_avx2_asm.S +17 -15
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_rej_uniform_avx2_asm.S +7 -6
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_tomont_avx2_asm.S +5 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +4 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +1 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +31 -44
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +1 -1
- data/lib/pq_crypto/internal.rb +10 -0
- data/lib/pq_crypto/kem.rb +5 -10
- data/lib/pq_crypto/pkcs8/der.rb +26 -11
- data/lib/pq_crypto/pkcs8/private_key_choice.rb +21 -25
- data/lib/pq_crypto/signature.rb +28 -40
- data/lib/pq_crypto/spki.rb +36 -23
- data/lib/pq_crypto/version.rb +1 -1
- data/script/vendor_libs.rb +6 -6
- metadata +36 -1
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
|
|
26
26
|
#include "../../../common.h"
|
|
27
27
|
|
|
28
|
-
#if defined(
|
|
28
|
+
#if defined(MLK_SYS_X86_64_AVX2) && \
|
|
29
|
+
defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \
|
|
29
30
|
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
|
|
30
31
|
/*yaml
|
|
31
32
|
Name: reduce_avx2_asm
|
|
@@ -104,27 +105,27 @@ MLK_ASM_FN_SYMBOL(reduce_avx2_asm)
|
|
|
104
105
|
vpsubw %ymm0, %ymm2, %ymm2
|
|
105
106
|
vpsraw $0xf, %ymm2, %ymm12
|
|
106
107
|
vpand %ymm0, %ymm12, %ymm12
|
|
107
|
-
vpaddw %
|
|
108
|
+
vpaddw %ymm2, %ymm12, %ymm2
|
|
108
109
|
vpsubw %ymm0, %ymm3, %ymm3
|
|
109
110
|
vpsraw $0xf, %ymm3, %ymm12
|
|
110
111
|
vpand %ymm0, %ymm12, %ymm12
|
|
111
|
-
vpaddw %
|
|
112
|
+
vpaddw %ymm3, %ymm12, %ymm3
|
|
112
113
|
vpsubw %ymm0, %ymm4, %ymm4
|
|
113
114
|
vpsraw $0xf, %ymm4, %ymm12
|
|
114
115
|
vpand %ymm0, %ymm12, %ymm12
|
|
115
|
-
vpaddw %
|
|
116
|
+
vpaddw %ymm4, %ymm12, %ymm4
|
|
116
117
|
vpsubw %ymm0, %ymm5, %ymm5
|
|
117
118
|
vpsraw $0xf, %ymm5, %ymm12
|
|
118
119
|
vpand %ymm0, %ymm12, %ymm12
|
|
119
|
-
vpaddw %
|
|
120
|
+
vpaddw %ymm5, %ymm12, %ymm5
|
|
120
121
|
vpsubw %ymm0, %ymm6, %ymm6
|
|
121
122
|
vpsraw $0xf, %ymm6, %ymm12
|
|
122
123
|
vpand %ymm0, %ymm12, %ymm12
|
|
123
|
-
vpaddw %
|
|
124
|
+
vpaddw %ymm6, %ymm12, %ymm6
|
|
124
125
|
vpsubw %ymm0, %ymm7, %ymm7
|
|
125
126
|
vpsraw $0xf, %ymm7, %ymm12
|
|
126
127
|
vpand %ymm0, %ymm12, %ymm12
|
|
127
|
-
vpaddw %
|
|
128
|
+
vpaddw %ymm7, %ymm12, %ymm7
|
|
128
129
|
vpsubw %ymm0, %ymm8, %ymm8
|
|
129
130
|
vpsraw $0xf, %ymm8, %ymm12
|
|
130
131
|
vpand %ymm0, %ymm12, %ymm12
|
|
@@ -184,27 +185,27 @@ MLK_ASM_FN_SYMBOL(reduce_avx2_asm)
|
|
|
184
185
|
vpsubw %ymm0, %ymm2, %ymm2
|
|
185
186
|
vpsraw $0xf, %ymm2, %ymm12
|
|
186
187
|
vpand %ymm0, %ymm12, %ymm12
|
|
187
|
-
vpaddw %
|
|
188
|
+
vpaddw %ymm2, %ymm12, %ymm2
|
|
188
189
|
vpsubw %ymm0, %ymm3, %ymm3
|
|
189
190
|
vpsraw $0xf, %ymm3, %ymm12
|
|
190
191
|
vpand %ymm0, %ymm12, %ymm12
|
|
191
|
-
vpaddw %
|
|
192
|
+
vpaddw %ymm3, %ymm12, %ymm3
|
|
192
193
|
vpsubw %ymm0, %ymm4, %ymm4
|
|
193
194
|
vpsraw $0xf, %ymm4, %ymm12
|
|
194
195
|
vpand %ymm0, %ymm12, %ymm12
|
|
195
|
-
vpaddw %
|
|
196
|
+
vpaddw %ymm4, %ymm12, %ymm4
|
|
196
197
|
vpsubw %ymm0, %ymm5, %ymm5
|
|
197
198
|
vpsraw $0xf, %ymm5, %ymm12
|
|
198
199
|
vpand %ymm0, %ymm12, %ymm12
|
|
199
|
-
vpaddw %
|
|
200
|
+
vpaddw %ymm5, %ymm12, %ymm5
|
|
200
201
|
vpsubw %ymm0, %ymm6, %ymm6
|
|
201
202
|
vpsraw $0xf, %ymm6, %ymm12
|
|
202
203
|
vpand %ymm0, %ymm12, %ymm12
|
|
203
|
-
vpaddw %
|
|
204
|
+
vpaddw %ymm6, %ymm12, %ymm6
|
|
204
205
|
vpsubw %ymm0, %ymm7, %ymm7
|
|
205
206
|
vpsraw $0xf, %ymm7, %ymm12
|
|
206
207
|
vpand %ymm0, %ymm12, %ymm12
|
|
207
|
-
vpaddw %
|
|
208
|
+
vpaddw %ymm7, %ymm12, %ymm7
|
|
208
209
|
vpsubw %ymm0, %ymm8, %ymm8
|
|
209
210
|
vpsraw $0xf, %ymm8, %ymm12
|
|
210
211
|
vpand %ymm0, %ymm12, %ymm12
|
|
@@ -221,13 +222,14 @@ MLK_ASM_FN_SYMBOL(reduce_avx2_asm)
|
|
|
221
222
|
vmovdqa %ymm7, 0x1a0(%rdi)
|
|
222
223
|
vmovdqa %ymm8, 0x1c0(%rdi)
|
|
223
224
|
vmovdqa %ymm9, 0x1e0(%rdi)
|
|
225
|
+
vzeroupper
|
|
224
226
|
retq
|
|
225
227
|
.cfi_endproc
|
|
226
228
|
|
|
227
229
|
MLK_ASM_FN_SIZE(reduce_avx2_asm)
|
|
228
230
|
|
|
229
|
-
#endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT &&
|
|
230
|
-
|
|
231
|
+
#endif /* MLK_SYS_X86_64_AVX2 && MLK_ARITH_BACKEND_X86_64_DEFAULT && \
|
|
232
|
+
!MLK_CONFIG_MULTILEVEL_NO_SHARED */
|
|
231
233
|
|
|
232
234
|
#if defined(__ELF__)
|
|
233
235
|
.section .note.GNU-stack,"",%progbits
|
data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_rej_uniform_avx2_asm.S
CHANGED
|
@@ -13,19 +13,20 @@
|
|
|
13
13
|
* 16-bit coefficients.
|
|
14
14
|
* - const uint8_t *buf: pointer to input buffer
|
|
15
15
|
* (assumed to be uniform random bytes)
|
|
16
|
-
* -
|
|
16
|
+
* - uint64_t buflen: length of input buffer in bytes.
|
|
17
17
|
* Must be a multiple of 12.
|
|
18
18
|
*
|
|
19
19
|
* Returns number of sampled 16-bit integers (at most MLKEM_N).
|
|
20
20
|
**************************************************/
|
|
21
21
|
#include "../../../common.h"
|
|
22
22
|
|
|
23
|
-
#if defined(
|
|
23
|
+
#if defined(MLK_SYS_X86_64_AVX2) && \
|
|
24
|
+
defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \
|
|
24
25
|
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
|
|
25
26
|
/*yaml
|
|
26
27
|
Name: rej_uniform_avx2_asm
|
|
27
28
|
Description: x86_64 AVX2 rejection sampling
|
|
28
|
-
Signature: uint64_t mlk_rej_uniform_avx2_asm(int16_t *r, const uint8_t *buf,
|
|
29
|
+
Signature: uint64_t mlk_rej_uniform_avx2_asm(int16_t *r, const uint8_t *buf, uint64_t buflen, const uint8_t *table)
|
|
29
30
|
ABI:
|
|
30
31
|
Architecture: x86_64
|
|
31
32
|
CallingConvention: SysV
|
|
@@ -44,7 +45,7 @@
|
|
|
44
45
|
description: Input buffer
|
|
45
46
|
rdx:
|
|
46
47
|
type: scalar
|
|
47
|
-
c_parameter:
|
|
48
|
+
c_parameter: uint64_t buflen
|
|
48
49
|
description: Length of input buffer (must be multiple of 12)
|
|
49
50
|
test_with: 504 # MLKEM_GEN_MATRIX_NBLOCKS * MLK_XOF_RATE
|
|
50
51
|
rcx:
|
|
@@ -128,8 +129,8 @@ Lmlk_rej_uniform_asm_end:
|
|
|
128
129
|
|
|
129
130
|
MLK_ASM_FN_SIZE(rej_uniform_avx2_asm)
|
|
130
131
|
|
|
131
|
-
#endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT &&
|
|
132
|
-
|
|
132
|
+
#endif /* MLK_SYS_X86_64_AVX2 && MLK_ARITH_BACKEND_X86_64_DEFAULT && \
|
|
133
|
+
!MLK_CONFIG_MULTILEVEL_NO_SHARED */
|
|
133
134
|
|
|
134
135
|
#if defined(__ELF__)
|
|
135
136
|
.section .note.GNU-stack,"",%progbits
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
#include "../../../common.h"
|
|
26
|
-
#if defined(
|
|
26
|
+
#if defined(MLK_SYS_X86_64_AVX2) && \
|
|
27
|
+
defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \
|
|
27
28
|
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \
|
|
28
29
|
!defined(MLK_CONFIG_NO_KEYPAIR_API)
|
|
29
30
|
/*yaml
|
|
@@ -159,13 +160,14 @@ MLK_ASM_FN_SYMBOL(tomont_avx2_asm)
|
|
|
159
160
|
vmovdqa %ymm8, 0x1a0(%rdi)
|
|
160
161
|
vmovdqa %ymm9, 0x1c0(%rdi)
|
|
161
162
|
vmovdqa %ymm10, 0x1e0(%rdi)
|
|
163
|
+
vzeroupper
|
|
162
164
|
retq
|
|
163
165
|
.cfi_endproc
|
|
164
166
|
|
|
165
167
|
MLK_ASM_FN_SIZE(tomont_avx2_asm)
|
|
166
168
|
|
|
167
|
-
#endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT &&
|
|
168
|
-
&& !MLK_CONFIG_NO_KEYPAIR_API */
|
|
169
|
+
#endif /* MLK_SYS_X86_64_AVX2 && MLK_ARITH_BACKEND_X86_64_DEFAULT && \
|
|
170
|
+
!MLK_CONFIG_MULTILEVEL_NO_SHARED && !MLK_CONFIG_NO_KEYPAIR_API */
|
|
169
171
|
|
|
170
172
|
#if defined(__ELF__)
|
|
171
173
|
.section .note.GNU-stack,"",%progbits
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
#include "poly_k.h"
|
|
26
|
-
|
|
27
26
|
#include "debug.h"
|
|
28
27
|
#include "sampling.h"
|
|
29
28
|
#include "symmetric.h"
|
|
@@ -361,8 +360,7 @@ void mlk_poly_getnoise_eta1_4x(mlk_poly *r0, mlk_poly *r1, mlk_poly *r2,
|
|
|
361
360
|
extkey[2][MLKEM_SYMBYTES] = nonce2;
|
|
362
361
|
extkey[3][MLKEM_SYMBYTES] = nonce3;
|
|
363
362
|
|
|
364
|
-
#if !defined(
|
|
365
|
-
!defined(MLK_CONFIG_SERIAL_FIPS202_ONLY)
|
|
363
|
+
#if !defined(MLK_CONFIG_SERIAL_FIPS202_ONLY)
|
|
366
364
|
mlk_prf_eta1_x4(buf, extkey);
|
|
367
365
|
#else
|
|
368
366
|
mlk_prf_eta1(buf[0], extkey[0]);
|
|
@@ -372,8 +370,7 @@ void mlk_poly_getnoise_eta1_4x(mlk_poly *r0, mlk_poly *r1, mlk_poly *r2,
|
|
|
372
370
|
{
|
|
373
371
|
mlk_prf_eta1(buf[3], extkey[3]);
|
|
374
372
|
}
|
|
375
|
-
#endif /*
|
|
376
|
-
!MLK_CONFIG_SERIAL_FIPS202_ONLY) */
|
|
373
|
+
#endif /* MLK_CONFIG_SERIAL_FIPS202_ONLY */
|
|
377
374
|
|
|
378
375
|
mlk_poly_cbd_eta1(r0, buf[0]);
|
|
379
376
|
mlk_poly_cbd_eta1(r1, buf[1]);
|
|
@@ -486,16 +483,14 @@ void mlk_poly_getnoise_eta1122_4x(mlk_poly *r0, mlk_poly *r1, mlk_poly *r2,
|
|
|
486
483
|
/* On systems with fast batched Keccak, we use 4-fold batched PRF,
|
|
487
484
|
* even though that means generating more random data in buf[2] and buf[3]
|
|
488
485
|
* than necessary. */
|
|
489
|
-
#if !defined(
|
|
490
|
-
!defined(MLK_CONFIG_SERIAL_FIPS202_ONLY)
|
|
486
|
+
#if !defined(MLK_CONFIG_SERIAL_FIPS202_ONLY)
|
|
491
487
|
mlk_prf_eta1_x4(buf, extkey);
|
|
492
488
|
#else
|
|
493
489
|
mlk_prf_eta1(buf[0], extkey[0]);
|
|
494
490
|
mlk_prf_eta1(buf[1], extkey[1]);
|
|
495
491
|
mlk_prf_eta2(buf[2], extkey[2]);
|
|
496
492
|
mlk_prf_eta2(buf[3], extkey[3]);
|
|
497
|
-
#endif /*
|
|
498
|
-
!MLK_CONFIG_SERIAL_FIPS202_ONLY) */
|
|
493
|
+
#endif /* MLK_CONFIG_SERIAL_FIPS202_ONLY */
|
|
499
494
|
|
|
500
495
|
mlk_poly_cbd_eta1(r0, buf[0]);
|
|
501
496
|
mlk_poly_cbd_eta1(r1, buf[1]);
|
|
@@ -552,7 +552,7 @@ __contract__(
|
|
|
552
552
|
* @spec{Implements `SamplePolyCBD_{eta2} (PRF_{eta2} (sigma, N))`:
|
|
553
553
|
* @[FIPS203, Algorithm 8, SamplePolyCBD_eta] and @[FIPS203, Eq (4.3),
|
|
554
554
|
* PRF_eta]. `SamplePolyCBD_{eta2} (PRF_{eta2} (sigma, N))` appears in
|
|
555
|
-
* @[FIPS203, Algorithm 14, K-PKE.Encrypt,
|
|
555
|
+
* @[FIPS203, Algorithm 14, K-PKE.Encrypt, L17].}
|
|
556
556
|
*
|
|
557
557
|
* @param[out] r Output polynomial.
|
|
558
558
|
* @param[in] seed Input seed (of length MLKEM_SYMBYTES bytes).
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
#ifndef MLK_SYS_H
|
|
6
6
|
#define MLK_SYS_H
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/* This header must not depend on configuration options: configuration
|
|
9
|
+
* hooks may include it before all options are defined, and its include
|
|
10
|
+
* guard prevents re-evaluation. Evaluate options in common.h instead. */
|
|
11
11
|
|
|
12
12
|
/* Try to find endianness, if not forced through CFLAGS already */
|
|
13
13
|
#if !defined(MLK_SYS_LITTLE_ENDIAN) && !defined(MLK_SYS_BIG_ENDIAN)
|
|
@@ -57,8 +57,9 @@
|
|
|
57
57
|
#define MLK_SYS_AARCH64_EB
|
|
58
58
|
#endif
|
|
59
59
|
|
|
60
|
-
/* Check if
|
|
61
|
-
|
|
60
|
+
/* Check if the Armv8.1-M compilation target supports MVE. Armv8.1-M
|
|
61
|
+
* architecture support alone does not imply that MVE is enabled. */
|
|
62
|
+
#if defined(__ARM_FEATURE_MVE)
|
|
62
63
|
#define MLK_SYS_ARMV81M_MVE
|
|
63
64
|
#endif
|
|
64
65
|
|
|
@@ -68,20 +69,38 @@
|
|
|
68
69
|
#if defined(__AVX2__)
|
|
69
70
|
#define MLK_SYS_X86_64_AVX2
|
|
70
71
|
#endif
|
|
72
|
+
/* Check if the compilation target supports the AVX-512 extensions used by
|
|
73
|
+
* the AVX-512 backend: AVX-512F, AVX-512VL and AVX-512DQ. */
|
|
74
|
+
#if defined(__AVX512F__) && defined(__AVX512VL__) && defined(__AVX512DQ__)
|
|
75
|
+
#define MLK_SYS_X86_64_AVX512
|
|
76
|
+
#endif
|
|
71
77
|
#endif /* __x86_64__ || _M_X64 || _M_AMD64 */
|
|
72
78
|
|
|
73
79
|
#if defined(MLK_SYS_LITTLE_ENDIAN) && defined(__powerpc64__)
|
|
74
80
|
#define MLK_SYS_PPC64LE
|
|
75
81
|
#endif
|
|
76
82
|
|
|
83
|
+
/* Check if the PPC64LE compilation target supports the vector instructions
|
|
84
|
+
* used by the POWER8 backend: AltiVec/VMX, VSX, and POWER8 vector extensions
|
|
85
|
+
* (Power ISA 2.07). AltiVec predates POWER8; VSX was introduced in POWER7. */
|
|
86
|
+
#if defined(MLK_SYS_PPC64LE) && defined(__ALTIVEC__) && defined(__VSX__) && \
|
|
87
|
+
defined(__POWER8_VECTOR__)
|
|
88
|
+
#define MLK_SYS_PPC64LE_POWER8_VECTOR
|
|
89
|
+
#endif
|
|
90
|
+
|
|
77
91
|
#if defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64
|
|
78
92
|
#define MLK_SYS_RISCV64
|
|
79
93
|
#endif
|
|
80
94
|
|
|
95
|
+
/* check-magic: off */
|
|
96
|
+
/* The RVV backend requires v0.12 or later of the RVV intrinsics
|
|
97
|
+
* (__riscv_v_intrinsic >= 12000); older compilers such as gcc 13 fall
|
|
98
|
+
* back to C. */
|
|
81
99
|
#if defined(MLK_SYS_RISCV64) && defined(__riscv_vector) && \
|
|
82
|
-
defined(__riscv_v_intrinsic)
|
|
100
|
+
defined(__riscv_v_intrinsic) && __riscv_v_intrinsic >= 12000
|
|
83
101
|
#define MLK_SYS_RISCV64_RVV
|
|
84
102
|
#endif
|
|
103
|
+
/* check-magic: on */
|
|
85
104
|
|
|
86
105
|
#if defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 32
|
|
87
106
|
#define MLK_SYS_RISCV32
|
|
@@ -235,23 +254,6 @@
|
|
|
235
254
|
#endif
|
|
236
255
|
#endif /* MLK_SYS_X86_64 */
|
|
237
256
|
|
|
238
|
-
#if defined(MLK_CONFIG_CT_TESTING_ENABLED) && !defined(__ASSEMBLER__)
|
|
239
|
-
#include <valgrind/memcheck.h>
|
|
240
|
-
#define MLK_CT_TESTING_SECRET(ptr, len) \
|
|
241
|
-
VALGRIND_MAKE_MEM_UNDEFINED((ptr), (len))
|
|
242
|
-
#define MLK_CT_TESTING_DECLASSIFY(ptr, len) \
|
|
243
|
-
VALGRIND_MAKE_MEM_DEFINED((ptr), (len))
|
|
244
|
-
#else /* MLK_CONFIG_CT_TESTING_ENABLED && !__ASSEMBLER__ */
|
|
245
|
-
#define MLK_CT_TESTING_SECRET(ptr, len) \
|
|
246
|
-
do \
|
|
247
|
-
{ \
|
|
248
|
-
} while (0)
|
|
249
|
-
#define MLK_CT_TESTING_DECLASSIFY(ptr, len) \
|
|
250
|
-
do \
|
|
251
|
-
{ \
|
|
252
|
-
} while (0)
|
|
253
|
-
#endif /* !(MLK_CONFIG_CT_TESTING_ENABLED && !__ASSEMBLER__) */
|
|
254
|
-
|
|
255
257
|
#if defined(__GNUC__) || defined(__clang__)
|
|
256
258
|
#define MLK_MUST_CHECK_RETURN_VALUE __attribute__((warn_unused_result))
|
|
257
259
|
#else
|
|
@@ -289,32 +291,17 @@ typedef enum
|
|
|
289
291
|
{
|
|
290
292
|
/* x86_64 */
|
|
291
293
|
MLK_SYS_CAP_X86_64_AVX2,
|
|
294
|
+
/* AVX-512F, AVX-512VL and AVX-512DQ */
|
|
295
|
+
MLK_SYS_CAP_X86_64_AVX512,
|
|
292
296
|
/* AArch64 */
|
|
293
297
|
MLK_SYS_CAP_AARCH64_NEON,
|
|
294
298
|
MLK_SYS_CAP_AARCH64_SHA3,
|
|
295
299
|
/* Armv8.1-M */
|
|
296
|
-
MLK_SYS_CAP_ARMV81M_MVE
|
|
300
|
+
MLK_SYS_CAP_ARMV81M_MVE,
|
|
301
|
+
/* PowerPC64 */
|
|
302
|
+
/* AltiVec/VMX, VSX, and POWER8 vector extensions (Power ISA 2.07). */
|
|
303
|
+
MLK_SYS_CAP_PPC64LE_POWER8_VECTOR
|
|
297
304
|
} mlk_sys_cap;
|
|
298
|
-
|
|
299
|
-
#if !defined(MLK_CONFIG_CUSTOM_CAPABILITY_FUNC)
|
|
300
|
-
#include "cbmc.h"
|
|
301
|
-
|
|
302
|
-
MLK_MUST_CHECK_RETURN_VALUE
|
|
303
|
-
static MLK_INLINE int mlk_sys_check_capability(mlk_sys_cap cap)
|
|
304
|
-
__contract__(
|
|
305
|
-
ensures(return_value == 0 || return_value == 1)
|
|
306
|
-
)
|
|
307
|
-
{
|
|
308
|
-
/* By default, we rely on compile-time feature detection/specification:
|
|
309
|
-
* If a feature is enabled at compile-time, we assume it is supported by
|
|
310
|
-
* the host that the resulting library/binary will be built on.
|
|
311
|
-
* If this assumption is not true, you MUST overwrite this function.
|
|
312
|
-
* See the documentation of MLK_CONFIG_CUSTOM_CAPABILITY_FUNC in
|
|
313
|
-
* mlkem_native_config.h for more information. */
|
|
314
|
-
(void)cap;
|
|
315
|
-
return 1;
|
|
316
|
-
}
|
|
317
|
-
#endif /* !MLK_CONFIG_CUSTOM_CAPABILITY_FUNC */
|
|
318
305
|
#endif /* !__ASSEMBLER__ */
|
|
319
306
|
|
|
320
307
|
#endif /* !MLK_SYS_H */
|
|
@@ -320,7 +320,7 @@ __contract__(ensures(return_value == (cond ? a : b)))
|
|
|
320
320
|
* @spec{Used to securely compute conditional move in @[FIPS203, Algorithm
|
|
321
321
|
* 18 (ML-KEM.Decaps_Internal, L9-11].}
|
|
322
322
|
*
|
|
323
|
-
* @reference{`
|
|
323
|
+
* @reference{`verify()` in the reference implementation @[REF]. We return
|
|
324
324
|
* `uint8_t`, not `int`. We use an additional XOR-accumulator in the
|
|
325
325
|
* comparison loop which prevents early abort if the OR-accumulator is 0xFF.
|
|
326
326
|
* We use a value barrier to convert the OR-accumulator into a mask; the
|
data/lib/pq_crypto/internal.rb
CHANGED
|
@@ -29,5 +29,15 @@ module PQCrypto
|
|
|
29
29
|
def constant_time_equal?(left, right)
|
|
30
30
|
PQCrypto.__send__(:native_ct_equals, left, right)
|
|
31
31
|
end
|
|
32
|
+
|
|
33
|
+
def validate_algorithm_match!(expected, actual, algorithms:, family:)
|
|
34
|
+
unless algorithms.key?(expected)
|
|
35
|
+
raise SerializationError, "Unsupported #{family} algorithm: #{expected.inspect}"
|
|
36
|
+
end
|
|
37
|
+
return if expected == actual
|
|
38
|
+
|
|
39
|
+
raise SerializationError,
|
|
40
|
+
"Expected #{expected.inspect}, got #{actual.inspect} (SPKI key algorithm mismatch)"
|
|
41
|
+
end
|
|
32
42
|
end
|
|
33
43
|
end
|
data/lib/pq_crypto/kem.rb
CHANGED
|
@@ -90,13 +90,13 @@ module PQCrypto
|
|
|
90
90
|
|
|
91
91
|
def public_key_from_spki_der(der, algorithm: nil)
|
|
92
92
|
resolved_algorithm, bytes = SPKI.decode_der(der)
|
|
93
|
-
|
|
93
|
+
validate_spki_algorithm!(algorithm, resolved_algorithm) if algorithm
|
|
94
94
|
PublicKey.new(resolve_algorithm!(resolved_algorithm), bytes)
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
def public_key_from_spki_pem(pem, algorithm: nil)
|
|
98
98
|
resolved_algorithm, bytes = SPKI.decode_pem(pem)
|
|
99
|
-
|
|
99
|
+
validate_spki_algorithm!(algorithm, resolved_algorithm) if algorithm
|
|
100
100
|
PublicKey.new(resolve_algorithm!(resolved_algorithm), bytes)
|
|
101
101
|
end
|
|
102
102
|
|
|
@@ -141,14 +141,9 @@ module PQCrypto
|
|
|
141
141
|
NATIVE_DISPATCH.fetch(resolve_algorithm!(algorithm)).fetch(operation)
|
|
142
142
|
end
|
|
143
143
|
|
|
144
|
-
def
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
raise SerializationError,
|
|
149
|
-
"Expected #{expected.inspect}, got #{actual_algorithm.inspect} (SPKI key algorithm mismatch)"
|
|
150
|
-
rescue UnsupportedAlgorithmError => e
|
|
151
|
-
raise SerializationError, e.message
|
|
144
|
+
def validate_spki_algorithm!(expected_algorithm, actual_algorithm)
|
|
145
|
+
Internal.validate_algorithm_match!(expected_algorithm, actual_algorithm,
|
|
146
|
+
algorithms: DETAILS, family: "KEM")
|
|
152
147
|
end
|
|
153
148
|
end
|
|
154
149
|
|
data/lib/pq_crypto/pkcs8/der.rb
CHANGED
|
@@ -44,24 +44,39 @@ module PQCrypto
|
|
|
44
44
|
|
|
45
45
|
return [first, 1] if first < 0x80
|
|
46
46
|
|
|
47
|
+
length_octets = long_length_octet_count(first)
|
|
48
|
+
length = decode_long_length(der, offset, length_octets)
|
|
49
|
+
|
|
50
|
+
[length, 1 + length_octets]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def long_length_octet_count(first)
|
|
47
54
|
length_octets = first & 0x7f
|
|
48
55
|
raise SerializationError, "PKCS#8 DER indefinite length is not allowed" if length_octets.zero?
|
|
49
56
|
raise SerializationError, "PKCS#8 DER length is too large" if length_octets > 4
|
|
50
|
-
if offset + 1 + length_octets > der.bytesize
|
|
51
|
-
raise SerializationError, "PKCS#8 DER length exceeds available data"
|
|
52
|
-
end
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
byte = der.getbyte(offset + 1 + i)
|
|
57
|
-
length = (length << 8) | byte
|
|
58
|
-
end
|
|
58
|
+
length_octets
|
|
59
|
+
end
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
def decode_long_length(der, offset, length_octets)
|
|
62
|
+
ensure_long_length_available!(der, offset, length_octets)
|
|
63
|
+
length = length_octets.times.reduce(0) do |total, index|
|
|
64
|
+
(total << 8) | der.getbyte(offset + 1 + index)
|
|
62
65
|
end
|
|
66
|
+
ensure_minimal_long_length!(der, offset, length, length_octets)
|
|
67
|
+
length
|
|
68
|
+
end
|
|
63
69
|
|
|
64
|
-
|
|
70
|
+
def ensure_long_length_available!(der, offset, length_octets)
|
|
71
|
+
return if offset + 1 + length_octets <= der.bytesize
|
|
72
|
+
|
|
73
|
+
raise SerializationError, "PKCS#8 DER length exceeds available data"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def ensure_minimal_long_length!(der, offset, length, length_octets)
|
|
77
|
+
return unless length < 0x80 || (length_octets > 1 && der.getbyte(offset + 1).zero?)
|
|
78
|
+
|
|
79
|
+
raise SerializationError, "PKCS#8 DER length is not minimally encoded"
|
|
65
80
|
end
|
|
66
81
|
end
|
|
67
82
|
end
|
|
@@ -6,6 +6,8 @@ module PQCrypto
|
|
|
6
6
|
SEED_TAG = 0x80
|
|
7
7
|
EXPANDED_TAG = 0x04
|
|
8
8
|
BOTH_TAG = 0x30
|
|
9
|
+
COMPONENT_TAGS = { seed: SEED_TAG, expanded: EXPANDED_TAG }.freeze
|
|
10
|
+
COMPONENT_LABELS = { seed: "seed", expanded: "expandedKey" }.freeze
|
|
9
11
|
|
|
10
12
|
KEYPAIR_FROM_SEED_METHODS = {
|
|
11
13
|
ml_kem_512: :native_ml_kem_512_keypair_from_seed,
|
|
@@ -23,9 +25,9 @@ module PQCrypto
|
|
|
23
25
|
|
|
24
26
|
case format
|
|
25
27
|
when :seed
|
|
26
|
-
|
|
28
|
+
encode_component(algorithm, secret_material, format)
|
|
27
29
|
when :expanded
|
|
28
|
-
|
|
30
|
+
encode_component(algorithm, secret_material, format)
|
|
29
31
|
when :both
|
|
30
32
|
encode_both(algorithm, secret_material)
|
|
31
33
|
else
|
|
@@ -40,10 +42,10 @@ module PQCrypto
|
|
|
40
42
|
case tag
|
|
41
43
|
when SEED_TAG
|
|
42
44
|
ensure_format_supported!(algorithm, :seed)
|
|
43
|
-
|
|
45
|
+
decode_component(algorithm, choice_der, :seed)
|
|
44
46
|
when EXPANDED_TAG
|
|
45
47
|
ensure_format_supported!(algorithm, :expanded)
|
|
46
|
-
|
|
48
|
+
decode_component(algorithm, choice_der, :expanded)
|
|
47
49
|
when BOTH_TAG
|
|
48
50
|
ensure_format_supported!(algorithm, :both)
|
|
49
51
|
decode_both(algorithm, choice_der)
|
|
@@ -104,20 +106,13 @@ module PQCrypto
|
|
|
104
106
|
"Invalid #{algorithm.inspect} expanded private key length: expected #{expected}, got #{expanded.bytesize}"
|
|
105
107
|
end
|
|
106
108
|
|
|
107
|
-
def
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
def decode_component(algorithm, choice_der, format)
|
|
110
|
+
label = COMPONENT_LABELS.fetch(format)
|
|
111
|
+
_tag, bytes, next_offset = DER.decode_tlv(choice_der, 0, expected_tag: COMPONENT_TAGS.fetch(format), label: label)
|
|
112
|
+
raise SerializationError, "PKCS#8 #{label} contains trailing data" unless next_offset == choice_der.bytesize
|
|
110
113
|
|
|
111
|
-
|
|
112
|
-
[algorithm,
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def decode_expanded(algorithm, choice_der)
|
|
116
|
-
_tag, bytes, next_offset = DER.decode_tlv(choice_der, 0, expected_tag: EXPANDED_TAG, label: "expandedKey")
|
|
117
|
-
raise SerializationError, "PKCS#8 expandedKey contains trailing data" unless next_offset == choice_der.bytesize
|
|
118
|
-
|
|
119
|
-
validate_expanded_length!(algorithm, bytes)
|
|
120
|
-
[algorithm, :expanded, bytes]
|
|
114
|
+
validate_component_length!(algorithm, format, bytes)
|
|
115
|
+
[algorithm, format, bytes]
|
|
121
116
|
end
|
|
122
117
|
|
|
123
118
|
def decode_both(algorithm, choice_der)
|
|
@@ -135,18 +130,19 @@ module PQCrypto
|
|
|
135
130
|
[algorithm, :both, [seed_bytes, expanded_bytes]]
|
|
136
131
|
end
|
|
137
132
|
|
|
138
|
-
def
|
|
139
|
-
|
|
140
|
-
|
|
133
|
+
def encode_component(algorithm, secret_material, format)
|
|
134
|
+
bytes = Internal.binary_string(secret_material)
|
|
135
|
+
validate_component_length!(algorithm, format, bytes)
|
|
141
136
|
|
|
142
|
-
DER.encode_tlv(
|
|
137
|
+
DER.encode_tlv(COMPONENT_TAGS.fetch(format), bytes)
|
|
143
138
|
end
|
|
144
139
|
|
|
145
|
-
def
|
|
146
|
-
|
|
147
|
-
|
|
140
|
+
def validate_component_length!(algorithm, format, bytes)
|
|
141
|
+
expected = profile(algorithm).fetch(format == :seed ? :seed_bytes : :expanded_bytes)
|
|
142
|
+
return if bytes.bytesize == expected
|
|
148
143
|
|
|
149
|
-
|
|
144
|
+
raise SerializationError,
|
|
145
|
+
"Invalid #{algorithm.inspect} #{format} private key length: expected #{expected}, got #{bytes.bytesize}"
|
|
150
146
|
end
|
|
151
147
|
|
|
152
148
|
def encode_both(algorithm, secret_material)
|
data/lib/pq_crypto/signature.rb
CHANGED
|
@@ -80,13 +80,13 @@ module PQCrypto
|
|
|
80
80
|
|
|
81
81
|
def public_key_from_spki_der(der, algorithm: nil)
|
|
82
82
|
resolved_algorithm, bytes = SPKI.decode_der(der)
|
|
83
|
-
|
|
83
|
+
validate_spki_algorithm!(algorithm, resolved_algorithm) if algorithm
|
|
84
84
|
PublicKey.new(resolve_algorithm!(resolved_algorithm), bytes)
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
def public_key_from_spki_pem(pem, algorithm: nil)
|
|
88
88
|
resolved_algorithm, bytes = SPKI.decode_pem(pem)
|
|
89
|
-
|
|
89
|
+
validate_spki_algorithm!(algorithm, resolved_algorithm) if algorithm
|
|
90
90
|
PublicKey.new(resolve_algorithm!(resolved_algorithm), bytes)
|
|
91
91
|
end
|
|
92
92
|
|
|
@@ -147,14 +147,9 @@ module PQCrypto
|
|
|
147
147
|
NATIVE_DISPATCH.key?(algorithm) && NATIVE_DISPATCH.fetch(algorithm).key?(:check_secret_key)
|
|
148
148
|
end
|
|
149
149
|
|
|
150
|
-
def
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
raise SerializationError,
|
|
155
|
-
"Expected #{expected.inspect}, got #{actual_algorithm.inspect} (SPKI key algorithm mismatch)"
|
|
156
|
-
rescue UnsupportedAlgorithmError => e
|
|
157
|
-
raise SerializationError, e.message
|
|
150
|
+
def validate_spki_algorithm!(expected_algorithm, actual_algorithm)
|
|
151
|
+
Internal.validate_algorithm_match!(expected_algorithm, actual_algorithm,
|
|
152
|
+
algorithms: DETAILS, family: "signature")
|
|
158
153
|
end
|
|
159
154
|
|
|
160
155
|
def _streaming_sign(secret_key, io, chunk_size, context)
|
|
@@ -165,25 +160,12 @@ module PQCrypto
|
|
|
165
160
|
|
|
166
161
|
algorithm = secret_key.algorithm
|
|
167
162
|
sk_bytes = secret_key.__send__(:bytes_for_native)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
rescue ArgumentError => e
|
|
171
|
-
raise InvalidKeyError, e.message
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
builder = PQCrypto.__send__(:_native_mldsa_mu_builder_new, tr, context)
|
|
175
|
-
builder_consumed = false
|
|
176
|
-
mu = nil
|
|
177
|
-
begin
|
|
178
|
-
_drain_io_into_builder(io, builder, chunk_size)
|
|
179
|
-
mu = PQCrypto.__send__(:_native_mldsa_mu_builder_finalize, builder)
|
|
180
|
-
builder_consumed = true
|
|
163
|
+
tr = extract_tr(:_native_mldsa_extract_tr, algorithm, sk_bytes)
|
|
164
|
+
with_streaming_mu(tr, io, chunk_size, context) do |mu|
|
|
181
165
|
PQCrypto.__send__(:_native_mldsa_sign_mu, algorithm, mu, sk_bytes)
|
|
182
|
-
ensure
|
|
183
|
-
PQCrypto.__send__(:_native_mldsa_mu_builder_release, builder) unless builder_consumed
|
|
184
|
-
PQCrypto.secure_wipe(tr) if tr && !tr.frozen?
|
|
185
|
-
PQCrypto.secure_wipe(mu) if mu && !mu.frozen?
|
|
186
166
|
end
|
|
167
|
+
ensure
|
|
168
|
+
Internal.safe_wipe(tr) if defined?(tr)
|
|
187
169
|
end
|
|
188
170
|
|
|
189
171
|
def _streaming_verify(public_key, io, signature, chunk_size, context)
|
|
@@ -194,26 +176,32 @@ module PQCrypto
|
|
|
194
176
|
|
|
195
177
|
algorithm = public_key.algorithm
|
|
196
178
|
pk_bytes = public_key.__send__(:bytes_for_native)
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
179
|
+
sig_bytes = Internal.binary_string(signature)
|
|
180
|
+
tr = extract_tr(:_native_mldsa_compute_tr, algorithm, pk_bytes)
|
|
181
|
+
with_streaming_mu(tr, io, chunk_size, context) do |mu|
|
|
182
|
+
PQCrypto.__send__(:_native_mldsa_verify_mu, algorithm, mu, sig_bytes, pk_bytes)
|
|
201
183
|
end
|
|
184
|
+
ensure
|
|
185
|
+
Internal.safe_wipe(tr) if defined?(tr)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def extract_tr(native_method, algorithm, key_bytes)
|
|
189
|
+
PQCrypto.__send__(native_method, algorithm, key_bytes)
|
|
190
|
+
rescue ArgumentError => e
|
|
191
|
+
raise InvalidKeyError, e.message
|
|
192
|
+
end
|
|
202
193
|
|
|
203
|
-
|
|
204
|
-
|
|
194
|
+
def with_streaming_mu(tr, io, chunk_size, context)
|
|
195
|
+
builder = nil
|
|
205
196
|
mu = nil
|
|
206
|
-
sig_bytes = Internal.binary_string(signature)
|
|
207
197
|
begin
|
|
198
|
+
builder = PQCrypto.__send__(:_native_mldsa_mu_builder_new, tr, context)
|
|
208
199
|
_drain_io_into_builder(io, builder, chunk_size)
|
|
209
200
|
mu = PQCrypto.__send__(:_native_mldsa_mu_builder_finalize, builder)
|
|
210
|
-
|
|
211
|
-
PQCrypto.__send__(:_native_mldsa_verify_mu, algorithm, mu, sig_bytes, pk_bytes)
|
|
201
|
+
yield mu
|
|
212
202
|
ensure
|
|
213
|
-
PQCrypto.__send__(:_native_mldsa_mu_builder_release, builder)
|
|
214
|
-
|
|
215
|
-
PQCrypto.secure_wipe(tr) if tr && !tr.frozen?
|
|
216
|
-
PQCrypto.secure_wipe(mu) if mu && !mu.frozen?
|
|
203
|
+
PQCrypto.__send__(:_native_mldsa_mu_builder_release, builder) if builder
|
|
204
|
+
Internal.safe_wipe(mu) if defined?(mu)
|
|
217
205
|
end
|
|
218
206
|
end
|
|
219
207
|
|