/src/openssl/providers/implementations/signature/ml_dsa_sig.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2024-2026 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
5 | | * this file except in compliance with the License. You can obtain a copy |
6 | | * in the file LICENSE in the source distribution or at |
7 | | * https://www.openssl.org/source/license.html |
8 | | */ |
9 | | |
10 | | #include "internal/deprecated.h" |
11 | | |
12 | | #include <assert.h> |
13 | | #include <string.h> /* memset */ |
14 | | #include <openssl/core_names.h> |
15 | | #include <openssl/err.h> |
16 | | #include <openssl/rand.h> |
17 | | #include <openssl/proverr.h> |
18 | | #include "prov/implementations.h" |
19 | | #include "prov/providercommon.h" |
20 | | #include "prov/provider_ctx.h" |
21 | | #include "prov/der_ml_dsa.h" |
22 | | #include "crypto/ml_dsa.h" |
23 | | #include "internal/common.h" |
24 | | #include "internal/packet.h" |
25 | | #include "internal/sizes.h" |
26 | | #include "internal/fips.h" |
27 | | |
28 | | #define ml_dsa_set_ctx_params_st ml_dsa_verifymsg_set_ctx_params_st |
29 | | #define ml_dsa_set_ctx_params_decoder ml_dsa_verifymsg_set_ctx_params_decoder |
30 | | |
31 | | #include "providers/implementations/signature/ml_dsa_sig.inc" |
32 | | |
33 | | #define ML_DSA_MESSAGE_ENCODE_RAW 0 |
34 | 0 | #define ML_DSA_MESSAGE_ENCODE_PURE 1 |
35 | | |
36 | | static OSSL_FUNC_signature_sign_message_init_fn ml_dsa_sign_msg_init; |
37 | | static OSSL_FUNC_signature_sign_message_update_fn ml_dsa_signverify_msg_update; |
38 | | static OSSL_FUNC_signature_sign_message_final_fn ml_dsa_sign_msg_final; |
39 | | static OSSL_FUNC_signature_sign_fn ml_dsa_sign; |
40 | | static OSSL_FUNC_signature_verify_message_init_fn ml_dsa_verify_msg_init; |
41 | | static OSSL_FUNC_signature_verify_message_update_fn ml_dsa_signverify_msg_update; |
42 | | static OSSL_FUNC_signature_verify_message_final_fn ml_dsa_verify_msg_final; |
43 | | static OSSL_FUNC_signature_verify_fn ml_dsa_verify; |
44 | | static OSSL_FUNC_signature_digest_sign_init_fn ml_dsa_digest_signverify_init; |
45 | | static OSSL_FUNC_signature_digest_sign_fn ml_dsa_digest_sign; |
46 | | static OSSL_FUNC_signature_digest_verify_fn ml_dsa_digest_verify; |
47 | | static OSSL_FUNC_signature_freectx_fn ml_dsa_freectx; |
48 | | static OSSL_FUNC_signature_set_ctx_params_fn ml_dsa_set_ctx_params; |
49 | | static OSSL_FUNC_signature_settable_ctx_params_fn ml_dsa_settable_ctx_params; |
50 | | static OSSL_FUNC_signature_get_ctx_params_fn ml_dsa_get_ctx_params; |
51 | | static OSSL_FUNC_signature_gettable_ctx_params_fn ml_dsa_gettable_ctx_params; |
52 | | static OSSL_FUNC_signature_dupctx_fn ml_dsa_dupctx; |
53 | | |
54 | | typedef struct { |
55 | | ML_DSA_KEY *key; |
56 | | OSSL_LIB_CTX *libctx; |
57 | | uint8_t context_string[ML_DSA_MAX_CONTEXT_STRING_LEN]; |
58 | | size_t context_string_len; |
59 | | uint8_t test_entropy[ML_DSA_ENTROPY_LEN]; |
60 | | size_t test_entropy_len; |
61 | | int msg_encode; |
62 | | int deterministic; |
63 | | int evp_type; |
64 | | /* The Algorithm Identifier of the signature algorithm */ |
65 | | uint8_t aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE]; |
66 | | size_t aid_len; |
67 | | int mu; /* Flag indicating we should begin from \mu, not the message */ |
68 | | |
69 | | int operation; |
70 | | EVP_MD_CTX *md_ctx; /* Ctx for msg_init/update/final interface */ |
71 | | unsigned char *sig; /* Signature, for verification */ |
72 | | size_t siglen; |
73 | | } PROV_ML_DSA_CTX; |
74 | | |
75 | | static void ml_dsa_freectx(void *vctx) |
76 | 0 | { |
77 | 0 | PROV_ML_DSA_CTX *ctx = (PROV_ML_DSA_CTX *)vctx; |
78 | |
|
79 | 0 | EVP_MD_CTX_free(ctx->md_ctx); |
80 | 0 | OPENSSL_cleanse(ctx->test_entropy, ctx->test_entropy_len); |
81 | 0 | OPENSSL_free(ctx->sig); |
82 | 0 | OPENSSL_free(ctx); |
83 | 0 | } |
84 | | |
85 | | static void *ml_dsa_newctx(void *provctx, int evp_type, const char *propq) |
86 | 0 | { |
87 | 0 | PROV_ML_DSA_CTX *ctx; |
88 | |
|
89 | 0 | if (!ossl_prov_is_running()) |
90 | 0 | return NULL; |
91 | | |
92 | | #ifdef FIPS_MODULE |
93 | | if (!ossl_deferred_self_test(PROV_LIBCTX_OF(provctx), |
94 | | ST_ID_SIG_ML_DSA_65)) |
95 | | return NULL; |
96 | | #endif |
97 | | |
98 | 0 | ctx = OPENSSL_zalloc(sizeof(PROV_ML_DSA_CTX)); |
99 | 0 | if (ctx == NULL) |
100 | 0 | return NULL; |
101 | | |
102 | 0 | ctx->libctx = PROV_LIBCTX_OF(provctx); |
103 | 0 | ctx->msg_encode = ML_DSA_MESSAGE_ENCODE_PURE; |
104 | 0 | ctx->evp_type = evp_type; |
105 | 0 | return ctx; |
106 | 0 | } |
107 | | |
108 | | static void *ml_dsa_dupctx(void *vctx) |
109 | 0 | { |
110 | 0 | PROV_ML_DSA_CTX *srcctx = (PROV_ML_DSA_CTX *)vctx; |
111 | 0 | PROV_ML_DSA_CTX *dstctx; |
112 | |
|
113 | 0 | if (!ossl_prov_is_running()) |
114 | 0 | return NULL; |
115 | | |
116 | | /* |
117 | | * Note that the ML_DSA_KEY is ref counted via EVP_PKEY so we can just copy |
118 | | * the key here. |
119 | | */ |
120 | 0 | dstctx = OPENSSL_memdup(srcctx, sizeof(*srcctx)); |
121 | |
|
122 | 0 | if (dstctx == NULL) |
123 | 0 | return NULL; |
124 | | |
125 | 0 | if (srcctx->sig != NULL) { |
126 | 0 | dstctx->sig = OPENSSL_memdup(srcctx->sig, srcctx->siglen); |
127 | 0 | if (dstctx->sig == NULL) { |
128 | | /* |
129 | | * Can't call ml_dsa_freectx() here, as it would free |
130 | | * md_ctx which has not been duplicated yet. |
131 | | */ |
132 | 0 | OPENSSL_free(dstctx); |
133 | 0 | return NULL; |
134 | 0 | } |
135 | 0 | } |
136 | | |
137 | 0 | if (srcctx->md_ctx != NULL) { |
138 | 0 | dstctx->md_ctx = EVP_MD_CTX_dup(srcctx->md_ctx); |
139 | 0 | if (dstctx->md_ctx == NULL) { |
140 | 0 | ml_dsa_freectx(dstctx); |
141 | 0 | return NULL; |
142 | 0 | } |
143 | 0 | } |
144 | | |
145 | 0 | return dstctx; |
146 | 0 | } |
147 | | |
148 | | static int set_alg_id_buffer(PROV_ML_DSA_CTX *ctx) |
149 | 0 | { |
150 | 0 | int ret; |
151 | 0 | WPACKET pkt; |
152 | 0 | uint8_t *aid = NULL; |
153 | | |
154 | | /* |
155 | | * We do not care about DER writing errors. |
156 | | * All it really means is that for some reason, there's no |
157 | | * AlgorithmIdentifier to be had, but the operation itself is |
158 | | * still valid, just as long as it's not used to construct |
159 | | * anything that needs an AlgorithmIdentifier. |
160 | | */ |
161 | 0 | ctx->aid_len = 0; |
162 | 0 | ret = WPACKET_init_der(&pkt, ctx->aid_buf, sizeof(ctx->aid_buf)); |
163 | 0 | ret = ret && ossl_DER_w_algorithmIdentifier_ML_DSA(&pkt, -1, ctx->key); |
164 | 0 | if (ret && WPACKET_finish(&pkt)) { |
165 | 0 | WPACKET_get_total_written(&pkt, &ctx->aid_len); |
166 | 0 | aid = WPACKET_get_curr(&pkt); |
167 | 0 | } |
168 | 0 | WPACKET_cleanup(&pkt); |
169 | 0 | if (aid != NULL && ctx->aid_len != 0) |
170 | 0 | memmove(ctx->aid_buf, aid, ctx->aid_len); |
171 | 0 | return 1; |
172 | 0 | } |
173 | | |
174 | | static int ml_dsa_signverify_msg_init(void *vctx, void *vkey, |
175 | | const OSSL_PARAM params[], int operation, |
176 | | const char *desc) |
177 | 0 | { |
178 | 0 | PROV_ML_DSA_CTX *ctx = (PROV_ML_DSA_CTX *)vctx; |
179 | 0 | ML_DSA_KEY *key = vkey; |
180 | |
|
181 | 0 | if (!ossl_prov_is_running() |
182 | 0 | || ctx == NULL) |
183 | 0 | return 0; |
184 | | |
185 | 0 | if (vkey == NULL && ctx->key == NULL) { |
186 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET); |
187 | 0 | return 0; |
188 | 0 | } |
189 | | |
190 | 0 | if (key != NULL) |
191 | 0 | ctx->key = vkey; |
192 | 0 | if (!ossl_ml_dsa_key_matches(ctx->key, ctx->evp_type)) |
193 | 0 | return 0; |
194 | | |
195 | 0 | set_alg_id_buffer(ctx); |
196 | 0 | ctx->mu = 0; |
197 | 0 | ctx->operation = operation; |
198 | |
|
199 | 0 | return ml_dsa_set_ctx_params(ctx, params); |
200 | 0 | } |
201 | | |
202 | | static int ml_dsa_sign_msg_init(void *vctx, void *vkey, const OSSL_PARAM params[]) |
203 | 0 | { |
204 | 0 | return ml_dsa_signverify_msg_init(vctx, vkey, params, |
205 | 0 | EVP_PKEY_OP_SIGNMSG, "ML_DSA Sign Init"); |
206 | 0 | } |
207 | | |
208 | | static int ml_dsa_digest_signverify_init(void *vctx, const char *mdname, |
209 | | void *vkey, const OSSL_PARAM params[]) |
210 | 0 | { |
211 | 0 | PROV_ML_DSA_CTX *ctx = (PROV_ML_DSA_CTX *)vctx; |
212 | |
|
213 | 0 | if (mdname != NULL && mdname[0] != '\0') { |
214 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST, |
215 | 0 | "Explicit digest not supported for ML-DSA operations"); |
216 | 0 | return 0; |
217 | 0 | } |
218 | | |
219 | 0 | ctx->mu = 0; |
220 | |
|
221 | 0 | if (vkey == NULL && ctx->key != NULL) |
222 | 0 | return ml_dsa_set_ctx_params(ctx, params); |
223 | | |
224 | 0 | return ml_dsa_signverify_msg_init(vctx, vkey, params, |
225 | 0 | EVP_PKEY_OP_SIGN, "ML_DSA Sign Init"); |
226 | 0 | } |
227 | | |
228 | | static int ml_dsa_signverify_msg_update(void *vctx, |
229 | | const unsigned char *data, |
230 | | size_t datalen) |
231 | 0 | { |
232 | 0 | PROV_ML_DSA_CTX *ctx = (PROV_ML_DSA_CTX *)vctx; |
233 | |
|
234 | 0 | if (ctx == NULL) |
235 | 0 | return 0; |
236 | | |
237 | 0 | if (!ossl_prov_is_running()) |
238 | 0 | return 0; |
239 | | |
240 | 0 | if (ctx->mu) |
241 | 0 | return 0; |
242 | | |
243 | 0 | if (ctx->md_ctx == NULL) { |
244 | 0 | ctx->md_ctx = ossl_ml_dsa_mu_init(ctx->key, ctx->msg_encode, |
245 | 0 | ctx->context_string, |
246 | 0 | ctx->context_string_len); |
247 | 0 | if (ctx->md_ctx == NULL) |
248 | 0 | return 0; |
249 | 0 | } |
250 | | |
251 | 0 | return ossl_ml_dsa_mu_update(ctx->md_ctx, data, datalen); |
252 | 0 | } |
253 | | |
254 | | static int ml_dsa_sign_msg_final(void *vctx, unsigned char *sig, |
255 | | size_t *siglen, size_t sigsize) |
256 | 0 | { |
257 | 0 | PROV_ML_DSA_CTX *ctx = (PROV_ML_DSA_CTX *)vctx; |
258 | 0 | uint8_t rand_tmp[ML_DSA_ENTROPY_LEN], *rnd = NULL; |
259 | 0 | uint8_t mu[ML_DSA_MU_BYTES]; |
260 | 0 | int ret = 0; |
261 | |
|
262 | 0 | if (ctx == NULL) |
263 | 0 | return 0; |
264 | | |
265 | 0 | if (!ossl_prov_is_running()) |
266 | 0 | return 0; |
267 | | |
268 | 0 | if (ctx->md_ctx == NULL) |
269 | 0 | return 0; |
270 | | |
271 | 0 | if (sig != NULL) { |
272 | 0 | if (ctx->test_entropy_len != 0) { |
273 | 0 | rnd = ctx->test_entropy; |
274 | 0 | } else { |
275 | 0 | rnd = rand_tmp; |
276 | |
|
277 | 0 | if (ctx->deterministic == 1) |
278 | 0 | memset(rnd, 0, sizeof(rand_tmp)); |
279 | 0 | else if (RAND_priv_bytes_ex(ctx->libctx, rnd, sizeof(rand_tmp), 0) <= 0) |
280 | 0 | return 0; |
281 | 0 | } |
282 | | |
283 | 0 | if (!ossl_ml_dsa_mu_finalize(ctx->md_ctx, mu, sizeof(mu))) { |
284 | 0 | OPENSSL_cleanse(mu, sizeof(mu)); |
285 | 0 | return 0; |
286 | 0 | } |
287 | 0 | } |
288 | | |
289 | 0 | ret = ossl_ml_dsa_sign(ctx->key, 1, mu, sizeof(mu), NULL, 0, rnd, |
290 | 0 | sizeof(rand_tmp), 0, sig, siglen, sigsize); |
291 | 0 | if (rnd != ctx->test_entropy) |
292 | 0 | OPENSSL_cleanse(rand_tmp, sizeof(rand_tmp)); |
293 | 0 | OPENSSL_cleanse(mu, sizeof(mu)); |
294 | 0 | return ret; |
295 | 0 | } |
296 | | |
297 | | static int ml_dsa_sign(void *vctx, uint8_t *sig, size_t *siglen, size_t sigsize, |
298 | | const uint8_t *msg, size_t msg_len) |
299 | 0 | { |
300 | 0 | int ret = 0; |
301 | 0 | PROV_ML_DSA_CTX *ctx = (PROV_ML_DSA_CTX *)vctx; |
302 | 0 | uint8_t rand_tmp[ML_DSA_ENTROPY_LEN], *rnd = NULL; |
303 | |
|
304 | 0 | if (!ossl_prov_is_running()) |
305 | 0 | return 0; |
306 | | |
307 | 0 | if (sig != NULL) { |
308 | 0 | if (ctx->test_entropy_len != 0) { |
309 | 0 | rnd = ctx->test_entropy; |
310 | 0 | } else { |
311 | 0 | rnd = rand_tmp; |
312 | |
|
313 | 0 | if (ctx->deterministic == 1) |
314 | 0 | memset(rnd, 0, sizeof(rand_tmp)); |
315 | 0 | else if (RAND_priv_bytes_ex(ctx->libctx, rnd, sizeof(rand_tmp), 0) <= 0) |
316 | 0 | return 0; |
317 | 0 | } |
318 | 0 | } |
319 | 0 | ret = ossl_ml_dsa_sign(ctx->key, ctx->mu, msg, msg_len, |
320 | 0 | ctx->context_string, ctx->context_string_len, |
321 | 0 | rnd, sizeof(rand_tmp), ctx->msg_encode, |
322 | 0 | sig, siglen, sigsize); |
323 | 0 | if (rnd != ctx->test_entropy) |
324 | 0 | OPENSSL_cleanse(rand_tmp, sizeof(rand_tmp)); |
325 | 0 | return ret; |
326 | 0 | } |
327 | | |
328 | | static int ml_dsa_digest_sign(void *vctx, uint8_t *sig, size_t *siglen, size_t sigsize, |
329 | | const uint8_t *tbs, size_t tbslen) |
330 | 0 | { |
331 | 0 | return ml_dsa_sign(vctx, sig, siglen, sigsize, tbs, tbslen); |
332 | 0 | } |
333 | | |
334 | | static int ml_dsa_verify_msg_init(void *vctx, void *vkey, const OSSL_PARAM params[]) |
335 | 0 | { |
336 | 0 | return ml_dsa_signverify_msg_init(vctx, vkey, params, EVP_PKEY_OP_VERIFYMSG, |
337 | 0 | "ML_DSA Verify Init"); |
338 | 0 | } |
339 | | |
340 | | static int ml_dsa_verify_msg_final(void *vctx) |
341 | 0 | { |
342 | 0 | PROV_ML_DSA_CTX *ctx = (PROV_ML_DSA_CTX *)vctx; |
343 | 0 | uint8_t mu[ML_DSA_MU_BYTES]; |
344 | 0 | int ret = 0; |
345 | |
|
346 | 0 | if (!ossl_prov_is_running()) |
347 | 0 | return 0; |
348 | | |
349 | 0 | if (ctx->md_ctx == NULL) |
350 | 0 | return 0; |
351 | | |
352 | 0 | if (ossl_ml_dsa_mu_finalize(ctx->md_ctx, mu, sizeof(mu))) |
353 | 0 | ret = ossl_ml_dsa_verify(ctx->key, 1, mu, sizeof(mu), NULL, 0, 0, |
354 | 0 | ctx->sig, ctx->siglen); |
355 | |
|
356 | 0 | OPENSSL_cleanse(mu, sizeof(mu)); |
357 | 0 | return ret; |
358 | 0 | } |
359 | | |
360 | | static int ml_dsa_verify(void *vctx, const uint8_t *sig, size_t siglen, |
361 | | const uint8_t *msg, size_t msg_len) |
362 | 0 | { |
363 | 0 | PROV_ML_DSA_CTX *ctx = (PROV_ML_DSA_CTX *)vctx; |
364 | |
|
365 | 0 | if (!ossl_prov_is_running()) |
366 | 0 | return 0; |
367 | 0 | return ossl_ml_dsa_verify(ctx->key, ctx->mu, msg, msg_len, |
368 | 0 | ctx->context_string, ctx->context_string_len, |
369 | 0 | ctx->msg_encode, sig, siglen); |
370 | 0 | } |
371 | | static int ml_dsa_digest_verify(void *vctx, |
372 | | const uint8_t *sig, size_t siglen, |
373 | | const uint8_t *tbs, size_t tbslen) |
374 | 0 | { |
375 | 0 | return ml_dsa_verify(vctx, sig, siglen, tbs, tbslen); |
376 | 0 | } |
377 | | |
378 | | /* |
379 | | * Only need the param list for the signing case. The decoder and structure |
380 | | * are shared between the sign and verify cases. |
381 | | */ |
382 | | |
383 | | static int ml_dsa_set_ctx_params(void *vctx, const OSSL_PARAM params[]) |
384 | 0 | { |
385 | 0 | PROV_ML_DSA_CTX *pctx = (PROV_ML_DSA_CTX *)vctx; |
386 | 0 | struct ml_dsa_verifymsg_set_ctx_params_st p; |
387 | |
|
388 | 0 | if (pctx == NULL || !ml_dsa_verifymsg_set_ctx_params_decoder(params, &p)) |
389 | 0 | return 0; |
390 | | |
391 | 0 | if (p.ctx != NULL) { |
392 | 0 | void *vp = pctx->context_string; |
393 | |
|
394 | 0 | if (!OSSL_PARAM_get_octet_string(p.ctx, &vp, sizeof(pctx->context_string), |
395 | 0 | &(pctx->context_string_len))) { |
396 | 0 | pctx->context_string_len = 0; |
397 | 0 | return 0; |
398 | 0 | } |
399 | 0 | } |
400 | | |
401 | 0 | if (p.ent != NULL) { |
402 | 0 | void *vp = pctx->test_entropy; |
403 | |
|
404 | 0 | pctx->test_entropy_len = 0; |
405 | 0 | if (!OSSL_PARAM_get_octet_string(p.ent, &vp, sizeof(pctx->test_entropy), |
406 | 0 | &(pctx->test_entropy_len))) |
407 | 0 | return 0; |
408 | 0 | if (pctx->test_entropy_len != sizeof(pctx->test_entropy)) { |
409 | 0 | pctx->test_entropy_len = 0; |
410 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_SEED_LENGTH); |
411 | 0 | return 0; |
412 | 0 | } |
413 | 0 | } |
414 | | |
415 | 0 | if (p.det != NULL && !OSSL_PARAM_get_int(p.det, &pctx->deterministic)) |
416 | 0 | return 0; |
417 | | |
418 | 0 | if (p.msgenc != NULL && !OSSL_PARAM_get_int(p.msgenc, &pctx->msg_encode)) |
419 | 0 | return 0; |
420 | | |
421 | 0 | if (p.mu != NULL && !OSSL_PARAM_get_int(p.mu, &pctx->mu)) |
422 | 0 | return 0; |
423 | | |
424 | 0 | if (p.sig != NULL && pctx->operation == EVP_PKEY_OP_VERIFYMSG) { |
425 | 0 | OPENSSL_free(pctx->sig); |
426 | 0 | pctx->sig = NULL; |
427 | 0 | pctx->siglen = 0; |
428 | 0 | if (!OSSL_PARAM_get_octet_string(p.sig, (void **)&pctx->sig, |
429 | 0 | 0, &pctx->siglen)) |
430 | 0 | return 0; |
431 | 0 | } |
432 | | |
433 | 0 | return 1; |
434 | 0 | } |
435 | | |
436 | | static const OSSL_PARAM *ml_dsa_settable_ctx_params(void *vctx, |
437 | | ossl_unused void *provctx) |
438 | 0 | { |
439 | 0 | PROV_ML_DSA_CTX *pctx = (PROV_ML_DSA_CTX *)vctx; |
440 | |
|
441 | 0 | if (pctx != NULL && pctx->operation == EVP_PKEY_OP_VERIFYMSG) |
442 | 0 | return ml_dsa_verifymsg_set_ctx_params_list; |
443 | 0 | else |
444 | 0 | return ml_dsa_set_ctx_params_list; |
445 | 0 | } |
446 | | |
447 | | static const OSSL_PARAM *ml_dsa_gettable_ctx_params(ossl_unused void *vctx, |
448 | | ossl_unused void *provctx) |
449 | 0 | { |
450 | 0 | return ml_dsa_get_ctx_params_list; |
451 | 0 | } |
452 | | |
453 | | static int ml_dsa_get_ctx_params(void *vctx, OSSL_PARAM *params) |
454 | 0 | { |
455 | 0 | PROV_ML_DSA_CTX *ctx = (PROV_ML_DSA_CTX *)vctx; |
456 | 0 | struct ml_dsa_get_ctx_params_st p; |
457 | |
|
458 | 0 | if (ctx == NULL || !ml_dsa_get_ctx_params_decoder(params, &p)) |
459 | 0 | return 0; |
460 | | |
461 | 0 | if (p.id != NULL |
462 | 0 | && !OSSL_PARAM_set_octet_string(p.id, |
463 | 0 | ctx->aid_len == 0 ? NULL : ctx->aid_buf, |
464 | 0 | ctx->aid_len)) |
465 | 0 | return 0; |
466 | | |
467 | 0 | return 1; |
468 | 0 | } |
469 | | |
470 | | #define MAKE_SIGNATURE_FUNCTIONS(alg) \ |
471 | | static OSSL_FUNC_signature_newctx_fn ml_dsa_##alg##_newctx; \ |
472 | | static void *ml_dsa_##alg##_newctx(void *provctx, const char *propq) \ |
473 | 0 | { \ |
474 | 0 | return ml_dsa_newctx(provctx, EVP_PKEY_ML_DSA_##alg, propq); \ |
475 | 0 | } \ Unexecuted instantiation: ml_dsa_sig.c:ml_dsa_44_newctx Unexecuted instantiation: ml_dsa_sig.c:ml_dsa_65_newctx Unexecuted instantiation: ml_dsa_sig.c:ml_dsa_87_newctx |
476 | | const OSSL_DISPATCH ossl_ml_dsa_##alg##_signature_functions[] = { \ |
477 | | { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))ml_dsa_##alg##_newctx }, \ |
478 | | { OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_INIT, \ |
479 | | (void (*)(void))ml_dsa_sign_msg_init }, \ |
480 | | { OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_UPDATE, \ |
481 | | (void (*)(void))ml_dsa_signverify_msg_update }, \ |
482 | | { OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_FINAL, \ |
483 | | (void (*)(void))ml_dsa_sign_msg_final }, \ |
484 | | { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))ml_dsa_sign }, \ |
485 | | { OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_INIT, \ |
486 | | (void (*)(void))ml_dsa_verify_msg_init }, \ |
487 | | { OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_UPDATE, \ |
488 | | (void (*)(void))ml_dsa_signverify_msg_update }, \ |
489 | | { OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_FINAL, \ |
490 | | (void (*)(void))ml_dsa_verify_msg_final }, \ |
491 | | { OSSL_FUNC_SIGNATURE_VERIFY, (void (*)(void))ml_dsa_verify }, \ |
492 | | { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT, \ |
493 | | (void (*)(void))ml_dsa_digest_signverify_init }, \ |
494 | | { OSSL_FUNC_SIGNATURE_DIGEST_SIGN, \ |
495 | | (void (*)(void))ml_dsa_digest_sign }, \ |
496 | | { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT, \ |
497 | | (void (*)(void))ml_dsa_digest_signverify_init }, \ |
498 | | { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY, \ |
499 | | (void (*)(void))ml_dsa_digest_verify }, \ |
500 | | { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))ml_dsa_freectx }, \ |
501 | | { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, \ |
502 | | (void (*)(void))ml_dsa_set_ctx_params }, \ |
503 | | { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS, \ |
504 | | (void (*)(void))ml_dsa_settable_ctx_params }, \ |
505 | | { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, \ |
506 | | (void (*)(void))ml_dsa_get_ctx_params }, \ |
507 | | { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS, \ |
508 | | (void (*)(void))ml_dsa_gettable_ctx_params }, \ |
509 | | { OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))ml_dsa_dupctx }, \ |
510 | | OSSL_DISPATCH_END \ |
511 | | } |
512 | | |
513 | | MAKE_SIGNATURE_FUNCTIONS(44); |
514 | | MAKE_SIGNATURE_FUNCTIONS(65); |
515 | | MAKE_SIGNATURE_FUNCTIONS(87); |