Coverage Report

Created: 2025-12-31 06:58

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-2024 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
0
{
94
0
    if (psm2ctx->md == NULL) /* We need an SM3 md to compare with */
95
0
        psm2ctx->md = EVP_MD_fetch(psm2ctx->libctx, psm2ctx->mdname,
96
0
            psm2ctx->propq);
97
0
    if (psm2ctx->md == NULL)
98
0
        return 0;
99
100
    /* XOF digests don't work */
101
0
    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
0
    if (mdname == NULL)
107
0
        return 1;
108
109
0
    if (strlen(mdname) >= sizeof(psm2ctx->mdname)
110
0
        || !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
0
    OPENSSL_strlcpy(psm2ctx->mdname, mdname, sizeof(psm2ctx->mdname));
117
0
    return 1;
118
0
}
119
120
static void *sm2sig_newctx(void *provctx, const char *propq)
121
0
{
122
0
    PROV_SM2_CTX *ctx = OPENSSL_zalloc(sizeof(PROV_SM2_CTX));
123
124
0
    if (ctx == NULL)
125
0
        return NULL;
126
127
0
    ctx->libctx = PROV_LIBCTX_OF(provctx);
128
0
    if (propq != NULL && (ctx->propq = OPENSSL_strdup(propq)) == NULL) {
129
0
        OPENSSL_free(ctx);
130
0
        return NULL;
131
0
    }
132
0
    ctx->mdsize = SM3_DIGEST_LENGTH;
133
0
    strcpy(ctx->mdname, OSSL_DIGEST_NAME_SM3);
134
0
    return ctx;
135
0
}
136
137
static int sm2sig_signature_init(void *vpsm2ctx, void *ec,
138
    const OSSL_PARAM params[])
139
0
{
140
0
    PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
141
142
0
    if (!ossl_prov_is_running()
143
0
        || psm2ctx == NULL)
144
0
        return 0;
145
146
0
    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
0
    if (ec != NULL) {
152
0
        if (!EC_KEY_up_ref(ec))
153
0
            return 0;
154
0
        EC_KEY_free(psm2ctx->ec);
155
0
        psm2ctx->ec = ec;
156
0
    }
157
158
0
    return sm2sig_set_ctx_params(psm2ctx, params);
159
0
}
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
0
{
192
0
    PROV_SM2_CTX *ctx = (PROV_SM2_CTX *)vpsm2ctx;
193
194
0
    if (ctx->mdsize != 0 && tbslen != ctx->mdsize)
195
0
        return 0;
196
197
0
    return ossl_sm2_internal_verify(tbs, tbslen, sig, siglen, ctx->ec);
198
0
}
199
200
static void free_md(PROV_SM2_CTX *ctx)
201
0
{
202
0
    EVP_MD_CTX_free(ctx->mdctx);
203
0
    EVP_MD_free(ctx->md);
204
0
    ctx->mdctx = NULL;
205
0
    ctx->md = NULL;
206
0
}
207
208
static int sm2sig_digest_signverify_init(void *vpsm2ctx, const char *mdname,
209
    void *ec, const OSSL_PARAM params[])
210
0
{
211
0
    PROV_SM2_CTX *ctx = (PROV_SM2_CTX *)vpsm2ctx;
212
0
    int md_nid;
213
0
    WPACKET pkt;
214
0
    int ret = 0;
215
0
    unsigned char *aid = NULL;
216
217
0
    if (!sm2sig_signature_init(vpsm2ctx, ec, params)
218
0
        || !sm2sig_set_mdname(ctx, mdname))
219
0
        return ret;
220
221
0
    if (ctx->mdctx == NULL) {
222
0
        ctx->mdctx = EVP_MD_CTX_new();
223
0
        if (ctx->mdctx == NULL)
224
0
            goto error;
225
0
    }
226
227
0
    md_nid = EVP_MD_get_type(ctx->md);
228
229
    /*
230
     * We do not care about DER writing errors.
231
     * All it really means is that for some reason, there's no
232
     * AlgorithmIdentifier to be had, but the operation itself is
233
     * still valid, just as long as it's not used to construct
234
     * anything that needs an AlgorithmIdentifier.
235
     */
236
0
    ctx->aid_len = 0;
237
0
    if (WPACKET_init_der(&pkt, ctx->aid_buf, sizeof(ctx->aid_buf))
238
0
        && ossl_DER_w_algorithmIdentifier_SM2_with_MD(&pkt, -1, ctx->ec, md_nid)
239
0
        && WPACKET_finish(&pkt)) {
240
0
        WPACKET_get_total_written(&pkt, &ctx->aid_len);
241
0
        aid = WPACKET_get_curr(&pkt);
242
0
    }
243
0
    WPACKET_cleanup(&pkt);
244
0
    if (aid != NULL && ctx->aid_len != 0)
245
0
        memmove(ctx->aid_buf, aid, ctx->aid_len);
246
247
0
    if (!EVP_DigestInit_ex2(ctx->mdctx, ctx->md, params))
248
0
        goto error;
249
250
0
    ctx->flag_compute_z_digest = 1;
251
252
0
    ret = 1;
253
254
0
error:
255
0
    return ret;
256
0
}
257
258
static int sm2sig_compute_z_digest(PROV_SM2_CTX *ctx)
259
0
{
260
0
    uint8_t *z = NULL;
261
0
    int ret = 1;
262
263
0
    if (ctx->flag_compute_z_digest) {
264
        /* Only do this once */
265
0
        ctx->flag_compute_z_digest = 0;
266
267
0
        if ((z = OPENSSL_zalloc(ctx->mdsize)) == NULL
268
            /* get hashed prefix 'z' of tbs message */
269
0
            || !ossl_sm2_compute_z_digest(z, ctx->md, ctx->id, ctx->id_len,
270
0
                ctx->ec)
271
0
            || !EVP_DigestUpdate(ctx->mdctx, z, ctx->mdsize))
272
0
            ret = 0;
273
0
        OPENSSL_free(z);
274
0
    }
275
276
0
    return ret;
277
0
}
278
279
int sm2sig_digest_signverify_update(void *vpsm2ctx, const unsigned char *data,
280
    size_t datalen)
281
0
{
282
0
    PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
283
284
0
    if (psm2ctx == NULL || psm2ctx->mdctx == NULL)
285
0
        return 0;
286
287
0
    return sm2sig_compute_z_digest(psm2ctx)
288
0
        && EVP_DigestUpdate(psm2ctx->mdctx, data, datalen);
289
0
}
290
291
int sm2sig_digest_sign_final(void *vpsm2ctx, unsigned char *sig, size_t *siglen,
292
    size_t sigsize)
293
0
{
294
0
    PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
295
0
    unsigned char digest[EVP_MAX_MD_SIZE];
296
0
    unsigned int dlen = 0;
297
298
0
    if (psm2ctx == NULL || psm2ctx->mdctx == NULL)
299
0
        return 0;
300
301
    /*
302
     * If sig is NULL then we're just finding out the sig size. Other fields
303
     * are ignored. Defer to sm2sig_sign.
304
     */
305
0
    if (sig != NULL) {
306
0
        if (!(sm2sig_compute_z_digest(psm2ctx)
307
0
                && EVP_DigestFinal_ex(psm2ctx->mdctx, digest, &dlen)))
308
0
            return 0;
309
0
    }
310
311
0
    return sm2sig_sign(vpsm2ctx, sig, siglen, sigsize, digest, (size_t)dlen);
312
0
}
313
314
int sm2sig_digest_verify_final(void *vpsm2ctx, const unsigned char *sig,
315
    size_t siglen)
316
0
{
317
0
    PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
318
0
    unsigned char digest[EVP_MAX_MD_SIZE];
319
0
    unsigned int dlen = 0;
320
0
    int md_size;
321
322
0
    if (psm2ctx == NULL || psm2ctx->mdctx == NULL)
323
0
        return 0;
324
325
0
    md_size = EVP_MD_get_size(psm2ctx->md);
326
0
    if (md_size <= 0 || md_size > (int)sizeof(digest))
327
0
        return 0;
328
329
0
    if (!(sm2sig_compute_z_digest(psm2ctx)
330
0
            && EVP_DigestFinal_ex(psm2ctx->mdctx, digest, &dlen)))
331
0
        return 0;
332
333
0
    return sm2sig_verify(vpsm2ctx, sig, siglen, digest, (size_t)dlen);
334
0
}
335
336
static void sm2sig_freectx(void *vpsm2ctx)
337
0
{
338
0
    PROV_SM2_CTX *ctx = (PROV_SM2_CTX *)vpsm2ctx;
339
340
0
    free_md(ctx);
341
0
    EC_KEY_free(ctx->ec);
342
0
    OPENSSL_free(ctx->propq);
343
0
    OPENSSL_free(ctx->id);
344
0
    OPENSSL_free(ctx);
345
0
}
346
347
static void *sm2sig_dupctx(void *vpsm2ctx)
348
0
{
349
0
    PROV_SM2_CTX *srcctx = (PROV_SM2_CTX *)vpsm2ctx;
350
0
    PROV_SM2_CTX *dstctx;
351
352
0
    dstctx = OPENSSL_zalloc(sizeof(*srcctx));
353
0
    if (dstctx == NULL)
354
0
        return NULL;
355
356
0
    *dstctx = *srcctx;
357
0
    dstctx->ec = NULL;
358
0
    dstctx->propq = NULL;
359
0
    dstctx->md = NULL;
360
0
    dstctx->mdctx = NULL;
361
0
    dstctx->id = NULL;
362
363
0
    if (srcctx->ec != NULL && !EC_KEY_up_ref(srcctx->ec))
364
0
        goto err;
365
0
    dstctx->ec = srcctx->ec;
366
367
0
    if (srcctx->propq != NULL) {
368
0
        dstctx->propq = OPENSSL_strdup(srcctx->propq);
369
0
        if (dstctx->propq == NULL)
370
0
            goto err;
371
0
    }
372
373
0
    if (srcctx->md != NULL && !EVP_MD_up_ref(srcctx->md))
374
0
        goto err;
375
0
    dstctx->md = srcctx->md;
376
377
0
    if (srcctx->mdctx != NULL) {
378
0
        dstctx->mdctx = EVP_MD_CTX_new();
379
0
        if (dstctx->mdctx == NULL
380
0
            || !EVP_MD_CTX_copy_ex(dstctx->mdctx, srcctx->mdctx))
381
0
            goto err;
382
0
    }
383
384
0
    if (srcctx->id != NULL) {
385
0
        dstctx->id = OPENSSL_malloc(srcctx->id_len);
386
0
        if (dstctx->id == NULL)
387
0
            goto err;
388
0
        dstctx->id_len = srcctx->id_len;
389
0
        memcpy(dstctx->id, srcctx->id, srcctx->id_len);
390
0
    }
391
392
0
    return dstctx;
393
0
err:
394
0
    sm2sig_freectx(dstctx);
395
0
    return NULL;
396
0
}
397
398
static int sm2sig_get_ctx_params(void *vpsm2ctx, OSSL_PARAM *params)
399
0
{
400
0
    PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
401
0
    OSSL_PARAM *p;
402
403
0
    if (psm2ctx == NULL)
404
0
        return 0;
405
406
0
    p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
407
0
    if (p != NULL
408
0
        && !OSSL_PARAM_set_octet_string(p,
409
0
            psm2ctx->aid_len == 0 ? NULL : psm2ctx->aid_buf,
410
0
            psm2ctx->aid_len))
411
0
        return 0;
412
413
0
    p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE);
414
0
    if (p != NULL && !OSSL_PARAM_set_size_t(p, psm2ctx->mdsize))
415
0
        return 0;
416
417
0
    p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST);
