Coverage Report

Created: 2026-10-28 06:28

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