pq_crypto 0.6.4 → 0.6.6
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 +180 -0
- data/README.md +7 -0
- data/ext/pqcrypto/extconf.rb +4 -1
- data/ext/pqcrypto/pq_externalmu.c +35 -0
- data/ext/pqcrypto/pqcrypto_native_api.h +85 -75
- data/ext/pqcrypto/pqcrypto_ruby_secure.c +16 -9
- data/ext/pqcrypto/pqcrypto_secure.c +43 -33
- data/ext/pqcrypto/pqcrypto_secure.h +52 -47
- data/ext/pqcrypto/pqcrypto_version.h +1 -1
- data/ext/pqcrypto/vendor/.vendored +7 -7
- data/ext/pqcrypto/vendor/mldsa-native/BUILDING.md +5 -2
- data/ext/pqcrypto/vendor/mldsa-native/LICENSE +21 -2
- data/ext/pqcrypto/vendor/mldsa-native/README.md +20 -7
- data/ext/pqcrypto/vendor/mldsa-native/RELEASE.md +160 -0
- data/ext/pqcrypto/vendor/mldsa-native/SECURITY.md +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/README.md +2 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +85 -59
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +292 -348
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +122 -76
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +184 -86
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +49 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +49 -81
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/context.h +152 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +25 -12
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c +2 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +2 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +2 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +9 -11
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +19 -11
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +7 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +7 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +12 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +12 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +3 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +3 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +6 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +3 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +11 -11
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +9 -22
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +8 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +1 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/{state_extract_bytes_x4_mve.S → keccak_f1600_x4_state_extract_bytes_mve.S} +14 -14
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/{state_xor_bytes_x4_mve.S → keccak_f1600_x4_state_xor_bytes_mve.S} +12 -12
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +5 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +2 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +1 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +36 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +62 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +87 -54
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{intt_aarch64_asm.S → mldsa_intt_aarch64_asm.S} +39 -6
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{ntt_aarch64_asm.S → mldsa_ntt_aarch64_asm.S} +39 -6
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{pointwise_montgomery_aarch64_asm.S → mldsa_pointwise_montgomery_aarch64_asm.S} +25 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_caddq_aarch64_asm.S → mldsa_poly_caddq_aarch64_asm.S} +19 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_chknorm_aarch64_asm.S → mldsa_poly_chknorm_aarch64_asm.S} +24 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_decompose_32_aarch64_asm.S → mldsa_poly_decompose_32_aarch64_asm.S} +25 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_decompose_88_aarch64_asm.S → mldsa_poly_decompose_88_aarch64_asm.S} +25 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_use_hint_32_aarch64_asm.S → mldsa_poly_use_hint_32_aarch64_asm.S} +25 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_use_hint_88_aarch64_asm.S → mldsa_poly_use_hint_88_aarch64_asm.S} +25 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S → mldsa_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S} +31 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S → mldsa_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S} +31 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S → mldsa_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S} +31 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{polyz_unpack_17_aarch64_asm.S → mldsa_polyz_unpack_17_aarch64_asm.S} +31 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{polyz_unpack_19_aarch64_asm.S → mldsa_polyz_unpack_19_aarch64_asm.S} +31 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{rej_uniform_aarch64_asm.S → mldsa_rej_uniform_aarch64_asm.S} +48 -15
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{rej_uniform_eta2_aarch64_asm.S → mldsa_rej_uniform_eta2_aarch64_asm.S} +42 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{rej_uniform_eta4_aarch64_asm.S → mldsa_rej_uniform_eta4_aarch64_asm.S} +42 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +11 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/meta.h +3 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +28 -28
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +171 -49
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{intt_avx2_asm.S → mldsa_intt_avx2_asm.S} +23 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{ntt_avx2_asm.S → mldsa_ntt_avx2_asm.S} +23 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{nttunpack_avx2_asm.S → mldsa_nttunpack_avx2_asm.S} +17 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{pointwise_acc_l4_avx2_asm.S → mldsa_pointwise_acc_l4_avx2_asm.S} +37 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{pointwise_acc_l5_avx2_asm.S → mldsa_pointwise_acc_l5_avx2_asm.S} +37 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{pointwise_acc_l7_avx2_asm.S → mldsa_pointwise_acc_l7_avx2_asm.S} +37 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{pointwise_avx2_asm.S → mldsa_pointwise_avx2_asm.S} +31 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{poly_caddq_avx2_asm.S → mldsa_poly_caddq_avx2_asm.S} +18 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_chknorm_avx2_asm.S +176 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_32_avx2_asm.S +490 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_88_avx2_asm.S +489 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_32_avx2_asm.S +123 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_88_avx2_asm.S +125 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_17_avx2_asm.S +355 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_19_avx2_asm.S +355 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_avx2_asm.S +132 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta2_avx2_asm.S +205 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S +176 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +27 -36
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +42 -8
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/params.h +93 -17
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +74 -15
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +97 -11
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +7 -38
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +49 -7
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +16 -17
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +26 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +3 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +18 -19
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +15 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +28 -6
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +311 -246
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +245 -240
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sys.h +64 -5
- data/ext/pqcrypto/vendor/mlkem-native/BUILDING.md +5 -2
- data/ext/pqcrypto/vendor/mlkem-native/LICENSE +21 -3
- data/ext/pqcrypto/vendor/mlkem-native/README.md +4 -6
- data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +211 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/README.md +2 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +25 -34
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +79 -142
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +62 -71
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +77 -39
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +25 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +48 -34
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +25 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +14 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/context.h +51 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +2 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/auto.h +20 -12
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +5 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +5 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +5 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +10 -7
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +10 -7
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +1 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +3 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +3 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +6 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +3 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/api.h +11 -11
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/mve.h +8 -22
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +8 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/{state_extract_bytes_x4_mve.S → keccak_f1600_x4_state_extract_bytes_mve.S} +14 -14
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/{state_xor_bytes_x4_mve.S → keccak_f1600_x4_state_xor_bytes_mve.S} +12 -12
- 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/keccak_f1600_x4_avx2_asm.S +36 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +22 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +20 -11
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +39 -11
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +64 -15
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +44 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +2 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +11 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{intt_aarch64_asm.S → mlkem_intt_aarch64_asm.S} +16 -9
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{ntt_aarch64_asm.S → mlkem_ntt_aarch64_asm.S} +10 -7
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_mulcache_compute_aarch64_asm.S → mlkem_poly_mulcache_compute_aarch64_asm.S} +6 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_reduce_aarch64_asm.S → mlkem_poly_reduce_aarch64_asm.S} +6 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tobytes_aarch64_asm.S → mlkem_poly_tobytes_aarch64_asm.S} +12 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tomont_aarch64_asm.S → mlkem_poly_tomont_aarch64_asm.S} +11 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S} +6 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S} +6 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S} +6 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{rej_uniform_aarch64_asm.S → mlkem_rej_uniform_aarch64_asm.S} +17 -17
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +21 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +1 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/meta.h +4 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{intt_ppc_asm.S → mlkem_intt_ppc_asm.S} +29 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{ntt_ppc_asm.S → mlkem_ntt_ppc_asm.S} +22 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{poly_tomont_ppc_asm.S → mlkem_poly_tomont_ppc_asm.S} +25 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{reduce_ppc_asm.S → mlkem_reduce_ppc_asm.S} +22 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +4 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/arith_native_riscv64.h +4 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +6 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +45 -25
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +20 -20
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +14 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +8 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{intt_avx2_asm.S → mlkem_intt_avx2_asm.S} +27 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntt_avx2_asm.S → mlkem_ntt_avx2_asm.S} +23 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttfrombytes_avx2_asm.S → mlkem_nttfrombytes_avx2_asm.S} +27 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntttobytes_avx2_asm.S → mlkem_ntttobytes_avx2_asm.S} +27 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttunpack_avx2_asm.S → mlkem_nttunpack_avx2_asm.S} +17 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d10_avx2_asm.S → mlkem_poly_compress_d10_avx2_asm.S} +34 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d11_avx2_asm.S → mlkem_poly_compress_d11_avx2_asm.S} +33 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d4_avx2_asm.S → mlkem_poly_compress_d4_avx2_asm.S} +34 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d5_avx2_asm.S → mlkem_poly_compress_d5_avx2_asm.S} +33 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d10_avx2_asm.S → mlkem_poly_decompress_d10_avx2_asm.S} +32 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d11_avx2_asm.S → mlkem_poly_decompress_d11_avx2_asm.S} +32 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d4_avx2_asm.S → mlkem_poly_decompress_d4_avx2_asm.S} +32 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d5_avx2_asm.S → mlkem_poly_decompress_d5_avx2_asm.S} +32 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_mulcache_compute_avx2_asm.S → mlkem_poly_mulcache_compute_avx2_asm.S} +29 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S} +35 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S} +35 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S} +35 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{reduce_avx2_asm.S → mlkem_reduce_avx2_asm.S} +17 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{rej_uniform_avx2_asm.S → mlkem_rej_uniform_avx2_asm.S} +40 -7
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{tomont_avx2_asm.S → mlkem_tomont_avx2_asm.S} +20 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +7 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +6 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +25 -4
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +33 -4
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +4 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +4 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +21 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +11 -10
- data/lib/pq_crypto/version.rb +1 -1
- data/script/vendor_libs.rb +6 -6
- metadata +79 -79
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_chknorm_avx2.c +0 -52
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +0 -157
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +0 -157
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +0 -103
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +0 -105
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +0 -94
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +0 -96
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_avx2.c +0 -126
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +0 -157
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +0 -141
|
@@ -23,6 +23,11 @@
|
|
|
23
23
|
* Make sure the configuration file is in the include path
|
|
24
24
|
* (this is "mldsa_native_config.h" by default, or MLD_CONFIG_FILE if defined).
|
|
25
25
|
*
|
|
26
|
+
* # API conventions
|
|
27
|
+
*
|
|
28
|
+
* Conventions shared by all functions below (return values, pointer validity,
|
|
29
|
+
* output buffers on error) are documented in API-CONVENTIONS.md.
|
|
30
|
+
*
|
|
26
31
|
* # Multi-level builds
|
|
27
32
|
*
|
|
28
33
|
* This header specifies a build of mldsa-native for a fixed security level.
|
|
@@ -30,47 +35,7 @@
|
|
|
30
35
|
* in the configuration file and include this header multiple times, setting
|
|
31
36
|
* MLD_CONFIG_PARAMETER_SET accordingly for each, and #undef'ing the MLD_H
|
|
32
37
|
* 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
|
-
******************************************************************************/
|
|
38
|
+
*/
|
|
74
39
|
|
|
75
40
|
/******************************* Key sizes ************************************/
|
|
76
41
|
|
|
@@ -102,7 +67,13 @@
|
|
|
102
67
|
#define MLDSA65_CRHBYTES MLDSA_CRHBYTES
|
|
103
68
|
#define MLDSA87_CRHBYTES MLDSA_CRHBYTES
|
|
104
69
|
|
|
105
|
-
/* Size of TR
|
|
70
|
+
/* Size of TR in bytes (level-independent)
|
|
71
|
+
*
|
|
72
|
+
* TR = SHAKE256(pk, 64) is the hash of the public key. Callers of the
|
|
73
|
+
* external-mu API (signature_extmu / verify_extmu) that compute the message
|
|
74
|
+
* representative mu = SHAKE256(TR || M', MLDSA_CRHBYTES) themselves -- e.g. to
|
|
75
|
+
* sign or verify a message that is too large or streamed to hold in memory --
|
|
76
|
+
* need this constant to size the TR buffer. */
|
|
106
77
|
#define MLDSA_TRBYTES 64
|
|
107
78
|
#define MLDSA44_TRBYTES MLDSA_TRBYTES
|
|
108
79
|
#define MLDSA65_TRBYTES MLDSA_TRBYTES
|
|
@@ -124,33 +95,45 @@
|
|
|
124
95
|
|
|
125
96
|
/****************************** Error codes ***********************************/
|
|
126
97
|
|
|
127
|
-
/* Generic failure condition
|
|
128
|
-
|
|
98
|
+
/* Generic failure condition, reserved for failures not covered by a more
|
|
99
|
+
* specific error code. */
|
|
100
|
+
#define MLD_ERR_FAIL (-1)
|
|
129
101
|
/* An allocation failed. This can only happen if MLD_CONFIG_CUSTOM_ALLOC_FREE
|
|
130
102
|
* is defined and the provided MLD_CUSTOM_ALLOC can fail. */
|
|
131
|
-
#define MLD_ERR_OUT_OF_MEMORY -2
|
|
132
|
-
/* An
|
|
103
|
+
#define MLD_ERR_OUT_OF_MEMORY (-2)
|
|
104
|
+
/* An RNG failure occurred. Might be due to insufficient entropy or
|
|
133
105
|
* system misconfiguration. */
|
|
134
|
-
#define MLD_ERR_RNG_FAIL -3
|
|
106
|
+
#define MLD_ERR_RNG_FAIL (-3)
|
|
135
107
|
/* The signing rejection-sampling loop exceeded
|
|
136
108
|
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS iterations without producing a valid
|
|
137
|
-
* signature. With a FIPS 204 Appendix C compliant bound (>=
|
|
109
|
+
* signature. With a FIPS 204 Appendix C compliant bound (>= 821) this
|
|
138
110
|
* has probability < 2^-256. */
|
|
139
|
-
#define MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED -4
|
|
140
|
-
|
|
141
|
-
|
|
111
|
+
#define MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED (-4)
|
|
112
|
+
/* Signing was paused before completing, at the request of a caller-provided
|
|
113
|
+
* MLD_CONFIG_SIGN_HOOK_ATTEMPT hook (see mldsa_native_config.h). The caller
|
|
114
|
+
* resumes by re-invoking signing with the same inputs; the attempt hook,
|
|
115
|
+
* together with MLD_CONFIG_SIGN_HOOK_RESUME, decides where to continue. */
|
|
116
|
+
#define MLD_ERR_SIGNING_PAUSED (-5)
|
|
117
|
+
/* Signature verification failed: the signature is not valid for the given
|
|
118
|
+
* message and public key. Returned by the verification API. */
|
|
119
|
+
#define MLD_ERR_INVALID_SIGNATURE (-6)
|
|
120
|
+
/* Secret key validation failed: the secret key is malformed or internally
|
|
121
|
+
* inconsistent. Returned by pk_from_sk. */
|
|
122
|
+
#define MLD_ERR_INVALID_KEY (-7)
|
|
123
|
+
/* The Pairwise Consistency Test failed. Only possible when
|
|
124
|
+
* MLD_CONFIG_KEYGEN_PCT is enabled; signals that the freshly generated key
|
|
125
|
+
* pair failed its sign/verify self-test. */
|
|
126
|
+
#define MLD_ERR_PCT_FAIL (-8)
|
|
127
|
+
/* An argument was invalid, e.g. an unsupported pre-hash algorithm or a context
|
|
128
|
+
* string longer than 255 bytes. */
|
|
129
|
+
#define MLD_ERR_INVALID_ARG (-9)
|
|
130
|
+
|
|
131
|
+
/********************* Namespacing and Qualifiers *****************************/
|
|
142
132
|
|
|
143
133
|
#define MLD_API_CONCAT_(x, y) x##y
|
|
144
134
|
#define MLD_API_CONCAT(x, y) MLD_API_CONCAT_(x, y)
|
|
145
135
|
#define MLD_API_CONCAT_UNDERSCORE(x, y) MLD_API_CONCAT(MLD_API_CONCAT(x, _), y)
|
|
146
136
|
|
|
147
|
-
#if !defined(MLD_CONFIG_API_PARAMETER_SET)
|
|
148
|
-
/* Recommended configuration via same config file as used for the build. */
|
|
149
|
-
|
|
150
|
-
/* For now, we derive the legacy API configuration MLD_CONFIG_API_XXX from
|
|
151
|
-
* the config file. In mldsa-native-v2, this will be removed and we will
|
|
152
|
-
* exclusively work with MLD_CONFIG_XXX. */
|
|
153
|
-
|
|
154
137
|
/* You need to make sure the config file is in the include path. */
|
|
155
138
|
#if defined(MLD_CONFIG_FILE)
|
|
156
139
|
#include MLD_CONFIG_FILE
|
|
@@ -158,53 +141,55 @@
|
|
|
158
141
|
#include "mldsa_native_config.h"
|
|
159
142
|
#endif
|
|
160
143
|
|
|
161
|
-
|
|
162
|
-
|
|
144
|
+
/* Namespace prefix for the public API symbols. For multi-level builds, the
|
|
145
|
+
* parameter set is appended to disambiguate the security levels. */
|
|
163
146
|
#if defined(MLD_CONFIG_MULTILEVEL_BUILD)
|
|
164
|
-
#define
|
|
147
|
+
#define MLD_API_NAMESPACE_PREFIX \
|
|
165
148
|
MLD_API_CONCAT(MLD_CONFIG_NAMESPACE_PREFIX, MLD_CONFIG_PARAMETER_SET)
|
|
166
149
|
#else
|
|
167
|
-
#define
|
|
168
|
-
#endif
|
|
169
|
-
|
|
170
|
-
#if defined(MLD_CONFIG_NO_SUPERCOP)
|
|
171
|
-
#define MLD_CONFIG_API_NO_SUPERCOP
|
|
172
|
-
#endif
|
|
173
|
-
|
|
174
|
-
#if defined(MLD_CONFIG_CONSTANTS_ONLY)
|
|
175
|
-
#define MLD_CONFIG_API_CONSTANTS_ONLY
|
|
176
|
-
#endif
|
|
177
|
-
|
|
178
|
-
#if defined(MLD_CONFIG_EXTERNAL_API_QUALIFIER)
|
|
179
|
-
#define MLD_CONFIG_API_QUALIFIER MLD_CONFIG_EXTERNAL_API_QUALIFIER
|
|
150
|
+
#define MLD_API_NAMESPACE_PREFIX MLD_CONFIG_NAMESPACE_PREFIX
|
|
180
151
|
#endif
|
|
181
152
|
|
|
182
|
-
#else /* !MLD_CONFIG_API_PARAMETER_SET */
|
|
183
|
-
#define MLD_API_LEGACY_CONFIG
|
|
184
|
-
|
|
185
|
-
#endif /* MLD_CONFIG_API_PARAMETER_SET */
|
|
186
|
-
|
|
187
153
|
#define MLD_API_NAMESPACE(sym) \
|
|
188
|
-
MLD_API_CONCAT_UNDERSCORE(
|
|
154
|
+
MLD_API_CONCAT_UNDERSCORE(MLD_API_NAMESPACE_PREFIX, sym)
|
|
189
155
|
|
|
190
|
-
#if defined(__GNUC__) || defined(
|
|
156
|
+
#if defined(__GNUC__) || defined(__clang__)
|
|
191
157
|
#define MLD_API_MUST_CHECK_RETURN_VALUE __attribute__((warn_unused_result))
|
|
192
158
|
#else
|
|
193
159
|
#define MLD_API_MUST_CHECK_RETURN_VALUE
|
|
194
160
|
#endif
|
|
195
161
|
|
|
196
|
-
#if defined(
|
|
197
|
-
#define MLD_API_QUALIFIER
|
|
162
|
+
#if defined(MLD_CONFIG_EXTERNAL_API_QUALIFIER)
|
|
163
|
+
#define MLD_API_QUALIFIER MLD_CONFIG_EXTERNAL_API_QUALIFIER
|
|
198
164
|
#else
|
|
199
165
|
#define MLD_API_QUALIFIER
|
|
200
166
|
#endif
|
|
201
167
|
|
|
202
|
-
|
|
168
|
+
/* Hash algorithm constants for domain separation */
|
|
169
|
+
#define MLD_PREHASH_NONE 0
|
|
170
|
+
#define MLD_PREHASH_SHA2_224 1
|
|
171
|
+
#define MLD_PREHASH_SHA2_256 2
|
|
172
|
+
#define MLD_PREHASH_SHA2_384 3
|
|
173
|
+
#define MLD_PREHASH_SHA2_512 4
|
|
174
|
+
#define MLD_PREHASH_SHA2_512_224 5
|
|
175
|
+
#define MLD_PREHASH_SHA2_512_256 6
|
|
176
|
+
#define MLD_PREHASH_SHA3_224 7
|
|
177
|
+
#define MLD_PREHASH_SHA3_256 8
|
|
178
|
+
#define MLD_PREHASH_SHA3_384 9
|
|
179
|
+
#define MLD_PREHASH_SHA3_512 10
|
|
180
|
+
#define MLD_PREHASH_SHAKE_128 11
|
|
181
|
+
#define MLD_PREHASH_SHAKE_256 12
|
|
182
|
+
|
|
183
|
+
/* Maximum formatted domain separation message length */
|
|
184
|
+
#define MLD_DOMAIN_SEPARATION_MAX_BYTES (2 + 255 + 11 + 64)
|
|
185
|
+
|
|
186
|
+
/****************************** Function API **********************************/
|
|
187
|
+
|
|
188
|
+
#if !defined(MLD_CONFIG_CONSTANTS_ONLY)
|
|
203
189
|
|
|
204
190
|
#include <stddef.h>
|
|
205
191
|
#include <stdint.h>
|
|
206
192
|
|
|
207
|
-
|
|
208
193
|
#ifdef __cplusplus
|
|
209
194
|
extern "C"
|
|
210
195
|
{
|
|
@@ -220,7 +205,7 @@ extern "C"
|
|
|
220
205
|
* @warning The seed must be generated by a cryptographically secure random
|
|
221
206
|
* number generator.
|
|
222
207
|
*
|
|
223
|
-
* @spec{Implements @[FIPS204 Algorithm 6
|
|
208
|
+
* @spec{Implements @[FIPS204, Algorithm 6, ML-DSA.KeyGen_internal].}
|
|
224
209
|
*
|
|
225
210
|
* @param[out] pk Output public key.
|
|
226
211
|
* @param[out] sk Output private key.
|
|
@@ -233,20 +218,25 @@ extern "C"
|
|
|
233
218
|
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
234
219
|
* used and an allocation via
|
|
235
220
|
* MLD_CUSTOM_ALLOC returned NULL.
|
|
236
|
-
* @retval MLD_ERR_RNG_FAIL Random number generation failed
|
|
237
|
-
*
|
|
238
|
-
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
239
|
-
* iterations. Only possible when
|
|
240
|
-
* MLD_CONFIG_KEYGEN_PCT is enabled.
|
|
241
|
-
* @retval MLD_ERR_FAIL Other kinds of failure, including
|
|
242
|
-
* PCT failure if
|
|
221
|
+
* @retval MLD_ERR_RNG_FAIL Random number generation failed
|
|
222
|
+
* during the PCT. Only possible when
|
|
243
223
|
* MLD_CONFIG_KEYGEN_PCT is enabled.
|
|
224
|
+
* @retval MLD_ERR_SIGNING_PAUSED The PCT's signing step was paused by
|
|
225
|
+
* a MLD_CONFIG_SIGN_HOOK_ATTEMPT hook.
|
|
226
|
+
* This should currently never happen:
|
|
227
|
+
* signing hooks require
|
|
228
|
+
* MLD_CONFIG_NO_RANDOMIZED_API, which
|
|
229
|
+
* is incompatible with
|
|
230
|
+
* MLD_CONFIG_KEYGEN_PCT, so the two
|
|
231
|
+
* cannot be enabled simultaneously.
|
|
232
|
+
* @retval MLD_ERR_PCT_FAIL MLD_CONFIG_KEYGEN_PCT is enabled and
|
|
233
|
+
* the PCT check failed.
|
|
244
234
|
*/
|
|
245
235
|
MLD_API_QUALIFIER
|
|
246
236
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
247
237
|
int MLD_API_NAMESPACE(keypair_internal)(
|
|
248
|
-
uint8_t pk[MLDSA_PUBLICKEYBYTES(
|
|
249
|
-
uint8_t sk[MLDSA_SECRETKEYBYTES(
|
|
238
|
+
uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_PARAMETER_SET)],
|
|
239
|
+
uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_PARAMETER_SET)],
|
|
250
240
|
const uint8_t seed[MLDSA_SEEDBYTES]
|
|
251
241
|
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
252
242
|
,
|
|
@@ -255,13 +245,14 @@ int MLD_API_NAMESPACE(keypair_internal)(
|
|
|
255
245
|
);
|
|
256
246
|
|
|
257
247
|
#if !defined(MLD_CONFIG_CORE_API_ONLY)
|
|
248
|
+
#if !defined(MLD_CONFIG_NO_RANDOMIZED_API)
|
|
258
249
|
/**
|
|
259
250
|
* Generate a public-private key pair.
|
|
260
251
|
*
|
|
261
252
|
* When MLD_CONFIG_KEYGEN_PCT is set, performs a Pairwise Consistency Test
|
|
262
253
|
* (PCT) as required by FIPS 140-3 IG.
|
|
263
254
|
*
|
|
264
|
-
* @spec{Implements @[FIPS204 Algorithm 1
|
|
255
|
+
* @spec{Implements @[FIPS204, Algorithm 1, ML-DSA.KeyGen].}
|
|
265
256
|
*
|
|
266
257
|
* @param[out] pk Output public key.
|
|
267
258
|
* @param[out] sk Output private key.
|
|
@@ -274,23 +265,28 @@ int MLD_API_NAMESPACE(keypair_internal)(
|
|
|
274
265
|
* used and an allocation via
|
|
275
266
|
* MLD_CUSTOM_ALLOC returned NULL.
|
|
276
267
|
* @retval MLD_ERR_RNG_FAIL Random number generation failed.
|
|
277
|
-
* @retval
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
268
|
+
* @retval MLD_ERR_SIGNING_PAUSED The PCT's signing step was paused by
|
|
269
|
+
* a MLD_CONFIG_SIGN_HOOK_ATTEMPT hook.
|
|
270
|
+
* This should currently never happen:
|
|
271
|
+
* signing hooks require
|
|
272
|
+
* MLD_CONFIG_NO_RANDOMIZED_API, which
|
|
273
|
+
* is incompatible with
|
|
274
|
+
* MLD_CONFIG_KEYGEN_PCT, so the two
|
|
275
|
+
* cannot be enabled simultaneously.
|
|
276
|
+
* @retval MLD_ERR_PCT_FAIL MLD_CONFIG_KEYGEN_PCT is enabled and
|
|
282
277
|
* the PCT check failed.
|
|
283
278
|
*/
|
|
284
279
|
MLD_API_QUALIFIER
|
|
285
280
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
286
281
|
int MLD_API_NAMESPACE(keypair)(
|
|
287
|
-
uint8_t pk[MLDSA_PUBLICKEYBYTES(
|
|
288
|
-
uint8_t sk[MLDSA_SECRETKEYBYTES(
|
|
282
|
+
uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_PARAMETER_SET)],
|
|
283
|
+
uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_PARAMETER_SET)]
|
|
289
284
|
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
290
285
|
,
|
|
291
286
|
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
292
287
|
#endif
|
|
293
288
|
);
|
|
289
|
+
#endif /* !MLD_CONFIG_NO_RANDOMIZED_API */
|
|
294
290
|
#endif /* !MLD_CONFIG_CORE_API_ONLY */
|
|
295
291
|
#endif /* !MLD_CONFIG_NO_KEYPAIR_API */
|
|
296
292
|
|
|
@@ -298,13 +294,16 @@ int MLD_API_NAMESPACE(keypair)(
|
|
|
298
294
|
/**
|
|
299
295
|
* Compute signature using a caller-supplied random seed and prefix.
|
|
300
296
|
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
297
|
+
* On error (non-zero return value), the signature buffer sig is zeroized.
|
|
298
|
+
*
|
|
299
|
+
* @spec{Implements @[FIPS204, Algorithm 7, ML-DSA.Sign_internal].}
|
|
303
300
|
*
|
|
304
|
-
* @
|
|
301
|
+
* @warning This function does not perform secret key validation.
|
|
302
|
+
* Callers importing serialized keys can use pk_from_sk
|
|
303
|
+
* to validate them before signing.
|
|
305
304
|
*
|
|
306
|
-
* @param[out] sig
|
|
307
|
-
*
|
|
305
|
+
* @param[out] sig Pointer to buffer to hold the generated signature of
|
|
306
|
+
* MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET) bytes.
|
|
308
307
|
* @param[in] m Pointer to message to be signed (when
|
|
309
308
|
* externalmu == 0), or to a precomputed
|
|
310
309
|
* message representative mu (when externalmu != 0).
|
|
@@ -315,7 +314,7 @@ int MLD_API_NAMESPACE(keypair)(
|
|
|
315
314
|
* @param prelen Length of prefix string. Ignored when
|
|
316
315
|
* externalmu != 0.
|
|
317
316
|
* @param[in] rnd Random seed.
|
|
318
|
-
* @param[in] sk Bit-packed secret key.
|
|
317
|
+
* @param[in] sk Bit-packed secret key; assumed to be valid.
|
|
319
318
|
* @param externalmu 0: m/mlen is the raw message; mu = H(tr, pre, m) is
|
|
320
319
|
* computed internally.
|
|
321
320
|
* non-zero: m points to a precomputed mu of
|
|
@@ -331,15 +330,16 @@ int MLD_API_NAMESPACE(keypair)(
|
|
|
331
330
|
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The rejection-sampling loop exceeded
|
|
332
331
|
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
333
332
|
* iterations.
|
|
334
|
-
* @retval
|
|
333
|
+
* @retval MLD_ERR_SIGNING_PAUSED A MLD_CONFIG_SIGN_HOOK_ATTEMPT hook
|
|
334
|
+
* paused signing; re-invoke to resume.
|
|
335
335
|
*/
|
|
336
336
|
MLD_API_QUALIFIER
|
|
337
337
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
338
338
|
int MLD_API_NAMESPACE(signature_internal)(
|
|
339
|
-
uint8_t sig[MLDSA_BYTES(
|
|
340
|
-
|
|
339
|
+
uint8_t sig[MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET)], const uint8_t *m,
|
|
340
|
+
size_t mlen, const uint8_t *pre, size_t prelen,
|
|
341
341
|
const uint8_t rnd[MLDSA_RNDBYTES],
|
|
342
|
-
const uint8_t sk[MLDSA_SECRETKEYBYTES(
|
|
342
|
+
const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_PARAMETER_SET)],
|
|
343
343
|
int externalmu
|
|
344
344
|
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
345
345
|
,
|
|
@@ -348,20 +348,26 @@ int MLD_API_NAMESPACE(signature_internal)(
|
|
|
348
348
|
);
|
|
349
349
|
|
|
350
350
|
#if !defined(MLD_CONFIG_CORE_API_ONLY)
|
|
351
|
+
#if !defined(MLD_CONFIG_NO_RANDOMIZED_API)
|
|
351
352
|
/**
|
|
352
353
|
* Compute signature. This function implements the randomized variant of
|
|
353
354
|
* ML-DSA. If you require the deterministic variant, use
|
|
354
|
-
*
|
|
355
|
+
* signature_internal directly.
|
|
356
|
+
*
|
|
357
|
+
* @spec{Implements @[FIPS204, Algorithm 2, ML-DSA.Sign].}
|
|
355
358
|
*
|
|
356
|
-
* @
|
|
359
|
+
* @warning This function does not perform secret key validation.
|
|
360
|
+
* Callers importing serialized keys can use pk_from_sk
|
|
361
|
+
* to validate them before signing.
|
|
357
362
|
*
|
|
358
|
-
* @param[out] sig
|
|
359
|
-
*
|
|
360
|
-
* @param[in] m Pointer to message to be signed.
|
|
363
|
+
* @param[out] sig Pointer to buffer to hold the generated signature of
|
|
364
|
+
* MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET) bytes.
|
|
365
|
+
* @param[in] m Pointer to message to be signed. May be NULL if
|
|
366
|
+
* mlen == 0.
|
|
361
367
|
* @param mlen Length of message.
|
|
362
368
|
* @param[in] ctx Pointer to context string. May be NULL if ctxlen == 0.
|
|
363
369
|
* @param ctxlen Length of context string. Should be <= 255.
|
|
364
|
-
* @param[in] sk Bit-packed secret key.
|
|
370
|
+
* @param[in] sk Bit-packed secret key; assumed to be valid.
|
|
365
371
|
* @param context Application context. Only present when
|
|
366
372
|
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
367
373
|
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
@@ -374,14 +380,17 @@ int MLD_API_NAMESPACE(signature_internal)(
|
|
|
374
380
|
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The rejection-sampling loop exceeded
|
|
375
381
|
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
376
382
|
* iterations.
|
|
377
|
-
* @retval
|
|
383
|
+
* @retval MLD_ERR_SIGNING_PAUSED A MLD_CONFIG_SIGN_HOOK_ATTEMPT hook
|
|
384
|
+
* paused signing; re-invoke to resume.
|
|
385
|
+
* @retval MLD_ERR_INVALID_ARG The context string exceeded 255
|
|
386
|
+
* bytes.
|
|
378
387
|
*/
|
|
379
388
|
MLD_API_QUALIFIER
|
|
380
389
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
381
390
|
int MLD_API_NAMESPACE(signature)(
|
|
382
|
-
uint8_t sig[MLDSA_BYTES(
|
|
383
|
-
|
|
384
|
-
const uint8_t sk[MLDSA_SECRETKEYBYTES(
|
|
391
|
+
uint8_t sig[MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET)], const uint8_t *m,
|
|
392
|
+
size_t mlen, const uint8_t *ctx, size_t ctxlen,
|
|
393
|
+
const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_PARAMETER_SET)]
|
|
385
394
|
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
386
395
|
,
|
|
387
396
|
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
@@ -395,12 +404,16 @@ int MLD_API_NAMESPACE(signature)(
|
|
|
395
404
|
* 0x00 || ctxlen || ctx || msg for pure ML-DSA). This is useful when the
|
|
396
405
|
* message is large or streamed and cannot be held in memory.
|
|
397
406
|
*
|
|
398
|
-
* @spec{Implements @[FIPS204 Algorithm 2
|
|
407
|
+
* @spec{Implements @[FIPS204, Algorithm 2, ML-DSA.Sign external mu variant].}
|
|
399
408
|
*
|
|
400
|
-
* @
|
|
401
|
-
*
|
|
409
|
+
* @warning This function does not perform secret key validation.
|
|
410
|
+
* Callers importing serialized keys can use pk_from_sk
|
|
411
|
+
* to validate them before signing.
|
|
412
|
+
*
|
|
413
|
+
* @param[out] sig Pointer to buffer to hold the generated signature of
|
|
414
|
+
* MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET) bytes.
|
|
402
415
|
* @param[in] mu Precomputed message representative.
|
|
403
|
-
* @param[in] sk Bit-packed secret key.
|
|
416
|
+
* @param[in] sk Bit-packed secret key; assumed to be valid.
|
|
404
417
|
* @param context Application context. Only present when
|
|
405
418
|
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
406
419
|
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
@@ -413,57 +426,22 @@ int MLD_API_NAMESPACE(signature)(
|
|
|
413
426
|
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The rejection-sampling loop exceeded
|
|
414
427
|
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
415
428
|
* iterations.
|
|
416
|
-
* @retval
|
|
429
|
+
* @retval MLD_ERR_SIGNING_PAUSED A MLD_CONFIG_SIGN_HOOK_ATTEMPT hook
|
|
430
|
+
* paused signing; re-invoke to resume.
|
|
417
431
|
*/
|
|
418
432
|
MLD_API_QUALIFIER
|
|
419
433
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
420
434
|
int MLD_API_NAMESPACE(signature_extmu)(
|
|
421
|
-
uint8_t sig[MLDSA_BYTES(
|
|
435
|
+
uint8_t sig[MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET)],
|
|
422
436
|
const uint8_t mu[MLDSA_CRHBYTES],
|
|
423
|
-
const uint8_t sk[MLDSA_SECRETKEYBYTES(
|
|
437
|
+
const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_PARAMETER_SET)]
|
|
424
438
|
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
425
439
|
,
|
|
426
440
|
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
427
441
|
#endif
|
|
428
442
|
);
|
|
429
443
|
|
|
430
|
-
|
|
431
|
-
* Compute signed message. This function implements the randomized variant of
|
|
432
|
-
* ML-DSA. If you require the deterministic variant, use
|
|
433
|
-
* crypto_sign_signature_internal directly.
|
|
434
|
-
*
|
|
435
|
-
* @param[out] sm Pointer to output signed message (allocated array with
|
|
436
|
-
* MLDSA{44,65,87}_BYTES + mlen bytes); can be equal to m.
|
|
437
|
-
* @param[out] smlen Pointer to output length of signed message.
|
|
438
|
-
* @param[in] m Pointer to message to be signed.
|
|
439
|
-
* @param mlen Length of message.
|
|
440
|
-
* @param[in] ctx Pointer to context string.
|
|
441
|
-
* @param ctxlen Length of context string.
|
|
442
|
-
* @param[in] sk Bit-packed secret key.
|
|
443
|
-
* @param context Application context. Only present when
|
|
444
|
-
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
445
|
-
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
446
|
-
*
|
|
447
|
-
* @retval 0 Success.
|
|
448
|
-
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
449
|
-
* used and an allocation via
|
|
450
|
-
* MLD_CUSTOM_ALLOC returned NULL.
|
|
451
|
-
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The rejection-sampling loop exceeded
|
|
452
|
-
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
453
|
-
* iterations.
|
|
454
|
-
* @retval MLD_ERR_FAIL Other kinds of failure.
|
|
455
|
-
*/
|
|
456
|
-
MLD_API_QUALIFIER
|
|
457
|
-
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
458
|
-
int MLD_API_NAMESPACE(sign)(
|
|
459
|
-
uint8_t *sm, size_t *smlen, const uint8_t *m, size_t mlen,
|
|
460
|
-
const uint8_t *ctx, size_t ctxlen,
|
|
461
|
-
const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]
|
|
462
|
-
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
463
|
-
,
|
|
464
|
-
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
465
|
-
#endif
|
|
466
|
-
);
|
|
444
|
+
#endif /* !MLD_CONFIG_NO_RANDOMIZED_API */
|
|
467
445
|
#endif /* !MLD_CONFIG_CORE_API_ONLY */
|
|
468
446
|
#endif /* !MLD_CONFIG_NO_SIGN_API */
|
|
469
447
|
|
|
@@ -471,10 +449,10 @@ int MLD_API_NAMESPACE(sign)(
|
|
|
471
449
|
/**
|
|
472
450
|
* Verify signature. Internal API.
|
|
473
451
|
*
|
|
474
|
-
* @spec{Implements @[FIPS204 Algorithm 8
|
|
452
|
+
* @spec{Implements @[FIPS204, Algorithm 8, ML-DSA.Verify_internal].}
|
|
475
453
|
*
|
|
476
|
-
* @param[in] sig Pointer to input signature
|
|
477
|
-
*
|
|
454
|
+
* @param[in] sig Pointer to input signature of
|
|
455
|
+
* MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET) bytes.
|
|
478
456
|
* @param[in] m Pointer to message (when externalmu == 0), or to a
|
|
479
457
|
* precomputed message representative mu (when
|
|
480
458
|
* externalmu != 0).
|
|
@@ -491,17 +469,18 @@ int MLD_API_NAMESPACE(sign)(
|
|
|
491
469
|
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
492
470
|
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
493
471
|
*
|
|
494
|
-
* @retval 0
|
|
495
|
-
* @retval MLD_ERR_OUT_OF_MEMORY
|
|
496
|
-
*
|
|
497
|
-
*
|
|
472
|
+
* @retval 0 Success.
|
|
473
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
474
|
+
* used and an allocation via
|
|
475
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
476
|
+
* @retval MLD_ERR_INVALID_SIGNATURE Signature verification failed.
|
|
498
477
|
*/
|
|
499
478
|
MLD_API_QUALIFIER
|
|
500
479
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
501
480
|
int MLD_API_NAMESPACE(verify_internal)(
|
|
502
|
-
const uint8_t
|
|
503
|
-
const uint8_t *pre, size_t prelen,
|
|
504
|
-
const uint8_t pk[MLDSA_PUBLICKEYBYTES(
|
|
481
|
+
const uint8_t sig[MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET)], const uint8_t *m,
|
|
482
|
+
size_t mlen, const uint8_t *pre, size_t prelen,
|
|
483
|
+
const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_PARAMETER_SET)],
|
|
505
484
|
int externalmu
|
|
506
485
|
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
507
486
|
,
|
|
@@ -513,11 +492,11 @@ int MLD_API_NAMESPACE(verify_internal)(
|
|
|
513
492
|
/**
|
|
514
493
|
* Verify signature.
|
|
515
494
|
*
|
|
516
|
-
* @spec{Implements @[FIPS204 Algorithm 3
|
|
495
|
+
* @spec{Implements @[FIPS204, Algorithm 3, ML-DSA.Verify].}
|
|
517
496
|
*
|
|
518
|
-
* @param[in] sig Pointer to input signature
|
|
519
|
-
*
|
|
520
|
-
* @param[in] m Pointer to message.
|
|
497
|
+
* @param[in] sig Pointer to input signature of
|
|
498
|
+
* MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET) bytes.
|
|
499
|
+
* @param[in] m Pointer to message. May be NULL if mlen == 0.
|
|
521
500
|
* @param mlen Length of message.
|
|
522
501
|
* @param[in] ctx Pointer to context string. May be NULL if ctxlen == 0.
|
|
523
502
|
* @param ctxlen Length of context string.
|
|
@@ -526,17 +505,19 @@ int MLD_API_NAMESPACE(verify_internal)(
|
|
|
526
505
|
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
527
506
|
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
528
507
|
*
|
|
529
|
-
* @retval 0
|
|
530
|
-
* @retval MLD_ERR_OUT_OF_MEMORY
|
|
531
|
-
*
|
|
532
|
-
*
|
|
508
|
+
* @retval 0 Success.
|
|
509
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
510
|
+
* used and an allocation via
|
|
511
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
512
|
+
* @retval MLD_ERR_INVALID_SIGNATURE Signature verification failed.
|
|
513
|
+
* @retval MLD_ERR_INVALID_ARG The context string exceeded 255 bytes.
|
|
533
514
|
*/
|
|
534
515
|
MLD_API_QUALIFIER
|
|
535
516
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
536
517
|
int MLD_API_NAMESPACE(verify)(
|
|
537
|
-
const uint8_t
|
|
538
|
-
const uint8_t *ctx, size_t ctxlen,
|
|
539
|
-
const uint8_t pk[MLDSA_PUBLICKEYBYTES(
|
|
518
|
+
const uint8_t sig[MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET)], const uint8_t *m,
|
|
519
|
+
size_t mlen, const uint8_t *ctx, size_t ctxlen,
|
|
520
|
+
const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_PARAMETER_SET)]
|
|
540
521
|
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
541
522
|
,
|
|
542
523
|
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
@@ -550,86 +531,43 @@ int MLD_API_NAMESPACE(verify)(
|
|
|
550
531
|
* 0x00 || ctxlen || ctx || msg for pure ML-DSA). The same mu must have
|
|
551
532
|
* been used at signing time.
|
|
552
533
|
*
|
|
553
|
-
* @spec{Implements @[FIPS204 Algorithm 3
|
|
534
|
+
* @spec{Implements @[FIPS204, Algorithm 3, ML-DSA.Verify external mu variant].}
|
|
554
535
|
*
|
|
555
|
-
* @param[in] sig Pointer to input signature
|
|
556
|
-
*
|
|
536
|
+
* @param[in] sig Pointer to input signature of
|
|
537
|
+
* MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET) bytes.
|
|
557
538
|
* @param[in] mu Precomputed message representative.
|
|
558
539
|
* @param[in] pk Bit-packed public key.
|
|
559
540
|
* @param context Application context. Only present when
|
|
560
541
|
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
561
542
|
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
562
543
|
*
|
|
563
|
-
* @retval 0
|
|
564
|
-
* @retval MLD_ERR_OUT_OF_MEMORY
|
|
565
|
-
*
|
|
566
|
-
*
|
|
544
|
+
* @retval 0 Success.
|
|
545
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
546
|
+
* used and an allocation via
|
|
547
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
548
|
+
* @retval MLD_ERR_INVALID_SIGNATURE Signature verification failed.
|
|
567
549
|
*/
|
|
568
550
|
MLD_API_QUALIFIER
|
|
569
551
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
570
552
|
int MLD_API_NAMESPACE(verify_extmu)(
|
|
571
|
-
const uint8_t
|
|
572
|
-
const uint8_t
|
|
553
|
+
const uint8_t sig[MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET)],
|
|
554
|
+
const uint8_t mu[MLDSA_CRHBYTES],
|
|
555
|
+
const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_PARAMETER_SET)]
|
|
573
556
|
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
574
557
|
,
|
|
575
558
|
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
576
559
|
#endif
|
|
577
560
|
);
|
|
578
561
|
|
|
579
|
-
/**
|
|
580
|
-
* Verify signed message.
|
|
581
|
-
*
|
|
582
|
-
* @param[out] m Pointer to output message (allocated array with smlen
|
|
583
|
-
* bytes); can be equal to sm.
|
|
584
|
-
* @param[out] mlen Pointer to output length of message.
|
|
585
|
-
* @param[in] sm Pointer to signed message.
|
|
586
|
-
* @param smlen Length of signed message.
|
|
587
|
-
* @param[in] ctx Pointer to context string.
|
|
588
|
-
* @param ctxlen Length of context string.
|
|
589
|
-
* @param[in] pk Bit-packed public key.
|
|
590
|
-
* @param context Application context. Only present when
|
|
591
|
-
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
592
|
-
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
593
|
-
*
|
|
594
|
-
* @retval 0 Success.
|
|
595
|
-
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was used and an
|
|
596
|
-
* allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
597
|
-
* @retval MLD_ERR_FAIL Signature verification failed.
|
|
598
|
-
*/
|
|
599
|
-
MLD_API_QUALIFIER
|
|
600
|
-
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
601
|
-
int MLD_API_NAMESPACE(open)(
|
|
602
|
-
uint8_t *m, size_t *mlen, const uint8_t *sm, size_t smlen,
|
|
603
|
-
const uint8_t *ctx, size_t ctxlen,
|
|
604
|
-
const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]
|
|
605
|
-
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
606
|
-
,
|
|
607
|
-
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
608
|
-
#endif
|
|
609
|
-
);
|
|
610
562
|
#endif /* !MLD_CONFIG_CORE_API_ONLY */
|
|
611
563
|
#endif /* !MLD_CONFIG_NO_VERIFY_API */
|
|
612
564
|
|
|
613
|
-
/* Hash algorithm constants for domain separation */
|
|
614
|
-
#define MLD_PREHASH_NONE 0
|
|
615
|
-
#define MLD_PREHASH_SHA2_224 1
|
|
616
|
-
#define MLD_PREHASH_SHA2_256 2
|
|
617
|
-
#define MLD_PREHASH_SHA2_384 3
|
|
618
|
-
#define MLD_PREHASH_SHA2_512 4
|
|
619
|
-
#define MLD_PREHASH_SHA2_512_224 5
|
|
620
|
-
#define MLD_PREHASH_SHA2_512_256 6
|
|
621
|
-
#define MLD_PREHASH_SHA3_224 7
|
|
622
|
-
#define MLD_PREHASH_SHA3_256 8
|
|
623
|
-
#define MLD_PREHASH_SHA3_384 9
|
|
624
|
-
#define MLD_PREHASH_SHA3_512 10
|
|
625
|
-
#define MLD_PREHASH_SHAKE_128 11
|
|
626
|
-
#define MLD_PREHASH_SHAKE_256 12
|
|
627
|
-
|
|
628
565
|
#if !defined(MLD_CONFIG_CORE_API_ONLY)
|
|
629
566
|
#if !defined(MLD_CONFIG_NO_SIGN_API)
|
|
630
567
|
/**
|
|
631
|
-
*
|
|
632
|
-
*
|
|
568
|
+
* Compute signature with pre-hashed message.
|
|
569
|
+
*
|
|
570
|
+
* @spec{Implements @[FIPS204, Algorithm 4, HashML-DSA.Sign].}
|
|
633
571
|
*
|
|
634
572
|
* Supported hash algorithm constants:
|
|
635
573
|
* MLD_PREHASH_SHA2_224, MLD_PREHASH_SHA2_256, MLD_PREHASH_SHA2_384,
|
|
@@ -637,17 +575,26 @@ int MLD_API_NAMESPACE(open)(
|
|
|
637
575
|
* MLD_PREHASH_SHA3_224, MLD_PREHASH_SHA3_256, MLD_PREHASH_SHA3_384,
|
|
638
576
|
* MLD_PREHASH_SHA3_512, MLD_PREHASH_SHAKE_128, MLD_PREHASH_SHAKE_256.
|
|
639
577
|
*
|
|
578
|
+
* MLD_PREHASH_NONE is rejected by this API.
|
|
579
|
+
*
|
|
640
580
|
* @warning This is an unstable API that may change in the future. If you need
|
|
641
|
-
* a stable API use
|
|
581
|
+
* a stable API use signature_pre_hash_shake256.
|
|
582
|
+
*
|
|
583
|
+
* @warning This function does not perform secret key validation.
|
|
584
|
+
* Callers importing serialized keys can use pk_from_sk
|
|
585
|
+
* to validate them before signing.
|
|
642
586
|
*
|
|
643
|
-
* @param[out] sig
|
|
644
|
-
*
|
|
587
|
+
* @param[out] sig Pointer to buffer to hold the generated signature of
|
|
588
|
+
* MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET) bytes.
|
|
645
589
|
* @param[in] ph Pointer to pre-hashed message.
|
|
646
|
-
* @param phlen Length of pre-hashed message.
|
|
647
|
-
*
|
|
590
|
+
* @param phlen Length of pre-hashed message. Must match the output
|
|
591
|
+
* length of hashalg (the digest size for SHA-2/SHA-3,
|
|
592
|
+
* 32 bytes for MLD_PREHASH_SHAKE_128, 64 bytes for
|
|
593
|
+
* MLD_PREHASH_SHAKE_256).
|
|
594
|
+
* @param[in] ctx Pointer to context string. May be NULL if ctxlen == 0.
|
|
648
595
|
* @param ctxlen Length of context string.
|
|
649
596
|
* @param[in] rnd Random seed.
|
|
650
|
-
* @param[in] sk Bit-packed secret key.
|
|
597
|
+
* @param[in] sk Bit-packed secret key; assumed to be valid.
|
|
651
598
|
* @param hashalg Hash algorithm constant (one of MLD_PREHASH_*).
|
|
652
599
|
* @param context Application context. Only present when
|
|
653
600
|
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
@@ -660,15 +607,21 @@ int MLD_API_NAMESPACE(open)(
|
|
|
660
607
|
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The rejection-sampling loop exceeded
|
|
661
608
|
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
662
609
|
* iterations.
|
|
663
|
-
* @retval
|
|
610
|
+
* @retval MLD_ERR_SIGNING_PAUSED A MLD_CONFIG_SIGN_HOOK_ATTEMPT hook
|
|
611
|
+
* paused signing; re-invoke to resume.
|
|
612
|
+
* @retval MLD_ERR_INVALID_ARG The pre-hash algorithm was
|
|
613
|
+
* MLD_PREHASH_NONE or unsupported,
|
|
614
|
+
* phlen did not match the output
|
|
615
|
+
* length of hashalg, or the context
|
|
616
|
+
* string exceeded 255 bytes.
|
|
664
617
|
*/
|
|
665
618
|
MLD_API_QUALIFIER
|
|
666
619
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
667
620
|
int MLD_API_NAMESPACE(signature_pre_hash_internal)(
|
|
668
|
-
uint8_t sig[MLDSA_BYTES(
|
|
669
|
-
|
|
621
|
+
uint8_t sig[MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET)], const uint8_t *ph,
|
|
622
|
+
size_t phlen, const uint8_t *ctx, size_t ctxlen,
|
|
670
623
|
const uint8_t rnd[MLDSA_RNDBYTES],
|
|
671
|
-
const uint8_t sk[MLDSA_SECRETKEYBYTES(
|
|
624
|
+
const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_PARAMETER_SET)],
|
|
672
625
|
int hashalg
|
|
673
626
|
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
674
627
|
,
|
|
@@ -679,8 +632,9 @@ int MLD_API_NAMESPACE(signature_pre_hash_internal)(
|
|
|
679
632
|
|
|
680
633
|
#if !defined(MLD_CONFIG_NO_VERIFY_API)
|
|
681
634
|
/**
|
|
682
|
-
*
|
|
683
|
-
*
|
|
635
|
+
* Verifies signature with pre-hashed message.
|
|
636
|
+
*
|
|
637
|
+
* @spec{Implements @[FIPS204, Algorithm 5, HashML-DSA.Verify].}
|
|
684
638
|
*
|
|
685
639
|
* Supported hash algorithm constants:
|
|
686
640
|
* MLD_PREHASH_SHA2_224, MLD_PREHASH_SHA2_256, MLD_PREHASH_SHA2_384,
|
|
@@ -688,14 +642,19 @@ int MLD_API_NAMESPACE(signature_pre_hash_internal)(
|
|
|
688
642
|
* MLD_PREHASH_SHA3_224, MLD_PREHASH_SHA3_256, MLD_PREHASH_SHA3_384,
|
|
689
643
|
* MLD_PREHASH_SHA3_512, MLD_PREHASH_SHAKE_128, MLD_PREHASH_SHAKE_256.
|
|
690
644
|
*
|
|
645
|
+
* MLD_PREHASH_NONE is rejected by this API.
|
|
646
|
+
*
|
|
691
647
|
* @warning This is an unstable API that may change in the future. If you need
|
|
692
|
-
* a stable API use
|
|
648
|
+
* a stable API use verify_pre_hash_shake256.
|
|
693
649
|
*
|
|
694
|
-
* @param[in] sig Pointer to input signature
|
|
695
|
-
*
|
|
650
|
+
* @param[in] sig Pointer to input signature of
|
|
651
|
+
* MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET) bytes.
|
|
696
652
|
* @param[in] ph Pointer to pre-hashed message.
|
|
697
|
-
* @param phlen Length of pre-hashed message.
|
|
698
|
-
*
|
|
653
|
+
* @param phlen Length of pre-hashed message. Must match the output
|
|
654
|
+
* length of hashalg (the digest size for SHA-2/SHA-3,
|
|
655
|
+
* 32 bytes for MLD_PREHASH_SHAKE_128, 64 bytes for
|
|
656
|
+
* MLD_PREHASH_SHAKE_256).
|
|
657
|
+
* @param[in] ctx Pointer to context string. May be NULL if ctxlen == 0.
|
|
699
658
|
* @param ctxlen Length of context string.
|
|
700
659
|
* @param[in] pk Bit-packed public key.
|
|
701
660
|
* @param hashalg Hash algorithm constant (one of MLD_PREHASH_*).
|
|
@@ -703,17 +662,23 @@ int MLD_API_NAMESPACE(signature_pre_hash_internal)(
|
|
|
703
662
|
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
704
663
|
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
705
664
|
*
|
|
706
|
-
* @retval 0
|
|
707
|
-
* @retval MLD_ERR_OUT_OF_MEMORY
|
|
708
|
-
*
|
|
709
|
-
*
|
|
665
|
+
* @retval 0 Success.
|
|
666
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
667
|
+
* used and an allocation via
|
|
668
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
669
|
+
* @retval MLD_ERR_INVALID_SIGNATURE Signature verification failed.
|
|
670
|
+
* @retval MLD_ERR_INVALID_ARG The pre-hash algorithm was
|
|
671
|
+
* MLD_PREHASH_NONE or unsupported, phlen
|
|
672
|
+
* did not match the output length of
|
|
673
|
+
* hashalg, or the context string exceeded
|
|
674
|
+
* 255 bytes.
|
|
710
675
|
*/
|
|
711
676
|
MLD_API_QUALIFIER
|
|
712
677
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
713
678
|
int MLD_API_NAMESPACE(verify_pre_hash_internal)(
|
|
714
|
-
const uint8_t
|
|
715
|
-
const uint8_t *ctx, size_t ctxlen,
|
|
716
|
-
const uint8_t pk[MLDSA_PUBLICKEYBYTES(
|
|
679
|
+
const uint8_t sig[MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET)], const uint8_t *ph,
|
|
680
|
+
size_t phlen, const uint8_t *ctx, size_t ctxlen,
|
|
681
|
+
const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_PARAMETER_SET)],
|
|
717
682
|
int hashalg
|
|
718
683
|
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
719
684
|
,
|
|
@@ -724,19 +689,25 @@ int MLD_API_NAMESPACE(verify_pre_hash_internal)(
|
|
|
724
689
|
|
|
725
690
|
#if !defined(MLD_CONFIG_NO_SIGN_API)
|
|
726
691
|
/**
|
|
727
|
-
* FIPS 204: Algorithm 4 HashML-DSA.Sign with SHAKE256.
|
|
728
|
-
*
|
|
729
692
|
* Compute signature with pre-hashed message using SHAKE256. This function
|
|
730
693
|
* computes the SHAKE256 hash of the message internally.
|
|
731
694
|
*
|
|
732
|
-
* @
|
|
733
|
-
*
|
|
734
|
-
*
|
|
695
|
+
* @spec{Implements @[FIPS204, Algorithm 4, HashML-DSA.Sign] with SHAKE256 as
|
|
696
|
+
* the pre-hash.}
|
|
697
|
+
*
|
|
698
|
+
* @warning This function does not perform secret key validation.
|
|
699
|
+
* Callers importing serialized keys can use pk_from_sk
|
|
700
|
+
* to validate them before signing.
|
|
701
|
+
*
|
|
702
|
+
* @param[out] sig Pointer to buffer to hold the generated signature of
|
|
703
|
+
* MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET) bytes.
|
|
704
|
+
* @param[in] m Pointer to message to be hashed and signed. May be
|
|
705
|
+
* NULL if mlen == 0.
|
|
735
706
|
* @param mlen Length of message.
|
|
736
|
-
* @param[in] ctx Pointer to context string.
|
|
707
|
+
* @param[in] ctx Pointer to context string. May be NULL if ctxlen == 0.
|
|
737
708
|
* @param ctxlen Length of context string.
|
|
738
709
|
* @param[in] rnd Random seed.
|
|
739
|
-
* @param[in] sk Bit-packed secret key.
|
|
710
|
+
* @param[in] sk Bit-packed secret key; assumed to be valid.
|
|
740
711
|
* @param context Application context. Only present when
|
|
741
712
|
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
742
713
|
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
@@ -748,15 +719,18 @@ int MLD_API_NAMESPACE(verify_pre_hash_internal)(
|
|
|
748
719
|
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The rejection-sampling loop exceeded
|
|
749
720
|
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
750
721
|
* iterations.
|
|
751
|
-
* @retval
|
|
722
|
+
* @retval MLD_ERR_SIGNING_PAUSED A MLD_CONFIG_SIGN_HOOK_ATTEMPT hook
|
|
723
|
+
* paused signing; re-invoke to resume.
|
|
724
|
+
* @retval MLD_ERR_INVALID_ARG The context string exceeded 255
|
|
725
|
+
* bytes.
|
|
752
726
|
*/
|
|
753
727
|
MLD_API_QUALIFIER
|
|
754
728
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
755
729
|
int MLD_API_NAMESPACE(signature_pre_hash_shake256)(
|
|
756
|
-
uint8_t sig[MLDSA_BYTES(
|
|
757
|
-
|
|
730
|
+
uint8_t sig[MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET)], const uint8_t *m,
|
|
731
|
+
size_t mlen, const uint8_t *ctx, size_t ctxlen,
|
|
758
732
|
const uint8_t rnd[MLDSA_RNDBYTES],
|
|
759
|
-
const uint8_t sk[MLDSA_SECRETKEYBYTES(
|
|
733
|
+
const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_PARAMETER_SET)]
|
|
760
734
|
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
761
735
|
,
|
|
762
736
|
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
@@ -766,33 +740,37 @@ int MLD_API_NAMESPACE(signature_pre_hash_shake256)(
|
|
|
766
740
|
|
|
767
741
|
#if !defined(MLD_CONFIG_NO_VERIFY_API)
|
|
768
742
|
/**
|
|
769
|
-
* FIPS 204: Algorithm 5 HashML-DSA.Verify with SHAKE256.
|
|
770
|
-
*
|
|
771
743
|
* Verify signature with pre-hashed message using SHAKE256. This function
|
|
772
744
|
* computes the SHAKE256 hash of the message internally.
|
|
773
745
|
*
|
|
774
|
-
* @
|
|
775
|
-
*
|
|
776
|
-
*
|
|
746
|
+
* @spec{Implements @[FIPS204, Algorithm 5, HashML-DSA.Verify] with SHAKE256 as
|
|
747
|
+
* the pre-hash.}
|
|
748
|
+
*
|
|
749
|
+
* @param[in] sig Pointer to input signature of
|
|
750
|
+
* MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET) bytes.
|
|
751
|
+
* @param[in] m Pointer to message to be hashed and verified. May be
|
|
752
|
+
* NULL if mlen == 0.
|
|
777
753
|
* @param mlen Length of message.
|
|
778
|
-
* @param[in] ctx Pointer to context string.
|
|
754
|
+
* @param[in] ctx Pointer to context string. May be NULL if ctxlen == 0.
|
|
779
755
|
* @param ctxlen Length of context string.
|
|
780
756
|
* @param[in] pk Bit-packed public key.
|
|
781
757
|
* @param context Application context. Only present when
|
|
782
758
|
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
783
759
|
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
784
760
|
*
|
|
785
|
-
* @retval 0
|
|
786
|
-
* @retval MLD_ERR_OUT_OF_MEMORY
|
|
787
|
-
*
|
|
788
|
-
*
|
|
761
|
+
* @retval 0 Success.
|
|
762
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
763
|
+
* used and an allocation via
|
|
764
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
765
|
+
* @retval MLD_ERR_INVALID_SIGNATURE Signature verification failed.
|
|
766
|
+
* @retval MLD_ERR_INVALID_ARG The context string exceeded 255 bytes.
|
|
789
767
|
*/
|
|
790
768
|
MLD_API_QUALIFIER
|
|
791
769
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
792
770
|
int MLD_API_NAMESPACE(verify_pre_hash_shake256)(
|
|
793
|
-
const uint8_t
|
|
794
|
-
const uint8_t *ctx, size_t ctxlen,
|
|
795
|
-
const uint8_t pk[MLDSA_PUBLICKEYBYTES(
|
|
771
|
+
const uint8_t sig[MLDSA_BYTES(MLD_CONFIG_PARAMETER_SET)], const uint8_t *m,
|
|
772
|
+
size_t mlen, const uint8_t *ctx, size_t ctxlen,
|
|
773
|
+
const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_PARAMETER_SET)]
|
|
796
774
|
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
797
775
|
,
|
|
798
776
|
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
@@ -801,9 +779,6 @@ int MLD_API_NAMESPACE(verify_pre_hash_shake256)(
|
|
|
801
779
|
#endif /* !MLD_CONFIG_NO_VERIFY_API */
|
|
802
780
|
#endif /* !MLD_CONFIG_CORE_API_ONLY */
|
|
803
781
|
|
|
804
|
-
/* Maximum formatted domain separation message length */
|
|
805
|
-
#define MLD_DOMAIN_SEPARATION_MAX_BYTES (2 + 255 + 11 + 64)
|
|
806
|
-
|
|
807
782
|
#if !defined(MLD_CONFIG_CORE_API_ONLY)
|
|
808
783
|
/**
|
|
809
784
|
* Prepare domain separation prefix for ML-DSA signing.
|
|
@@ -817,26 +792,31 @@ int MLD_API_NAMESPACE(verify_pre_hash_shake256)(
|
|
|
817
792
|
* This function is useful for building incremental signing APIs.
|
|
818
793
|
*
|
|
819
794
|
* @spec{For HashML-DSA (hashalg != MLD_PREHASH_NONE), implements
|
|
820
|
-
* @[FIPS204, Algorithm 4,
|
|
821
|
-
* implements
|
|
795
|
+
* @[FIPS204, Algorithm 4, line 23]. For Pure ML-DSA
|
|
796
|
+
* (hashalg == MLD_PREHASH_NONE), implements
|
|
822
797
|
* ```
|
|
823
798
|
* M' <- BytesToBits(IntegerToBytes(0, 1)
|
|
824
799
|
* || IntegerToBytes(|ctx|, 1)
|
|
825
800
|
* || ctx
|
|
826
801
|
* ```
|
|
827
|
-
* which is part of @[FIPS204, Algorithm 2
|
|
828
|
-
* @[FIPS204, Algorithm 3
|
|
802
|
+
* which is part of @[FIPS204, Algorithm 2, ML-DSA.Sign, line 10] and
|
|
803
|
+
* @[FIPS204, Algorithm 3, ML-DSA.Verify, line 5].}
|
|
829
804
|
*
|
|
830
805
|
* @param[out] prefix Output domain separation prefix buffer.
|
|
831
806
|
* @param[in] ph Pointer to pre-hashed message (ignored for pure
|
|
832
807
|
* ML-DSA).
|
|
833
|
-
* @param phlen Length of pre-hashed message
|
|
834
|
-
*
|
|
808
|
+
* @param phlen Length of pre-hashed message; must match the output
|
|
809
|
+
* length of hashalg (ignored for pure ML-DSA).
|
|
810
|
+
* @param[in] ctx Pointer to context string. May be NULL if ctxlen == 0.
|
|
835
811
|
* @param ctxlen Length of context string.
|
|
836
812
|
* @param hashalg Hash algorithm constant (MLD_PREHASH_NONE for pure
|
|
837
813
|
* ML-DSA, or MLD_PREHASH_* for HashML-DSA).
|
|
838
814
|
*
|
|
839
815
|
* @return The total length of the formatted prefix, or 0 on error.
|
|
816
|
+
* Errors are:
|
|
817
|
+
* - The context string exceeded 255 bytes.
|
|
818
|
+
* - For HashML-DSA: hashalg was unsupported, ph was NULL, or phlen
|
|
819
|
+
* did not match the output length of hashalg.
|
|
840
820
|
*/
|
|
841
821
|
MLD_API_QUALIFIER
|
|
842
822
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
@@ -849,7 +829,7 @@ size_t MLD_API_NAMESPACE(prepare_domain_separation_prefix)(
|
|
|
849
829
|
* Perform basic validity checks on secret key, and derive public key.
|
|
850
830
|
*
|
|
851
831
|
* Referring to the decoding of the secret key `sk=(rho, K, tr, s1, s2, t0)`
|
|
852
|
-
* (cf. @[FIPS204, Algorithm 25 skDecode]), the following checks are
|
|
832
|
+
* (cf. @[FIPS204, Algorithm 25, skDecode]), the following checks are
|
|
853
833
|
* performed:
|
|
854
834
|
* - Check that s1 and s2 have coefficients in [-MLDSA_ETA, MLDSA_ETA].
|
|
855
835
|
* - Check that t0 and tr stored in sk match recomputed values.
|
|
@@ -866,13 +846,13 @@ size_t MLD_API_NAMESPACE(prepare_domain_separation_prefix)(
|
|
|
866
846
|
* @retval 0 Success.
|
|
867
847
|
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was used and an
|
|
868
848
|
* allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
869
|
-
* @retval
|
|
849
|
+
* @retval MLD_ERR_INVALID_KEY Secret key validation failed.
|
|
870
850
|
*/
|
|
871
851
|
MLD_API_QUALIFIER
|
|
872
852
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
873
853
|
int MLD_API_NAMESPACE(pk_from_sk)(
|
|
874
|
-
uint8_t pk[MLDSA_PUBLICKEYBYTES(
|
|
875
|
-
const uint8_t sk[MLDSA_SECRETKEYBYTES(
|
|
854
|
+
uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_PARAMETER_SET)],
|
|
855
|
+
const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_PARAMETER_SET)]
|
|
876
856
|
#ifdef MLD_CONFIG_CONTEXT_PARAMETER
|
|
877
857
|
,
|
|
878
858
|
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
@@ -885,43 +865,9 @@ int MLD_API_NAMESPACE(pk_from_sk)(
|
|
|
885
865
|
}
|
|
886
866
|
#endif
|
|
887
867
|
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
#if !defined(MLD_CONFIG_API_NO_SUPERCOP)
|
|
891
|
-
/* Export API in SUPERCOP naming scheme CRYPTO_xxx / crypto_sign_xxx */
|
|
892
|
-
#define CRYPTO_SECRETKEYBYTES MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)
|
|
893
|
-
#define CRYPTO_PUBLICKEYBYTES MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)
|
|
894
|
-
#define CRYPTO_BYTES MLDSA_BYTES(MLD_CONFIG_API_PARAMETER_SET)
|
|
895
|
-
|
|
896
|
-
#define crypto_sign_keypair MLD_API_NAMESPACE(keypair)
|
|
897
|
-
#define crypto_sign_signature MLD_API_NAMESPACE(signature)
|
|
898
|
-
#define crypto_sign MLD_API_NAMESPACE(sign)
|
|
899
|
-
#define crypto_sign_verify MLD_API_NAMESPACE(verify)
|
|
900
|
-
#define crypto_sign_open MLD_API_NAMESPACE(open)
|
|
901
|
-
|
|
902
|
-
#else /* !MLD_CONFIG_API_NO_SUPERCOP */
|
|
903
|
-
|
|
904
|
-
/* If the SUPERCOP API is not needed, we can undefine the various helper macros
|
|
905
|
-
* above. Otherwise, they are needed for lazy evaluation of crypto_sign_xxx. */
|
|
906
|
-
#if !defined(MLD_API_LEGACY_CONFIG)
|
|
907
|
-
#undef MLD_CONFIG_API_PARAMETER_SET
|
|
908
|
-
#undef MLD_CONFIG_API_NAMESPACE_PREFIX
|
|
909
|
-
#undef MLD_CONFIG_API_NO_SUPERCOP
|
|
910
|
-
#undef MLD_CONFIG_API_CONSTANTS_ONLY
|
|
911
|
-
#undef MLD_CONFIG_API_QUALIFIER
|
|
912
|
-
#endif /* !MLD_API_LEGACY_CONFIG */
|
|
913
|
-
|
|
914
|
-
#undef MLD_API_CONCAT
|
|
915
|
-
#undef MLD_API_CONCAT_
|
|
916
|
-
#undef MLD_API_CONCAT_UNDERSCORE
|
|
917
|
-
#undef MLD_API_NAMESPACE
|
|
918
|
-
#undef MLD_API_MUST_CHECK_RETURN_VALUE
|
|
919
|
-
#undef MLD_API_QUALIFIER
|
|
920
|
-
#undef MLD_API_LEGACY_CONFIG
|
|
921
|
-
|
|
922
|
-
#endif /* MLD_CONFIG_API_NO_SUPERCOP */
|
|
923
|
-
#endif /* !MLD_CONFIG_API_CONSTANTS_ONLY */
|
|
868
|
+
#undef MLD_API_NAMESPACE_PREFIX
|
|
924
869
|
|
|
870
|
+
#endif /* !MLD_CONFIG_CONSTANTS_ONLY */
|
|
925
871
|
|
|
926
872
|
/***************************** Memory Usage **********************************/
|
|
927
873
|
|
|
@@ -941,7 +887,7 @@ int MLD_API_NAMESPACE(pk_from_sk)(
|
|
|
941
887
|
* fixed-sized buffer and a simple allocator (e.g., bump allocator).
|
|
942
888
|
*/
|
|
943
889
|
/* check-magic: off */
|
|
944
|
-
#if
|
|
890
|
+
#if !defined(MLD_CONFIG_REDUCE_RAM)
|
|
945
891
|
#define MLD_TOTAL_ALLOC_44_KEYPAIR_NO_PCT 26912
|
|
946
892
|
#define MLD_TOTAL_ALLOC_44_KEYPAIR_PCT 48480
|
|
947
893
|
#define MLD_TOTAL_ALLOC_44_PK_FROM_SK 28480
|
|
@@ -957,7 +903,7 @@ int MLD_API_NAMESPACE(pk_from_sk)(
|
|
|
957
903
|
#define MLD_TOTAL_ALLOC_87_PK_FROM_SK 78272
|
|
958
904
|
#define MLD_TOTAL_ALLOC_87_SIGN 108224
|
|
959
905
|
#define MLD_TOTAL_ALLOC_87_VERIFY 68800
|
|
960
|
-
#else /*
|
|
906
|
+
#else /* !MLD_CONFIG_REDUCE_RAM */
|
|
961
907
|
#define MLD_TOTAL_ALLOC_44_KEYPAIR_NO_PCT 11584
|
|
962
908
|
#define MLD_TOTAL_ALLOC_44_KEYPAIR_PCT 16896
|
|
963
909
|
#define MLD_TOTAL_ALLOC_44_PK_FROM_SK 13152
|
|
@@ -973,15 +919,13 @@ int MLD_API_NAMESPACE(pk_from_sk)(
|
|
|
973
919
|
#define MLD_TOTAL_ALLOC_87_PK_FROM_SK 21984
|
|
974
920
|
#define MLD_TOTAL_ALLOC_87_SIGN 21344
|
|
975
921
|
#define MLD_TOTAL_ALLOC_87_VERIFY 12512
|
|
976
|
-
#endif /*
|
|
922
|
+
#endif /* MLD_CONFIG_REDUCE_RAM */
|
|
977
923
|
/* check-magic: on */
|
|
978
924
|
|
|
979
925
|
/*
|
|
980
926
|
* MLD_TOTAL_ALLOC_*_KEYPAIR adapts based on MLD_CONFIG_KEYGEN_PCT.
|
|
981
|
-
* For legacy config, we don't know which options are used, so assume
|
|
982
|
-
* the worst case (PCT enabled).
|
|
983
927
|
*/
|
|
984
|
-
#if defined(
|
|
928
|
+
#if defined(MLD_CONFIG_KEYGEN_PCT)
|
|
985
929
|
#define MLD_TOTAL_ALLOC_44_KEYPAIR MLD_TOTAL_ALLOC_44_KEYPAIR_PCT
|
|
986
930
|
#define MLD_TOTAL_ALLOC_65_KEYPAIR MLD_TOTAL_ALLOC_65_KEYPAIR_PCT
|
|
987
931
|
#define MLD_TOTAL_ALLOC_87_KEYPAIR MLD_TOTAL_ALLOC_87_KEYPAIR_PCT
|