418
0
    if (p != NULL && !OSSL_PARAM_set_utf8_string(p, psm2ctx->md == NULL ? psm2ctx->mdname : EVP_MD_get0_name(psm2ctx->md)))
419
0
        return 0;
420
421
0
    return 1;
422
0
}
423
424
static const OSSL_PARAM known_gettable_ctx_params[] = {
425
    OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_ALGORITHM_ID, NULL, 0),
426
    OSSL_PARAM_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE, NULL),
427
    OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
428
    OSSL_PARAM_END
429
};
430
431
static const OSSL_PARAM *sm2sig_gettable_ctx_params(ossl_unused void *vpsm2ctx,
432
    ossl_unused void *provctx)
433
0
{
434
0
    return known_gettable_ctx_params;
435
0
}
436
437
static int sm2sig_set_ctx_params(void *vpsm2ctx, const OSSL_PARAM params[])
438
0
{
439
0
    PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
440
0
    const OSSL_PARAM *p;
441
0
    size_t mdsize;
442
443
0
    if (psm2ctx == NULL)
444
0
        return 0;
445
0
    if (ossl_param_is_empty(params))
446
0
        return 1;
447
448
0
    p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_DIST_ID);
449
0
    if (p != NULL) {
450
0
        void *tmp_id = NULL;
451
0
        size_t tmp_idlen = 0;
452
453
        /*
454
         * If the 'z' digest has already been computed, the ID is set too late
455
         */
456
0
        if (!psm2ctx->flag_compute_z_digest)
457
0
            return 0;
458
459
0
        if (p->data_size != 0
460
0
            && !OSSL_PARAM_get_octet_string(p, &tmp_id, 0, &tmp_idlen))
461
0
            return 0;
462
0
        OPENSSL_free(psm2ctx->id);
463
0
        psm2ctx->id = tmp_id;
464
0
        psm2ctx->id_len = tmp_idlen;
465
0
    }
