pq_crypto 0.6.1 → 0.6.3
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 +10 -0
- data/SECURITY.md +7 -0
- data/ext/pqcrypto/pqcrypto_version.h +1 -1
- data/ext/pqcrypto/vendor/.vendored +7 -7
- data/ext/pqcrypto/vendor/mldsa-native/README.md +23 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/README.md +23 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +114 -58
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +498 -461
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +145 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +456 -422
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +47 -25
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +26 -14
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +56 -81
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +17 -24
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.c +33 -40
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +67 -87
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +19 -14
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +13 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +84 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +10 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +6 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +22 -15
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +376 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +204 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +259 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +1077 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +987 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +16 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +2 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +4 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +60 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +48 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +18 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +658 -582
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +5 -100
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +26 -25
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +334 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +355 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +8 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/{xkcp.h → keccak_f1600_x4_avx2.h} +11 -8
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +44 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +454 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +52 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +37 -28
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +213 -196
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +248 -64
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt_aarch64_asm.S +753 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +129 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +145 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +177 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt_aarch64_asm.S +653 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery_aarch64_asm.S +84 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_aarch64_asm.S +53 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_aarch64_asm.S +55 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_aarch64_asm.S +86 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_aarch64_asm.S +86 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_aarch64_asm.S +103 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_aarch64_asm.S +111 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_aarch64_asm.S +75 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_aarch64_asm.S +72 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +23 -11
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_aarch64_asm.S +189 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_aarch64_asm.S +137 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_aarch64_asm.S +130 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +520 -516
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +34 -33
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +202 -242
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +25 -17
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +112 -28
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt_avx2_asm.S +2311 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt_avx2_asm.S +2383 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack_avx2_asm.S +238 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4_avx2_asm.S +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5_avx2_asm.S +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7_avx2_asm.S +187 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_avx2_asm.S +130 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2_asm.S +190 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +9 -8
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +10 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +8 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +8 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +130 -129
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +109 -180
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +169 -150
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +56 -40
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +149 -164
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +52 -57
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +132 -167
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +57 -424
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +167 -474
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +308 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +653 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +22 -29
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +37 -43
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +511 -367
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +456 -417
- data/ext/pqcrypto/vendor/mlkem-native/README.md +6 -3
- data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +22 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +77 -36
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +135 -146
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +116 -72
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +351 -415
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +43 -20
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +16 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +57 -31
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +260 -349
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.h +17 -24
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +35 -37
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +43 -57
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +14 -15
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +5 -4
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +42 -6
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/fips202_native_aarch64.h +31 -20
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x1_scalar_asm.S → keccak_f1600_x1_scalar_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x1_v84a_asm.S → keccak_f1600_x1_v84a_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x2_v84a_asm.S → keccak_f1600_x2_v84a_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x4_v8a_scalar_hybrid_asm.S → keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S → keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +10 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +2 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +1 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +4 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +1 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/fips202_native_armv81m.h +2 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +55 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +26 -25
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +58 -14
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +57 -16
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +2 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +2 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +10 -7
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/{keccak_f1600_x4_avx2.S → keccak_f1600_x4_avx2_asm.S} +13 -11
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +12 -11
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +167 -136
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +75 -68
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +135 -157
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +15 -13
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +143 -135
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +52 -46
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{intt.S → intt_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{ntt.S → ntt_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_mulcache_compute_asm.S → poly_mulcache_compute_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_reduce_asm.S → poly_reduce_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tobytes_asm.S → poly_tobytes_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tomont_asm.S → poly_tomont_aarch64_asm.S} +10 -12
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_asm_k2.S → polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_asm_k3.S → polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_asm_k4.S → polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S} +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{rej_uniform_asm.S → rej_uniform_aarch64_asm.S} +12 -12
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_table.c +514 -513
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +254 -253
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +6 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/README.md +6 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/meta.h +77 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/arith_native_ppc64le.h +24 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/consts.c +299 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/consts.h +34 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/intt_ppc_asm.S +3222 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/ntt_ppc_asm.S +1651 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/poly_tomont_ppc_asm.S +294 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/reduce_ppc_asm.S +710 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +5 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +18 -16
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +19 -24
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +53 -65
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +20 -20
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +106 -88
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +45 -35
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.c +1 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.h +1 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{intt.S → intt_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntt.S → ntt_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttfrombytes.S → nttfrombytes_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntttobytes.S → ntttobytes_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttunpack.S → nttunpack_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d10.S → poly_compress_d10_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d11.S → poly_compress_d11_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d4.S → poly_compress_d4_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d5.S → poly_compress_d5_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d10.S → poly_decompress_d10_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d11.S → poly_decompress_d11_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d4.S → poly_decompress_d4_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d5.S → poly_decompress_d5_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{mulcache_compute.S → poly_mulcache_compute_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_asm_k2.S → polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_asm_k3.S → polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_asm_k4.S → polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{reduce.S → reduce_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{rej_uniform_asm.S → rej_uniform_avx2_asm.S} +9 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_table.c +514 -513
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{tomont.S → tomont_avx2_asm.S} +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +61 -57
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +89 -116
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +31 -32
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +226 -301
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/randombytes.h +21 -29
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +68 -63
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +37 -48
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +44 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +141 -159
- data/lib/pq_crypto/version.rb +1 -1
- data/script/vendor_libs.rb +6 -6
- metadata +86 -71
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +0 -376
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +0 -204
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +0 -259
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +0 -1077
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +0 -987
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +0 -488
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +0 -16
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +0 -753
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +0 -129
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +0 -145
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +0 -177
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +0 -653
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +0 -79
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +0 -53
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +0 -55
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +0 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +0 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +0 -102
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +0 -110
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +0 -72
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +0 -69
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +0 -189
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +0 -135
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +0 -128
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +0 -2311
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +0 -2383
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +0 -239
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +0 -131
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +0 -139
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +0 -155
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +0 -187
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +0 -61
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
#include "randombytes.h"
|
|
24
24
|
#include "sampling.h"
|
|
25
25
|
#include "symmetric.h"
|
|
26
|
+
#include "verify.h"
|
|
26
27
|
|
|
27
28
|
/* Parameter set namespacing
|
|
28
29
|
* This is to facilitate building multiple instances
|
|
@@ -39,24 +40,21 @@
|
|
|
39
40
|
MLK_ADD_PARAM_SET(mlk_polyvec_permute_bitrev_to_custom)
|
|
40
41
|
#define mlk_polymat_permute_bitrev_to_custom \
|
|
41
42
|
MLK_ADD_PARAM_SET(mlk_polymat_permute_bitrev_to_custom)
|
|
43
|
+
#define mlk_keypair_getnoise_eta1 MLK_ADD_PARAM_SET(mlk_keypair_getnoise_eta1)
|
|
44
|
+
#define mlk_enc_getnoise_eta1_eta2 MLK_ADD_PARAM_SET(mlk_enc_getnoise_eta1_eta2)
|
|
42
45
|
/* End of parameter set namespacing */
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
*
|
|
47
|
+
/**
|
|
48
|
+
* Serialize the public key as the concatenation of the serialized vector of
|
|
49
|
+
* polynomials pk and the public seed used to generate the matrix A.
|
|
46
50
|
*
|
|
47
|
-
*
|
|
48
|
-
* serialized vector of polynomials pk
|
|
49
|
-
* and the public seed used to generate the matrix A.
|
|
51
|
+
* @spec{Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen), L19].}
|
|
50
52
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
|
|
56
|
-
* Specification:
|
|
57
|
-
* Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen), L19]
|
|
58
|
-
*
|
|
59
|
-
**************************************************/
|
|
53
|
+
* @param[out] r Output serialized public key.
|
|
54
|
+
* @param[in] pk Input public-key polyvec. Must have coefficients within
|
|
55
|
+
* [0,..,MLKEM_Q-1].
|
|
56
|
+
* @param[in] seed Input public seed.
|
|
57
|
+
*/
|
|
60
58
|
static void mlk_pack_pk(uint8_t r[MLKEM_INDCPA_PUBLICKEYBYTES],
|
|
61
59
|
const mlk_polyvec *pk,
|
|
62
60
|
const uint8_t seed[MLKEM_SYMBYTES])
|
|
@@ -66,22 +64,17 @@ static void mlk_pack_pk(uint8_t r[MLKEM_INDCPA_PUBLICKEYBYTES],
|
|
|
66
64
|
mlk_memcpy(r + MLKEM_POLYVECBYTES, seed, MLKEM_SYMBYTES);
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
|
|
70
|
-
*
|
|
67
|
+
/**
|
|
68
|
+
* De-serialize public key from a byte array; approximate inverse of
|
|
69
|
+
* mlk_pack_pk.
|
|
71
70
|
*
|
|
72
|
-
*
|
|
73
|
-
* approximate inverse of mlk_pack_pk
|
|
71
|
+
* @spec{Implements @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L2-3].}
|
|
74
72
|
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
|
|
80
|
-
*
|
|
81
|
-
* Specification:
|
|
82
|
-
* Implements @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L2-3]
|
|
83
|
-
*
|
|
84
|
-
**************************************************/
|
|
73
|
+
* @param[out] pk Output public-key polynomial vector. Coefficients
|
|
74
|
+
* will be normalized to [0,1,..,MLKEM_Q-1].
|
|
75
|
+
* @param[out] seed Output seed to generate matrix A.
|
|
76
|
+
* @param[in] packedpk Input serialized public key.
|
|
77
|
+
*/
|
|
85
78
|
static void mlk_unpack_pk(mlk_polyvec *pk, uint8_t seed[MLKEM_SYMBYTES],
|
|
86
79
|
const uint8_t packedpk[MLKEM_INDCPA_PUBLICKEYBYTES])
|
|
87
80
|
{
|
|
@@ -94,19 +87,14 @@ static void mlk_unpack_pk(mlk_polyvec *pk, uint8_t seed[MLKEM_SYMBYTES],
|
|
|
94
87
|
* work with the easily provable bound by MLKEM_UINT12_LIMIT. */
|
|
95
88
|
}
|
|
96
89
|
|
|
97
|
-
|
|
98
|
-
*
|
|
90
|
+
/**
|
|
91
|
+
* Serialize the secret key.
|
|
99
92
|
*
|
|
100
|
-
*
|
|
93
|
+
* @spec{Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen), L20].}
|
|
101
94
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
|
|
105
|
-
*
|
|
106
|
-
* Specification:
|
|
107
|
-
* Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen), L20]
|
|
108
|
-
*
|
|
109
|
-
**************************************************/
|
|
95
|
+
* @param[out] r Output serialized secret key.
|
|
96
|
+
* @param[in] sk Input vector of polynomials (secret key).
|
|
97
|
+
*/
|
|
110
98
|
static void mlk_pack_sk(uint8_t r[MLKEM_INDCPA_SECRETKEYBYTES],
|
|
111
99
|
const mlk_polyvec *sk)
|
|
112
100
|
{
|
|
@@ -114,41 +102,31 @@ static void mlk_pack_sk(uint8_t r[MLKEM_INDCPA_SECRETKEYBYTES],
|
|
|
114
102
|
mlk_polyvec_tobytes(r, sk);
|
|
115
103
|
}
|
|
116
104
|
|
|
117
|
-
|
|
118
|
-
*
|
|
105
|
+
/**
|
|
106
|
+
* De-serialize the secret key; inverse of mlk_pack_sk.
|
|
119
107
|
*
|
|
120
|
-
*
|
|
108
|
+
* @spec{Implements @[FIPS203, Algorithm 15 (K-PKE.Decrypt), L5].}
|
|
121
109
|
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
|
|
125
|
-
* key
|
|
126
|
-
*
|
|
127
|
-
* Specification:
|
|
128
|
-
* Implements @[FIPS203, Algorithm 15 (K-PKE.Decrypt), L5]
|
|
129
|
-
*
|
|
130
|
-
**************************************************/
|
|
110
|
+
* @param[out] sk Output vector of polynomials (secret key).
|
|
111
|
+
* @param[in] packedsk Input serialized secret key.
|
|
112
|
+
*/
|
|
131
113
|
static void mlk_unpack_sk(mlk_polyvec *sk,
|
|
132
114
|
const uint8_t packedsk[MLKEM_INDCPA_SECRETKEYBYTES])
|
|
133
115
|
{
|
|
134
116
|
mlk_polyvec_frombytes(sk, packedsk);
|
|
135
117
|
}
|
|
136
118
|
|
|
137
|
-
|
|
138
|
-
*
|
|
119
|
+
/**
|
|
120
|
+
* Serialize the ciphertext as the concatenation of the compressed and
|
|
121
|
+
* serialized vector of polynomials b and the compressed and serialized
|
|
122
|
+
* polynomial v.
|
|
139
123
|
*
|
|
140
|
-
*
|
|
141
|
-
* compressed and serialized vector of polynomials b
|
|
142
|
-
* and the compressed and serialized polynomial v
|
|
124
|
+
* @spec{Implements @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L22-23].}
|
|
143
125
|
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
|
|
148
|
-
* Specification:
|
|
149
|
-
* Implements @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L22-23]
|
|
150
|
-
*
|
|
151
|
-
**************************************************/
|
|
126
|
+
* @param[out] r Output serialized ciphertext.
|
|
127
|
+
* @param[in] b Input vector of polynomials b.
|
|
128
|
+
* @param[in] v Input polynomial v.
|
|
129
|
+
*/
|
|
152
130
|
static void mlk_pack_ciphertext(uint8_t r[MLKEM_INDCPA_BYTES],
|
|
153
131
|
const mlk_polyvec *b, mlk_poly *v)
|
|
154
132
|
{
|
|
@@ -156,20 +134,16 @@ static void mlk_pack_ciphertext(uint8_t r[MLKEM_INDCPA_BYTES],
|
|
|
156
134
|
mlk_poly_compress_dv(r + MLKEM_POLYVECCOMPRESSEDBYTES_DU, v);
|
|
157
135
|
}
|
|
158
136
|
|
|
159
|
-
|
|
160
|
-
*
|
|
137
|
+
/**
|
|
138
|
+
* De-serialize and decompress ciphertext from a byte array; approximate
|
|
139
|
+
* inverse of mlk_pack_ciphertext.
|
|
161
140
|
*
|
|
162
|
-
*
|
|
163
|
-
* approximate inverse of mlk_pack_ciphertext
|
|
141
|
+
* @spec{Implements @[FIPS203, Algorithm 15 (K-PKE.Decrypt), L1-4].}
|
|
164
142
|
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
|
|
169
|
-
* Specification:
|
|
170
|
-
* Implements @[FIPS203, Algorithm 15 (K-PKE.Decrypt), L1-4]
|
|
171
|
-
*
|
|
172
|
-
**************************************************/
|
|
143
|
+
* @param[out] b Output vector of polynomials b.
|
|
144
|
+
* @param[out] v Output polynomial v.
|
|
145
|
+
* @param[in] c Input serialized ciphertext.
|
|
146
|
+
*/
|
|
173
147
|
static void mlk_unpack_ciphertext(mlk_polyvec *b, mlk_poly *v,
|
|
174
148
|
const uint8_t c[MLKEM_INDCPA_BYTES])
|
|
175
149
|
{
|
|
@@ -201,7 +175,8 @@ __contract__(
|
|
|
201
175
|
assigns(i, memory_slice(v, sizeof(mlk_polyvec)))
|
|
202
176
|
invariant(i <= MLKEM_K)
|
|
203
177
|
invariant(forall(x, 0, MLKEM_K,
|
|
204
|
-
array_bound(v->vec[x].coeffs, 0, MLKEM_N, 0, MLKEM_Q)))
|
|
178
|
+
array_bound(v->vec[x].coeffs, 0, MLKEM_N, 0, MLKEM_Q)))
|
|
179
|
+
decreases(MLKEM_K - i))
|
|
205
180
|
{
|
|
206
181
|
mlk_poly_permute_bitrev_to_custom(v->vec[i].coeffs);
|
|
207
182
|
}
|
|
@@ -228,7 +203,8 @@ __contract__(
|
|
|
228
203
|
assigns(i, memory_slice(a, sizeof(mlk_polymat)))
|
|
229
204
|
invariant(i <= MLKEM_K)
|
|
230
205
|
invariant(forall(x, 0, MLKEM_K, forall(y, 0, MLKEM_K,
|
|
231
|
-
array_bound(a->vec[x].vec[y].coeffs, 0, MLKEM_N, 0, MLKEM_Q))))
|
|
206
|
+
array_bound(a->vec[x].vec[y].coeffs, 0, MLKEM_N, 0, MLKEM_Q))))
|
|
207
|
+
decreases(MLKEM_K - i))
|
|
232
208
|
{
|
|
233
209
|
mlk_polyvec_permute_bitrev_to_custom(&a->vec[i]);
|
|
234
210
|
}
|
|
@@ -323,23 +299,18 @@ void mlk_gen_matrix(mlk_polymat *a, const uint8_t seed[MLKEM_SYMBYTES],
|
|
|
323
299
|
mlk_zeroize(seed_ext, sizeof(seed_ext));
|
|
324
300
|
}
|
|
325
301
|
|
|
326
|
-
|
|
327
|
-
*
|
|
302
|
+
/**
|
|
303
|
+
* Compute matrix-vector product in NTT domain, via Montgomery multiplication.
|
|
328
304
|
*
|
|
329
|
-
*
|
|
330
|
-
* via Montgomery multiplication.
|
|
305
|
+
* @spec{Implements @[FIPS203, Section 2.4.7, Eq (2.12), (2.13)].}
|
|
331
306
|
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
|
|
339
|
-
*
|
|
340
|
-
* Specification: Implements @[FIPS203, Section 2.4.7, Eq (2.12), (2.13)]
|
|
341
|
-
*
|
|
342
|
-
**************************************************/
|
|
307
|
+
* @param[out] out Output polynomial vector.
|
|
308
|
+
* @param[in] a Input matrix. Must be in NTT domain and have coefficients
|
|
309
|
+
* of absolute value < 4096.
|
|
310
|
+
* @param[in] v Input polynomial vector. Must be in NTT domain.
|
|
311
|
+
* @param[in] vc Mulcache for @p v, computed via
|
|
312
|
+
* mlk_polyvec_mulcache_compute().
|
|
313
|
+
*/
|
|
343
314
|
static void mlk_matvec_mul(mlk_polyvec *out, const mlk_polymat *a,
|
|
344
315
|
const mlk_polyvec *v, const mlk_polyvec_mulcache *vc)
|
|
345
316
|
__contract__(
|
|
@@ -356,15 +327,111 @@ __contract__(
|
|
|
356
327
|
for (i = 0; i < MLKEM_K; i++)
|
|
357
328
|
__loop__(
|
|
358
329
|
assigns(i, memory_slice(out, sizeof(mlk_polyvec)))
|
|
359
|
-
invariant(i <= MLKEM_K)
|
|
330
|
+
invariant(i <= MLKEM_K)
|
|
331
|
+
decreases(MLKEM_K - i))
|
|
360
332
|
{
|
|
361
333
|
mlk_polyvec_basemul_acc_montgomery_cached(&out->vec[i], &a->vec[i], v, vc);
|
|
362
334
|
}
|
|
363
335
|
}
|
|
364
336
|
|
|
337
|
+
/**
|
|
338
|
+
* Compute and fill the pv and e polyvec structures needed by
|
|
339
|
+
* mlk_keypair_derand(). Uses x4-batched versions of `poly_getnoise` to
|
|
340
|
+
* leverage batched Keccak-f1600.
|
|
341
|
+
*
|
|
342
|
+
* @spec{Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen)] steps 8-15.}
|
|
343
|
+
*
|
|
344
|
+
* @param[out] pv Output polynomial vector.
|
|
345
|
+
* @param[out] e Output polynomial vector.
|
|
346
|
+
* @param[in] seed Seed bytes for sampling.
|
|
347
|
+
*/
|
|
348
|
+
static void mlk_keypair_getnoise_eta1(mlk_polyvec *pv, mlk_polyvec *e,
|
|
349
|
+
const uint8_t seed[MLKEM_SYMBYTES])
|
|
350
|
+
__contract__(
|
|
351
|
+
requires(memory_no_alias(pv, sizeof(mlk_polyvec)))
|
|
352
|
+
requires(memory_no_alias(e, sizeof(mlk_polyvec)))
|
|
353
|
+
requires(memory_no_alias(seed, MLKEM_SYMBYTES))
|
|
354
|
+
assigns(memory_slice(pv, sizeof(mlk_polyvec)))
|
|
355
|
+
assigns(memory_slice(e, sizeof(mlk_polyvec)))
|
|
356
|
+
ensures(forall(k0, 0, MLKEM_K, array_abs_bound(pv->vec[k0].coeffs, 0, MLKEM_N, MLKEM_ETA1 + 1)))
|
|
357
|
+
ensures(forall(k1, 0, MLKEM_K, array_abs_bound(e->vec[k1].coeffs, 0, MLKEM_N, MLKEM_ETA1 + 1)))
|
|
358
|
+
)
|
|
359
|
+
{
|
|
360
|
+
#if MLKEM_K == 2
|
|
361
|
+
mlk_poly_getnoise_eta1_4x(&pv->vec[0], &pv->vec[1], /* Fill elements of pv */
|
|
362
|
+
&e->vec[0], &e->vec[1], /* and two elements of e */
|
|
363
|
+
seed, 0, 1, 2, 3);
|
|
364
|
+
#elif MLKEM_K == 3
|
|
365
|
+
/*
|
|
366
|
+
* Only the first three output buffers are needed, so we pass NULL as
|
|
367
|
+
* the fourth parameter, and 0xFF as its dummy nonce.
|
|
368
|
+
*/
|
|
369
|
+
mlk_poly_getnoise_eta1_4x(&pv->vec[0], &pv->vec[1], &pv->vec[2], NULL, seed,
|
|
370
|
+
0, 1, 2, 0xFF);
|
|
371
|
+
/* Same here */
|
|
372
|
+
mlk_poly_getnoise_eta1_4x(&e->vec[0], &e->vec[1], &e->vec[2], NULL, seed, 3,
|
|
373
|
+
4, 5, 0xFF);
|
|
374
|
+
#elif MLKEM_K == 4
|
|
375
|
+
mlk_poly_getnoise_eta1_4x(&pv->vec[0], &pv->vec[1], &pv->vec[2], &pv->vec[3],
|
|
376
|
+
seed, 0, 1, 2, 3);
|
|
377
|
+
mlk_poly_getnoise_eta1_4x(&e->vec[0], &e->vec[1], &e->vec[2], &e->vec[3],
|
|
378
|
+
seed, 4, 5, 6, 7);
|
|
379
|
+
#endif /* MLKEM_K == 4 */
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Compute and fill the sp, ep, and epp polynomial structures needed by
|
|
384
|
+
* mlk_indcpa_enc(). Uses x4-batched versions of `poly_getnoise` to leverage
|
|
385
|
+
* batched Keccak-f1600.
|
|
386
|
+
*
|
|
387
|
+
* @spec{Implements @[FIPS203, Algorithm 14 (K-PKE.Encrypt)] steps 9-16.}
|
|
388
|
+
*
|
|
389
|
+
* @param[out] sp Output polynomial vector.
|
|
390
|
+
* @param[out] ep Output polynomial vector.
|
|
391
|
+
* @param[out] epp Output polynomial.
|
|
392
|
+
* @param[in] coins Seed bytes for sampling.
|
|
393
|
+
*/
|
|
394
|
+
static void mlk_enc_getnoise_eta1_eta2(mlk_polyvec *sp, mlk_polyvec *ep,
|
|
395
|
+
mlk_poly *epp,
|
|
396
|
+
const uint8_t coins[MLKEM_SYMBYTES])
|
|
397
|
+
__contract__(
|
|
398
|
+
requires(memory_no_alias(sp, sizeof(mlk_polyvec)))
|
|
399
|
+
requires(memory_no_alias(ep, sizeof(mlk_polyvec)))
|
|
400
|
+
requires(memory_no_alias(epp, sizeof(mlk_poly)))
|
|
401
|
+
requires(memory_no_alias(coins, MLKEM_SYMBYTES))
|
|
402
|
+
assigns(memory_slice(sp, sizeof(mlk_polyvec)))
|
|
403
|
+
assigns(memory_slice(ep, sizeof(mlk_polyvec)))
|
|
404
|
+
assigns(memory_slice(epp, sizeof(mlk_poly)))
|
|
405
|
+
ensures(forall(k0, 0, MLKEM_K, array_abs_bound(sp->vec[k0].coeffs, 0, MLKEM_N, MLKEM_ETA1 + 1)))
|
|
406
|
+
ensures(forall(k1, 0, MLKEM_K, array_abs_bound(ep->vec[k1].coeffs, 0, MLKEM_N, MLKEM_ETA2 + 1)))
|
|
407
|
+
ensures(array_abs_bound(epp->coeffs, 0, MLKEM_N, MLKEM_ETA2 + 1))
|
|
408
|
+
)
|
|
409
|
+
{
|
|
410
|
+
#if MLKEM_K == 2
|
|
411
|
+
mlk_poly_getnoise_eta1122_4x(&sp->vec[0], &sp->vec[1], &ep->vec[0],
|
|
412
|
+
&ep->vec[1], coins, 0, 1, 2, 3);
|
|
413
|
+
mlk_poly_getnoise_eta2(epp, coins, 4);
|
|
414
|
+
#elif MLKEM_K == 3
|
|
415
|
+
/*
|
|
416
|
+
* In this call, only the first three output buffers are needed,
|
|
417
|
+
* so we pass NULL as the fourth parameter, and 0xFF as its dummy nonce.
|
|
418
|
+
*/
|
|
419
|
+
mlk_poly_getnoise_eta1_4x(&sp->vec[0], &sp->vec[1], &sp->vec[2], NULL, coins,
|
|
420
|
+
0, 1, 2, 0xFF /* irrelevant */);
|
|
421
|
+
/* The fourth output buffer in this call _is_ used. */
|
|
422
|
+
mlk_poly_getnoise_eta2_4x(&ep->vec[0], &ep->vec[1], &ep->vec[2], epp, coins,
|
|
423
|
+
3, 4, 5, 6);
|
|
424
|
+
#elif MLKEM_K == 4
|
|
425
|
+
mlk_poly_getnoise_eta1_4x(&sp->vec[0], &sp->vec[1], &sp->vec[2], &sp->vec[3],
|
|
426
|
+
coins, 0, 1, 2, 3);
|
|
427
|
+
mlk_poly_getnoise_eta2_4x(&ep->vec[0], &ep->vec[1], &ep->vec[2], &ep->vec[3],
|
|
428
|
+
coins, 4, 5, 6, 7);
|
|
429
|
+
mlk_poly_getnoise_eta2(epp, coins, 8);
|
|
430
|
+
#endif /* MLKEM_K == 4 */
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
|
|
365
434
|
/* Reference: `indcpa_keypair_derand()` in the reference implementation @[REF].
|
|
366
|
-
* - We use x4-batched versions of `poly_getnoise` to leverage
|
|
367
|
-
* batched x4-batched Keccak-f1600.
|
|
368
435
|
* - We use a different implementation of `gen_matrix()` which
|
|
369
436
|
* uses x4-batched Keccak-f1600 (see `mlk_gen_matrix()` above).
|
|
370
437
|
* - We use a mulcache to speed up matrix-vector multiplication.
|
|
@@ -413,25 +480,7 @@ int mlk_indcpa_keypair_derand(uint8_t pk[MLKEM_INDCPA_PUBLICKEYBYTES],
|
|
|
413
480
|
|
|
414
481
|
mlk_gen_matrix(a, publicseed, 0 /* no transpose */);
|
|
415
482
|
|
|
416
|
-
|
|
417
|
-
mlk_poly_getnoise_eta1_4x(&skpv->vec[0], &skpv->vec[1], &e->vec[0],
|
|
418
|
-
&e->vec[1], noiseseed, 0, 1, 2, 3);
|
|
419
|
-
#elif MLKEM_K == 3
|
|
420
|
-
/*
|
|
421
|
-
* Only the first three output buffers are needed.
|
|
422
|
-
* The laster parameter is a dummy that's overwritten later.
|
|
423
|
-
*/
|
|
424
|
-
mlk_poly_getnoise_eta1_4x(&skpv->vec[0], &skpv->vec[1], &skpv->vec[2], NULL,
|
|
425
|
-
noiseseed, 0, 1, 2, 0xFF /* irrelevant */);
|
|
426
|
-
/* Same here */
|
|
427
|
-
mlk_poly_getnoise_eta1_4x(&e->vec[0], &e->vec[1], &e->vec[2], NULL, noiseseed,
|
|
428
|
-
3, 4, 5, 0xFF /* irrelevant */);
|
|
429
|
-
#elif MLKEM_K == 4
|
|
430
|
-
mlk_poly_getnoise_eta1_4x(&skpv->vec[0], &skpv->vec[1], &skpv->vec[2],
|
|
431
|
-
&skpv->vec[3], noiseseed, 0, 1, 2, 3);
|
|
432
|
-
mlk_poly_getnoise_eta1_4x(&e->vec[0], &e->vec[1], &e->vec[2], &e->vec[3],
|
|
433
|
-
noiseseed, 4, 5, 6, 7);
|
|
434
|
-
#endif /* MLKEM_K == 4 */
|
|
483
|
+
mlk_keypair_getnoise_eta1(skpv, e, noiseseed);
|
|
435
484
|
|
|
436
485
|
mlk_polyvec_ntt(skpv);
|
|
437
486
|
mlk_polyvec_ntt(e);
|
|
@@ -507,27 +556,7 @@ int mlk_indcpa_enc(uint8_t c[MLKEM_INDCPA_BYTES],
|
|
|
507
556
|
|
|
508
557
|
mlk_gen_matrix(at, seed, 1 /* transpose */);
|
|
509
558
|
|
|
510
|
-
|
|
511
|
-
mlk_poly_getnoise_eta1122_4x(&sp->vec[0], &sp->vec[1], &ep->vec[0],
|
|
512
|
-
&ep->vec[1], coins, 0, 1, 2, 3);
|
|
513
|
-
mlk_poly_getnoise_eta2(epp, coins, 4);
|
|
514
|
-
#elif MLKEM_K == 3
|
|
515
|
-
/*
|
|
516
|
-
* In this call, only the first three output buffers are needed.
|
|
517
|
-
* The last parameter is a dummy that's overwritten later.
|
|
518
|
-
*/
|
|
519
|
-
mlk_poly_getnoise_eta1_4x(&sp->vec[0], &sp->vec[1], &sp->vec[2], NULL, coins,
|
|
520
|
-
0, 1, 2, 0xFF /* irrelevant */);
|
|
521
|
-
/* The fourth output buffer in this call _is_ used. */
|
|
522
|
-
mlk_poly_getnoise_eta2_4x(&ep->vec[0], &ep->vec[1], &ep->vec[2], epp, coins,
|
|
523
|
-
3, 4, 5, 6);
|
|
524
|
-
#elif MLKEM_K == 4
|
|
525
|
-
mlk_poly_getnoise_eta1_4x(&sp->vec[0], &sp->vec[1], &sp->vec[2], &sp->vec[3],
|
|
526
|
-
coins, 0, 1, 2, 3);
|
|
527
|
-
mlk_poly_getnoise_eta2_4x(&ep->vec[0], &ep->vec[1], &ep->vec[2], &ep->vec[3],
|
|
528
|
-
coins, 4, 5, 6, 7);
|
|
529
|
-
mlk_poly_getnoise_eta2(epp, coins, 8);
|
|
530
|
-
#endif /* MLKEM_K == 4 */
|
|
559
|
+
mlk_enc_getnoise_eta1_eta2(sp, ep, epp, coins);
|
|
531
560
|
|
|
532
561
|
mlk_polyvec_ntt(sp);
|
|
533
562
|
|
|
@@ -620,3 +649,5 @@ cleanup:
|
|
|
620
649
|
#undef mlk_matvec_mul
|
|
621
650
|
#undef mlk_polyvec_permute_bitrev_to_custom
|
|
622
651
|
#undef mlk_polymat_permute_bitrev_to_custom
|
|
652
|
+
#undef mlk_keypair_getnoise_eta1
|
|
653
|
+
#undef mlk_enc_getnoise_eta1_eta2
|
|
@@ -20,23 +20,19 @@
|
|
|
20
20
|
#include "poly_k.h"
|
|
21
21
|
|
|
22
22
|
#define mlk_gen_matrix MLK_NAMESPACE_K(gen_matrix)
|
|
23
|
-
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
* and @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L4-8].
|
|
37
|
-
* The `transposed` parameter only affects internal presentation.
|
|
38
|
-
*
|
|
39
|
-
**************************************************/
|
|
23
|
+
/**
|
|
24
|
+
* Deterministically generate matrix A (or the transpose of A) from a seed.
|
|
25
|
+
* Entries of the matrix are polynomials that look uniformly random.
|
|
26
|
+
* Performs rejection sampling on the output of an XOF.
|
|
27
|
+
*
|
|
28
|
+
* @spec{Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen), L3-7] and
|
|
29
|
+
* @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L4-8]. The @p transposed
|
|
30
|
+
* parameter only affects internal presentation.}
|
|
31
|
+
*
|
|
32
|
+
* @param[out] a Output matrix A.
|
|
33
|
+
* @param[in] seed Input seed.
|
|
34
|
+
* @param transposed Boolean deciding whether A or A^T is generated.
|
|
35
|
+
*/
|
|
40
36
|
MLK_INTERNAL_API
|
|
41
37
|
void mlk_gen_matrix(mlk_polymat *a, const uint8_t seed[MLKEM_SYMBYTES],
|
|
42
38
|
int transposed)
|
|
@@ -51,22 +47,27 @@ __contract__(
|
|
|
51
47
|
|
|
52
48
|
#define mlk_indcpa_keypair_derand \
|
|
53
49
|
MLK_NAMESPACE_K(indcpa_keypair_derand) MLK_CONTEXT_PARAMETERS_3
|
|
54
|
-
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Generate public and private key for the CPA-secure public-key encryption
|
|
52
|
+
* scheme underlying ML-KEM.
|
|
53
|
+
*
|
|
54
|
+
* @spec{Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen)].}
|
|
55
|
+
*
|
|
56
|
+
* @param[out] pk Output public key
|
|
57
|
+
* (length MLKEM_INDCPA_PUBLICKEYBYTES bytes).
|
|
58
|
+
* @param[out] sk Output private key
|
|
59
|
+
* (length MLKEM_INDCPA_SECRETKEYBYTES bytes).
|
|
60
|
+
* @param[in] coins Input randomness (length MLKEM_SYMBYTES bytes).
|
|
61
|
+
* @param context Application context. Only present when
|
|
62
|
+
* MLK_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
63
|
+
* MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
64
|
+
*
|
|
65
|
+
* @retval 0 Success.
|
|
66
|
+
* @retval MLK_ERR_FAIL MLK_CONFIG_KEYGEN_PCT enabled and PCT failed.
|
|
67
|
+
* @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and
|
|
68
|
+
* MLK_CUSTOM_ALLOC returned NULL.
|
|
69
|
+
* @retval MLK_ERR_RNG_FAIL Random number generation failed.
|
|
70
|
+
*/
|
|
70
71
|
MLK_INTERNAL_API
|
|
71
72
|
MLK_MUST_CHECK_RETURN_VALUE
|
|
72
73
|
int mlk_indcpa_keypair_derand(uint8_t pk[MLKEM_INDCPA_PUBLICKEYBYTES],
|
|
@@ -85,25 +86,27 @@ __contract__(
|
|
|
85
86
|
);
|
|
86
87
|
|
|
87
88
|
#define mlk_indcpa_enc MLK_NAMESPACE_K(indcpa_enc) MLK_CONTEXT_PARAMETERS_4
|
|
88
|
-
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Encryption function of the CPA-secure public-key encryption scheme
|
|
91
|
+
* underlying ML-KEM.
|
|
92
|
+
*
|
|
93
|
+
* @spec{Implements @[FIPS203, Algorithm 14 (K-PKE.Encrypt)].}
|
|
94
|
+
*
|
|
95
|
+
* @param[out] c Output ciphertext (length MLKEM_INDCPA_BYTES bytes).
|
|
96
|
+
* @param[in] m Input message (length MLKEM_INDCPA_MSGBYTES bytes).
|
|
97
|
+
* @param[in] pk Input public key
|
|
98
|
+
* (length MLKEM_INDCPA_PUBLICKEYBYTES bytes).
|
|
99
|
+
* @param[in] coins Input random coins used as seed (length MLKEM_SYMBYTES
|
|
100
|
+
* bytes) to deterministically generate all randomness.
|
|
101
|
+
* @param context Application context. Only present when
|
|
102
|
+
* MLK_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
103
|
+
* MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
104
|
+
*
|
|
105
|
+
* @retval 0 Success.
|
|
106
|
+
* @retval MLK_ERR_FAIL Operation failed.
|
|
107
|
+
* @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and
|
|
108
|
+
* MLK_CUSTOM_ALLOC returned NULL.
|
|
109
|
+
*/
|
|
107
110
|
MLK_INTERNAL_API
|
|
108
111
|
MLK_MUST_CHECK_RETURN_VALUE
|
|
109
112
|
int mlk_indcpa_enc(uint8_t c[MLKEM_INDCPA_BYTES],
|
|
@@ -122,22 +125,26 @@ __contract__(
|
|
|
122
125
|
);
|
|
123
126
|
|
|
124
127
|
#define mlk_indcpa_dec MLK_NAMESPACE_K(indcpa_dec) MLK_CONTEXT_PARAMETERS_3
|
|
125
|
-
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Decryption function of the CPA-secure public-key encryption scheme
|
|
130
|
+
* underlying ML-KEM.
|
|
131
|
+
*
|
|
132
|
+
* @spec{Implements @[FIPS203, Algorithm 15 (K-PKE.Decrypt)].}
|
|
133
|
+
*
|
|
134
|
+
* @param[out] m Output decrypted message
|
|
135
|
+
* (length MLKEM_INDCPA_MSGBYTES bytes).
|
|
136
|
+
* @param[in] c Input ciphertext (length MLKEM_INDCPA_BYTES bytes).
|
|
137
|
+
* @param[in] sk Input secret key
|
|
138
|
+
* (length MLKEM_INDCPA_SECRETKEYBYTES bytes).
|
|
139
|
+
* @param context Application context. Only present when
|
|
140
|
+
* MLK_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
141
|
+
* MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
142
|
+
*
|
|
143
|
+
* @retval 0 Success.
|
|
144
|
+
* @retval MLK_ERR_FAIL Operation failed.
|
|
145
|
+
* @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and
|
|
146
|
+
* MLK_CUSTOM_ALLOC returned NULL.
|
|
147
|
+
*/
|
|
141
148
|
MLK_INTERNAL_API
|
|
142
149
|
MLK_MUST_CHECK_RETURN_VALUE
|
|
143
150
|
int mlk_indcpa_dec(uint8_t m[MLKEM_INDCPA_MSGBYTES],
|