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
|
@@ -132,6 +132,11 @@
|
|
|
132
132
|
/* An rng failure occured. Might be due to insufficient entropy or
|
|
133
133
|
* system misconfiguration. */
|
|
134
134
|
#define MLD_ERR_RNG_FAIL -3
|
|
135
|
+
/* The signing rejection-sampling loop exceeded
|
|
136
|
+
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS iterations without producing a valid
|
|
137
|
+
* signature. With a FIPS 204 Appendix C compliant bound (>= 814) this
|
|
138
|
+
* has probability < 2^-256. */
|
|
139
|
+
#define MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED -4
|
|
135
140
|
|
|
136
141
|
/****************************** Function API **********************************/
|
|
137
142
|
|
|
@@ -205,32 +210,38 @@ extern "C"
|
|
|
205
210
|
{
|
|
206
211
|
#endif
|
|
207
212
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
|
|
213
|
+
#if !defined(MLD_CONFIG_NO_KEYPAIR_API)
|
|
214
|
+
/**
|
|
215
|
+
* Generate a public-private key pair from a seed.
|
|
216
|
+
*
|
|
217
|
+
* When MLD_CONFIG_KEYGEN_PCT is set, performs a Pairwise Consistency Test
|
|
218
|
+
* (PCT) as required by FIPS 140-3 IG.
|
|
219
|
+
*
|
|
220
|
+
* @warning The seed must be generated by a cryptographically secure random
|
|
221
|
+
* number generator.
|
|
222
|
+
*
|
|
223
|
+
* @spec{Implements @[FIPS204 Algorithm 6 (ML-DSA.KeyGen_internal)].}
|
|
224
|
+
*
|
|
225
|
+
* @param[out] pk Output public key.
|
|
226
|
+
* @param[out] sk Output private key.
|
|
227
|
+
* @param[in] seed Input random seed.
|
|
228
|
+
* @param context Application context. Only present when
|
|
229
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
230
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
231
|
+
*
|
|
232
|
+
* @retval 0 Success.
|
|
233
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
234
|
+
* used and an allocation via
|
|
235
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
236
|
+
* @retval MLD_ERR_RNG_FAIL Random number generation failed.
|
|
237
|
+
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The PCT's signing step exhausted
|
|
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
|
|
243
|
+
* MLD_CONFIG_KEYGEN_PCT is enabled.
|
|
244
|
+
*/
|
|
234
245
|
MLD_API_QUALIFIER
|
|
235
246
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
236
247
|
int MLD_API_NAMESPACE(keypair_internal)(
|
|
@@ -243,29 +254,33 @@ int MLD_API_NAMESPACE(keypair_internal)(
|
|
|
243
254
|
#endif
|
|
244
255
|
);
|
|
245
256
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
|
|
257
|
+
#if !defined(MLD_CONFIG_CORE_API_ONLY)
|
|
258
|
+
/**
|
|
259
|
+
* Generate a public-private key pair.
|
|
260
|
+
*
|
|
261
|
+
* When MLD_CONFIG_KEYGEN_PCT is set, performs a Pairwise Consistency Test
|
|
262
|
+
* (PCT) as required by FIPS 140-3 IG.
|
|
263
|
+
*
|
|
264
|
+
* @spec{Implements @[FIPS204 Algorithm 1 (ML-DSA.KeyGen)].}
|
|
265
|
+
*
|
|
266
|
+
* @param[out] pk Output public key.
|
|
267
|
+
* @param[out] sk Output private key.
|
|
268
|
+
* @param context Application context. Only present when
|
|
269
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
270
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
271
|
+
*
|
|
272
|
+
* @retval 0 Success.
|
|
273
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
274
|
+
* used and an allocation via
|
|
275
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
276
|
+
* @retval MLD_ERR_RNG_FAIL Random number generation failed.
|
|
277
|
+
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The PCT's signing step exhausted
|
|
278
|
+
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
279
|
+
* iterations. Only possible when
|
|
280
|
+
* MLD_CONFIG_KEYGEN_PCT is enabled.
|
|
281
|
+
* @retval MLD_ERR_FAIL MLD_CONFIG_KEYGEN_PCT is enabled and
|
|
282
|
+
* the PCT check failed.
|
|
283
|
+
*/
|
|
269
284
|
MLD_API_QUALIFIER
|
|
270
285
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
271
286
|
int MLD_API_NAMESPACE(keypair)(
|
|
@@ -276,39 +291,48 @@ int MLD_API_NAMESPACE(keypair)(
|
|
|
276
291
|
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
277
292
|
#endif
|
|
278
293
|
);
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
|
|
294
|
+
#endif /* !MLD_CONFIG_CORE_API_ONLY */
|
|
295
|
+
#endif /* !MLD_CONFIG_NO_KEYPAIR_API */
|
|
296
|
+
|
|
297
|
+
#if !defined(MLD_CONFIG_NO_SIGN_API)
|
|
298
|
+
/**
|
|
299
|
+
* Compute signature using a caller-supplied random seed and prefix.
|
|
300
|
+
*
|
|
301
|
+
* If the returned value is non-zero, then the values of *sig and *siglen
|
|
302
|
+
* should not be referenced.
|
|
303
|
+
*
|
|
304
|
+
* @spec{Implements @[FIPS204 Algorithm 7 (ML-DSA.Sign_internal)].}
|
|
305
|
+
*
|
|
306
|
+
* @param[out] sig Output signature.
|
|
307
|
+
* @param[out] siglen Pointer to output length of signature.
|
|
308
|
+
* @param[in] m Pointer to message to be signed (when
|
|
309
|
+
* externalmu == 0), or to a precomputed
|
|
310
|
+
* message representative mu (when externalmu != 0).
|
|
311
|
+
* @param mlen Length of m. Must equal MLDSA_CRHBYTES when
|
|
312
|
+
* externalmu != 0.
|
|
313
|
+
* @param[in] pre Pointer to prefix string. Ignored when
|
|
314
|
+
* externalmu != 0.
|
|
315
|
+
* @param prelen Length of prefix string. Ignored when
|
|
316
|
+
* externalmu != 0.
|
|
317
|
+
* @param[in] rnd Random seed.
|
|
318
|
+
* @param[in] sk Bit-packed secret key.
|
|
319
|
+
* @param externalmu 0: m/mlen is the raw message; mu = H(tr, pre, m) is
|
|
320
|
+
* computed internally.
|
|
321
|
+
* non-zero: m points to a precomputed mu of
|
|
322
|
+
* MLDSA_CRHBYTES bytes; pre/prelen unused.
|
|
323
|
+
* @param context Application context. Only present when
|
|
324
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
325
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
326
|
+
*
|
|
327
|
+
* @retval 0 Success.
|
|
328
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
329
|
+
* used and an allocation via
|
|
330
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
331
|
+
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The rejection-sampling loop exceeded
|
|
332
|
+
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
333
|
+
* iterations.
|
|
334
|
+
* @retval MLD_ERR_FAIL Other kinds of failure.
|
|
335
|
+
*/
|
|
312
336
|
MLD_API_QUALIFIER
|
|
313
337
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
314
338
|
int MLD_API_NAMESPACE(signature_internal)(
|
|
@@ -323,36 +347,35 @@ int MLD_API_NAMESPACE(signature_internal)(
|
|
|
323
347
|
#endif
|
|
324
348
|
);
|
|
325
349
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
|
|
355
|
-
**************************************************/
|
|
350
|
+
#if !defined(MLD_CONFIG_CORE_API_ONLY)
|
|
351
|
+
/**
|
|
352
|
+
* Compute signature. This function implements the randomized variant of
|
|
353
|
+
* ML-DSA. If you require the deterministic variant, use
|
|
354
|
+
* crypto_sign_signature_internal directly.
|
|
355
|
+
*
|
|
356
|
+
* @spec{Implements @[FIPS204 Algorithm 2 (ML-DSA.Sign)].}
|
|
357
|
+
*
|
|
358
|
+
* @param[out] sig Output signature.
|
|
359
|
+
* @param[out] siglen Pointer to output length of signature.
|
|
360
|
+
* @param[in] m Pointer to message to be signed.
|
|
361
|
+
* @param mlen Length of message.
|
|
362
|
+
* @param[in] ctx Pointer to context string. May be NULL if ctxlen == 0.
|
|
363
|
+
* @param ctxlen Length of context string. Should be <= 255.
|
|
364
|
+
* @param[in] sk Bit-packed secret key.
|
|
365
|
+
* @param context Application context. Only present when
|
|
366
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
367
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
368
|
+
*
|
|
369
|
+
* @retval 0 Success.
|
|
370
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
371
|
+
* used and an allocation via
|
|
372
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
373
|
+
* @retval MLD_ERR_RNG_FAIL Random number generation failed.
|
|
374
|
+
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The rejection-sampling loop exceeded
|
|
375
|
+
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
376
|
+
* iterations.
|
|
377
|
+
* @retval MLD_ERR_FAIL Other kinds of failure.
|
|
378
|
+
*/
|
|
356
379
|
MLD_API_QUALIFIER
|
|
357
380
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
358
381
|
int MLD_API_NAMESPACE(signature)(
|
|
@@ -365,31 +388,33 @@ int MLD_API_NAMESPACE(signature)(
|
|
|
365
388
|
#endif
|
|
366
389
|
);
|
|
367
390
|
|
|
368
|
-
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
|
|
391
|
+
/**
|
|
392
|
+
* Compute signature in "external mu" mode: the caller has already computed
|
|
393
|
+
* the message representative mu = SHAKE256(tr || M', 64), where
|
|
394
|
+
* tr = SHAKE256(pk, 64) and M' is the FIPS 204 formatted message (e.g.
|
|
395
|
+
* 0x00 || ctxlen || ctx || msg for pure ML-DSA). This is useful when the
|
|
396
|
+
* message is large or streamed and cannot be held in memory.
|
|
397
|
+
*
|
|
398
|
+
* @spec{Implements @[FIPS204 Algorithm 2 (ML-DSA.Sign external mu variant)].}
|
|
399
|
+
*
|
|
400
|
+
* @param[out] sig Output signature.
|
|
401
|
+
* @param[out] siglen Pointer to output length of signature.
|
|
402
|
+
* @param[in] mu Precomputed message representative.
|
|
403
|
+
* @param[in] sk Bit-packed secret key.
|
|
404
|
+
* @param context Application context. Only present when
|
|
405
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
406
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
407
|
+
*
|
|
408
|
+
* @retval 0 Success.
|
|
409
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
410
|
+
* used and an allocation via
|
|
411
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
412
|
+
* @retval MLD_ERR_RNG_FAIL Random number generation failed.
|
|
413
|
+
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The rejection-sampling loop exceeded
|
|
414
|
+
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
415
|
+
* iterations.
|
|
416
|
+
* @retval MLD_ERR_FAIL Other kinds of failure.
|
|
417
|
+
*/
|
|
393
418
|
MLD_API_QUALIFIER
|
|
394
419
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
395
420
|
int MLD_API_NAMESPACE(signature_extmu)(
|
|
@@ -402,31 +427,32 @@ int MLD_API_NAMESPACE(signature_extmu)(
|
|
|
402
427
|
#endif
|
|
403
428
|
);
|
|
404
429
|
|
|
405
|
-
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
|
|
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
|
+
*/
|
|
430
456
|
MLD_API_QUALIFIER
|
|
431
457
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
432
458
|
int MLD_API_NAMESPACE(sign)(
|
|
@@ -438,32 +464,38 @@ int MLD_API_NAMESPACE(sign)(
|
|
|
438
464
|
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
439
465
|
#endif
|
|
440
466
|
);
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
|
|
467
|
+
#endif /* !MLD_CONFIG_CORE_API_ONLY */
|
|
468
|
+
#endif /* !MLD_CONFIG_NO_SIGN_API */
|
|
469
|
+
|
|
470
|
+
#if !defined(MLD_CONFIG_NO_VERIFY_API)
|
|
471
|
+
/**
|
|
472
|
+
* Verify signature. Internal API.
|
|
473
|
+
*
|
|
474
|
+
* @spec{Implements @[FIPS204 Algorithm 8 (ML-DSA.Verify_internal)].}
|
|
475
|
+
*
|
|
476
|
+
* @param[in] sig Pointer to input signature.
|
|
477
|
+
* @param siglen Length of signature.
|
|
478
|
+
* @param[in] m Pointer to message (when externalmu == 0), or to a
|
|
479
|
+
* precomputed message representative mu (when
|
|
480
|
+
* externalmu != 0).
|
|
481
|
+
* @param mlen Length of m. Must equal MLDSA_CRHBYTES when
|
|
482
|
+
* externalmu != 0.
|
|
483
|
+
* @param[in] pre Pointer to prefix string. Ignored when externalmu != 0.
|
|
484
|
+
* @param prelen Length of prefix string. Ignored when externalmu != 0.
|
|
485
|
+
* @param[in] pk Bit-packed public key.
|
|
486
|
+
* @param externalmu 0: m/mlen is the raw message; mu = H(H(pk), pre, m) is
|
|
487
|
+
* computed internally.
|
|
488
|
+
* non-zero: m points to a precomputed mu of
|
|
489
|
+
* MLDSA_CRHBYTES bytes; pre/prelen unused.
|
|
490
|
+
* @param context Application context. Only present when
|
|
491
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
492
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
493
|
+
*
|
|
494
|
+
* @retval 0 Success.
|
|
495
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was used and an
|
|
496
|
+
* allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
497
|
+
* @retval MLD_ERR_FAIL Signature verification failed.
|
|
498
|
+
*/
|
|
467
499
|
MLD_API_QUALIFIER
|
|
468
500
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
469
501
|
int MLD_API_NAMESPACE(verify_internal)(
|
|
@@ -477,31 +509,28 @@ int MLD_API_NAMESPACE(verify_internal)(
|
|
|
477
509
|
#endif
|
|
478
510
|
);
|
|
479
511
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
*
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
*
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
|
|
502
|
-
* Specification: Implements @[FIPS204 Algorithm 3 (ML-DSA.Verify)]
|
|
503
|
-
*
|
|
504
|
-
**************************************************/
|
|
512
|
+
#if !defined(MLD_CONFIG_CORE_API_ONLY)
|
|
513
|
+
/**
|
|
514
|
+
* Verify signature.
|
|
515
|
+
*
|
|
516
|
+
* @spec{Implements @[FIPS204 Algorithm 3 (ML-DSA.Verify)].}
|
|
517
|
+
*
|
|
518
|
+
* @param[in] sig Pointer to input signature.
|
|
519
|
+
* @param siglen Length of signature.
|
|
520
|
+
* @param[in] m Pointer to message.
|
|
521
|
+
* @param mlen Length of message.
|
|
522
|
+
* @param[in] ctx Pointer to context string. May be NULL if ctxlen == 0.
|
|
523
|
+
* @param ctxlen Length of context string.
|
|
524
|
+
* @param[in] pk Bit-packed public key.
|
|
525
|
+
* @param context Application context. Only present when
|
|
526
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
527
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
528
|
+
*
|
|
529
|
+
* @retval 0 Success.
|
|
530
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was used and an
|
|
531
|
+
* allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
532
|
+
* @retval MLD_ERR_FAIL Signature verification failed.
|
|
533
|
+
*/
|
|
505
534
|
MLD_API_QUALIFIER
|
|
506
535
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
507
536
|
int MLD_API_NAMESPACE(verify)(
|
|
@@ -514,29 +543,28 @@ int MLD_API_NAMESPACE(verify)(
|
|
|
514
543
|
#endif
|
|
515
544
|
);
|
|
516
545
|
|
|
517
|
-
|
|
518
|
-
*
|
|
519
|
-
*
|
|
520
|
-
*
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
*
|
|
538
|
-
|
|
539
|
-
**************************************************/
|
|
546
|
+
/**
|
|
547
|
+
* Verify signature in "external mu" mode: the caller has already computed
|
|
548
|
+
* the message representative mu = SHAKE256(tr || M', 64), where
|
|
549
|
+
* tr = SHAKE256(pk, 64) and M' is the FIPS 204 formatted message (e.g.
|
|
550
|
+
* 0x00 || ctxlen || ctx || msg for pure ML-DSA). The same mu must have
|
|
551
|
+
* been used at signing time.
|
|
552
|
+
*
|
|
553
|
+
* @spec{Implements @[FIPS204 Algorithm 3 (ML-DSA.Verify external mu variant)].}
|
|
554
|
+
*
|
|
555
|
+
* @param[in] sig Pointer to input signature.
|
|
556
|
+
* @param siglen Length of signature.
|
|
557
|
+
* @param[in] mu Precomputed message representative.
|
|
558
|
+
* @param[in] pk Bit-packed public key.
|
|
559
|
+
* @param context Application context. Only present when
|
|
560
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
561
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
562
|
+
*
|
|
563
|
+
* @retval 0 Success.
|
|
564
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was used and an
|
|
565
|
+
* allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
566
|
+
* @retval MLD_ERR_FAIL Signature verification failed.
|
|
567
|
+
*/
|
|
540
568
|
MLD_API_QUALIFIER
|
|
541
569
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
542
570
|
int MLD_API_NAMESPACE(verify_extmu)(
|
|
@@ -548,28 +576,26 @@ int MLD_API_NAMESPACE(verify_extmu)(
|
|
|
548
576
|
#endif
|
|
549
577
|
);
|
|
550
578
|
|
|
551
|
-
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
*
|
|
564
|
-
*
|
|
565
|
-
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
|
|
571
|
-
* - MLD_ERR_FAIL: Signature verification failed
|
|
572
|
-
**************************************************/
|
|
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
|
+
*/
|
|
573
599
|
MLD_API_QUALIFIER
|
|
574
600
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
575
601
|
int MLD_API_NAMESPACE(open)(
|
|
@@ -581,10 +607,10 @@ int MLD_API_NAMESPACE(open)(
|
|
|
581
607
|
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
582
608
|
#endif
|
|
583
609
|
);
|
|
610
|
+
#endif /* !MLD_CONFIG_CORE_API_ONLY */
|
|
611
|
+
#endif /* !MLD_CONFIG_NO_VERIFY_API */
|
|
584
612
|
|
|
585
|
-
|
|
586
|
-
* Hash algorithm constants for domain separation
|
|
587
|
-
**************************************************/
|
|
613
|
+
/* Hash algorithm constants for domain separation */
|
|
588
614
|
#define MLD_PREHASH_NONE 0
|
|
589
615
|
#define MLD_PREHASH_SHA2_224 1
|
|
590
616
|
#define MLD_PREHASH_SHA2_256 2
|
|
@@ -599,41 +625,43 @@ int MLD_API_NAMESPACE(open)(
|
|
|
599
625
|
#define MLD_PREHASH_SHAKE_128 11
|
|
600
626
|
#define MLD_PREHASH_SHAKE_256 12
|
|
601
627
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
*
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
* Arguments:
|
|
609
|
-
* - uint8_t sig[MLDSA_BYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
610
|
-
* output signature
|
|
611
|
-
* - size_t *siglen: pointer to output length of signature
|
|
612
|
-
* - const uint8_t *ph: pointer to pre-hashed message
|
|
613
|
-
* - size_t phlen: length of pre-hashed message
|
|
614
|
-
* - const uint8_t *ctx: pointer to context string
|
|
615
|
-
* - size_t ctxlen: length of context string
|
|
616
|
-
* - const uint8_t rnd[MLDSA_RNDBYTES]:
|
|
617
|
-
* random seed
|
|
618
|
-
* - const uint8_t sk[MLDSA_SECRETKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
619
|
-
* bit-packed secret key
|
|
620
|
-
* - int hashalg: hash algorithm constant (one of MLD_PREHASH_*)
|
|
621
|
-
*
|
|
622
|
-
* Returns:
|
|
623
|
-
* - 0: Success
|
|
624
|
-
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
625
|
-
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
626
|
-
* - MLD_ERR_FAIL: Other kinds of failure
|
|
628
|
+
#if !defined(MLD_CONFIG_CORE_API_ONLY)
|
|
629
|
+
#if !defined(MLD_CONFIG_NO_SIGN_API)
|
|
630
|
+
/**
|
|
631
|
+
* FIPS 204: Algorithm 4 HashML-DSA.Sign. Compute signature with pre-hashed
|
|
632
|
+
* message.
|
|
627
633
|
*
|
|
628
634
|
* Supported hash algorithm constants:
|
|
629
635
|
* MLD_PREHASH_SHA2_224, MLD_PREHASH_SHA2_256, MLD_PREHASH_SHA2_384,
|
|
630
636
|
* MLD_PREHASH_SHA2_512, MLD_PREHASH_SHA2_512_224, MLD_PREHASH_SHA2_512_256,
|
|
631
637
|
* MLD_PREHASH_SHA3_224, MLD_PREHASH_SHA3_256, MLD_PREHASH_SHA3_384,
|
|
632
|
-
* MLD_PREHASH_SHA3_512, MLD_PREHASH_SHAKE_128, MLD_PREHASH_SHAKE_256
|
|
638
|
+
* MLD_PREHASH_SHA3_512, MLD_PREHASH_SHAKE_128, MLD_PREHASH_SHAKE_256.
|
|
633
639
|
*
|
|
634
|
-
*
|
|
640
|
+
* @warning This is an unstable API that may change in the future. If you need
|
|
635
641
|
* a stable API use crypto_sign_signature_pre_hash_shake256.
|
|
636
|
-
|
|
642
|
+
*
|
|
643
|
+
* @param[out] sig Output signature.
|
|
644
|
+
* @param[out] siglen Pointer to output length of signature.
|
|
645
|
+
* @param[in] ph Pointer to pre-hashed message.
|
|
646
|
+
* @param phlen Length of pre-hashed message.
|
|
647
|
+
* @param[in] ctx Pointer to context string.
|
|
648
|
+
* @param ctxlen Length of context string.
|
|
649
|
+
* @param[in] rnd Random seed.
|
|
650
|
+
* @param[in] sk Bit-packed secret key.
|
|
651
|
+
* @param hashalg Hash algorithm constant (one of MLD_PREHASH_*).
|
|
652
|
+
* @param context Application context. Only present when
|
|
653
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
654
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
655
|
+
*
|
|
656
|
+
* @retval 0 Success.
|
|
657
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
658
|
+
* used and an allocation via
|
|
659
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
660
|
+
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The rejection-sampling loop exceeded
|
|
661
|
+
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
662
|
+
* iterations.
|
|
663
|
+
* @retval MLD_ERR_FAIL Other kinds of failure.
|
|
664
|
+
*/
|
|
637
665
|
MLD_API_QUALIFIER
|
|
638
666
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
639
667
|
int MLD_API_NAMESPACE(signature_pre_hash_internal)(
|
|
@@ -647,38 +675,39 @@ int MLD_API_NAMESPACE(signature_pre_hash_internal)(
|
|
|
647
675
|
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
648
676
|
#endif
|
|
649
677
|
);
|
|
678
|
+
#endif /* !MLD_CONFIG_NO_SIGN_API */
|
|
650
679
|
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
*
|
|
654
|
-
*
|
|
655
|
-
* Verifies signature with pre-hashed message.
|
|
656
|
-
*
|
|
657
|
-
* Arguments:
|
|
658
|
-
* - const uint8_t *sig: pointer to input signature
|
|
659
|
-
* - size_t siglen: length of signature
|
|
660
|
-
* - const uint8_t *ph: pointer to pre-hashed message
|
|
661
|
-
* - size_t phlen: length of pre-hashed message
|
|
662
|
-
* - const uint8_t *ctx: pointer to context string
|
|
663
|
-
* - size_t ctxlen: length of context string
|
|
664
|
-
* - const uint8_t pk[MLDSA_PUBLICKEYBYTES(MLD_CONFIG_API_PARAMETER_SET)]:
|
|
665
|
-
* bit-packed public key
|
|
666
|
-
* - int hashalg: hash algorithm constant (one of MLD_PREHASH_*)
|
|
667
|
-
*
|
|
668
|
-
* Returns: - 0: Success
|
|
669
|
-
* - MLD_ERR_OUT_OF_MEMORY: If MLD_CONFIG_CUSTOM_ALLOC_FREE is
|
|
670
|
-
* used and an allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
671
|
-
* - MLD_ERR_FAIL: Signature verification failed
|
|
680
|
+
#if !defined(MLD_CONFIG_NO_VERIFY_API)
|
|
681
|
+
/**
|
|
682
|
+
* FIPS 204: Algorithm 5 HashML-DSA.Verify. Verifies signature with pre-hashed
|
|
683
|
+
* message.
|
|
672
684
|
*
|
|
673
685
|
* Supported hash algorithm constants:
|
|
674
686
|
* MLD_PREHASH_SHA2_224, MLD_PREHASH_SHA2_256, MLD_PREHASH_SHA2_384,
|
|
675
687
|
* MLD_PREHASH_SHA2_512, MLD_PREHASH_SHA2_512_224, MLD_PREHASH_SHA2_512_256,
|
|
676
688
|
* MLD_PREHASH_SHA3_224, MLD_PREHASH_SHA3_256, MLD_PREHASH_SHA3_384,
|
|
677
|
-
* MLD_PREHASH_SHA3_512, MLD_PREHASH_SHAKE_128, MLD_PREHASH_SHAKE_256
|
|
689
|
+
* MLD_PREHASH_SHA3_512, MLD_PREHASH_SHAKE_128, MLD_PREHASH_SHAKE_256.
|
|
678
690
|
*
|
|
679
|
-
*
|
|
691
|
+
* @warning This is an unstable API that may change in the future. If you need
|
|
680
692
|
* a stable API use crypto_sign_verify_pre_hash_shake256.
|
|
681
|
-
|
|
693
|
+
*
|
|
694
|
+
* @param[in] sig Pointer to input signature.
|
|
695
|
+
* @param siglen Length of signature.
|
|
696
|
+
* @param[in] ph Pointer to pre-hashed message.
|
|
697
|
+
* @param phlen Length of pre-hashed message.
|
|
698
|
+
* @param[in] ctx Pointer to context string.
|
|
699
|
+
* @param ctxlen Length of context string.
|
|
700
|
+
* @param[in] pk Bit-packed public key.
|
|
701
|
+
* @param hashalg Hash algorithm constant (one of MLD_PREHASH_*).
|
|
702
|
+
* @param context Application context. Only present when
|
|
703
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
704
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
705
|
+
*
|
|
706
|
+
* @retval 0 Success.
|
|
707
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was used and an
|
|
708
|
+
* allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
709
|
+
* @retval MLD_ERR_FAIL Signature verification failed.
|
|
710
|
+
*/
|
|
682
711
|
MLD_API_QUALIFIER
|
|
683
712
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
684
713
|
int MLD_API_NAMESPACE(verify_pre_hash_internal)(
|
|
@@ -691,34 +720,36 @@ int MLD_API_NAMESPACE(verify_pre_hash_internal)(
|
|
|
691
720
|
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
692
721
|
#endif
|
|
693
722
|
);
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
*
|
|
701
|
-
*
|
|
702
|
-
*
|
|
703
|
-
*
|
|
704
|
-
*
|
|
705
|
-
*
|
|
706
|
-
*
|
|
707
|
-
*
|
|
708
|
-
*
|
|
709
|
-
*
|
|
710
|
-
*
|
|
711
|
-
*
|
|
712
|
-
*
|
|
713
|
-
*
|
|
714
|
-
*
|
|
715
|
-
*
|
|
716
|
-
*
|
|
717
|
-
*
|
|
718
|
-
*
|
|
719
|
-
*
|
|
720
|
-
*
|
|
721
|
-
|
|
723
|
+
#endif /* !MLD_CONFIG_NO_VERIFY_API */
|
|
724
|
+
|
|
725
|
+
#if !defined(MLD_CONFIG_NO_SIGN_API)
|
|
726
|
+
/**
|
|
727
|
+
* FIPS 204: Algorithm 4 HashML-DSA.Sign with SHAKE256.
|
|
728
|
+
*
|
|
729
|
+
* Compute signature with pre-hashed message using SHAKE256. This function
|
|
730
|
+
* computes the SHAKE256 hash of the message internally.
|
|
731
|
+
*
|
|
732
|
+
* @param[out] sig Output signature.
|
|
733
|
+
* @param[out] siglen Pointer to output length of signature.
|
|
734
|
+
* @param[in] m Pointer to message to be hashed and signed.
|
|
735
|
+
* @param mlen Length of message.
|
|
736
|
+
* @param[in] ctx Pointer to context string.
|
|
737
|
+
* @param ctxlen Length of context string.
|
|
738
|
+
* @param[in] rnd Random seed.
|
|
739
|
+
* @param[in] sk Bit-packed secret key.
|
|
740
|
+
* @param context Application context. Only present when
|
|
741
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
742
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
743
|
+
*
|
|
744
|
+
* @retval 0 Success.
|
|
745
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was
|
|
746
|
+
* used and an allocation via
|
|
747
|
+
* MLD_CUSTOM_ALLOC returned NULL.
|
|
748
|
+
* @retval MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED The rejection-sampling loop exceeded
|
|
749
|
+
* MLD_CONFIG_MAX_SIGNING_ATTEMPTS
|
|
750
|
+
* iterations.
|
|
751
|
+
* @retval MLD_ERR_FAIL Other kinds of failure.
|
|
752
|
+
*/
|
|
722
753
|
MLD_API_QUALIFIER
|
|
723
754
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
724
755
|
int MLD_API_NAMESPACE(signature_pre_hash_shake256)(
|
|
@@ -731,31 +762,31 @@ int MLD_API_NAMESPACE(signature_pre_hash_shake256)(
|
|
|
731
762
|
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
732
763
|
#endif
|
|
733
764
|
);
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
*
|
|
739
|
-
*
|
|
740
|
-
*
|
|
741
|
-
*internally.
|
|
742
|
-
*
|
|
743
|
-
*
|
|
744
|
-
*
|
|
745
|
-
*
|
|
746
|
-
*
|
|
747
|
-
*
|
|
748
|
-
*
|
|
749
|
-
*
|
|
750
|
-
*
|
|
751
|
-
*
|
|
752
|
-
*
|
|
753
|
-
*
|
|
754
|
-
*
|
|
755
|
-
*
|
|
756
|
-
*
|
|
757
|
-
*
|
|
758
|
-
|
|
765
|
+
#endif /* !MLD_CONFIG_NO_SIGN_API */
|
|
766
|
+
|
|
767
|
+
#if !defined(MLD_CONFIG_NO_VERIFY_API)
|
|
768
|
+
/**
|
|
769
|
+
* FIPS 204: Algorithm 5 HashML-DSA.Verify with SHAKE256.
|
|
770
|
+
*
|
|
771
|
+
* Verify signature with pre-hashed message using SHAKE256. This function
|
|
772
|
+
* computes the SHAKE256 hash of the message internally.
|
|
773
|
+
*
|
|
774
|
+
* @param[in] sig Pointer to input signature.
|
|
775
|
+
* @param siglen Length of signature.
|
|
776
|
+
* @param[in] m Pointer to message to be hashed and verified.
|
|
777
|
+
* @param mlen Length of message.
|
|
778
|
+
* @param[in] ctx Pointer to context string.
|
|
779
|
+
* @param ctxlen Length of context string.
|
|
780
|
+
* @param[in] pk Bit-packed public key.
|
|
781
|
+
* @param context Application context. Only present when
|
|
782
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
783
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
784
|
+
*
|
|
785
|
+
* @retval 0 Success.
|
|
786
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was used and an
|
|
787
|
+
* allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
788
|
+
* @retval MLD_ERR_FAIL Signature verification failed.
|
|
789
|
+
*/
|
|
759
790
|
MLD_API_QUALIFIER
|
|
760
791
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
761
792
|
int MLD_API_NAMESPACE(verify_pre_hash_shake256)(
|
|
@@ -767,79 +798,76 @@ int MLD_API_NAMESPACE(verify_pre_hash_shake256)(
|
|
|
767
798
|
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
768
799
|
#endif
|
|
769
800
|
);
|
|
801
|
+
#endif /* !MLD_CONFIG_NO_VERIFY_API */
|
|
802
|
+
#endif /* !MLD_CONFIG_CORE_API_ONLY */
|
|
770
803
|
|
|
771
804
|
/* Maximum formatted domain separation message length */
|
|
772
805
|
#define MLD_DOMAIN_SEPARATION_MAX_BYTES (2 + 255 + 11 + 64)
|
|
773
806
|
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
*
|
|
777
|
-
*
|
|
778
|
-
*
|
|
779
|
-
*
|
|
780
|
-
*
|
|
781
|
-
*
|
|
782
|
-
*
|
|
783
|
-
* Arguments: - uint8_t prefix[MLD_DOMAIN_SEPARATION_MAX_BYTES]:
|
|
784
|
-
* output domain separation prefix buffer
|
|
785
|
-
* - const uint8_t *ph: pointer to pre-hashed message
|
|
786
|
-
* (ignored for pure ML-DSA)
|
|
787
|
-
* - size_t phlen: length of pre-hashed message
|
|
788
|
-
* (ignored for pure ML-DSA)
|
|
789
|
-
* - const uint8_t *ctx: pointer to context string (may be NULL)
|
|
790
|
-
* - size_t ctxlen: length of context string
|
|
791
|
-
* - int hashalg: hash algorithm constant
|
|
792
|
-
* (MLD_PREHASH_NONE for pure ML-DSA, or MLD_PREHASH_* for
|
|
793
|
-
* HashML-DSA)
|
|
794
|
-
*
|
|
795
|
-
* Returns the total length of the formatted prefix, or 0 on error.
|
|
807
|
+
#if !defined(MLD_CONFIG_CORE_API_ONLY)
|
|
808
|
+
/**
|
|
809
|
+
* Prepare domain separation prefix for ML-DSA signing.
|
|
810
|
+
*
|
|
811
|
+
* For pure ML-DSA (hashalg == MLD_PREHASH_NONE):
|
|
812
|
+
* Format: 0x00 || ctxlen (1 byte) || ctx.
|
|
813
|
+
*
|
|
814
|
+
* For HashML-DSA (hashalg != MLD_PREHASH_NONE):
|
|
815
|
+
* Format: 0x01 || ctxlen (1 byte) || ctx || oid (11 bytes) || ph.
|
|
796
816
|
*
|
|
797
817
|
* This function is useful for building incremental signing APIs.
|
|
798
818
|
*
|
|
799
|
-
*
|
|
800
|
-
*
|
|
801
|
-
*
|
|
802
|
-
*
|
|
803
|
-
*
|
|
804
|
-
*
|
|
805
|
-
*
|
|
806
|
-
*
|
|
807
|
-
*
|
|
808
|
-
*
|
|
809
|
-
*
|
|
810
|
-
*
|
|
811
|
-
|
|
819
|
+
* @spec{For HashML-DSA (hashalg != MLD_PREHASH_NONE), implements
|
|
820
|
+
* @[FIPS204, Algorithm 4, L23]. For Pure ML-DSA (hashalg == MLD_PREHASH_NONE),
|
|
821
|
+
* implements
|
|
822
|
+
* ```
|
|
823
|
+
* M' <- BytesToBits(IntegerToBytes(0, 1)
|
|
824
|
+
* || IntegerToBytes(|ctx|, 1)
|
|
825
|
+
* || ctx
|
|
826
|
+
* ```
|
|
827
|
+
* which is part of @[FIPS204, Algorithm 2 (ML-DSA.Sign), L10] and
|
|
828
|
+
* @[FIPS204, Algorithm 3 (ML-DSA.Verify), L5].}
|
|
829
|
+
*
|
|
830
|
+
* @param[out] prefix Output domain separation prefix buffer.
|
|
831
|
+
* @param[in] ph Pointer to pre-hashed message (ignored for pure
|
|
832
|
+
* ML-DSA).
|
|
833
|
+
* @param phlen Length of pre-hashed message (ignored for pure ML-DSA).
|
|
834
|
+
* @param[in] ctx Pointer to context string (may be NULL).
|
|
835
|
+
* @param ctxlen Length of context string.
|
|
836
|
+
* @param hashalg Hash algorithm constant (MLD_PREHASH_NONE for pure
|
|
837
|
+
* ML-DSA, or MLD_PREHASH_* for HashML-DSA).
|
|
838
|
+
*
|
|
839
|
+
* @return The total length of the formatted prefix, or 0 on error.
|
|
840
|
+
*/
|
|
812
841
|
MLD_API_QUALIFIER
|
|
813
842
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
814
843
|
size_t MLD_API_NAMESPACE(prepare_domain_separation_prefix)(
|
|
815
844
|
uint8_t prefix[MLD_DOMAIN_SEPARATION_MAX_BYTES], const uint8_t *ph,
|
|
816
845
|
size_t phlen, const uint8_t *ctx, size_t ctxlen, int hashalg);
|
|
817
846
|
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
*
|
|
821
|
-
*
|
|
822
|
-
*
|
|
823
|
-
*
|
|
824
|
-
*
|
|
825
|
-
*
|
|
826
|
-
*
|
|
827
|
-
*
|
|
828
|
-
*
|
|
829
|
-
*
|
|
830
|
-
*
|
|
831
|
-
*
|
|
832
|
-
*
|
|
833
|
-
*
|
|
834
|
-
*
|
|
835
|
-
*
|
|
836
|
-
*
|
|
837
|
-
*
|
|
838
|
-
*
|
|
839
|
-
*
|
|
840
|
-
*
|
|
841
|
-
|
|
842
|
-
**************************************************/
|
|
847
|
+
#if !defined(MLD_CONFIG_NO_KEYPAIR_API)
|
|
848
|
+
/**
|
|
849
|
+
* Perform basic validity checks on secret key, and derive public key.
|
|
850
|
+
*
|
|
851
|
+
* 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
|
|
853
|
+
* performed:
|
|
854
|
+
* - Check that s1 and s2 have coefficients in [-MLDSA_ETA, MLDSA_ETA].
|
|
855
|
+
* - Check that t0 and tr stored in sk match recomputed values.
|
|
856
|
+
*
|
|
857
|
+
* @note This function leaks whether the secret key is valid or invalid
|
|
858
|
+
* through its return value and timing.
|
|
859
|
+
*
|
|
860
|
+
* @param[out] pk Output public key.
|
|
861
|
+
* @param[in] sk Input secret key.
|
|
862
|
+
* @param context Application context. Only present when
|
|
863
|
+
* MLD_CONFIG_CONTEXT_PARAMETER is defined; type set by
|
|
864
|
+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
|
|
865
|
+
*
|
|
866
|
+
* @retval 0 Success.
|
|
867
|
+
* @retval MLD_ERR_OUT_OF_MEMORY MLD_CONFIG_CUSTOM_ALLOC_FREE was used and an
|
|
868
|
+
* allocation via MLD_CUSTOM_ALLOC returned NULL.
|
|
869
|
+
* @retval MLD_ERR_FAIL Secret key validation failed.
|
|
870
|
+
*/
|
|
843
871
|
MLD_API_QUALIFIER
|
|
844
872
|
MLD_API_MUST_CHECK_RETURN_VALUE
|
|
845
873
|
int MLD_API_NAMESPACE(pk_from_sk)(
|
|
@@ -850,6 +878,8 @@ int MLD_API_NAMESPACE(pk_from_sk)(
|
|
|
850
878
|
MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
|
|
851
879
|
#endif
|
|
852
880
|
);
|
|
881
|
+
#endif /* !MLD_CONFIG_NO_KEYPAIR_API */
|
|
882
|
+
#endif /* !MLD_CONFIG_CORE_API_ONLY */
|
|
853
883
|
|
|
854
884
|
#ifdef __cplusplus
|
|
855
885
|
}
|
|
@@ -912,31 +942,37 @@ int MLD_API_NAMESPACE(pk_from_sk)(
|
|
|
912
942
|
*/
|
|
913
943
|
/* check-magic: off */
|
|
914
944
|
#if defined(MLD_API_LEGACY_CONFIG) || !defined(MLD_CONFIG_REDUCE_RAM)
|
|
915
|
-
#define MLD_TOTAL_ALLOC_44_KEYPAIR_NO_PCT
|
|
916
|
-
#define MLD_TOTAL_ALLOC_44_KEYPAIR_PCT
|
|
917
|
-
#define
|
|
918
|
-
#define
|
|
919
|
-
#define
|
|
920
|
-
#define
|
|
921
|
-
#define
|
|
922
|
-
#define
|
|
923
|
-
#define
|
|
924
|
-
#define
|
|
925
|
-
#define
|
|
926
|
-
#define
|
|
945
|
+
#define MLD_TOTAL_ALLOC_44_KEYPAIR_NO_PCT 26912
|
|
946
|
+
#define MLD_TOTAL_ALLOC_44_KEYPAIR_PCT 48480
|
|
947
|
+
#define MLD_TOTAL_ALLOC_44_PK_FROM_SK 28480
|
|
948
|
+
#define MLD_TOTAL_ALLOC_44_SIGN 44704
|
|
949
|
+
#define MLD_TOTAL_ALLOC_44_VERIFY 24448
|
|
950
|
+
#define MLD_TOTAL_ALLOC_65_KEYPAIR_NO_PCT 44320
|
|
951
|
+
#define MLD_TOTAL_ALLOC_65_KEYPAIR_PCT 74624
|
|
952
|
+
#define MLD_TOTAL_ALLOC_65_PK_FROM_SK 46720
|
|
953
|
+
#define MLD_TOTAL_ALLOC_65_SIGN 69312
|
|
954
|
+
#define MLD_TOTAL_ALLOC_65_VERIFY 39872
|
|
955
|
+
#define MLD_TOTAL_ALLOC_87_KEYPAIR_NO_PCT 75040
|
|
956
|
+
#define MLD_TOTAL_ALLOC_87_KEYPAIR_PCT 115488
|
|
957
|
+
#define MLD_TOTAL_ALLOC_87_PK_FROM_SK 78272
|
|
958
|
+
#define MLD_TOTAL_ALLOC_87_SIGN 108224
|
|
959
|
+
#define MLD_TOTAL_ALLOC_87_VERIFY 68800
|
|
927
960
|
#else /* MLD_API_LEGACY_CONFIG || !MLD_CONFIG_REDUCE_RAM */
|
|
928
|
-
#define MLD_TOTAL_ALLOC_44_KEYPAIR_NO_PCT
|
|
929
|
-
#define MLD_TOTAL_ALLOC_44_KEYPAIR_PCT
|
|
930
|
-
#define
|
|
931
|
-
#define
|
|
932
|
-
#define
|
|
933
|
-
#define
|
|
934
|
-
#define
|
|
935
|
-
#define
|
|
936
|
-
#define
|
|
937
|
-
#define
|
|
938
|
-
#define
|
|
939
|
-
#define
|
|
961
|
+
#define MLD_TOTAL_ALLOC_44_KEYPAIR_NO_PCT 11584
|
|
962
|
+
#define MLD_TOTAL_ALLOC_44_KEYPAIR_PCT 16896
|
|
963
|
+
#define MLD_TOTAL_ALLOC_44_PK_FROM_SK 13152
|
|
964
|
+
#define MLD_TOTAL_ALLOC_44_SIGN 13120
|
|
965
|
+
#define MLD_TOTAL_ALLOC_44_VERIFY 9120
|
|
966
|
+
#define MLD_TOTAL_ALLOC_65_KEYPAIR_NO_PCT 14656
|
|
967
|
+
#define MLD_TOTAL_ALLOC_65_KEYPAIR_PCT 22560
|
|
968
|
+
#define MLD_TOTAL_ALLOC_65_PK_FROM_SK 17056
|
|
969
|
+
#define MLD_TOTAL_ALLOC_65_SIGN 17248
|
|
970
|
+
#define MLD_TOTAL_ALLOC_65_VERIFY 10208
|
|
971
|
+
#define MLD_TOTAL_ALLOC_87_KEYPAIR_NO_PCT 18752
|
|
972
|
+
#define MLD_TOTAL_ALLOC_87_KEYPAIR_PCT 28608
|
|
973
|
+
#define MLD_TOTAL_ALLOC_87_PK_FROM_SK 21984
|
|
974
|
+
#define MLD_TOTAL_ALLOC_87_SIGN 21344
|
|
975
|
+
#define MLD_TOTAL_ALLOC_87_VERIFY 12512
|
|
940
976
|
#endif /* !(MLD_API_LEGACY_CONFIG || !MLD_CONFIG_REDUCE_RAM) */
|
|
941
977
|
/* check-magic: on */
|
|
942
978
|
|
|
@@ -957,19 +993,20 @@ int MLD_API_NAMESPACE(pk_from_sk)(
|
|
|
957
993
|
|
|
958
994
|
#define MLD_MAX3_(a, b, c) \
|
|
959
995
|
((a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c)))
|
|
996
|
+
#define MLD_MAX4_(a, b, c, d) MLD_MAX3_((a), (b), MLD_MAX3_((c), (d), (d)))
|
|
960
997
|
|
|
961
998
|
/*
|
|
962
|
-
* `MLD_TOTAL_ALLOC_{44,65,87}` is the maximum across
|
|
963
|
-
* parameter set.
|
|
999
|
+
* `MLD_TOTAL_ALLOC_{44,65,87}` is the maximum across standard API operations
|
|
1000
|
+
* (keygen, sign, verify) for each parameter set.
|
|
964
1001
|
*/
|
|
965
|
-
#define MLD_TOTAL_ALLOC_44
|
|
966
|
-
|
|
967
|
-
MLD_TOTAL_ALLOC_44_VERIFY)
|
|
968
|
-
#define MLD_TOTAL_ALLOC_65
|
|
969
|
-
|
|
970
|
-
MLD_TOTAL_ALLOC_65_VERIFY)
|
|
971
|
-
#define MLD_TOTAL_ALLOC_87
|
|
972
|
-
|
|
973
|
-
MLD_TOTAL_ALLOC_87_VERIFY)
|
|
1002
|
+
#define MLD_TOTAL_ALLOC_44 \
|
|
1003
|
+
MLD_MAX4_(MLD_TOTAL_ALLOC_44_KEYPAIR, MLD_TOTAL_ALLOC_44_PK_FROM_SK, \
|
|
1004
|
+
MLD_TOTAL_ALLOC_44_SIGN, MLD_TOTAL_ALLOC_44_VERIFY)
|
|
1005
|
+
#define MLD_TOTAL_ALLOC_65 \
|
|
1006
|
+
MLD_MAX4_(MLD_TOTAL_ALLOC_65_KEYPAIR, MLD_TOTAL_ALLOC_65_PK_FROM_SK, \
|
|
1007
|
+
MLD_TOTAL_ALLOC_65_SIGN, MLD_TOTAL_ALLOC_65_VERIFY)
|
|
1008
|
+
#define MLD_TOTAL_ALLOC_87 \
|
|
1009
|
+
MLD_MAX4_(MLD_TOTAL_ALLOC_87_KEYPAIR, MLD_TOTAL_ALLOC_87_PK_FROM_SK, \
|
|
1010
|
+
MLD_TOTAL_ALLOC_87_SIGN, MLD_TOTAL_ALLOC_87_VERIFY)
|
|
974
1011
|
|
|
975
1012
|
#endif /* !MLD_H */
|