466
467
    /*
468
     * The following code checks that the size is the same as the SM3 digest
469
     * size returning an error otherwise.
470
     * If there is ever any different digest algorithm allowed with SM2
471
     * this needs to be adjusted accordingly.
472
     */
473
0
    p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE);
474
0
    if (p != NULL && (!OSSL_PARAM_get_size_t(p, &mdsize) || mdsize != psm2ctx->mdsize))
475
0
        return 0;
476
477
0
    p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST);
478
0
    if (p != NULL) {
479
0
        char *mdname = NULL;
480
481
0
        if (!OSSL_PARAM_get_utf8_string(p, &mdname, 0))
482
0
            return 0;
483
0
        if (!sm2sig_set_mdname(psm2ctx, mdname)) {
484
0
            OPENSSL_free(mdname);
485
0
            return 0;
486
0
        }
487
0
        OPENSSL_free(mdname);
488
0
    }
489
490
0
    return 1;
491
0
}
492
493
static const OSSL_PARAM known_settable_ctx_params[] = {
494
    OSSL_PARAM_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE, NULL),
495
    OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
496
    OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_DIST_ID, NULL, 0),
497
    OSSL_PARAM_END
498
};
499
500
static const OSSL_PARAM *sm2sig_settable_ctx_params(ossl_unused void *vpsm2ctx,
501
    ossl_unused void *provctx)
