pq_crypto 0.6.1 → 0.6.2
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 +5 -0
- data/SECURITY.md +7 -0
- data/ext/pqcrypto/pqcrypto_version.h +1 -1
- data/ext/pqcrypto/vendor/.vendored +4 -4
- data/ext/pqcrypto/vendor/mldsa-native/README.md +23 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/README.md +23 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +114 -58
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +498 -461
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +145 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +456 -422
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +47 -25
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +26 -14
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +56 -81
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +17 -24
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.c +33 -40
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +67 -87
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +19 -14
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +13 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +84 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +10 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +6 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +22 -15
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +376 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +204 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +259 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +1077 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +987 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +16 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +2 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +4 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +60 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +48 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +18 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +658 -582
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +5 -100
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +26 -25
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +334 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +355 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +8 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/{xkcp.h → keccak_f1600_x4_avx2.h} +11 -8
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +44 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +454 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +52 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +37 -28
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +213 -196
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +248 -64
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt_aarch64_asm.S +753 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +129 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +145 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +177 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt_aarch64_asm.S +653 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery_aarch64_asm.S +84 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_aarch64_asm.S +53 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_aarch64_asm.S +55 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_aarch64_asm.S +86 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_aarch64_asm.S +86 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_aarch64_asm.S +103 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_aarch64_asm.S +111 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_aarch64_asm.S +75 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_aarch64_asm.S +72 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +23 -11
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_aarch64_asm.S +189 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_aarch64_asm.S +137 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_aarch64_asm.S +130 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +520 -516
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +34 -33
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +202 -242
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +25 -17
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +112 -28
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt_avx2_asm.S +2311 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt_avx2_asm.S +2383 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack_avx2_asm.S +238 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4_avx2_asm.S +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5_avx2_asm.S +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7_avx2_asm.S +187 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_avx2_asm.S +130 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2_asm.S +190 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +9 -8
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +10 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +8 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +8 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +130 -129
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +109 -180
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +169 -150
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +56 -40
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +149 -164
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +52 -57
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +132 -167
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +57 -424
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +167 -474
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +308 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +653 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +22 -29
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +37 -43
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +511 -367
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +456 -417
- data/lib/pq_crypto/version.rb +1 -1
- data/script/vendor_libs.rb +3 -3
- metadata +41 -35
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +0 -376
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +0 -204
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +0 -259
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +0 -1077
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +0 -987
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +0 -488
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +0 -16
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +0 -753
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +0 -129
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +0 -145
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +0 -177
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +0 -653
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +0 -79
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +0 -53
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +0 -55
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +0 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +0 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +0 -102
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +0 -110
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +0 -72
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +0 -69
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +0 -189
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +0 -135
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +0 -128
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +0 -2311
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +0 -2383
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +0 -239
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +0 -131
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +0 -139
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +0 -155
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +0 -187
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +0 -61
|
@@ -71,9 +71,7 @@
|
|
|
71
71
|
#define mld_sign_pk_from_sk \
|
|
72
72
|
MLD_NAMESPACE_KL(pk_from_sk) MLD_CONTEXT_PARAMETERS_2
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
* Hash algorithm constants for domain separation
|
|
76
|
-
**************************************************/
|
|
74
|
+
/* Hash algorithm constants for domain separation */
|
|
77
75
|
#define MLD_PREHASH_NONE 0
|
|
78
76
|
#define MLD_PREHASH_SHA2_224 1
|
|
79
77
|
#define MLD_PREHASH_SHA2_256 2
|
|
@@ -88,27 +86,35 @@
|
|
|
88
86
|
#define MLD_PREHASH_SHAKE_128 11
|
|
89
87
|
#define MLD_PREHASH_SHAKE_256 12
|
|
90
88
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
|
|
89
|
+
#if !defined(MLD_CONFIG_NO_KEYPAIR_API)
|
|
90
|
+
/**
|
|
91
|
+
* Generate a public-private key pair from a seed.
|
|
92
|
+
*
|
|
93
|
+
* When MLD_CONFIG_KEYGEN_PCT is set, performs a Pairwise Consistency Test
|
|
94
|
+
* (PCT) as required by FIPS 140-3 IG.
|
|
95
|
+
*
|
|
96
|
+
* @spec{Implements @[FIPS204 Algorithm 6 (ML-DSA.KeyGen_internal)].}
|
|
97
|
+
*
|
|
98
|
+
* @param[out] pk Output public key.
|
|
99
|
+
* @param[out] sk Output private key.
|
|
100
|
+
* @param[in] seed Input random seed.
|
|
101
|
+
* @param context Application context. Only present when
|
|
102
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
103
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
104
|
+
*
|
|
105
|
+
* @retval 0 Success.
|
|
106
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
107
|
+
* used and an allocation via
|
|
108
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
109
|
+
* @retval MLD_ERR_RNG_FAIL Random number generation failed.
|
|
110
|
+
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The PCT's signing step exhausted
|
|
111
|
+
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
112
|
+
* iterations. Only possible when
|
|
113
|
+
* MLD_CONFIG_KEYGEN_PCT is enabled.
|
|
114
|
+
* @retval MLD_ERR_FAIL Other kinds of failure, including
|
|
115
|
+
* PCT failure if
|
|
116
|
+
* MLD_CONFIG_KEYGEN_PCT is enabled.
|
|
117
|
+
*/
|
|
112
118
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
113
119
|
MLD_EXTERNAL_API
|
|
114
120
|
int mld_sign_keypair_internal(uint8_t pk[MLDSA_CRYPTO_PUBLICKEYBYTES],
|
|
@@ -121,30 +127,37 @@ __contract__(
|
|
|
121
127
|
requires(memory_no_alias(seed, MLDSA_SEEDBYTES))
|
|
122
128
|
assigns(object_whole(pk))
|
|
123
129
|
assigns(object_whole(sk))
|
|
124
|
-
ensures(return_value == 0 || return_value
|
|
125
|
-
return_value == MLD_ERR_OUT_OF_MEMORY || return_value == MLD_ERR_RNG_FAIL)
|
|
130
|
+
ensures(return_value == 0 || MLD_ANY_ERROR(return_value))
|
|
126
131
|
);
|
|
127
132
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
|
|
133
|
+
#if !defined(MLD_CONFIG_CORE_API_ONLY)
|
|
134
|
+
/**
|
|
135
|
+
* Generate a public-private key pair.
|
|
136
|
+
*
|
|
137
|
+
* When MLD_CONFIG_KEYGEN_PCT is set, performs a Pairwise Consistency Test
|
|
138
|
+
* (PCT) as required by FIPS 140-3 IG.
|
|
139
|
+
*
|
|
140
|
+
* @spec{Implements @[FIPS204 Algorithm 1 (ML-DSA.KeyGen)].}
|
|
141
|
+
*
|
|
142
|
+
* @param[out] pk Output public key.
|
|
143
|
+
* @param[out] sk Output private key.
|
|
144
|
+
* @param context Application context. Only present when
|
|
145
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
146
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
147
|
+
*
|
|
148
|
+
* @retval 0 Success.
|
|
149
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
150
|
+
* used and an allocation via
|
|
151
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
152
|
+
* @retval MLD_ERR_RNG_FAIL Random number generation failed.
|
|
153
|
+
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The PCT's signing step exhausted
|
|
154
|
+
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
155
|
+
* iterations. Only possible when
|
|
156
|
+
* MLD_CONFIG_KEYGEN_PCT is enabled.
|
|
157
|
+
* @retval MLD_ERR_FAIL Other kinds of failure, including
|
|
158
|
+
* PCT failure if
|
|
159
|
+
* MLD_CONFIG_KEYGEN_PCT is enabled.
|
|
160
|
+
*/
|
|
148
161
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
149
162
|
MLD_EXTERNAL_API
|
|
150
163
|
int mld_sign_keypair(uint8_t pk[MLDSA_CRYPTO_PUBLICKEYBYTES],
|
|
@@ -155,41 +168,48 @@ __contract__(
|
|
|
155
168
|
requires(memory_no_alias(sk, MLDSA_CRYPTO_SECRETKEYBYTES))
|
|
156
169
|
assigns(object_whole(pk))
|
|
157
170
|
assigns(object_whole(sk))
|
|
158
|
-
ensures(return_value == 0 || return_value
|
|
159
|
-
return_value == MLD_ERR_OUT_OF_MEMORY || return_value == MLD_ERR_RNG_FAIL)
|
|
171
|
+
ensures(return_value == 0 || MLD_ANY_ERROR(return_value))
|
|
160
172
|
);
|
|
173
|
+
#endif /* !MLD_CONFIG_CORE_API_ONLY */
|
|
174
|
+
#endif /* !MLD_CONFIG_NO_KEYPAIR_API */
|
|
161
175
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
|
|
176
|
+
#if !defined(MLD_CONFIG_NO_SIGN_API)
|
|
177
|
+
/**
|
|
178
|
+
* Compute signature using internal randomness.
|
|
179
|
+
*
|
|
180
|
+
* If the returned value is non-zero, then the values of *sig and *siglen
|
|
181
|
+
* should not be referenced.
|
|
182
|
+
*
|
|
183
|
+
* @param[out] sig Output signature.
|
|
184
|
+
* @param[out] siglen Pointer to output length of signature.
|
|
185
|
+
* @param[in] m Pointer to message to be signed (when
|
|
186
|
+
* externalmu == 0), or to a precomputed
|
|
187
|
+
* message representative mu (when externalmu != 0).
|
|
188
|
+
* @param mlen Length of m. Must equal MLDSA_CRHBYTES when
|
|
189
|
+
* externalmu != 0.
|
|
190
|
+
* @param[in] pre Pointer to prefix string. Ignored when
|
|
191
|
+
* externalmu != 0.
|
|
192
|
+
* @param prelen Length of prefix string. Ignored when
|
|
193
|
+
* externalmu != 0.
|
|
194
|
+
* @param[in] rnd Random seed.
|
|
195
|
+
* @param[in] sk Bit-packed secret key.
|
|
196
|
+
* @param externalmu 0: m/mlen is the raw message; mu = H(tr, pre, m) is
|
|
197
|
+
* computed internally.
|
|
198
|
+
* non-zero: m points to a precomputed mu of
|
|
199
|
+
* MLDSA_CRHBYTES bytes; pre/prelen unused.
|
|
200
|
+
* @param context Application context. Only present when
|
|
201
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
202
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
203
|
+
*
|
|
204
|
+
* @retval 0 Success.
|
|
205
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
206
|
+
* used and an allocation via
|
|
207
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
208
|
+
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The rejection-sampling loop exceeded
|
|
209
|
+
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
210
|
+
* iterations.
|
|
211
|
+
* @retval MLD_ERR_FAIL Other kinds of failure.
|
|
212
|
+
*/
|
|
193
213
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
194
214
|
MLD_EXTERNAL_API
|
|
195
215
|
int mld_sign_signature_internal(uint8_t sig[MLDSA_CRYPTO_BYTES], size_t *siglen,
|
|
@@ -207,44 +227,46 @@ __contract__(
|
|
|
207
227
|
requires(memory_no_alias(m, mlen))
|
|
208
228
|
requires(memory_no_alias(rnd, MLDSA_RNDBYTES))
|
|
209
229
|
requires(memory_no_alias(sk, MLDSA_CRYPTO_SECRETKEYBYTES))
|
|
210
|
-
requires((externalmu == 0
|
|
211
|
-
|
|
230
|
+
requires((externalmu == 0) ==> ((prelen == 0) || memory_no_alias(pre, prelen)))
|
|
231
|
+
requires((externalmu != 0) ==> (mlen == MLDSA_CRHBYTES))
|
|
212
232
|
assigns(memory_slice(sig, MLDSA_CRYPTO_BYTES))
|
|
213
233
|
assigns(object_whole(siglen))
|
|
214
234
|
ensures(return_value == 0 || return_value == MLD_ERR_FAIL ||
|
|
215
|
-
return_value == MLD_ERR_OUT_OF_MEMORY
|
|
235
|
+
return_value == MLD_ERR_OUT_OF_MEMORY ||
|
|
236
|
+
return_value == MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED)
|
|
216
237
|
ensures(return_value == 0 ==> *siglen == MLDSA_CRYPTO_BYTES)
|
|
217
238
|
ensures(return_value != 0 ==> *siglen == 0)
|
|
218
239
|
);
|
|
219
240
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
|
|
241
|
+
#if !defined(MLD_CONFIG_CORE_API_ONLY)
|
|
242
|
+
/**
|
|
243
|
+
* Compute signature. This function implements the randomized variant of
|
|
244
|
+
* ML-DSA. If you require the deterministic variant, use
|
|
245
|
+
* mld_sign_signature_internal directly.
|
|
246
|
+
*
|
|
247
|
+
* @spec{Implements @[FIPS204 Algorithm 2 (ML-DSA.Sign)].}
|
|
248
|
+
*
|
|
249
|
+
* @param[out] sig Output signature.
|
|
250
|
+
* @param[out] siglen Pointer to output length of signature.
|
|
251
|
+
* @param[in] m Pointer to message to be signed.
|
|
252
|
+
* @param mlen Length of message.
|
|
253
|
+
* @param[in] ctx Pointer to context string. May be NULL if ctxlen == 0.
|
|
254
|
+
* @param ctxlen Length of context string. Should be <= 255.
|
|
255
|
+
* @param[in] sk Bit-packed secret key.
|
|
256
|
+
* @param context Application context. Only present when
|
|
257
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
258
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
259
|
+
*
|
|
260
|
+
* @retval 0 Success.
|
|
261
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
262
|
+
* used and an allocation via
|
|
263
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
264
|
+
* @retval MLD_ERR_RNG_FAIL Random number generation failed.
|
|
265
|
+
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The rejection-sampling loop exceeded
|
|
266
|
+
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
267
|
+
* iterations.
|
|
268
|
+
* @retval MLD_ERR_FAIL Other kinds of failure.
|
|
269
|
+
*/
|
|
248
270
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
249
271
|
MLD_EXTERNAL_API
|
|
250
272
|
int mld_sign_signature(uint8_t sig[MLDSA_CRYPTO_BYTES], size_t *siglen,
|
|
@@ -263,34 +285,37 @@ __contract__(
|
|
|
263
285
|
assigns(memory_slice(sig, MLDSA_CRYPTO_BYTES))
|
|
264
286
|
assigns(object_whole(siglen))
|
|
265
287
|
ensures((return_value == 0 && *siglen == MLDSA_CRYPTO_BYTES) ||
|
|
266
|
-
((return_value
|
|
288
|
+
(MLD_ANY_ERROR(return_value) && *siglen == 0))
|
|
267
289
|
);
|
|
268
290
|
|
|
269
|
-
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
|
|
291
|
+
/**
|
|
292
|
+
* Compute signature in "external mu" mode: the caller has already computed
|
|
293
|
+
* the message representative mu = SHAKE256(tr || M', 64), where
|
|
294
|
+
* tr = SHAKE256(pk, 64) and M' is the FIPS 204 formatted message (e.g.
|
|
295
|
+
* 0x00 || ctxlen || ctx || msg for pure ML-DSA). This is the randomized
|
|
296
|
+
* variant; for the deterministic variant, use mld_sign_signature_internal
|
|
297
|
+
* directly with externalmu set to non-zero and an all-zero rnd.
|
|
298
|
+
*
|
|
299
|
+
* @spec{Implements @[FIPS204 Algorithm 2 (ML-DSA.Sign external mu variant)].}
|
|
300
|
+
*
|
|
301
|
+
* @param[out] sig Output signature.
|
|
302
|
+
* @param[out] siglen Pointer to output length of signature.
|
|
303
|
+
* @param[in] mu Precomputed message representative.
|
|
304
|
+
* @param[in] sk Bit-packed secret key.
|
|
305
|
+
* @param context Application context. Only present when
|
|
306
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
307
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
308
|
+
*
|
|
309
|
+
* @retval 0 Success.
|
|
310
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
311
|
+
* used and an allocation via
|
|
312
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
313
|
+
* @retval MLD_ERR_RNG_FAIL Random number generation failed.
|
|
314
|
+
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The rejection-sampling loop exceeded
|
|
315
|
+
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
316
|
+
* iterations.
|
|
317
|
+
* @retval MLD_ERR_FAIL Other kinds of failure.
|
|
318
|
+
*/
|
|
294
319
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
295
320
|
MLD_EXTERNAL_API
|
|
296
321
|
int mld_sign_signature_extmu(uint8_t sig[MLDSA_CRYPTO_BYTES], size_t *siglen,
|
|
@@ -305,31 +330,33 @@ __contract__(
|
|
|
305
330
|
assigns(memory_slice(sig, MLDSA_CRYPTO_BYTES))
|
|
306
331
|
assigns(object_whole(siglen))
|
|
307
332
|
ensures((return_value == 0 && *siglen == MLDSA_CRYPTO_BYTES) ||
|
|
308
|
-
((return_value
|
|
333
|
+
(MLD_ANY_ERROR(return_value) && *siglen == 0))
|
|
309
334
|
);
|
|
310
335
|
|
|
311
|
-
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*mlen
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
|
|
336
|
+
/**
|
|
337
|
+
* Compute signed message.
|
|
338
|
+
*
|
|
339
|
+
* @param[out] sm Pointer to output signed message (allocated array with
|
|
340
|
+
* MLDSA_CRYPTO_BYTES + mlen bytes); can be equal to m.
|
|
341
|
+
* @param[out] smlen Pointer to output length of signed message.
|
|
342
|
+
* @param[in] m Pointer to message to be signed.
|
|
343
|
+
* @param mlen Length of message.
|
|
344
|
+
* @param[in] ctx Pointer to context string.
|
|
345
|
+
* @param ctxlen Length of context string.
|
|
346
|
+
* @param[in] sk Bit-packed secret key.
|
|
347
|
+
* @param context Application context. Only present when
|
|
348
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
349
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
350
|
+
*
|
|
351
|
+
* @retval 0 Success.
|
|
352
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
353
|
+
* used and an allocation via
|
|
354
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
355
|
+
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The rejection-sampling loop exceeded
|
|
356
|
+
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
357
|
+
* iterations.
|
|
358
|
+
* @retval MLD_ERR_FAIL Other kinds of failure.
|
|
359
|
+
*/
|
|
333
360
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
334
361
|
MLD_EXTERNAL_API
|
|
335
362
|
int mld_sign(uint8_t *sm, size_t *smlen, const uint8_t *m, size_t mlen,
|
|
@@ -347,35 +374,40 @@ __contract__(
|
|
|
347
374
|
assigns(memory_slice(sm, MLDSA_CRYPTO_BYTES + mlen))
|
|
348
375
|
assigns(object_whole(smlen))
|
|
349
376
|
ensures((return_value == 0 && *smlen == MLDSA_CRYPTO_BYTES + mlen) ||
|
|
350
|
-
(return_value ==
|
|
351
|
-
|| return_value == MLD_ERR_OUT_OF_MEMORY
|
|
352
|
-
|| return_value == MLD_ERR_RNG_FAIL))
|
|
377
|
+
(MLD_ANY_ERROR(return_value) && *smlen == 0))
|
|
353
378
|
);
|
|
379
|
+
#endif /* !MLD_CONFIG_CORE_API_ONLY */
|
|
380
|
+
#endif /* !MLD_CONFIG_NO_SIGN_API */
|
|
354
381
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
|
|
382
|
+
#if !defined(MLD_CONFIG_NO_VERIFY_API)
|
|
383
|
+
/**
|
|
384
|
+
* Verify signature.
|
|
385
|
+
*
|
|
386
|
+
* @spec{Implements @[FIPS204 Algorithm 8 (ML-DSA.Verify_internal)].}
|
|
387
|
+
*
|
|
388
|
+
* @param[in] sig Pointer to input signature.
|
|
389
|
+
* @param siglen Length of signature.
|
|
390
|
+
* @param[in] m Pointer to message (when externalmu == 0), or to a
|
|
391
|
+
* precomputed message representative mu (when
|
|
392
|
+
* externalmu != 0).
|
|
393
|
+
* @param mlen Length of m. Must equal MLDSA_CRHBYTES when
|
|
394
|
+
* externalmu != 0.
|
|
395
|
+
* @param[in] pre Pointer to prefix string. Ignored when externalmu != 0.
|
|
396
|
+
* @param prelen Length of prefix string. Ignored when externalmu != 0.
|
|
397
|
+
* @param[in] pk Bit-packed public key.
|
|
398
|
+
* @param externalmu 0: m/mlen is the raw message; mu = H(H(pk), pre, m) is
|
|
399
|
+
* computed internally.
|
|
400
|
+
* non-zero: m points to a precomputed mu of
|
|
401
|
+
* MLDSA_CRHBYTES bytes; pre/prelen unused.
|
|
402
|
+
* @param context Application context. Only present when
|
|
403
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
404
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
405
|
+
*
|
|
406
|
+
* @retval 0 Success.
|
|
407
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was used and an
|
|
408
|
+
* allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
409
|
+
* @retval MLD_ERR_FAIL Signature verification failed.
|
|
410
|
+
*/
|
|
379
411
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
380
412
|
MLD_EXTERNAL_API
|
|
381
413
|
int mld_sign_verify_internal(const uint8_t *sig, size_t siglen,
|
|
@@ -390,35 +422,34 @@ __contract__(
|
|
|
390
422
|
requires(siglen <= MLD_MAX_BUFFER_SIZE)
|
|
391
423
|
requires(memory_no_alias(sig, siglen))
|
|
392
424
|
requires(memory_no_alias(m, mlen))
|
|
393
|
-
requires(externalmu == 0
|
|
394
|
-
requires(externalmu
|
|
425
|
+
requires((externalmu == 0) ==> ((prelen == 0) || memory_no_alias(pre, prelen)))
|
|
426
|
+
requires((externalmu != 0) ==> (mlen == MLDSA_CRHBYTES))
|
|
395
427
|
requires(memory_no_alias(pk, MLDSA_CRYPTO_PUBLICKEYBYTES))
|
|
396
428
|
ensures(return_value == 0 || return_value == MLD_ERR_FAIL || return_value == MLD_ERR_OUT_OF_MEMORY)
|
|
397
429
|
);
|
|
398
430
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
|
|
421
|
-
**************************************************/
|
|
431
|
+
#if !defined(MLD_CONFIG_CORE_API_ONLY)
|
|
432
|
+
/**
|
|
433
|
+
* Verify signature.
|
|
434
|
+
*
|
|
435
|
+
* @spec{Implements @[FIPS204 Algorithm 3 (ML-DSA.Verify)].}
|
|
436
|
+
*
|
|
437
|
+
* @param[in] sig Pointer to input signature.
|
|
438
|
+
* @param siglen Length of signature.
|
|
439
|
+
* @param[in] m Pointer to message.
|
|
440
|
+
* @param mlen Length of message.
|
|
441
|
+
* @param[in] ctx Pointer to context string. May be NULL if ctxlen == 0.
|
|
442
|
+
* @param ctxlen Length of context string.
|
|
443
|
+
* @param[in] pk Bit-packed public key.
|
|
444
|
+
* @param context Application context. Only present when
|
|
445
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
446
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
447
|
+
*
|
|
448
|
+
* @retval 0 Success.
|
|
449
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was used and an
|
|
450
|
+
* allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
451
|
+
* @retval MLD_ERR_FAIL Signature verification failed.
|
|
452
|
+
*/
|
|
422
453
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
423
454
|
MLD_EXTERNAL_API
|
|
424
455
|
int mld_sign_verify(const uint8_t *sig, size_t siglen, const uint8_t *m,
|
|
@@ -436,27 +467,28 @@ __contract__(
|
|
|
436
467
|
ensures(return_value == 0 || return_value == MLD_ERR_FAIL || return_value == MLD_ERR_OUT_OF_MEMORY)
|
|
437
468
|
);
|
|
438
469
|
|
|
439
|
-
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
-
|
|
470
|
+
/**
|
|
471
|
+
* Verify signature in "external mu" mode: the caller has already computed
|
|
472
|
+
* the message representative mu = SHAKE256(tr || M', 64), where
|
|
473
|
+
* tr = SHAKE256(pk, 64) and M' is the FIPS 204 formatted message (e.g.
|
|
474
|
+
* 0x00 || ctxlen || ctx || msg for pure ML-DSA). The same mu must have been
|
|
475
|
+
* used at signing time.
|
|
476
|
+
*
|
|
477
|
+
* @spec{Implements @[FIPS204 Algorithm 3 (ML-DSA.Verify external mu variant)].}
|
|
478
|
+
*
|
|
479
|
+
* @param[in] sig Pointer to input signature.
|
|
480
|
+
* @param siglen Length of signature.
|
|
481
|
+
* @param[in] mu Precomputed message representative.
|
|
482
|
+
* @param[in] pk Bit-packed public key.
|
|
483
|
+
* @param context Application context. Only present when
|
|
484
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
485
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
486
|
+
*
|
|
487
|
+
* @retval 0 Success.
|
|
488
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was used and an
|
|
489
|
+
* allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
490
|
+
* @retval MLD_ERR_FAIL Signature verification failed.
|
|
491
|
+
*/
|
|
460
492
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
461
493
|
MLD_EXTERNAL_API
|
|
462
494
|
int mld_sign_verify_extmu(const uint8_t *sig, size_t siglen,
|
|
@@ -471,27 +503,26 @@ __contract__(
|
|
|
471
503
|
ensures(return_value == 0 || return_value == MLD_ERR_FAIL || return_value == MLD_ERR_OUT_OF_MEMORY)
|
|
472
504
|
);
|
|
473
505
|
|
|
474
|
-
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
*
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
|
|
494
|
-
**************************************************/
|
|
506
|
+
/**
|
|
507
|
+
* Verify signed message.
|
|
508
|
+
*
|
|
509
|
+
* @param[out] m Pointer to output message (allocated array with smlen
|
|
510
|
+
* bytes); can be equal to sm.
|
|
511
|
+
* @param[out] mlen Pointer to output length of message.
|
|
512
|
+
* @param[in] sm Pointer to signed message.
|
|
513
|
+
* @param smlen Length of signed message.
|
|
514
|
+
* @param[in] ctx Pointer to context string.
|
|
515
|
+
* @param ctxlen Length of context string.
|
|
516
|
+
* @param[in] pk Bit-packed public key.
|
|
517
|
+
* @param context Application context. Only present when
|
|
518
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
519
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
520
|
+
*
|
|
521
|
+
* @retval 0 Success.
|
|
522
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was used and an
|
|
523
|
+
* allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
524
|
+
* @retval MLD_ERR_FAIL Signature verification failed.
|
|
525
|
+
*/
|
|
495
526
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
496
527
|
MLD_EXTERNAL_API
|
|
497
528
|
int mld_sign_open(uint8_t *m, size_t *mlen, const uint8_t *sm, size_t smlen,
|
|
@@ -510,41 +541,46 @@ __contract__(
|
|
|
510
541
|
assigns(memory_slice(mlen, sizeof(size_t)))
|
|
511
542
|
ensures(return_value == 0 || return_value == MLD_ERR_FAIL || return_value == MLD_ERR_OUT_OF_MEMORY)
|
|
512
543
|
);
|
|
544
|
+
#endif /* !MLD_CONFIG_CORE_API_ONLY */
|
|
545
|
+
#endif /* !MLD_CONFIG_NO_VERIFY_API */
|
|
513
546
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
*
|
|
518
|
-
*
|
|
519
|
-
*
|
|
520
|
-
* Arguments: - uint8_t sig[MLDSA_CRYPTO_BYTES]:
|
|
521
|
-
* output signature
|
|
522
|
-
* - size_t *siglen: pointer to output length of signature
|
|
523
|
-
* - const uint8_t *ph: pointer to pre-hashed message
|
|
524
|
-
* - size_t phlen: length of pre-hashed message
|
|
525
|
-
* - const uint8_t *ctx: pointer to context string
|
|
526
|
-
* - size_t ctxlen: length of context string
|
|
527
|
-
* - const uint8_t rnd[MLDSA_RNDBYTES]:
|
|
528
|
-
* random seed
|
|
529
|
-
* - const uint8_t sk[MLDSA_CRYPTO_SECRETKEYBYTES]:
|
|
530
|
-
* bit-packed secret key
|
|
531
|
-
* - int hashalg: hash algorithm constant (one of
|
|
532
|
-
* MLD_PREHASH_*)
|
|
533
|
-
*
|
|
534
|
-
* Returns: - 0: Success
|
|
535
|
-
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
536
|
-
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
537
|
-
* - MLD_ERR_FAIL: Other kinds of failure
|
|
547
|
+
#if !defined(MLD_CONFIG_CORE_API_ONLY)
|
|
548
|
+
#if !defined(MLD_CONFIG_NO_SIGN_API)
|
|
549
|
+
/**
|
|
550
|
+
* FIPS 204: Algorithm 4 HashML-DSA.Sign. Compute signature with pre-hashed
|
|
551
|
+
* message.
|
|
538
552
|
*
|
|
539
553
|
* Supported hash algorithm constants:
|
|
540
554
|
* MLD_PREHASH_SHA2_224, MLD_PREHASH_SHA2_256, MLD_PREHASH_SHA2_384,
|
|
541
555
|
* MLD_PREHASH_SHA2_512, MLD_PREHASH_SHA2_512_224, MLD_PREHASH_SHA2_512_256,
|
|
542
556
|
* MLD_PREHASH_SHA3_224, MLD_PREHASH_SHA3_256, MLD_PREHASH_SHA3_384,
|
|
543
|
-
* MLD_PREHASH_SHA3_512, MLD_PREHASH_SHAKE_128, MLD_PREHASH_SHAKE_256
|
|
557
|
+
* MLD_PREHASH_SHA3_512, MLD_PREHASH_SHAKE_128, MLD_PREHASH_SHAKE_256.
|
|
544
558
|
*
|
|
545
|
-
*
|
|
559
|
+
* @warning This is an unstable API that may change in the future. If you need
|
|
546
560
|
* a stable API use mld_sign_signature_pre_hash_shake256.
|
|
547
|
-
|
|
561
|
+
*
|
|
562
|
+
* @param[out] sig Output signature.
|
|
563
|
+
* @param[out] siglen Pointer to output length of signature.
|
|
564
|
+
* @param[in] ph Pointer to pre-hashed message.
|
|
565
|
+
* @param phlen Length of pre-hashed message.
|
|
566
|
+
* @param[in] ctx Pointer to context string.
|
|
567
|
+
* @param ctxlen Length of context string.
|
|
568
|
+
* @param[in] rnd Random seed.
|
|
569
|
+
* @param[in] sk Bit-packed secret key.
|
|
570
|
+
* @param hashalg Hash algorithm constant (one of MLD_PREHASH_*).
|
|
571
|
+
* @param context Application context. Only present when
|
|
572
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
573
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
574
|
+
*
|
|
575
|
+
* @retval 0 Success.
|
|
576
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
577
|
+
* used and an allocation via
|
|
578
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
579
|
+
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The rejection-sampling loop exceeded
|
|
580
|
+
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
581
|
+
* iterations.
|
|
582
|
+
* @retval MLD_ERR_FAIL Other kinds of failure.
|
|
583
|
+
*/
|
|
548
584
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
549
585
|
MLD_EXTERNAL_API
|
|
550
586
|
int mld_sign_signature_pre_hash_internal(
|
|
@@ -565,40 +601,41 @@ __contract__(
|
|
|
565
601
|
assigns(memory_slice(sig, MLDSA_CRYPTO_BYTES))
|
|
566
602
|
assigns(object_whole(siglen))
|
|
567
603
|
ensures((return_value == 0 && *siglen == MLDSA_CRYPTO_BYTES) ||
|
|
568
|
-
((return_value == MLD_ERR_FAIL || return_value == MLD_ERR_OUT_OF_MEMORY) && *siglen == 0))
|
|
604
|
+
((return_value == MLD_ERR_FAIL || return_value == MLD_ERR_OUT_OF_MEMORY || return_value == MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED) && *siglen == 0))
|
|
569
605
|
);
|
|
606
|
+
#endif /* !MLD_CONFIG_NO_SIGN_API */
|
|
570
607
|
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
* Verifies signature with pre-hashed message.
|
|
576
|
-
*
|
|
577
|
-
* Arguments: - const uint8_t *sig: pointer to input signature
|
|
578
|
-
* - size_t siglen: length of signature
|
|
579
|
-
* - const uint8_t *ph: pointer to pre-hashed message
|
|
580
|
-
* - size_t phlen: length of pre-hashed message
|
|
581
|
-
* - const uint8_t *ctx: pointer to context string
|
|
582
|
-
* - size_t ctxlen: length of context string
|
|
583
|
-
* - const uint8_t pk[MLDSA_CRYPTO_PUBLICKEYBYTES]:
|
|
584
|
-
* bit-packed public key
|
|
585
|
-
* - int hashalg: hash algorithm constant (one of
|
|
586
|
-
* MLD_PREHASH_*)
|
|
587
|
-
*
|
|
588
|
-
* Returns: - 0: Success
|
|
589
|
-
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
590
|
-
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
591
|
-
* - MLD_ERR_FAIL: Signature verification failed
|
|
608
|
+
#if !defined(MLD_CONFIG_NO_VERIFY_API)
|
|
609
|
+
/**
|
|
610
|
+
* FIPS 204: Algorithm 5 HashML-DSA.Verify. Verify signature with pre-hashed
|
|
611
|
+
* message.
|
|
592
612
|
*
|
|
593
613
|
* Supported hash algorithm constants:
|
|
594
614
|
* MLD_PREHASH_SHA2_224, MLD_PREHASH_SHA2_256, MLD_PREHASH_SHA2_384,
|
|
595
615
|
* MLD_PREHASH_SHA2_512, MLD_PREHASH_SHA2_512_224, MLD_PREHASH_SHA2_512_256,
|
|
596
616
|
* MLD_PREHASH_SHA3_224, MLD_PREHASH_SHA3_256, MLD_PREHASH_SHA3_384,
|
|
597
|
-
* MLD_PREHASH_SHA3_512, MLD_PREHASH_SHAKE_128, MLD_PREHASH_SHAKE_256
|
|
617
|
+
* MLD_PREHASH_SHA3_512, MLD_PREHASH_SHAKE_128, MLD_PREHASH_SHAKE_256.
|
|
598
618
|
*
|
|
599
|
-
*
|
|
619
|
+
* @warning This is an unstable API that may change in the future. If you need
|
|
600
620
|
* a stable API use mld_sign_verify_pre_hash_shake256.
|
|
601
|
-
|
|
621
|
+
*
|
|
622
|
+
* @param[in] sig Pointer to input signature.
|
|
623
|
+
* @param siglen Length of signature.
|
|
624
|
+
* @param[in] ph Pointer to pre-hashed message.
|
|
625
|
+
* @param phlen Length of pre-hashed message.
|
|
626
|
+
* @param[in] ctx Pointer to context string.
|
|
627
|
+
* @param ctxlen Length of context string.
|
|
628
|
+
* @param[in] pk Bit-packed public key.
|
|
629
|
+
* @param hashalg Hash algorithm constant (one of MLD_PREHASH_*).
|
|
630
|
+
* @param context Application context. Only present when
|
|
631
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
632
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
633
|
+
*
|
|
634
|
+
* @retval 0 Success.
|
|
635
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was used and an
|
|
636
|
+
* allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
637
|
+
* @retval MLD_ERR_FAIL Signature verification failed.
|
|
638
|
+
*/
|
|
602
639
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
603
640
|
MLD_EXTERNAL_API
|
|
604
641
|
int mld_sign_verify_pre_hash_internal(
|
|
@@ -616,33 +653,36 @@ __contract__(
|
|
|
616
653
|
requires(memory_no_alias(pk, MLDSA_CRYPTO_PUBLICKEYBYTES))
|
|
617
654
|
ensures(return_value == 0 || return_value == MLD_ERR_FAIL || return_value == MLD_ERR_OUT_OF_MEMORY)
|
|
618
655
|
);
|
|
656
|
+
#endif /* !MLD_CONFIG_NO_VERIFY_API */
|
|
619
657
|
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
*
|
|
627
|
-
*
|
|
628
|
-
*
|
|
629
|
-
*
|
|
630
|
-
*
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
-
*
|
|
636
|
-
*
|
|
637
|
-
*
|
|
638
|
-
*
|
|
639
|
-
*
|
|
640
|
-
*
|
|
641
|
-
*
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
*
|
|
645
|
-
|
|
658
|
+
#if !defined(MLD_CONFIG_NO_SIGN_API)
|
|
659
|
+
/**
|
|
660
|
+
* FIPS 204: Algorithm 4 HashML-DSA.Sign with SHAKE256.
|
|
661
|
+
*
|
|
662
|
+
* Compute signature with pre-hashed message using SHAKE256. This function
|
|
663
|
+
* computes the SHAKE256 hash of the message internally.
|
|
664
|
+
*
|
|
665
|
+
* @param[out] sig Output signature.
|
|
666
|
+
* @param[out] siglen Pointer to output length of signature.
|
|
667
|
+
* @param[in] m Pointer to message to be hashed and signed.
|
|
668
|
+
* @param mlen Length of message.
|
|
669
|
+
* @param[in] ctx Pointer to context string.
|
|
670
|
+
* @param ctxlen Length of context string.
|
|
671
|
+
* @param[in] rnd Random seed.
|
|
672
|
+
* @param[in] sk Bit-packed secret key.
|
|
673
|
+
* @param context Application context. Only present when
|
|
674
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
675
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
676
|
+
*
|
|
677
|
+
* @retval 0 Success.
|
|
678
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
679
|
+
* used and an allocation via
|
|
680
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
681
|
+
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The rejection-sampling loop exceeded
|
|
682
|
+
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
683
|
+
* iterations.
|
|
684
|
+
* @retval MLD_ERR_FAIL Other kinds of failure.
|
|
685
|
+
*/
|
|
646
686
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
647
687
|
MLD_EXTERNAL_API
|
|
648
688
|
int mld_sign_signature_pre_hash_shake256(
|
|
@@ -663,33 +703,33 @@ __contract__(
|
|
|
663
703
|
assigns(memory_slice(sig, MLDSA_CRYPTO_BYTES))
|
|
664
704
|
assigns(object_whole(siglen))
|
|
665
705
|
ensures((return_value == 0 && *siglen == MLDSA_CRYPTO_BYTES) ||
|
|
666
|
-
((return_value == MLD_ERR_FAIL || return_value == MLD_ERR_OUT_OF_MEMORY) && *siglen == 0))
|
|
706
|
+
((return_value == MLD_ERR_FAIL || return_value == MLD_ERR_OUT_OF_MEMORY || return_value == MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED) && *siglen == 0))
|
|
667
707
|
);
|
|
708
|
+
#endif /* !MLD_CONFIG_NO_SIGN_API */
|
|
668
709
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
*
|
|
672
|
-
*
|
|
673
|
-
*
|
|
674
|
-
*
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
*
|
|
678
|
-
*
|
|
679
|
-
*
|
|
680
|
-
*
|
|
681
|
-
*
|
|
682
|
-
*
|
|
683
|
-
*
|
|
684
|
-
*
|
|
685
|
-
*
|
|
686
|
-
*
|
|
687
|
-
*
|
|
688
|
-
*
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
|
|
692
|
-
**************************************************/
|
|
710
|
+
#if !defined(MLD_CONFIG_NO_VERIFY_API)
|
|
711
|
+
/**
|
|
712
|
+
* FIPS 204: Algorithm 5 HashML-DSA.Verify with SHAKE256.
|
|
713
|
+
*
|
|
714
|
+
* Verify signature with pre-hashed message using SHAKE256. This function
|
|
715
|
+
* computes the SHAKE256 hash of the message internally.
|
|
716
|
+
*
|
|
717
|
+
* @param[in] sig Pointer to input signature.
|
|
718
|
+
* @param siglen Length of signature.
|
|
719
|
+
* @param[in] m Pointer to message to be hashed and verified.
|
|
720
|
+
* @param mlen Length of message.
|
|
721
|
+
* @param[in] ctx Pointer to context string.
|
|
722
|
+
* @param ctxlen Length of context string.
|
|
723
|
+
* @param[in] pk Bit-packed public key.
|
|
724
|
+
* @param context Application context. Only present when
|
|
725
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
726
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
727
|
+
*
|
|
728
|
+
* @retval 0 Success.
|
|
729
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was used and an
|
|
730
|
+
* allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
731
|
+
* @retval MLD_ERR_FAIL Signature verification failed.
|
|
732
|
+
*/
|
|
693
733
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
694
734
|
MLD_EXTERNAL_API
|
|
695
735
|
int mld_sign_verify_pre_hash_shake256(
|
|
@@ -707,50 +747,47 @@ __contract__(
|
|
|
707
747
|
requires(memory_no_alias(pk, MLDSA_CRYPTO_PUBLICKEYBYTES))
|
|
708
748
|
ensures(return_value == 0 || return_value == MLD_ERR_FAIL || return_value == MLD_ERR_OUT_OF_MEMORY)
|
|
709
749
|
);
|
|
750
|
+
#endif /* !MLD_CONFIG_NO_VERIFY_API */
|
|
710
751
|
|
|
752
|
+
#if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API)
|
|
711
753
|
/* Maximum formatted domain separation message length:
|
|
712
754
|
* - Pure ML-DSA: 0x00 || ctxlen || ctx (max 255)
|
|
713
755
|
* - HashML-DSA: 0x01 || ctxlen || ctx (max 255) || oid (11) || ph (max 64) */
|
|
714
756
|
#define MLD_DOMAIN_SEPARATION_MAX_BYTES (2 + 255 + 11 + 64)
|
|
715
757
|
|
|
716
|
-
|
|
717
|
-
*
|
|
718
|
-
*
|
|
719
|
-
*
|
|
720
|
-
*
|
|
721
|
-
*
|
|
722
|
-
*
|
|
723
|
-
*
|
|
724
|
-
*
|
|
725
|
-
* Arguments: - uint8_t prefix[MLD_DOMAIN_SEPARATION_MAX_BYTES]:
|
|
726
|
-
* output domain separation prefix buffer
|
|
727
|
-
* - const uint8_t *ph: pointer to pre-hashed message
|
|
728
|
-
* (ignored for pure ML-DSA)
|
|
729
|
-
* - size_t phlen: length of pre-hashed message
|
|
730
|
-
* (ignored for pure ML-DSA)
|
|
731
|
-
* - const uint8_t *ctx: pointer to context string (may be NULL)
|
|
732
|
-
* - size_t ctxlen: length of context string
|
|
733
|
-
* - int hashalg: hash algorithm constant
|
|
734
|
-
* (MLD_PREHASH_NONE for pure ML-DSA, or MLD_PREHASH_* for
|
|
735
|
-
* HashML-DSA)
|
|
736
|
-
*
|
|
737
|
-
* Returns the total length of the formatted prefix, or 0 on error.
|
|
758
|
+
/**
|
|
759
|
+
* Prepare domain separation prefix for ML-DSA signing.
|
|
760
|
+
*
|
|
761
|
+
* For pure ML-DSA (hashalg == MLD_PREHASH_NONE):
|
|
762
|
+
* Format: 0x00 || ctxlen (1 byte) || ctx.
|
|
763
|
+
*
|
|
764
|
+
* For HashML-DSA (hashalg != MLD_PREHASH_NONE):
|
|
765
|
+
* Format: 0x01 || ctxlen (1 byte) || ctx || oid (11 bytes) || ph.
|
|
738
766
|
*
|
|
739
767
|
* This function is useful for building incremental signing APIs.
|
|
740
768
|
*
|
|
741
|
-
*
|
|
742
|
-
*
|
|
743
|
-
*
|
|
744
|
-
*
|
|
745
|
-
*
|
|
746
|
-
*
|
|
747
|
-
*
|
|
748
|
-
*
|
|
749
|
-
*
|
|
750
|
-
*
|
|
751
|
-
*
|
|
752
|
-
*
|
|
753
|
-
|
|
769
|
+
* @spec{For HashML-DSA (hashalg != MLD_PREHASH_NONE), implements
|
|
770
|
+
* @[FIPS204, Algorithm 4, L23]. For Pure ML-DSA (hashalg == MLD_PREHASH_NONE),
|
|
771
|
+
* implements
|
|
772
|
+
* ```
|
|
773
|
+
* M' <- BytesToBits(IntegerToBytes(0, 1)
|
|
774
|
+
* || IntegerToBytes(|ctx|, 1)
|
|
775
|
+
* || ctx
|
|
776
|
+
* ```
|
|
777
|
+
* which is part of @[FIPS204, Algorithm 2 (ML-DSA.Sign), L10] and
|
|
778
|
+
* @[FIPS204, Algorithm 3 (ML-DSA.Verify), L5].}
|
|
779
|
+
*
|
|
780
|
+
* @param[out] prefix Output domain separation prefix buffer.
|
|
781
|
+
* @param[in] ph Pointer to pre-hashed message (ignored for pure
|
|
782
|
+
* ML-DSA).
|
|
783
|
+
* @param phlen Length of pre-hashed message (ignored for pure ML-DSA).
|
|
784
|
+
* @param[in] ctx Pointer to context string (may be NULL).
|
|
785
|
+
* @param ctxlen Length of context string.
|
|
786
|
+
* @param hashalg Hash algorithm constant (MLD_PREHASH_NONE for pure
|
|
787
|
+
* ML-DSA, or MLD_PREHASH_* for HashML-DSA).
|
|
788
|
+
*
|
|
789
|
+
* @return The total length of the formatted prefix, or 0 on error.
|
|
790
|
+
*/
|
|
754
791
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
755
792
|
MLD_EXTERNAL_API
|
|
756
793
|
size_t mld_prepare_domain_separation_prefix(
|
|
@@ -765,33 +802,32 @@ __contract__(
|
|
|
765
802
|
assigns(memory_slice(prefix, MLD_DOMAIN_SEPARATION_MAX_BYTES))
|
|
766
803
|
ensures(return_value <= MLD_DOMAIN_SEPARATION_MAX_BYTES)
|
|
767
804
|
);
|
|
805
|
+
#endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API */
|
|
768
806
|
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
*
|
|
772
|
-
*
|
|
773
|
-
*
|
|
774
|
-
*
|
|
775
|
-
*
|
|
776
|
-
*
|
|
777
|
-
*
|
|
778
|
-
*
|
|
779
|
-
*
|
|
780
|
-
*
|
|
781
|
-
*
|
|
782
|
-
*
|
|
783
|
-
*
|
|
784
|
-
*
|
|
785
|
-
*
|
|
786
|
-
*
|
|
787
|
-
*
|
|
788
|
-
*
|
|
789
|
-
*
|
|
790
|
-
*
|
|
791
|
-
*
|
|
792
|
-
|
|
793
|
-
* through its return value and timing.
|
|
794
|
-
**************************************************/
|
|
807
|
+
#if !defined(MLD_CONFIG_NO_KEYPAIR_API)
|
|
808
|
+
/**
|
|
809
|
+
* Perform basic validity checks on secret key, and derive public key.
|
|
810
|
+
*
|
|
811
|
+
* Referring to the decoding of the secret key `sk=(rho, K, tr, s1, s2, t0)`
|
|
812
|
+
* (cf. @[FIPS204, Algorithm 25 skDecode]), the following checks are
|
|
813
|
+
* performed:
|
|
814
|
+
* - Check that s1 and s2 have coefficients in [-MLDSA_ETA, MLDSA_ETA].
|
|
815
|
+
* - Check that t0 and tr stored in sk match recomputed values.
|
|
816
|
+
*
|
|
817
|
+
* @note This function leaks whether the secret key is valid or invalid
|
|
818
|
+
* through its return value and timing.
|
|
819
|
+
*
|
|
820
|
+
* @param[out] pk Output public key.
|
|
821
|
+
* @param[in] sk Input secret key.
|
|
822
|
+
* @param context Application context. Only present when
|
|
823
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
824
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
825
|
+
*
|
|
826
|
+
* @retval 0 Success.
|
|
827
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was used and an
|
|
828
|
+
* allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
829
|
+
* @retval MLD_ERR_FAIL Secret key validation failed.
|
|
830
|
+
*/
|
|
795
831
|
MLD_MUST_CHECK_RETURN_VALUE
|
|
796
832
|
MLD_EXTERNAL_API
|
|
797
833
|
int mld_sign_pk_from_sk(uint8_t pk[MLDSA_CRYPTO_PUBLICKEYBYTES],
|
|
@@ -803,4 +839,7 @@ __contract__(
|
|
|
803
839
|
assigns(memory_slice(pk, MLDSA_CRYPTO_PUBLICKEYBYTES))
|
|
804
840
|
ensures(return_value == 0 || return_value == MLD_ERR_FAIL || return_value == MLD_ERR_OUT_OF_MEMORY)
|
|
805
841
|
);
|
|
842
|
+
#endif /* !MLD_CONFIG_NO_KEYPAIR_API */
|
|
843
|
+
#endif /* !MLD_CONFIG_CORE_API_ONLY */
|
|
844
|
+
|
|
806
845
|
#endif /* !MLD_SIGN_H */
|