]>
Commit | Line | Data |
---|---|---|
d0b79f86 | 1 | /* |
a28d06f3 | 2 | * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved. |
d0b79f86 PY |
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 | /* | |
11 | * ECDSA low level APIs are deprecated for public use, but still ok for | |
12 | * internal use - SM2 implemetation uses ECDSA_size() function. | |
13 | */ | |
14 | #include "internal/deprecated.h" | |
15 | ||
16 | #include <string.h> /* memcpy */ | |
17 | #include <openssl/crypto.h> | |
18 | #include <openssl/core_dispatch.h> | |
19 | #include <openssl/core_names.h> | |
20 | #include <openssl/dsa.h> | |
21 | #include <openssl/params.h> | |
22 | #include <openssl/evp.h> | |
23 | #include <openssl/err.h> | |
2741128e | 24 | #include <openssl/proverr.h> |
d0b79f86 PY |
25 | #include "internal/nelem.h" |
26 | #include "internal/sizes.h" | |
27 | #include "internal/cryptlib.h" | |
d0b79f86 PY |
28 | #include "prov/implementations.h" |
29 | #include "prov/provider_ctx.h" | |
30 | #include "crypto/ec.h" | |
31 | #include "crypto/sm2.h" | |
32 | #include "prov/der_sm2.h" | |
33 | ||
34 | static OSSL_FUNC_signature_newctx_fn sm2sig_newctx; | |
35 | static OSSL_FUNC_signature_sign_init_fn sm2sig_signature_init; | |
36 | static OSSL_FUNC_signature_verify_init_fn sm2sig_signature_init; | |
37 | static OSSL_FUNC_signature_sign_fn sm2sig_sign; | |
38 | static OSSL_FUNC_signature_verify_fn sm2sig_verify; | |
39 | static OSSL_FUNC_signature_digest_sign_init_fn sm2sig_digest_signverify_init; | |
40 | static OSSL_FUNC_signature_digest_sign_update_fn sm2sig_digest_signverify_update; | |
41 | static OSSL_FUNC_signature_digest_sign_final_fn sm2sig_digest_sign_final; | |
42 | static OSSL_FUNC_signature_digest_verify_init_fn sm2sig_digest_signverify_init; | |
43 | static OSSL_FUNC_signature_digest_verify_update_fn sm2sig_digest_signverify_update; | |
44 | static OSSL_FUNC_signature_digest_verify_final_fn sm2sig_digest_verify_final; | |
45 | static OSSL_FUNC_signature_freectx_fn sm2sig_freectx; | |
46 | static OSSL_FUNC_signature_dupctx_fn sm2sig_dupctx; | |
47 | static OSSL_FUNC_signature_get_ctx_params_fn sm2sig_get_ctx_params; | |
48 | static OSSL_FUNC_signature_gettable_ctx_params_fn sm2sig_gettable_ctx_params; | |
49 | static OSSL_FUNC_signature_set_ctx_params_fn sm2sig_set_ctx_params; | |
50 | static OSSL_FUNC_signature_settable_ctx_params_fn sm2sig_settable_ctx_params; | |
51 | static OSSL_FUNC_signature_get_ctx_md_params_fn sm2sig_get_ctx_md_params; | |
52 | static OSSL_FUNC_signature_gettable_ctx_md_params_fn sm2sig_gettable_ctx_md_params; | |
53 | static OSSL_FUNC_signature_set_ctx_md_params_fn sm2sig_set_ctx_md_params; | |
54 | static OSSL_FUNC_signature_settable_ctx_md_params_fn sm2sig_settable_ctx_md_params; | |
55 | ||
56 | /* | |
57 | * What's passed as an actual key is defined by the KEYMGMT interface. | |
58 | * We happen to know that our KEYMGMT simply passes EC structures, so | |
59 | * we use that here too. | |
60 | */ | |
61 | typedef struct { | |
b4250010 | 62 | OSSL_LIB_CTX *libctx; |
d0b79f86 PY |
63 | char *propq; |
64 | EC_KEY *ec; | |
65 | ||
66 | /* | |
67 | * Flag to determine if the hash function can be changed (1) or not (0) | |
68 | * Because it's dangerous to change during a DigestSign or DigestVerify | |
69 | * operation, this flag is cleared by their Init function, and set again | |
70 | * by their Final function. | |
71 | */ | |
72 | unsigned int flag_allow_md : 1; | |
73 | /* | |
74 | * Flag to termine if the 'z' digest needs to be computed and fed to the | |
75 | * hash function. | |
76 | * This flag should be set on initialization and the compuation should | |
77 | * be performed only once, on first update. | |
78 | */ | |
79 | unsigned int flag_compute_z_digest : 1; | |
80 | ||
81 | char mdname[OSSL_MAX_NAME_SIZE]; | |
82 | ||
83 | /* The Algorithm Identifier of the combined signature algorithm */ | |
84 | unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE]; | |
85 | unsigned char *aid; | |
86 | size_t aid_len; | |
87 | ||
88 | /* main digest */ | |
89 | EVP_MD *md; | |
90 | EVP_MD_CTX *mdctx; | |
91 | size_t mdsize; | |
92 | ||
93 | /* SM2 ID used for calculating the Z value */ | |
94 | unsigned char *id; | |
95 | size_t id_len; | |
96 | } PROV_SM2_CTX; | |
97 | ||
d0b79f86 PY |
98 | static void *sm2sig_newctx(void *provctx, const char *propq) |
99 | { | |
100 | PROV_SM2_CTX *ctx = OPENSSL_zalloc(sizeof(PROV_SM2_CTX)); | |
101 | ||
102 | if (ctx == NULL) | |
103 | return NULL; | |
104 | ||
a829b735 | 105 | ctx->libctx = PROV_LIBCTX_OF(provctx); |
d0b79f86 PY |
106 | if (propq != NULL && (ctx->propq = OPENSSL_strdup(propq)) == NULL) { |
107 | OPENSSL_free(ctx); | |
108 | ctx = NULL; | |
109 | ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); | |
110 | } | |
111 | /* don't allow to change MD, and in fact there is no such need */ | |
112 | ctx->flag_allow_md = 0; | |
113 | return ctx; | |
114 | } | |
115 | ||
116 | static int sm2sig_signature_init(void *vpsm2ctx, void *ec) | |
117 | { | |
118 | PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx; | |
119 | ||
120 | if (psm2ctx == NULL || ec == NULL || !EC_KEY_up_ref(ec)) | |
121 | return 0; | |
122 | EC_KEY_free(psm2ctx->ec); | |
123 | psm2ctx->ec = ec; | |
124 | return 1; | |
125 | } | |
126 | ||
127 | static int sm2sig_sign(void *vpsm2ctx, unsigned char *sig, size_t *siglen, | |
128 | size_t sigsize, const unsigned char *tbs, size_t tbslen) | |
129 | { | |
130 | PROV_SM2_CTX *ctx = (PROV_SM2_CTX *)vpsm2ctx; | |
131 | int ret; | |
132 | unsigned int sltmp; | |
133 | /* SM2 uses ECDSA_size as well */ | |
134 | size_t ecsize = ECDSA_size(ctx->ec); | |
135 | ||
136 | if (sig == NULL) { | |
137 | *siglen = ecsize; | |
138 | return 1; | |
139 | } | |
140 | ||
141 | if (sigsize < (size_t)ecsize) | |
142 | return 0; | |
143 | ||
144 | if (ctx->mdsize != 0 && tbslen != ctx->mdsize) | |
145 | return 0; | |
146 | ||
32ab57cb | 147 | ret = ossl_sm2_internal_sign(tbs, tbslen, sig, &sltmp, ctx->ec); |
d0b79f86 PY |
148 | if (ret <= 0) |
149 | return 0; | |
150 | ||
151 | *siglen = sltmp; | |
152 | return 1; | |
153 | } | |
154 | ||
155 | static int sm2sig_verify(void *vpsm2ctx, const unsigned char *sig, size_t siglen, | |
156 | const unsigned char *tbs, size_t tbslen) | |
157 | { | |
158 | PROV_SM2_CTX *ctx = (PROV_SM2_CTX *)vpsm2ctx; | |
159 | ||
160 | if (ctx->mdsize != 0 && tbslen != ctx->mdsize) | |
161 | return 0; | |
162 | ||
32ab57cb | 163 | return ossl_sm2_internal_verify(tbs, tbslen, sig, siglen, ctx->ec); |
d0b79f86 PY |
164 | } |
165 | ||
166 | static void free_md(PROV_SM2_CTX *ctx) | |
167 | { | |
168 | EVP_MD_CTX_free(ctx->mdctx); | |
169 | EVP_MD_free(ctx->md); | |
170 | ctx->mdctx = NULL; | |
171 | ctx->md = NULL; | |
172 | ctx->mdsize = 0; | |
173 | } | |
174 | ||
175 | static int sm2sig_digest_signverify_init(void *vpsm2ctx, const char *mdname, | |
176 | void *ec) | |
177 | { | |
178 | PROV_SM2_CTX *ctx = (PROV_SM2_CTX *)vpsm2ctx; | |
b3d267ca | 179 | int md_nid = NID_sm3; |
d0b79f86 PY |
180 | WPACKET pkt; |
181 | int ret = 0; | |
182 | ||
183 | free_md(ctx); | |
184 | ||
185 | if (!sm2sig_signature_init(vpsm2ctx, ec)) | |
186 | return ret; | |
187 | ||
188 | ctx->md = EVP_MD_fetch(ctx->libctx, mdname, ctx->propq); | |
d0b79f86 PY |
189 | ctx->mdsize = EVP_MD_size(ctx->md); |
190 | ctx->mdctx = EVP_MD_CTX_new(); | |
191 | if (ctx->mdctx == NULL) | |
192 | goto error; | |
193 | ||
194 | /* | |
195 | * TODO(3.0) Should we care about DER writing errors? | |
196 | * All it really means is that for some reason, there's no | |
197 | * AlgorithmIdentifier to be had, but the operation itself is | |
198 | * still valid, just as long as it's not used to construct | |
199 | * anything that needs an AlgorithmIdentifier. | |
200 | */ | |
201 | ctx->aid_len = 0; | |
202 | if (WPACKET_init_der(&pkt, ctx->aid_buf, sizeof(ctx->aid_buf)) | |
203 | && DER_w_algorithmIdentifier_SM2_with_MD(&pkt, -1, ctx->ec, md_nid) | |
204 | && WPACKET_finish(&pkt)) { | |
205 | WPACKET_get_total_written(&pkt, &ctx->aid_len); | |
206 | ctx->aid = WPACKET_get_curr(&pkt); | |
207 | } | |
208 | WPACKET_cleanup(&pkt); | |
209 | ||
210 | if (!EVP_DigestInit_ex(ctx->mdctx, ctx->md, NULL)) | |
211 | goto error; | |
212 | ||
213 | ctx->flag_compute_z_digest = 1; | |
214 | ||
215 | ret = 1; | |
216 | ||
217 | error: | |
218 | if (!ret) | |
219 | free_md(ctx); | |
220 | return ret; | |
221 | } | |
222 | ||
223 | static int sm2sig_compute_z_digest(PROV_SM2_CTX *ctx) | |
224 | { | |
225 | uint8_t *z = NULL; | |
226 | int ret = 1; | |
227 | ||
228 | if (ctx->flag_compute_z_digest) { | |
229 | /* Only do this once */ | |
230 | ctx->flag_compute_z_digest = 0; | |
231 | ||
232 | if ((z = OPENSSL_zalloc(ctx->mdsize)) == NULL | |
233 | /* get hashed prefix 'z' of tbs message */ | |
32ab57cb SL |
234 | || !ossl_sm2_compute_z_digest(z, ctx->md, ctx->id, ctx->id_len, |
235 | ctx->ec) | |
d0b79f86 PY |
236 | || !EVP_DigestUpdate(ctx->mdctx, z, ctx->mdsize)) |
237 | ret = 0; | |
238 | OPENSSL_free(z); | |
239 | } | |
240 | ||
241 | return ret; | |
242 | } | |
243 | ||
244 | int sm2sig_digest_signverify_update(void *vpsm2ctx, const unsigned char *data, | |
245 | size_t datalen) | |
246 | { | |
247 | PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx; | |
248 | ||
249 | if (psm2ctx == NULL || psm2ctx->mdctx == NULL) | |
250 | return 0; | |
251 | ||
252 | return sm2sig_compute_z_digest(psm2ctx) | |
253 | && EVP_DigestUpdate(psm2ctx->mdctx, data, datalen); | |
254 | } | |
255 | ||
256 | int sm2sig_digest_sign_final(void *vpsm2ctx, unsigned char *sig, size_t *siglen, | |
257 | size_t sigsize) | |
258 | { | |
259 | PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx; | |
260 | unsigned char digest[EVP_MAX_MD_SIZE]; | |
261 | unsigned int dlen = 0; | |
262 | ||
263 | if (psm2ctx == NULL || psm2ctx->mdctx == NULL) | |
264 | return 0; | |
265 | ||
266 | /* | |
267 | * If sig is NULL then we're just finding out the sig size. Other fields | |
268 | * are ignored. Defer to sm2sig_sign. | |
269 | */ | |
270 | if (sig != NULL) { | |
271 | if (!(sm2sig_compute_z_digest(psm2ctx) | |
272 | && EVP_DigestFinal_ex(psm2ctx->mdctx, digest, &dlen))) | |
273 | return 0; | |
274 | } | |
275 | ||
276 | return sm2sig_sign(vpsm2ctx, sig, siglen, sigsize, digest, (size_t)dlen); | |
277 | } | |
278 | ||
279 | ||
280 | int sm2sig_digest_verify_final(void *vpsm2ctx, const unsigned char *sig, | |
281 | size_t siglen) | |
282 | { | |
283 | PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx; | |
284 | unsigned char digest[EVP_MAX_MD_SIZE]; | |
285 | unsigned int dlen = 0; | |
286 | ||
287 | if (psm2ctx == NULL || psm2ctx->mdctx == NULL) | |
288 | return 0; | |
289 | ||
290 | /* SM2 always use SM3 so it's not possible to exceed the limit */ | |
291 | if (!(sm2sig_compute_z_digest(psm2ctx) | |
292 | && EVP_DigestFinal_ex(psm2ctx->mdctx, digest, &dlen))) | |
293 | return 0; | |
294 | ||
295 | return sm2sig_verify(vpsm2ctx, sig, siglen, digest, (size_t)dlen); | |
296 | } | |
297 | ||
298 | static void sm2sig_freectx(void *vpsm2ctx) | |
299 | { | |
300 | PROV_SM2_CTX *ctx = (PROV_SM2_CTX *)vpsm2ctx; | |
301 | ||
302 | free_md(ctx); | |
303 | EC_KEY_free(ctx->ec); | |
304 | OPENSSL_free(ctx->id); | |
305 | OPENSSL_free(ctx); | |
306 | } | |
307 | ||
308 | static void *sm2sig_dupctx(void *vpsm2ctx) | |
309 | { | |
310 | PROV_SM2_CTX *srcctx = (PROV_SM2_CTX *)vpsm2ctx; | |
311 | PROV_SM2_CTX *dstctx; | |
312 | ||
313 | dstctx = OPENSSL_zalloc(sizeof(*srcctx)); | |
314 | if (dstctx == NULL) | |
315 | return NULL; | |
316 | ||
317 | *dstctx = *srcctx; | |
318 | dstctx->ec = NULL; | |
319 | dstctx->md = NULL; | |
320 | dstctx->mdctx = NULL; | |
321 | ||
322 | if (srcctx->ec != NULL && !EC_KEY_up_ref(srcctx->ec)) | |
323 | goto err; | |
324 | dstctx->ec = srcctx->ec; | |
325 | ||
326 | if (srcctx->md != NULL && !EVP_MD_up_ref(srcctx->md)) | |
327 | goto err; | |
328 | dstctx->md = srcctx->md; | |
329 | ||
330 | if (srcctx->mdctx != NULL) { | |
331 | dstctx->mdctx = EVP_MD_CTX_new(); | |
332 | if (dstctx->mdctx == NULL | |
333 | || !EVP_MD_CTX_copy_ex(dstctx->mdctx, srcctx->mdctx)) | |
334 | goto err; | |
335 | } | |
336 | ||
337 | if (srcctx->id != NULL) { | |
338 | dstctx->id = OPENSSL_malloc(srcctx->id_len); | |
339 | if (dstctx->id == NULL) | |
340 | goto err; | |
341 | dstctx->id_len = srcctx->id_len; | |
342 | memcpy(dstctx->id, srcctx->id, srcctx->id_len); | |
343 | } | |
344 | ||
345 | return dstctx; | |
346 | err: | |
347 | sm2sig_freectx(dstctx); | |
348 | return NULL; | |
349 | } | |
350 | ||
351 | static int sm2sig_get_ctx_params(void *vpsm2ctx, OSSL_PARAM *params) | |
352 | { | |
353 | PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx; | |
354 | OSSL_PARAM *p; | |
355 | ||
356 | if (psm2ctx == NULL || params == NULL) | |
357 | return 0; | |
358 | ||
359 | p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID); | |
360 | if (p != NULL | |
361 | && !OSSL_PARAM_set_octet_string(p, psm2ctx->aid, psm2ctx->aid_len)) | |
362 | return 0; | |
363 | ||
364 | p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE); | |
365 | if (p != NULL && !OSSL_PARAM_set_size_t(p, psm2ctx->mdsize)) | |
366 | return 0; | |
367 | ||
368 | p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST); | |
369 | if (p != NULL && !OSSL_PARAM_set_utf8_string(p, psm2ctx->md == NULL | |
370 | ? psm2ctx->mdname | |
371 | : EVP_MD_name(psm2ctx->md))) | |
372 | return 0; | |
373 | ||
374 | return 1; | |
375 | } | |
376 | ||
377 | static const OSSL_PARAM known_gettable_ctx_params[] = { | |
378 | OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_ALGORITHM_ID, NULL, 0), | |
379 | OSSL_PARAM_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE, NULL), | |
380 | OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0), | |
381 | OSSL_PARAM_END | |
382 | }; | |
383 | ||
384 | static const OSSL_PARAM *sm2sig_gettable_ctx_params(ossl_unused void *provctx) | |
385 | { | |
386 | return known_gettable_ctx_params; | |
387 | } | |
388 | ||
389 | static int sm2sig_set_ctx_params(void *vpsm2ctx, const OSSL_PARAM params[]) | |
390 | { | |
391 | PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx; | |
392 | const OSSL_PARAM *p; | |
393 | char *mdname; | |
394 | ||
395 | if (psm2ctx == NULL || params == NULL) | |
396 | return 0; | |
397 | ||
398 | p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_DIST_ID); | |
399 | if (p != NULL) { | |
400 | void *tmp_id = NULL; | |
401 | size_t tmp_idlen; | |
402 | ||
403 | /* | |
404 | * If the 'z' digest has already been computed, the ID is set too late | |
405 | */ | |
406 | if (!psm2ctx->flag_compute_z_digest) | |
407 | return 0; | |
408 | ||
409 | if (!OSSL_PARAM_get_octet_string(p, &tmp_id, 0, &tmp_idlen)) | |
410 | return 0; | |
411 | OPENSSL_free(psm2ctx->id); | |
412 | psm2ctx->id = tmp_id; | |
413 | psm2ctx->id_len = tmp_idlen; | |
414 | } | |
415 | ||
416 | if (psm2ctx->md != NULL) { | |
417 | /* | |
418 | * You cannot set the digest name/size when doing a DigestSign or | |
419 | * DigestVerify. | |
420 | */ | |
421 | return 1; | |
422 | } | |
423 | ||
424 | p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE); | |
425 | if (p != NULL && !OSSL_PARAM_get_size_t(p, &psm2ctx->mdsize)) | |
426 | return 0; | |
427 | ||
428 | /* | |
429 | * We never actually use the mdname, but we do support getting it later. | |
430 | * This can be useful for applications that want to know the MD that they | |
431 | * previously set. | |
432 | */ | |
433 | p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST); | |
434 | mdname = psm2ctx->mdname; | |
435 | if (p != NULL | |
436 | && !OSSL_PARAM_get_utf8_string(p, &mdname, sizeof(psm2ctx->mdname))) | |
437 | return 0; | |
438 | ||
439 | return 1; | |
440 | } | |
441 | ||
442 | static const OSSL_PARAM known_settable_ctx_params[] = { | |
443 | OSSL_PARAM_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE, NULL), | |
444 | OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0), | |
445 | OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_DIST_ID, NULL, 0), | |
446 | OSSL_PARAM_END | |
447 | }; | |
448 | ||
449 | static const OSSL_PARAM *sm2sig_settable_ctx_params(ossl_unused void *provctx) | |
450 | { | |
451 | /* | |
452 | * TODO(3.0): Should this function return a different set of settable ctx | |
453 | * params if the ctx is being used for a DigestSign/DigestVerify? In that | |
454 | * case it is not allowed to set the digest size/digest name because the | |
455 | * digest is explicitly set as part of the init. | |
456 | */ | |
457 | return known_settable_ctx_params; | |
458 | } | |
459 | ||
460 | static int sm2sig_get_ctx_md_params(void *vpsm2ctx, OSSL_PARAM *params) | |
461 | { | |
462 | PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx; | |
463 | ||
464 | if (psm2ctx->mdctx == NULL) | |
465 | return 0; | |
466 | ||
467 | return EVP_MD_CTX_get_params(psm2ctx->mdctx, params); | |
468 | } | |
469 | ||
470 | static const OSSL_PARAM *sm2sig_gettable_ctx_md_params(void *vpsm2ctx) | |
471 | { | |
472 | PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx; | |
473 | ||
474 | if (psm2ctx->md == NULL) | |
475 | return 0; | |
476 | ||
477 | return EVP_MD_gettable_ctx_params(psm2ctx->md); | |
478 | } | |
479 | ||
480 | static int sm2sig_set_ctx_md_params(void *vpsm2ctx, const OSSL_PARAM params[]) | |
481 | { | |
482 | PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx; | |
483 | ||
484 | if (psm2ctx->mdctx == NULL) | |
485 | return 0; | |
486 | ||
487 | return EVP_MD_CTX_set_params(psm2ctx->mdctx, params); | |
488 | } | |
489 | ||
490 | static const OSSL_PARAM *sm2sig_settable_ctx_md_params(void *vpsm2ctx) | |
491 | { | |
492 | PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx; | |
493 | ||
494 | if (psm2ctx->md == NULL) | |
495 | return 0; | |
496 | ||
497 | return EVP_MD_settable_ctx_params(psm2ctx->md); | |
498 | } | |
499 | ||
58f422f6 | 500 | const OSSL_DISPATCH ossl_sm2_signature_functions[] = { |
d0b79f86 PY |
501 | { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))sm2sig_newctx }, |
502 | { OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))sm2sig_signature_init }, | |
503 | { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))sm2sig_sign }, | |
504 | { OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))sm2sig_signature_init }, | |
505 | { OSSL_FUNC_SIGNATURE_VERIFY, (void (*)(void))sm2sig_verify }, | |
506 | { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT, | |
507 | (void (*)(void))sm2sig_digest_signverify_init }, | |
508 | { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE, | |
509 | (void (*)(void))sm2sig_digest_signverify_update }, | |
510 | { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL, | |
511 | (void (*)(void))sm2sig_digest_sign_final }, | |
512 | { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT, | |
513 | (void (*)(void))sm2sig_digest_signverify_init }, | |
514 | { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE, | |
515 | (void (*)(void))sm2sig_digest_signverify_update }, | |
516 | { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL, | |
517 | (void (*)(void))sm2sig_digest_verify_final }, | |
518 | { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))sm2sig_freectx }, | |
519 | { OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))sm2sig_dupctx }, | |
520 | { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void (*)(void))sm2sig_get_ctx_params }, | |
521 | { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS, | |
522 | (void (*)(void))sm2sig_gettable_ctx_params }, | |
523 | { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, (void (*)(void))sm2sig_set_ctx_params }, | |
524 | { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS, | |
525 | (void (*)(void))sm2sig_settable_ctx_params }, | |
526 | { OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS, | |
527 | (void (*)(void))sm2sig_get_ctx_md_params }, | |
528 | { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS, | |
529 | (void (*)(void))sm2sig_gettable_ctx_md_params }, | |
530 | { OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS, | |
531 | (void (*)(void))sm2sig_set_ctx_md_params }, | |
532 | { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS, | |
533 | (void (*)(void))sm2sig_settable_ctx_md_params }, | |
534 | { 0, NULL } | |
535 | }; |