502
5
{
503
5
    return known_settable_ctx_params;
504
5
}
505
506
static int sm2sig_get_ctx_md_params(void *vpsm2ctx, OSSL_PARAM *params)
507
0
{
508
0
    PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
509
510
0
    if (psm2ctx->mdctx == NULL)
511
0
        return 0;
512
513
0
    return EVP_MD_CTX_get_params(psm2ctx->mdctx, params);
514
0
}
515
516
static const OSSL_PARAM *sm2sig_gettable_ctx_md_params(void *vpsm2ctx)
517
0
{
518
0
    PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
519
520
0
    if (psm2ctx->md == NULL)
521
0
        return 0;
522
523
0
    return EVP_MD_gettable_ctx_params(psm2ctx->md);
524
0
}
525
526
static int sm2sig_set_ctx_md_params(void *vpsm2ctx, const OSSL_PARAM params[])
527
0
{
528
0
    PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
529
530
0
    if (psm2ctx->mdctx == NULL)
531
0
        return 0;
532
533
0
    return EVP_MD_CTX_set_params(psm2ctx->mdctx, params);
534
0
}
535
536
static const OSSL_PARAM *sm2sig_settable_ctx_md_params(void *vpsm2ctx)
537
0
{
538
0
    PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
539
540
0
    if (psm2ctx->md == NULL)
541
0
        return 0;
542
543
0
    return EVP_MD_settable_ctx_params(psm2ctx->md);
544
0
}
545
546
const OSSL_DISPATCH ossl_sm2_signature_functions[] = {
547
    { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))sm2sig_newctx },
548
    { OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))sm2sig_signature_init },
549
    { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))sm2sig_sign },
550
    { OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))sm2sig_signature_init },
551
    { OSSL_FUNC_SIGNATURE_VERIFY, (void (*)(void))sm2sig_verify },
552
    { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT,
553
        (void (*)(void))sm2sig_digest_signverify_init },
554
    { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE,
555
        (void (*)(void))sm2sig_digest_signverify_update },
556
    { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL,
557
        (void (*)(void))sm2sig_digest_sign_final },
558
    { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT,
559
        (void (*)(void))sm2sig_digest_signverify_init },
560
    { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE,
561
        (void (*)(void))sm2sig_digest_signverify_update },
562
    { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL,
563
        (void (*)(void))sm2sig_digest_verify_final },
564
    { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))sm2sig_freectx },
565
    { OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))sm2sig_dupctx },
566
    { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void (*)(void))sm2sig_get_ctx_params },
567
    { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS,
568
        (void (*)(void))sm2sig_gettable_ctx_params },
569
    { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, (void (*)(void))sm2sig_set_ctx_params },
570
    { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS,
571
        (void (*)(void))sm2sig_settable_ctx_params },
572
    { OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS,
573
        (void (*)(void))sm2sig_get_ctx_md_params },
574
    { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS,
575
        (void (*)(void))sm2sig_gettable_ctx_md_params },
576
    { OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS,
577
        (void (*)(void))sm2sig_set_ctx_md_params },
578
    { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS,
579
        (void (*)(void))sm2sig_settable_ctx_md_params },
580
    OSSL_DISPATCH_END
581
};