pq_crypto 0.3.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +56 -0
- data/CHANGELOG.md +62 -0
- data/GET_STARTED.md +366 -40
- data/README.md +76 -233
- data/SECURITY.md +107 -82
- data/ext/pqcrypto/extconf.rb +169 -87
- data/ext/pqcrypto/mldsa_api.h +1 -48
- data/ext/pqcrypto/mlkem_api.h +1 -18
- data/ext/pqcrypto/pq_externalmu.c +89 -204
- data/ext/pqcrypto/pqcrypto_native_api.h +129 -0
- data/ext/pqcrypto/pqcrypto_ruby_secure.c +484 -84
- data/ext/pqcrypto/pqcrypto_secure.c +203 -78
- data/ext/pqcrypto/pqcrypto_secure.h +53 -14
- data/ext/pqcrypto/pqcrypto_version.h +7 -0
- data/ext/pqcrypto/randombytes.h +9 -0
- data/ext/pqcrypto/vendor/.vendored +10 -5
- data/ext/pqcrypto/vendor/mldsa-native/BUILDING.md +105 -0
- data/ext/pqcrypto/vendor/mldsa-native/LICENSE +286 -0
- data/ext/pqcrypto/vendor/mldsa-native/META.yml +24 -0
- data/ext/pqcrypto/vendor/mldsa-native/README.md +221 -0
- data/ext/pqcrypto/vendor/mldsa-native/SECURITY.md +8 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +721 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +975 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +724 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +723 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +166 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +321 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.c +21 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +385 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c +73 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +130 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.c +277 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +244 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +182 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +117 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +438 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +105 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +71 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +62 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +376 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +204 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +259 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +1077 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +987 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +41 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +26 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +35 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +37 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +27 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +36 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +69 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/README.md +10 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +32 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +20 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +638 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +136 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +52 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +29 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +488 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +16 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/xkcp.h +31 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +247 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +231 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +150 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +753 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +129 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +145 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +177 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +653 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +79 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +53 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +55 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +85 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +85 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +102 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +110 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +72 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +69 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +40 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +189 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +135 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +128 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +543 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +62 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +649 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/meta.h +23 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +315 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +124 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +157 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +27 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +2311 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +2383 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +239 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +131 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +187 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +61 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_chknorm_avx2.c +52 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +102 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +104 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +91 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +93 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_avx2.c +126 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +160 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +293 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +224 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/params.h +77 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +991 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +393 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +946 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +360 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +877 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +725 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/randombytes.h +26 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +249 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +1511 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +806 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/symmetric.h +68 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sys.h +268 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/zetas.inc +55 -0
- data/ext/pqcrypto/vendor/mlkem-native/BUILDING.md +104 -0
- data/ext/pqcrypto/vendor/mlkem-native/LICENSE +294 -0
- data/ext/pqcrypto/vendor/mlkem-native/META.yml +30 -0
- data/ext/pqcrypto/vendor/mlkem-native/README.md +223 -0
- data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +86 -0
- data/ext/pqcrypto/vendor/mlkem-native/SECURITY.md +8 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/README.md +23 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +660 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +538 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +681 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +709 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +174 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +274 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +717 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +688 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.c +64 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.h +128 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +251 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +158 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +208 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +80 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +463 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.h +98 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/auto.h +70 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/fips202_native_aarch64.h +69 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +375 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +203 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +258 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +1076 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +986 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +46 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +25 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +34 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +35 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +26 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +35 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/api.h +117 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/README.md +10 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/mve.h +79 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/fips202_native_armv81m.h +35 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +667 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +40 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +51 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +290 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +314 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +28 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +33 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +41 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2.S +451 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +51 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +622 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +156 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +446 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +326 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/README.md +16 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +122 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +174 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +177 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/intt.S +628 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/ntt.S +562 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_mulcache_compute_asm.S +127 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_reduce_asm.S +150 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_tobytes_asm.S +117 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_tomont_asm.S +98 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k2.S +261 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k3.S +314 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k4.S +368 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_asm.S +226 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_table.c +542 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +637 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +25 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/README.md +11 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +128 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/arith_native_riscv64.h +45 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +81 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +145 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_izetas.inc +27 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +805 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_zetas.inc +27 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_zetas_basemul.inc +39 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/README.md +4 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +304 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +309 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +94 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +45 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.c +102 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.h +25 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/intt.S +719 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mulcache_compute.S +90 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/ntt.S +639 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/nttfrombytes.S +193 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/ntttobytes.S +181 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/nttunpack.S +174 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d10.S +382 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d11.S +448 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d4.S +163 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d5.S +220 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d10.S +228 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d11.S +277 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d4.S +180 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d5.S +192 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k2.S +502 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k3.S +750 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k4.S +998 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/reduce.S +218 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_asm.S +103 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_table.c +544 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/tomont.S +155 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/params.h +76 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +572 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +317 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +502 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +668 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/randombytes.h +60 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +362 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +118 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/symmetric.h +70 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +260 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.c +20 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +464 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/zetas.inc +30 -0
- data/lib/pq_crypto/algorithm_registry.rb +200 -0
- data/lib/pq_crypto/hybrid_kem.rb +1 -12
- data/lib/pq_crypto/kem.rb +104 -13
- data/lib/pq_crypto/pkcs8.rb +387 -0
- data/lib/pq_crypto/serialization.rb +1 -14
- data/lib/pq_crypto/signature.rb +123 -17
- data/lib/pq_crypto/spki.rb +131 -0
- data/lib/pq_crypto/version.rb +1 -1
- data/lib/pq_crypto.rb +79 -20
- data/script/vendor_libs.rb +88 -155
- metadata +241 -73
- data/ext/pqcrypto/vendor/pqclean/common/aes.c +0 -639
- data/ext/pqcrypto/vendor/pqclean/common/aes.h +0 -64
- data/ext/pqcrypto/vendor/pqclean/common/compat.h +0 -73
- data/ext/pqcrypto/vendor/pqclean/common/crypto_declassify.h +0 -7
- data/ext/pqcrypto/vendor/pqclean/common/fips202.c +0 -928
- data/ext/pqcrypto/vendor/pqclean/common/fips202.h +0 -166
- data/ext/pqcrypto/vendor/pqclean/common/keccak2x/feat.S +0 -168
- data/ext/pqcrypto/vendor/pqclean/common/keccak2x/fips202x2.c +0 -684
- data/ext/pqcrypto/vendor/pqclean/common/keccak2x/fips202x2.h +0 -60
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-times4-SIMD256.c +0 -1028
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-times4-SnP.h +0 -50
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-unrolling.macros +0 -198
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/Makefile +0 -8
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/Makefile.Microsoft_nmake +0 -8
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/SIMD256-config.h +0 -3
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/align.h +0 -34
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/brg_endian.h +0 -142
- data/ext/pqcrypto/vendor/pqclean/common/nistseedexpander.c +0 -101
- data/ext/pqcrypto/vendor/pqclean/common/nistseedexpander.h +0 -39
- data/ext/pqcrypto/vendor/pqclean/common/randombytes.c +0 -355
- data/ext/pqcrypto/vendor/pqclean/common/randombytes.h +0 -27
- data/ext/pqcrypto/vendor/pqclean/common/sha2.c +0 -769
- data/ext/pqcrypto/vendor/pqclean/common/sha2.h +0 -173
- data/ext/pqcrypto/vendor/pqclean/common/sp800-185.c +0 -156
- data/ext/pqcrypto/vendor/pqclean/common/sp800-185.h +0 -27
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/LICENSE +0 -5
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/Makefile +0 -19
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/Makefile.Microsoft_nmake +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/api.h +0 -18
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/cbd.c +0 -83
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/cbd.h +0 -11
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/indcpa.c +0 -327
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/indcpa.h +0 -22
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/kem.c +0 -164
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/kem.h +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/ntt.c +0 -146
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/ntt.h +0 -14
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/params.h +0 -36
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/poly.c +0 -299
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/poly.h +0 -37
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/polyvec.c +0 -188
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/polyvec.h +0 -26
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/reduce.c +0 -41
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/reduce.h +0 -13
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/symmetric-shake.c +0 -71
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/symmetric.h +0 -30
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/verify.c +0 -67
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/verify.h +0 -13
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/LICENSE +0 -5
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/Makefile +0 -19
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/Makefile.Microsoft_nmake +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/api.h +0 -50
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/ntt.c +0 -98
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/ntt.h +0 -10
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.c +0 -261
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.h +0 -31
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/params.h +0 -44
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.c +0 -799
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.h +0 -52
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.c +0 -415
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.h +0 -65
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/reduce.c +0 -69
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/reduce.h +0 -17
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/rounding.c +0 -92
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/rounding.h +0 -14
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/sign.c +0 -407
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/sign.h +0 -47
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric-shake.c +0 -26
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric.h +0 -34
|
@@ -0,0 +1,975 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) The mldsa-native project authors
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/* References
|
|
7
|
+
* ==========
|
|
8
|
+
*
|
|
9
|
+
* - [FIPS204]
|
|
10
|
+
* FIPS 204 Module-Lattice-Based Digital Signature Standard
|
|
11
|
+
* National Institute of Standards and Technology
|
|
12
|
+
* https://csrc.nist.gov/pubs/fips/204/final
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
#ifndef MLD_H
|
|
16
|
+
#define MLD_H
|
|
17
|
+
|
|
18
|
+
/*
|
|
19
|
+
* Public API for mldsa-native
|
|
20
|
+
*
|
|
21
|
+
* This header defines the public API of a single build of mldsa-native.
|
|
22
|
+
*
|
|
23
|
+
* Make sure the configuration file is in the include path
|
|
24
|
+
* (this is "mldsa_native_config.h" by default, or MLD_CONFIG_FILE if defined).
|
|
25
|
+
*
|
|
26
|
+
* # Multi-level builds
|
|
27
|
+
*
|
|
28
|
+
* This header specifies a build of mldsa-native for a fixed security level.
|
|
29
|
+
* If you need multiple security levels, leave the security level unspecified
|
|
30
|
+
* in the configuration file and include this header multiple times, setting
|
|
31
|
+
* MLD_CONFIG_PARAMETER_SET accordingly for each, and #undef'ing the MLD_H
|
|
32
|
+
* guard to allow multiple inclusions.
|
|
33
|
+
*
|
|
34
|
+
* # Legacy configuration (deprecated)
|
|
35
|
+
*
|
|
36
|
+
* Instead of providing the config file used for the build, you can
|
|
37
|
+
* alternatively set the following configuration options prior to
|
|
38
|
+
* including this header.
|
|
39
|
+
*
|
|
40
|
+
* This method of configuration is deprecated.
|
|
41
|
+
* It will be removed in mldsa-native-v2.
|
|
42
|
+
*
|
|
43
|
+
* - MLD_CONFIG_API_PARAMETER_SET [required]
|
|
44
|
+
*
|
|
45
|
+
* The parameter set used for the build; 44, 65, or 87.
|
|
46
|
+
*
|
|
47
|
+
* - MLD_CONFIG_API_NAMESPACE_PREFIX [required]
|
|
48
|
+
*
|
|
49
|
+
* The namespace prefix used for the build.
|
|
50
|
+
*
|
|
51
|
+
* NOTE:
|
|
52
|
+
* For a multi-level build, you must include the 44/65/87 suffixes
|
|
53
|
+
* in MLD_CONFIG_API_NAMESPACE_PREFIX.
|
|
54
|
+
*
|
|
55
|
+
* - MLD_CONFIG_API_NO_SUPERCOP [optional]
|
|
56
|
+
*
|
|
57
|
+
* By default, this header will also expose the mldsa-native API in the
|
|
58
|
+
* SUPERCOP naming convention crypto_sign_xxx. If you don't want/need this,
|
|
59
|
+
* set MLD_CONFIG_API_NO_SUPERCOP. You must set this for a multi-level build.
|
|
60
|
+
*
|
|
61
|
+
* - MLD_CONFIG_API_CONSTANTS_ONLY [optional]
|
|
62
|
+
*
|
|
63
|
+
* If you don't want this header to expose any function declarations,
|
|
64
|
+
* but only constants for the sizes of key material, set
|
|
65
|
+
* MLD_CONFIG_API_CONSTANTS_ONLY. In this case, you don't need to set
|
|
66
|
+
* MLD_CONFIG_API_PARAMETER_SET or MLD_CONFIG_API_NAMESPACE_PREFIX,
|
|
67
|
+
* nor include a configuration.
|
|
68
|
+
*
|
|
69
|
+
* - MLD_CONFIG_API_QUALIFIER [optional]
|
|
70
|
+
*
|
|
71
|
+
* Qualifier to apply to external API.
|
|
72
|
+
*
|
|
73
|
+
******************************************************************************/
|
|
74
|
+
|
|
75
|
+
/******************************* Key sizes ************************************/
|
|
76
|
+
|
|
77
|
+
/* Sizes of cryptographic material, per parameter set */
|
|
78
|
+
/* See mldsa/src/params.h for the arithmetic expressions giving rise to these */
|
|
79
|
+
/* check-magic: off */
|
|
80
|
+
#define MLDSA44_SECRETKEYBYTES 2560
|
|
81
|
+
#define MLDSA44_PUBLICKEYBYTES 1312
|
|
82
|
+
#define MLDSA44_BYTES 2420
|
|
83
|
+
|
|
84
|
+
#define MLDSA65_SECRETKEYBYTES 4032
|
|
85
|
+
#define MLDSA65_PUBLICKEYBYTES 1952
|
|
86
|
+
#define MLDSA65_BYTES 3309
|
|
87
|
+
|
|
88
|
+
#define MLDSA87_SECRETKEYBYTES 4896
|
|
89
|
+
#define MLDSA87_PUBLICKEYBYTES 2592
|
|
90
|
+
#define MLDSA87_BYTES 4627
|
|
91
|
+
/* check-magic: on */
|
|
92
|
+
|
|
93
|
+
/* Size of seed and randomness in bytes (level-independent) */
|
|
94
|
+
#define MLDSA_SEEDBYTES 32
|
|
95
|
+
#define MLDSA44_SEEDBYTES MLDSA_SEEDBYTES
|
|
96
|
+
#define MLDSA65_SEEDBYTES MLDSA_SEEDBYTES
|
|
97
|
+
#define MLDSA87_SEEDBYTES MLDSA_SEEDBYTES
|
|
98
|
+
|
|
99
|
+
/* Size of CRH output in bytes (level-independent) */
|
|
100
|
+
#define MLDSA_CRHBYTES 64
|
|
101
|
+
#define MLDSA44_CRHBYTES MLDSA_CRHBYTES
|
|
102
|
+
#define MLDSA65_CRHBYTES MLDSA_CRHBYTES
|
|
103
|
+
#define MLDSA87_CRHBYTES MLDSA_CRHBYTES
|
|
104
|
+
|
|
105
|
+
/* Size of TR output in bytes (level-independent) */
|
|
106
|
+
#define MLDSA_TRBYTES 64
|
|
107
|
+
#define MLDSA44_TRBYTES MLDSA_TRBYTES
|
|
108
|
+
#define MLDSA65_TRBYTES MLDSA_TRBYTES
|
|
109
|
+
#define MLDSA87_TRBYTES MLDSA_TRBYTES
|
|
110
|
+
|
|
111
|
+
/* Size of randomness for signing in bytes (level-independent) */
|
|
112
|
+
#define MLDSA_RNDBYTES 32
|
|
113
|
+
#define MLDSA44_RNDBYTES MLDSA_RNDBYTES
|
|
114
|
+
#define MLDSA65_RNDBYTES MLDSA_RNDBYTES
|
|
115
|
+
#define MLDSA87_RNDBYTES MLDSA_RNDBYTES
|
|
116
|
+
|
|
117
|
+
/* Sizes of cryptographic material, as a function of LVL=44,65,87 */
|
|
118
|
+
#define MLDSA_SECRETKEYBYTES_(LVL) MLDSA##LVL##_SECRETKEYBYTES
|
|
119
|
+
#define MLDSA_PUBLICKEYBYTES_(LVL) MLDSA##LVL##_PUBLICKEYBYTES
|
|
120
|
+
#define MLDSA_BYTES_(LVL) MLDSA##LVL##_BYTES
|
|
121
|
+
#define MLDSA_SECRETKEYBYTES(LVL) MLDSA_SECRETKEYBYTES_(LVL)
|
|
122
|
+
#define MLDSA_PUBLICKEYBYTES(LVL) MLDSA_PUBLICKEYBYTES_(LVL)
|
|
123
|
+
#define MLDSA_BYTES(LVL) MLDSA_BYTES_(LVL)
|
|
124
|
+
|
|
125
|
+
/****************************** Error codes ***********************************/
|
|
126
|
+
|
|
127
|
+
/* Generic failure condition */
|
|
128
|
+
#define MLD_ERR_FAIL -1
|
|
129
|
+
/* An allocation failed. This can only happen if MLD_CONFIG_CUSTOM_ALLOC_FREE
|
|
130
|
+
* is defined and the provided MLD_CUSTOM_ALLOC can fail. */
|
|
131
|
+
#define MLD_ERR_OUT_OF_MEMORY -2
|
|
132
|
+
/* An rng failure occured. Might be due to insufficient entropy or
|
|
133
|
+
* system misconfiguration. */
|
|
134
|
+
#define MLD_ERR_RNG_FAIL -3
|
|
135
|
+
|
|
136
|
+
/****************************** Function API **********************************/
|
|
137
|
+
|
|
138
|
+
#define MLD_API_CONCAT_(x, y) x##y
|
|
139
|
+
#define MLD_API_CONCAT(x, y) MLD_API_CONCAT_(x, y)
|
|
140
|
+
#define MLD_API_CONCAT_UNDERSCORE(x, y) MLD_API_CONCAT(MLD_API_CONCAT(x, _), y)
|
|
141
|
+
|
|
142
|
+
#if !defined(MLD_CONFIG_API_PARAMETER_SET)
|
|
143
|
+
/* Recommended configuration via same config file as used for the build. */
|
|
144
|
+
|
|
145
|
+
/* For now, we derive the legacy API configuration MLD_CONFIG_API_XXX from
|
|
146
|
+
* the config file. In mldsa-native-v2, this will be removed and we will
|
|
147
|
+
* exclusively work with MLD_CONFIG_XXX. */
|
|
148
|
+
|
|
149
|
+
/* You need to make sure the config file is in the include path. */
|
|
150
|
+
#if defined(MLD_CONFIG_FILE)
|
|
151
|
+
#include MLD_CONFIG_FILE
|
|
152
|
+
#else
|
|
153
|
+
#include "mldsa_native_config.h"
|
|
154
|
+
#endif
|
|
155
|
+
|
|
156
|
+
#define MLD_CONFIG_API_PARAMETER_SET MLD_CONFIG_PARAMETER_SET
|
|
157
|
+
|
|
158
|
+
#if defined(MLD_CONFIG_MULTILEVEL_BUILD)
|
|
159
|
+
#define MLD_CONFIG_API_NAMESPACE_PREFIX \
|
|
160
|
+
MLD_API_CONCAT(MLD_CONFIG_NAMESPACE_PREFIX, MLD_CONFIG_PARAMETER_SET)
|
|
161
|
+
#else
|
|
162
|
+
#define MLD_CONFIG_API_NAMESPACE_PREFIX MLD_CONFIG_NAMESPACE_PREFIX
|
|
163
|
+
#endif
|
|
164
|
+
|
|
165
|
+
#if defined(MLD_CONFIG_NO_SUPERCOP)
|
|
166
|
+
#define MLD_CONFIG_API_NO_SUPERCOP
|
|
167
|
+
#endif
|
|
168
|
+
|
|
169
|
+
#if defined(MLD_CONFIG_CONSTANTS_ONLY)
|
|
170
|
+
#define MLD_CONFIG_API_CONSTANTS_ONLY
|
|
171
|
+
#endif
|
|
172
|
+
|
|
173
|
+
#if defined(MLD_CONFIG_EXTERNAL_API_QUALIFIER)
|
|
174
|
+
#define MLD_CONFIG_API_QUALIFIER MLD_CONFIG_EXTERNAL_API_QUALIFIER
|
|
175
|
+
#endif
|
|
176
|
+
|
|
177
|
+
#else /* !MLD_CONFIG_API_PARAMETER_SET */
|
|
178
|
+
#define MLD_API_LEGACY_CONFIG
|
|
179
|
+
|
|
180
|
+
#endif /* MLD_CONFIG_API_PARAMETER_SET */
|
|
181
|
+
|
|
182
|
+
#define MLD_API_NAMESPACE(sym) \
|
|
183
|
+
MLD_API_CONCAT_UNDERSCORE(MLD_CONFIG_API_NAMESPACE_PREFIX, sym)
|
|
184
|
+
|
|
185
|
+
#if defined(__GNUC__) || defined(clang)
|
|
186
|
+
#define MLD_API_MUST_CHECK_RETURN_VALUE __attribute__((warn_unused_result))
|
|
187
|
+
#else
|
|
188
|
+
#define MLD_API_MUST_CHECK_RETURN_VALUE
|
|
189
|
+
#endif
|
|
190
|
+
|
|
191
|
+
#if defined(MLD_CONFIG_API_QUALIFIER)
|
|
192
|
+
#define MLD_API_QUALIFIER MLD_CONFIG_API_QUALIFIER
|
|
193
|
+
#else
|
|
194
|
+
#define MLD_API_QUALIFIER
|
|
195
|
+
#endif
|
|
196
|
+
|
|
197
|
+
#if !defined(MLD_CONFIG_API_CONSTANTS_ONLY)
|
|
198
|
+
|
|
199
|
+
#include <stddef.h>
|
|
200
|
+
#include <stdint.h>
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
#ifdef __cplusplus
|
|
204
|
+
extern "C"
|
|
205
|
+
{
|
|
206
|
+
#endif
|
|
207
|
+
|
|
208
|
+
/*************************************************
|
|
209
|
+
* Name: crypto_sign_keypair_internal
|
|
210
|
+
*
|
|
211
|
+
* Description: Generates public and private key. Internal API.
|
|
212
|
+
* When MLD_CONFIG_KEYGEN_PCT is set, performs a Pairwise
|
|
213
|
+
* Consistency Test (PCT) as required by FIPS 140-3 IG.
|
|
214
|
+
*
|
|
215
|
+
* Arguments:
|
|
216
|
+
* - uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
217
|
+
* output public key
|
|
218
|
+
* - uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
219
|
+
* output private key
|
|
220
|
+
* - const uint8_t seed[MLDSA_SEEDBYTES]:
|
|
221
|
+
* input random seed
|
|
222
|
+
*
|
|
223
|
+
* Returns:
|
|
224
|
+
* - 0: Success
|
|
225
|
+
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
226
|
+
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
227
|
+
* - MLD_ERR_RNG_FAIL: Random number generation failed.
|
|
228
|
+
* - MLD_ERR_FAIL: Other kinds of failure, incl. PCT failure
|
|
229
|
+
* if MLD_CONFIG_KEYGEN_PCT is enabled.
|
|
230
|
+
*
|
|
231
|
+
* Specification: Implements @[FIPS204 Algorithm 6 (ML-DSA.KeyGen_internal)]
|
|
232
|
+
*
|
|
233
|
+
**************************************************/
|
|
234
|
+
MLD_API_QUALIFIER
|
|
235
|
+
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
236
|
+
int MLD_API_NAMESPACE(keypair_internal)(
|
|
237
|
+
uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)],
|
|
238
|
+
uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)],
|
|
239
|
+
const uint8_t seed[MLDSA_SEEDBYTES]
|
|
240
|
+
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
241
|
+
,
|
|
242
|
+
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
243
|
+
#endif
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
/*************************************************
|
|
247
|
+
* Name: crypto_sign_keypair
|
|
248
|
+
*
|
|
249
|
+
* Description: Generates public and private key.
|
|
250
|
+
* When MLD_CONFIG_KEYGEN_PCT is set, performs a Pairwise
|
|
251
|
+
* Consistency Test (PCT) as required by FIPS 140-3 IG.
|
|
252
|
+
*
|
|
253
|
+
* Arguments:
|
|
254
|
+
* - uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
255
|
+
* output public key
|
|
256
|
+
* - uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
257
|
+
* output private key
|
|
258
|
+
*
|
|
259
|
+
* Returns: - 0: Success
|
|
260
|
+
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
261
|
+
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
262
|
+
* - MLD_ERR_RNG_FAIL: Random number generation failed.
|
|
263
|
+
* - MLD_ERR_FAIL: If MLD_CONFIG_KEYGEN_PCT is enabled and the
|
|
264
|
+
* PCT check failed.
|
|
265
|
+
*
|
|
266
|
+
* Specification: Implements @[FIPS204 Algorithm 1 (ML-DSA.KeyGen)]
|
|
267
|
+
*
|
|
268
|
+
**************************************************/
|
|
269
|
+
MLD_API_QUALIFIER
|
|
270
|
+
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
271
|
+
int MLD_API_NAMESPACE(keypair)(
|
|
272
|
+
uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)],
|
|
273
|
+
uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]
|
|
274
|
+
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
275
|
+
,
|
|
276
|
+
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
277
|
+
#endif
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
/*************************************************
|
|
281
|
+
* Name: crypto_sign_signature_internal
|
|
282
|
+
*
|
|
283
|
+
* Description: Computes signature. Internal API.
|
|
284
|
+
*
|
|
285
|
+
* Arguments:
|
|
286
|
+
* - uint8_t sig[MLDSA_BYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
287
|
+
* output signature
|
|
288
|
+
* - size_t *siglen: pointer to output length of signature
|
|
289
|
+
* - const uint8_t *m: pointer to message to be signed
|
|
290
|
+
* - size_t mlen: length of message
|
|
291
|
+
* - const uint8_t *pre: pointer to prefix string
|
|
292
|
+
* - size_t prelen: length of prefix string
|
|
293
|
+
* - const uint8_t rnd[MLDSA_RNDBYTES]:
|
|
294
|
+
* random seed
|
|
295
|
+
* - const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
296
|
+
* bit-packed secret key
|
|
297
|
+
* - int externalmu: indicates input message m is processed as mu
|
|
298
|
+
*
|
|
299
|
+
* Returns:
|
|
300
|
+
* - 0: Success
|
|
301
|
+
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
302
|
+
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
303
|
+
* - MLD_ERR_FAIL: Other kinds of failure
|
|
304
|
+
*
|
|
305
|
+
* If the returned value is non-zero, then the values of *sig and
|
|
306
|
+
* *siglen should not be referenced.
|
|
307
|
+
*
|
|
308
|
+
* Reference: This code differs from the reference implementation
|
|
309
|
+
* in that it adds an explicit check for nonce exhaustion
|
|
310
|
+
* and can return -1 in that case.
|
|
311
|
+
**************************************************/
|
|
312
|
+
MLD_API_QUALIFIER
|
|
313
|
+
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
314
|
+
int MLD_API_NAMESPACE(signature_internal)(
|
|
315
|
+
uint8_t sig[MLDSA_BYTES(MLD_CONFIG_API_PARAMETER_SET)], size_t *siglen,
|
|
316
|
+
const uint8_t *m, size_t mlen, const uint8_t *pre, size_t prelen,
|
|
317
|
+
const uint8_t rnd[MLDSA_RNDBYTES],
|
|
318
|
+
const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)],
|
|
319
|
+
int externalmu
|
|
320
|
+
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
321
|
+
,
|
|
322
|
+
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
323
|
+
#endif
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
/*************************************************
|
|
327
|
+
* Name: crypto_sign_signature
|
|
328
|
+
*
|
|
329
|
+
* Description: Computes signature. This function implements the randomized
|
|
330
|
+
* variant of ML-DSA. If you require the deterministic variant,
|
|
331
|
+
* use crypto_sign_signature_internal directly.
|
|
332
|
+
*
|
|
333
|
+
* Arguments:
|
|
334
|
+
* - uint8_t sig[MLDSA_BYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
335
|
+
* output signature
|
|
336
|
+
* - size_t *siglen: pointer to output length of signature
|
|
337
|
+
* - const uint8_t *m: pointer to message to be signed
|
|
338
|
+
* - size_t mlen: length of message
|
|
339
|
+
* - const uint8_t *ctx: pointer to context string.
|
|
340
|
+
* May be NULL if ctxlen == 0.
|
|
341
|
+
* - size_t ctxlen: length of context string.
|
|
342
|
+
* Should be <= 255.
|
|
343
|
+
* - const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
344
|
+
* bit-packed secret key
|
|
345
|
+
*
|
|
346
|
+
* Returns:
|
|
347
|
+
* - 0: Success
|
|
348
|
+
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
349
|
+
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
350
|
+
* - MLD_ERR_RNG_FAIL: Random number generation failed.
|
|
351
|
+
* - MLD_ERR_FAIL: Other kinds of failure.
|
|
352
|
+
*
|
|
353
|
+
* Specification: Implements @[FIPS204 Algorithm 2 (ML-DSA.Sign)]
|
|
354
|
+
*
|
|
355
|
+
**************************************************/
|
|
356
|
+
MLD_API_QUALIFIER
|
|
357
|
+
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
358
|
+
int MLD_API_NAMESPACE(signature)(
|
|
359
|
+
uint8_t sig[MLDSA_BYTES(MLD_CONFIG_API_PARAMETER_SET)], size_t *siglen,
|
|
360
|
+
const uint8_t *m, size_t mlen, const uint8_t *ctx, size_t ctxlen,
|
|
361
|
+
const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]
|
|
362
|
+
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
363
|
+
,
|
|
364
|
+
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
365
|
+
#endif
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
/*************************************************
|
|
369
|
+
* Name: crypto_sign_signature_extmu
|
|
370
|
+
*
|
|
371
|
+
* Description: Computes signature.
|
|
372
|
+
*
|
|
373
|
+
* Arguments:
|
|
374
|
+
* - uint8_t sig[MLDSA_BYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
375
|
+
* output signature
|
|
376
|
+
* - size_t *siglen: pointer to output length of signature
|
|
377
|
+
* - const uint8_t mu[MLDSA_CRHBYTES]:
|
|
378
|
+
* input mu to be signed
|
|
379
|
+
* - const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
380
|
+
* bit-packed secret key
|
|
381
|
+
*
|
|
382
|
+
* Returns:
|
|
383
|
+
* - 0: Success
|
|
384
|
+
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
385
|
+
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
386
|
+
* - MLD_ERR_RNG_FAIL: Random number generation failed.
|
|
387
|
+
* - MLD_ERR_FAIL: Other kinds of failure.
|
|
388
|
+
*
|
|
389
|
+
* Specification: Implements @[FIPS204 Algorithm 2 (ML-DSA.Sign external mu
|
|
390
|
+
* variant)]
|
|
391
|
+
*
|
|
392
|
+
**************************************************/
|
|
393
|
+
MLD_API_QUALIFIER
|
|
394
|
+
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
395
|
+
int MLD_API_NAMESPACE(signature_extmu)(
|
|
396
|
+
uint8_t sig[MLDSA_BYTES(MLD_CONFIG_API_PARAMETER_SET)], size_t *siglen,
|
|
397
|
+
const uint8_t mu[MLDSA_CRHBYTES],
|
|
398
|
+
const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]
|
|
399
|
+
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
400
|
+
,
|
|
401
|
+
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
402
|
+
#endif
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
/*************************************************
|
|
406
|
+
* Name: crypto_sign
|
|
407
|
+
*
|
|
408
|
+
* Description: Computes signature. This function implements the randomized
|
|
409
|
+
* variant of ML-DSA. If you require the deterministic variant,
|
|
410
|
+
* use crypto_sign_signature_internal directly.
|
|
411
|
+
*
|
|
412
|
+
* Arguments:
|
|
413
|
+
* - uint8_t *sm: pointer to output signed message (allocated array
|
|
414
|
+
* with MLDSA{44,65,87}_BYTES + mlen bytes), can be
|
|
415
|
+
* equal to m
|
|
416
|
+
* - size_t *smlen: pointer to output length of signed message
|
|
417
|
+
* - const uint8_t *m: pointer to message to be signed
|
|
418
|
+
* - size_t mlen: length of message
|
|
419
|
+
* - const uint8_t *ctx: pointer to context string
|
|
420
|
+
* - size_t ctxlen: length of context string
|
|
421
|
+
* - const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
422
|
+
* bit-packed secret key
|
|
423
|
+
*
|
|
424
|
+
* Returns:
|
|
425
|
+
* - 0: Success
|
|
426
|
+
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
427
|
+
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
428
|
+
* - MLD_ERR_FAIL: Other kinds of failure
|
|
429
|
+
**************************************************/
|
|
430
|
+
MLD_API_QUALIFIER
|
|
431
|
+
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
432
|
+
int MLD_API_NAMESPACE(sign)(
|
|
433
|
+
uint8_t *sm, size_t *smlen, const uint8_t *m, size_t mlen,
|
|
434
|
+
const uint8_t *ctx, size_t ctxlen,
|
|
435
|
+
const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]
|
|
436
|
+
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
437
|
+
,
|
|
438
|
+
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
439
|
+
#endif
|
|
440
|
+
);
|
|
441
|
+
|
|
442
|
+
/*************************************************
|
|
443
|
+
* Name: crypto_sign_verify_internal
|
|
444
|
+
*
|
|
445
|
+
* Description: Verifies signature. Internal API.
|
|
446
|
+
*
|
|
447
|
+
* Arguments:
|
|
448
|
+
* - const uint8_t *sig: pointer to input signature
|
|
449
|
+
* - size_t siglen: length of signature
|
|
450
|
+
* - const uint8_t *m: pointer to message
|
|
451
|
+
* - size_t mlen: length of message
|
|
452
|
+
* - const uint8_t *pre: pointer to prefix string
|
|
453
|
+
* - size_t prelen: length of prefix string
|
|
454
|
+
* - const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
455
|
+
* bit-packed public key
|
|
456
|
+
* - int externalmu: indicates input message m is processed as mu
|
|
457
|
+
*
|
|
458
|
+
* Returns:
|
|
459
|
+
* - 0: Success
|
|
460
|
+
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
461
|
+
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
462
|
+
* - MLD_ERR_FAIL: Signature verification failed
|
|
463
|
+
*
|
|
464
|
+
* Specification: Implements @[FIPS204 Algorithm 8 (ML-DSA.Verify_internal)]
|
|
465
|
+
*
|
|
466
|
+
**************************************************/
|
|
467
|
+
MLD_API_QUALIFIER
|
|
468
|
+
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
469
|
+
int MLD_API_NAMESPACE(verify_internal)(
|
|
470
|
+
const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen,
|
|
471
|
+
const uint8_t *pre, size_t prelen,
|
|
472
|
+
const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)],
|
|
473
|
+
int externalmu
|
|
474
|
+
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
475
|
+
,
|
|
476
|
+
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
477
|
+
#endif
|
|
478
|
+
);
|
|
479
|
+
|
|
480
|
+
/*************************************************
|
|
481
|
+
* Name: crypto_sign_verify
|
|
482
|
+
*
|
|
483
|
+
* Description: Verifies signature.
|
|
484
|
+
*
|
|
485
|
+
* Arguments:
|
|
486
|
+
* - const uint8_t *sig: pointer to input signature
|
|
487
|
+
* - size_t siglen: length of signature
|
|
488
|
+
* - const uint8_t *m: pointer to message
|
|
489
|
+
* - size_t mlen: length of message
|
|
490
|
+
* - const uint8_t *ctx: pointer to context string.
|
|
491
|
+
* May be NULL if ctxlen == 0.
|
|
492
|
+
* - size_t ctxlen: length of context string
|
|
493
|
+
* - const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
494
|
+
* bit-packed public key
|
|
495
|
+
*
|
|
496
|
+
* Returns:
|
|
497
|
+
* - 0: Success
|
|
498
|
+
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
499
|
+
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
500
|
+
* - MLD_ERR_FAIL: Signature verification failed
|
|
501
|
+
*
|
|
502
|
+
* Specification: Implements @[FIPS204 Algorithm 3 (ML-DSA.Verify)]
|
|
503
|
+
*
|
|
504
|
+
**************************************************/
|
|
505
|
+
MLD_API_QUALIFIER
|
|
506
|
+
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
507
|
+
int MLD_API_NAMESPACE(verify)(
|
|
508
|
+
const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen,
|
|
509
|
+
const uint8_t *ctx, size_t ctxlen,
|
|
510
|
+
const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]
|
|
511
|
+
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
512
|
+
,
|
|
513
|
+
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
514
|
+
#endif
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
/*************************************************
|
|
518
|
+
* Name: crypto_sign_verify_extmu
|
|
519
|
+
*
|
|
520
|
+
* Description: Verifies signature.
|
|
521
|
+
*
|
|
522
|
+
* Arguments:
|
|
523
|
+
* - const uint8_t *sig: pointer to input signature
|
|
524
|
+
* - size_t siglen: length of signature
|
|
525
|
+
* - const uint8_t mu[MLDSA_CRHBYTES]:
|
|
526
|
+
* input mu
|
|
527
|
+
* - const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
528
|
+
* bit-packed public key
|
|
529
|
+
*
|
|
530
|
+
* Returns:
|
|
531
|
+
* - 0: Success
|
|
532
|
+
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
533
|
+
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
534
|
+
* - MLD_ERR_FAIL: Signature verification failed
|
|
535
|
+
*
|
|
536
|
+
* Specification: Implements @[FIPS204 Algorithm 3 (ML-DSA.Verify external mu
|
|
537
|
+
* variant)]
|
|
538
|
+
*
|
|
539
|
+
**************************************************/
|
|
540
|
+
MLD_API_QUALIFIER
|
|
541
|
+
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
542
|
+
int MLD_API_NAMESPACE(verify_extmu)(
|
|
543
|
+
const uint8_t *sig, size_t siglen, const uint8_t mu[MLDSA_CRHBYTES],
|
|
544
|
+
const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]
|
|
545
|
+
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
546
|
+
,
|
|
547
|
+
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
548
|
+
#endif
|
|
549
|
+
);
|
|
550
|
+
|
|
551
|
+
/*************************************************
|
|
552
|
+
* Name: crypto_sign_open
|
|
553
|
+
*
|
|
554
|
+
* Description: Verify signed message.
|
|
555
|
+
*
|
|
556
|
+
* Arguments:
|
|
557
|
+
* - uint8_t *m: pointer to output message (allocated array with
|
|
558
|
+
* smlen bytes), can be equal to sm
|
|
559
|
+
* - size_t *mlen: pointer to output length of message
|
|
560
|
+
* - const uint8_t *sm: pointer to signed message
|
|
561
|
+
* - size_t smlen: length of signed message
|
|
562
|
+
* - const uint8_t *ctx: pointer to context string
|
|
563
|
+
* - size_t ctxlen: length of context string
|
|
564
|
+
* - const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
565
|
+
* bit-packed public key
|
|
566
|
+
*
|
|
567
|
+
* Returns:
|
|
568
|
+
* - 0: Success
|
|
569
|
+
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
570
|
+
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
571
|
+
* - MLD_ERR_FAIL: Signature verification failed
|
|
572
|
+
**************************************************/
|
|
573
|
+
MLD_API_QUALIFIER
|
|
574
|
+
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
575
|
+
int MLD_API_NAMESPACE(open)(
|
|
576
|
+
uint8_t *m, size_t *mlen, const uint8_t *sm, size_t smlen,
|
|
577
|
+
const uint8_t *ctx, size_t ctxlen,
|
|
578
|
+
const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]
|
|
579
|
+
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
580
|
+
,
|
|
581
|
+
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
582
|
+
#endif
|
|
583
|
+
);
|
|
584
|
+
|
|
585
|
+
/*************************************************
|
|
586
|
+
* Hash algorithm constants for domain separation
|
|
587
|
+
**************************************************/
|
|
588
|
+
#define MLD_PREHASH_NONE 0
|
|
589
|
+
#define MLD_PREHASH_SHA2_224 1
|
|
590
|
+
#define MLD_PREHASH_SHA2_256 2
|
|
591
|
+
#define MLD_PREHASH_SHA2_384 3
|
|
592
|
+
#define MLD_PREHASH_SHA2_512 4
|
|
593
|
+
#define MLD_PREHASH_SHA2_512_224 5
|
|
594
|
+
#define MLD_PREHASH_SHA2_512_256 6
|
|
595
|
+
#define MLD_PREHASH_SHA3_224 7
|
|
596
|
+
#define MLD_PREHASH_SHA3_256 8
|
|
597
|
+
#define MLD_PREHASH_SHA3_384 9
|
|
598
|
+
#define MLD_PREHASH_SHA3_512 10
|
|
599
|
+
#define MLD_PREHASH_SHAKE_128 11
|
|
600
|
+
#define MLD_PREHASH_SHAKE_256 12
|
|
601
|
+
|
|
602
|
+
/*************************************************
|
|
603
|
+
* Name: crypto_sign_signature_pre_hash_internal
|
|
604
|
+
*
|
|
605
|
+
* Description: FIPS 204: Algorithm 4 HashML-DSA.Sign.
|
|
606
|
+
* Computes signature with pre-hashed message.
|
|
607
|
+
*
|
|
608
|
+
* Arguments:
|
|
609
|
+
* - uint8_t sig[MLDSA_BYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
610
|
+
* output signature
|
|
611
|
+
* - size_t *siglen: pointer to output length of signature
|
|
612
|
+
* - const uint8_t *ph: pointer to pre-hashed message
|
|
613
|
+
* - size_t phlen: length of pre-hashed message
|
|
614
|
+
* - const uint8_t *ctx: pointer to context string
|
|
615
|
+
* - size_t ctxlen: length of context string
|
|
616
|
+
* - const uint8_t rnd[MLDSA_RNDBYTES]:
|
|
617
|
+
* random seed
|
|
618
|
+
* - const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
619
|
+
* bit-packed secret key
|
|
620
|
+
* - int hashalg: hash algorithm constant (one of MLD_PREHASH_*)
|
|
621
|
+
*
|
|
622
|
+
* Returns:
|
|
623
|
+
* - 0: Success
|
|
624
|
+
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
625
|
+
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
626
|
+
* - MLD_ERR_FAIL: Other kinds of failure
|
|
627
|
+
*
|
|
628
|
+
* Supported hash algorithm constants:
|
|
629
|
+
* MLD_PREHASH_SHA2_224, MLD_PREHASH_SHA2_256, MLD_PREHASH_SHA2_384,
|
|
630
|
+
* MLD_PREHASH_SHA2_512, MLD_PREHASH_SHA2_512_224, MLD_PREHASH_SHA2_512_256,
|
|
631
|
+
* MLD_PREHASH_SHA3_224, MLD_PREHASH_SHA3_256, MLD_PREHASH_SHA3_384,
|
|
632
|
+
* MLD_PREHASH_SHA3_512, MLD_PREHASH_SHAKE_128, MLD_PREHASH_SHAKE_256
|
|
633
|
+
*
|
|
634
|
+
* Warning: This is an unstable API that may change in the future. If you need
|
|
635
|
+
* a stable API use crypto_sign_signature_pre_hash_shake256.
|
|
636
|
+
**************************************************/
|
|
637
|
+
MLD_API_QUALIFIER
|
|
638
|
+
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
639
|
+
int MLD_API_NAMESPACE(signature_pre_hash_internal)(
|
|
640
|
+
uint8_t sig[MLDSA_BYTES(MLD_CONFIG_API_PARAMETER_SET)], size_t *siglen,
|
|
641
|
+
const uint8_t *ph, size_t phlen, const uint8_t *ctx, size_t ctxlen,
|
|
642
|
+
const uint8_t rnd[MLDSA_RNDBYTES],
|
|
643
|
+
const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)],
|
|
644
|
+
int hashalg
|
|
645
|
+
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
646
|
+
,
|
|
647
|
+
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
648
|
+
#endif
|
|
649
|
+
);
|
|
650
|
+
|
|
651
|
+
/*************************************************
|
|
652
|
+
* Name: crypto_sign_verify_pre_hash_internal
|
|
653
|
+
*
|
|
654
|
+
* Description: FIPS 204: Algorithm 5 HashML-DSA.Verify.
|
|
655
|
+
* Verifies signature with pre-hashed message.
|
|
656
|
+
*
|
|
657
|
+
* Arguments:
|
|
658
|
+
* - const uint8_t *sig: pointer to input signature
|
|
659
|
+
* - size_t siglen: length of signature
|
|
660
|
+
* - const uint8_t *ph: pointer to pre-hashed message
|
|
661
|
+
* - size_t phlen: length of pre-hashed message
|
|
662
|
+
* - const uint8_t *ctx: pointer to context string
|
|
663
|
+
* - size_t ctxlen: length of context string
|
|
664
|
+
* - const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
665
|
+
* bit-packed public key
|
|
666
|
+
* - int hashalg: hash algorithm constant (one of MLD_PREHASH_*)
|
|
667
|
+
*
|
|
668
|
+
* Returns: - 0: Success
|
|
669
|
+
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
670
|
+
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
671
|
+
* - MLD_ERR_FAIL: Signature verification failed
|
|
672
|
+
*
|
|
673
|
+
* Supported hash algorithm constants:
|
|
674
|
+
* MLD_PREHASH_SHA2_224, MLD_PREHASH_SHA2_256, MLD_PREHASH_SHA2_384,
|
|
675
|
+
* MLD_PREHASH_SHA2_512, MLD_PREHASH_SHA2_512_224, MLD_PREHASH_SHA2_512_256,
|
|
676
|
+
* MLD_PREHASH_SHA3_224, MLD_PREHASH_SHA3_256, MLD_PREHASH_SHA3_384,
|
|
677
|
+
* MLD_PREHASH_SHA3_512, MLD_PREHASH_SHAKE_128, MLD_PREHASH_SHAKE_256
|
|
678
|
+
*
|
|
679
|
+
* Warning: This is an unstable API that may change in the future. If you need
|
|
680
|
+
* a stable API use crypto_sign_verify_pre_hash_shake256.
|
|
681
|
+
**************************************************/
|
|
682
|
+
MLD_API_QUALIFIER
|
|
683
|
+
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
684
|
+
int MLD_API_NAMESPACE(verify_pre_hash_internal)(
|
|
685
|
+
const uint8_t *sig, size_t siglen, const uint8_t *ph, size_t phlen,
|
|
686
|
+
const uint8_t *ctx, size_t ctxlen,
|
|
687
|
+
const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)],
|
|
688
|
+
int hashalg
|
|
689
|
+
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
690
|
+
,
|
|
691
|
+
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
692
|
+
#endif
|
|
693
|
+
);
|
|
694
|
+
|
|
695
|
+
/*************************************************
|
|
696
|
+
* Name: crypto_sign_signature_pre_hash_shake256
|
|
697
|
+
*
|
|
698
|
+
* Description: FIPS 204: Algorithm 4 HashML-DSA.Sign with SHAKE256.
|
|
699
|
+
* Computes signature with pre-hashed message using SHAKE256.
|
|
700
|
+
* This function computes the SHAKE256 hash of the message
|
|
701
|
+
* internally.
|
|
702
|
+
*
|
|
703
|
+
* Arguments:
|
|
704
|
+
* - uint8_t sig[MLDSA_BYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
705
|
+
* output signature
|
|
706
|
+
* - size_t *siglen: pointer to output length of signature
|
|
707
|
+
* - const uint8_t *m: pointer to message to be hashed and signed
|
|
708
|
+
* - size_t mlen: length of message
|
|
709
|
+
* - const uint8_t *ctx: pointer to context string
|
|
710
|
+
* - size_t ctxlen: length of context string
|
|
711
|
+
* - const uint8_t rnd[MLDSA_RNDBYTES]:
|
|
712
|
+
* random seed
|
|
713
|
+
* - const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
714
|
+
* bit-packed secret key
|
|
715
|
+
*
|
|
716
|
+
* Returns:
|
|
717
|
+
* - 0: Success
|
|
718
|
+
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
719
|
+
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
720
|
+
* - MLD_ERR_FAIL: Other kinds of failure
|
|
721
|
+
**************************************************/
|
|
722
|
+
MLD_API_QUALIFIER
|
|
723
|
+
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
724
|
+
int MLD_API_NAMESPACE(signature_pre_hash_shake256)(
|
|
725
|
+
uint8_t sig[MLDSA_BYTES(MLD_CONFIG_API_PARAMETER_SET)], size_t *siglen,
|
|
726
|
+
const uint8_t *m, size_t mlen, const uint8_t *ctx, size_t ctxlen,
|
|
727
|
+
const uint8_t rnd[MLDSA_RNDBYTES],
|
|
728
|
+
const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]
|
|
729
|
+
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
730
|
+
,
|
|
731
|
+
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
732
|
+
#endif
|
|
733
|
+
);
|
|
734
|
+
|
|
735
|
+
/*************************************************
|
|
736
|
+
* Name: crypto_sign_verify_pre_hash_shake256
|
|
737
|
+
*
|
|
738
|
+
* Description: FIPS 204: Algorithm 5 HashML-DSA.Verify with SHAKE256.
|
|
739
|
+
* Verifies signature with pre-hashed message using SHAKE256.
|
|
740
|
+
* This function computes the SHAKE256 hash of the message
|
|
741
|
+
*internally.
|
|
742
|
+
*
|
|
743
|
+
* Arguments:
|
|
744
|
+
* - const uint8_t *sig: pointer to input signature
|
|
745
|
+
* - size_t siglen: length of signature
|
|
746
|
+
* - const uint8_t *m: pointer to message to be hashed and verified
|
|
747
|
+
* - size_t mlen: length of message
|
|
748
|
+
* - const uint8_t *ctx: pointer to context string
|
|
749
|
+
* - size_t ctxlen: length of context string
|
|
750
|
+
* - const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
751
|
+
* bit-packed public key
|
|
752
|
+
*
|
|
753
|
+
* Returns:
|
|
754
|
+
* - 0: Success
|
|
755
|
+
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
756
|
+
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
757
|
+
* - MLD_ERR_FAIL: Signature verification failed
|
|
758
|
+
**************************************************/
|
|
759
|
+
MLD_API_QUALIFIER
|
|
760
|
+
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
761
|
+
int MLD_API_NAMESPACE(verify_pre_hash_shake256)(
|
|
762
|
+
const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen,
|
|
763
|
+
const uint8_t *ctx, size_t ctxlen,
|
|
764
|
+
const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]
|
|
765
|
+
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
766
|
+
,
|
|
767
|
+
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
768
|
+
#endif
|
|
769
|
+
);
|
|
770
|
+
|
|
771
|
+
/* Maximum formatted domain separation message length */
|
|
772
|
+
#define MLD_DOMAIN_SEPARATION_MAX_BYTES (2 + 255 + 11 + 64)
|
|
773
|
+
|
|
774
|
+
/*************************************************
|
|
775
|
+
* Name: mld_prepare_domain_separation_prefix
|
|
776
|
+
*
|
|
777
|
+
* Description: Prepares domain separation prefix for ML-DSA signing.
|
|
778
|
+
* For pure ML-DSA (hashalg == MLD_PREHASH_NONE):
|
|
779
|
+
* Format: 0x00 || ctxlen (1 byte) || ctx
|
|
780
|
+
* For HashML-DSA (hashalg != MLD_PREHASH_NONE):
|
|
781
|
+
* Format: 0x01 || ctxlen (1 byte) || ctx || oid (11 bytes) || ph
|
|
782
|
+
*
|
|
783
|
+
* Arguments: - uint8_t prefix[MLD_DOMAIN_SEPARATION_MAX_BYTES]:
|
|
784
|
+
* output domain separation prefix buffer
|
|
785
|
+
* - const uint8_t *ph: pointer to pre-hashed message
|
|
786
|
+
* (ignored for pure ML-DSA)
|
|
787
|
+
* - size_t phlen: length of pre-hashed message
|
|
788
|
+
* (ignored for pure ML-DSA)
|
|
789
|
+
* - const uint8_t *ctx: pointer to context string (may be NULL)
|
|
790
|
+
* - size_t ctxlen: length of context string
|
|
791
|
+
* - int hashalg: hash algorithm constant
|
|
792
|
+
* (MLD_PREHASH_NONE for pure ML-DSA, or MLD_PREHASH_* for
|
|
793
|
+
* HashML-DSA)
|
|
794
|
+
*
|
|
795
|
+
* Returns the total length of the formatted prefix, or 0 on error.
|
|
796
|
+
*
|
|
797
|
+
* This function is useful for building incremental signing APIs.
|
|
798
|
+
*
|
|
799
|
+
* Specification:
|
|
800
|
+
* - For HashML-DSA (hashalg != MLD_PREHASH_NONE), implements
|
|
801
|
+
* @[FIPS204, Algorithm 4, L23]
|
|
802
|
+
* - For Pure ML-DSA (hashalg == MLD_PREHASH_NONE), implements
|
|
803
|
+
* ```
|
|
804
|
+
* M' <- BytesToBits(IntegerToBytes(0, 1)
|
|
805
|
+
* || IntegerToBytes(|ctx|, 1)
|
|
806
|
+
* || ctx
|
|
807
|
+
* ```
|
|
808
|
+
* which is part of @[FIPS204, Algorithm 2 (ML-DSA.Sign), L10] and
|
|
809
|
+
* @[FIPS204, Algorithm 3 (ML-DSA.Verify), L5].
|
|
810
|
+
*
|
|
811
|
+
**************************************************/
|
|
812
|
+
MLD_API_QUALIFIER
|
|
813
|
+
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
814
|
+
size_t MLD_API_NAMESPACE(prepare_domain_separation_prefix)(
|
|
815
|
+
uint8_t prefix[MLD_DOMAIN_SEPARATION_MAX_BYTES], const uint8_t *ph,
|
|
816
|
+
size_t phlen, const uint8_t *ctx, size_t ctxlen, int hashalg);
|
|
817
|
+
|
|
818
|
+
/*************************************************
|
|
819
|
+
* Name: crypto_sign_pk_from_sk
|
|
820
|
+
*
|
|
821
|
+
* Description: Performs basic validity checks on secret key, and derives
|
|
822
|
+
* public key.
|
|
823
|
+
*
|
|
824
|
+
* Referring to the decoding of the secret key
|
|
825
|
+
* `sk=(rho, K, tr, s1, s2, t0)`
|
|
826
|
+
* (cf. [@FIPS204, Algorithm 25 skDecode]),
|
|
827
|
+
* the following checks are performed:
|
|
828
|
+
* - Check that s1 and s2 have coefficients in
|
|
829
|
+
* [-MLDSA_ETA, MLDSA_ETA]
|
|
830
|
+
* - Check that t0 and tr stored in sk match recomputed values.
|
|
831
|
+
*
|
|
832
|
+
* Arguments: - uint8_t pk[CRYPTO_PUBLICKEYBYTES]: output public key
|
|
833
|
+
* - const uint8_t sk[CRYPTO_SECRETKEYBYTES]: input secret key
|
|
834
|
+
*
|
|
835
|
+
* Returns: - 0: Success
|
|
836
|
+
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
837
|
+
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
838
|
+
* - MLD_ERR_FAIL: Secret key validation failed
|
|
839
|
+
*
|
|
840
|
+
* Note: This function leaks whether the secret key is valid or invalid
|
|
841
|
+
* through its return value and timing.
|
|
842
|
+
**************************************************/
|
|
843
|
+
MLD_API_QUALIFIER
|
|
844
|
+
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
845
|
+
int MLD_API_NAMESPACE(pk_from_sk)(
|
|
846
|
+
uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)],
|
|
847
|
+
const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]
|
|
848
|
+
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
849
|
+
,
|
|
850
|
+
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
851
|
+
#endif
|
|
852
|
+
);
|
|
853
|
+
|
|
854
|
+
#ifdef __cplusplus
|
|
855
|
+
}
|
|
856
|
+
#endif
|
|
857
|
+
|
|
858
|
+
/****************************** SUPERCOP API *********************************/
|
|
859
|
+
|
|
860
|
+
#if !defined(MLD_CONFIG_API_NO_SUPERCOP)
|
|
861
|
+
/* Export API in SUPERCOP naming scheme CRYPTO_xxx / crypto_sign_xxx */
|
|
862
|
+
#define CRYPTO_SECRETKEYBYTES MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)
|
|
863
|
+
#define CRYPTO_PUBLICKEYBYTES MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)
|
|
864
|
+
#define CRYPTO_BYTES MLDSA_BYTES(MLD_CONFIG_API_PARAMETER_SET)
|
|
865
|
+
|
|
866
|
+
#define crypto_sign_keypair MLD_API_NAMESPACE(keypair)
|
|
867
|
+
#define crypto_sign_signature MLD_API_NAMESPACE(signature)
|
|
868
|
+
#define crypto_sign MLD_API_NAMESPACE(sign)
|
|
869
|
+
#define crypto_sign_verify MLD_API_NAMESPACE(verify)
|
|
870
|
+
#define crypto_sign_open MLD_API_NAMESPACE(open)
|
|
871
|
+
|
|
872
|
+
#else /* !MLD_CONFIG_API_NO_SUPERCOP */
|
|
873
|
+
|
|
874
|
+
/* If the SUPERCOP API is not needed, we can undefine the various helper macros
|
|
875
|
+
* above. Otherwise, they are needed for lazy evaluation of crypto_sign_xxx. */
|
|
876
|
+
#if !defined(MLD_API_LEGACY_CONFIG)
|
|
877
|
+
#undef MLD_CONFIG_API_PARAMETER_SET
|
|
878
|
+
#undef MLD_CONFIG_API_NAMESPACE_PREFIX
|
|
879
|
+
#undef MLD_CONFIG_API_NO_SUPERCOP
|
|
880
|
+
#undef MLD_CONFIG_API_CONSTANTS_ONLY
|
|
881
|
+
#undef MLD_CONFIG_API_QUALIFIER
|
|
882
|
+
#endif /* !MLD_API_LEGACY_CONFIG */
|
|
883
|
+
|
|
884
|
+
#undef MLD_API_CONCAT
|
|
885
|
+
#undef MLD_API_CONCAT_
|
|
886
|
+
#undef MLD_API_CONCAT_UNDERSCORE
|
|
887
|
+
#undef MLD_API_NAMESPACE
|
|
888
|
+
#undef MLD_API_MUST_CHECK_RETURN_VALUE
|
|
889
|
+
#undef MLD_API_QUALIFIER
|
|
890
|
+
#undef MLD_API_LEGACY_CONFIG
|
|
891
|
+
|
|
892
|
+
#endif /* MLD_CONFIG_API_NO_SUPERCOP */
|
|
893
|
+
#endif /* !MLD_CONFIG_API_CONSTANTS_ONLY */
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
/***************************** Memory Usage **********************************/
|
|
897
|
+
|
|
898
|
+
/*
|
|
899
|
+
* By default mldsa-native performs all memory allocations on the stack.
|
|
900
|
+
* Alternatively, mldsa-native supports custom allocation of large structures
|
|
901
|
+
* through the `MLD_CONFIG_CUSTOM_ALLOC_FREE` configuration option.
|
|
902
|
+
* See mldsa_native_config.h for details.
|
|
903
|
+
*
|
|
904
|
+
* `MLD_TOTAL_ALLOC_{44,65,87}_{KEYPAIR,SIGN,VERIFY}` indicates the maximum
|
|
905
|
+
* (accumulative) allocation via MLD_ALLOC for each parameter set and operation.
|
|
906
|
+
* Note that some stack allocation remains even
|
|
907
|
+
* when using custom allocators, so these values are lower than total stack
|
|
908
|
+
* usage with the default stack-only allocation.
|
|
909
|
+
*
|
|
910
|
+
* These constants may be used to implement custom allocations using a
|
|
911
|
+
* fixed-sized buffer and a simple allocator (e.g., bump allocator).
|
|
912
|
+
*/
|
|
913
|
+
/* check-magic: off */
|
|
914
|
+
#if defined(MLD_API_LEGACY_CONFIG) || !defined(MLD_CONFIG_REDUCE_RAM)
|
|
915
|
+
#define MLD_TOTAL_ALLOC_44_KEYPAIR_NO_PCT 45248
|
|
916
|
+
#define MLD_TOTAL_ALLOC_44_KEYPAIR_PCT 56640
|
|
917
|
+
#define MLD_TOTAL_ALLOC_44_SIGN 52896
|
|
918
|
+
#define MLD_TOTAL_ALLOC_44_VERIFY 38816
|
|
919
|
+
#define MLD_TOTAL_ALLOC_65_KEYPAIR_NO_PCT 71872
|
|
920
|
+
#define MLD_TOTAL_ALLOC_65_KEYPAIR_PCT 85856
|
|
921
|
+
#define MLD_TOTAL_ALLOC_65_SIGN 80576
|
|
922
|
+
#define MLD_TOTAL_ALLOC_65_VERIFY 62432
|
|
923
|
+
#define MLD_TOTAL_ALLOC_87_KEYPAIR_NO_PCT 112832
|
|
924
|
+
#define MLD_TOTAL_ALLOC_87_KEYPAIR_PCT 130816
|
|
925
|
+
#define MLD_TOTAL_ALLOC_87_SIGN 123584
|
|
926
|
+
#define MLD_TOTAL_ALLOC_87_VERIFY 99552
|
|
927
|
+
#else /* MLD_API_LEGACY_CONFIG || !MLD_CONFIG_REDUCE_RAM */
|
|
928
|
+
#define MLD_TOTAL_ALLOC_44_KEYPAIR_NO_PCT 32992
|
|
929
|
+
#define MLD_TOTAL_ALLOC_44_KEYPAIR_PCT 36192
|
|
930
|
+
#define MLD_TOTAL_ALLOC_44_SIGN 32448
|
|
931
|
+
#define MLD_TOTAL_ALLOC_44_VERIFY 22464
|
|
932
|
+
#define MLD_TOTAL_ALLOC_65_KEYPAIR_NO_PCT 46304
|
|
933
|
+
#define MLD_TOTAL_ALLOC_65_KEYPAIR_PCT 50048
|
|
934
|
+
#define MLD_TOTAL_ALLOC_65_SIGN 44768
|
|
935
|
+
#define MLD_TOTAL_ALLOC_65_VERIFY 30720
|
|
936
|
+
#define MLD_TOTAL_ALLOC_87_KEYPAIR_NO_PCT 62688
|
|
937
|
+
#define MLD_TOTAL_ALLOC_87_KEYPAIR_PCT 66336
|
|
938
|
+
#define MLD_TOTAL_ALLOC_87_SIGN 59104
|
|
939
|
+
#define MLD_TOTAL_ALLOC_87_VERIFY 41216
|
|
940
|
+
#endif /* !(MLD_API_LEGACY_CONFIG || !MLD_CONFIG_REDUCE_RAM) */
|
|
941
|
+
/* check-magic: on */
|
|
942
|
+
|
|
943
|
+
/*
|
|
944
|
+
* MLD_TOTAL_ALLOC_*_KEYPAIR adapts based on MLD_CONFIG_KEYGEN_PCT.
|
|
945
|
+
* For legacy config, we don't know which options are used, so assume
|
|
946
|
+
* the worst case (PCT enabled).
|
|
947
|
+
*/
|
|
948
|
+
#if defined(MLD_API_LEGACY_CONFIG) || defined(MLD_CONFIG_KEYGEN_PCT)
|
|
949
|
+
#define MLD_TOTAL_ALLOC_44_KEYPAIR MLD_TOTAL_ALLOC_44_KEYPAIR_PCT
|
|
950
|
+
#define MLD_TOTAL_ALLOC_65_KEYPAIR MLD_TOTAL_ALLOC_65_KEYPAIR_PCT
|
|
951
|
+
#define MLD_TOTAL_ALLOC_87_KEYPAIR MLD_TOTAL_ALLOC_87_KEYPAIR_PCT
|
|
952
|
+
#else
|
|
953
|
+
#define MLD_TOTAL_ALLOC_44_KEYPAIR MLD_TOTAL_ALLOC_44_KEYPAIR_NO_PCT
|
|
954
|
+
#define MLD_TOTAL_ALLOC_65_KEYPAIR MLD_TOTAL_ALLOC_65_KEYPAIR_NO_PCT
|
|
955
|
+
#define MLD_TOTAL_ALLOC_87_KEYPAIR MLD_TOTAL_ALLOC_87_KEYPAIR_NO_PCT
|
|
956
|
+
#endif
|
|
957
|
+
|
|
958
|
+
#define MLD_MAX3_(a, b, c) \
|
|
959
|
+
((a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c)))
|
|
960
|
+
|
|
961
|
+
/*
|
|
962
|
+
* `MLD_TOTAL_ALLOC_{44,65,87}` is the maximum across all operations for each
|
|
963
|
+
* parameter set.
|
|
964
|
+
*/
|
|
965
|
+
#define MLD_TOTAL_ALLOC_44 \
|
|
966
|
+
MLD_MAX3_(MLD_TOTAL_ALLOC_44_KEYPAIR, MLD_TOTAL_ALLOC_44_SIGN, \
|
|
967
|
+
MLD_TOTAL_ALLOC_44_VERIFY)
|
|
968
|
+
#define MLD_TOTAL_ALLOC_65 \
|
|
969
|
+
MLD_MAX3_(MLD_TOTAL_ALLOC_65_KEYPAIR, MLD_TOTAL_ALLOC_65_SIGN, \
|
|
970
|
+
MLD_TOTAL_ALLOC_65_VERIFY)
|
|
971
|
+
#define MLD_TOTAL_ALLOC_87 \
|
|
972
|
+
MLD_MAX3_(MLD_TOTAL_ALLOC_87_KEYPAIR, MLD_TOTAL_ALLOC_87_SIGN, \
|
|
973
|
+
MLD_TOTAL_ALLOC_87_VERIFY)
|
|
974
|
+
|
|
975
|
+
#endif /* !MLD_H */
|