Coverage Report

Created: 2025-10-28 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/providers/implementations/signature/dsa_sig.c
Line
Count
Source
1
/*
2
 * Copyright 2019-2025 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
 * DSA low level APIs are deprecated for public use, but still ok for
12
 * internal use.
13
 */
14
#include "internal/deprecated.h"
15
16
#include <string.h>
17
18
#include <openssl/crypto.h>
19
#include <openssl/core_dispatch.h>
20
#include <openssl/core_names.h>
21
#include <openssl/err.h>
22
#include <openssl/dsa.h>
23
#include <openssl/params.h>
24
#include <openssl/evp.h>
25
#include <openssl/proverr.h>
26
#include "internal/nelem.h"
27
#include "internal/sizes.h"
28
#include "internal/cryptlib.h"
29
#include "prov/providercommon.h"
30
#include "prov/implementations.h"
31
#include "prov/provider_ctx.h"
32
#include "prov/securitycheck.h"
33
#include "prov/der_dsa.h"
34
#include "crypto/dsa.h"
35
36
static OSSL_FUNC_signature_newctx_fn dsa_newctx;
37
static OSSL_FUNC_signature_sign_init_fn dsa_sign_init;
38
static OSSL_FUNC_signature_verify_init_fn dsa_verify_init;
39
static OSSL_FUNC_signature_sign_fn dsa_sign;
40
static OSSL_FUNC_signature_sign_message_update_fn dsa_signverify_message_update;
41
static OSSL_FUNC_signature_sign_message_final_fn dsa_sign_message_final;
42
static OSSL_FUNC_signature_verify_fn dsa_verify;
43
static OSSL_FUNC_signature_verify_message_update_fn dsa_signverify_message_update;
44
static OSSL_FUNC_signature_verify_message_final_fn dsa_verify_message_final;
45
static OSSL_FUNC_signature_digest_sign_init_fn dsa_digest_sign_init;
46
static OSSL_FUNC_signature_digest_sign_update_fn dsa_digest_signverify_update;
47
static OSSL_FUNC_signature_digest_sign_final_fn dsa_digest_sign_final;
48
static OSSL_FUNC_signature_digest_verify_init_fn dsa_digest_verify_init;
49
static OSSL_FUNC_signature_digest_verify_update_fn dsa_digest_signverify_update;
50
static OSSL_FUNC_signature_digest_verify_final_fn dsa_digest_verify_final;
51
static OSSL_FUNC_signature_freectx_fn dsa_freectx;
52
static OSSL_FUNC_signature_dupctx_fn dsa_dupctx;
53
static OSSL_FUNC_signature_query_key_types_fn dsa_sigalg_query_key_types;
54
static OSSL_FUNC_signature_get_ctx_params_fn dsa_get_ctx_params;
55
static OSSL_FUNC_signature_gettable_ctx_params_fn dsa_gettable_ctx_params;
56
static OSSL_FUNC_signature_set_ctx_params_fn dsa_set_ctx_params;
57
static OSSL_FUNC_signature_settable_ctx_params_fn dsa_settable_ctx_params;
58
static OSSL_FUNC_signature_get_ctx_md_params_fn dsa_get_ctx_md_params;
59
static OSSL_FUNC_signature_gettable_ctx_md_params_fn dsa_gettable_ctx_md_params;
60
static OSSL_FUNC_signature_set_ctx_md_params_fn dsa_set_ctx_md_params;
61
static OSSL_FUNC_signature_settable_ctx_md_params_fn dsa_settable_ctx_md_params;
62
static OSSL_FUNC_signature_set_ctx_params_fn dsa_sigalg_set_ctx_params;
63
static OSSL_FUNC_signature_settable_ctx_params_fn dsa_sigalg_settable_ctx_params;
64
65
/*
66
 * What's passed as an actual key is defined by the KEYMGMT interface.
67
 * We happen to know that our KEYMGMT simply passes DSA structures, so
68
 * we use that here too.
69
 */
70
71
typedef struct {
72
    OSSL_LIB_CTX *libctx;
73
    char *propq;
74
    DSA *dsa;
75
    /* |operation| reuses EVP's operation bitfield */
76
    int operation;
77
78
    /*
79
     * Flag to determine if a full sigalg is run (1) or if a composable
80
     * signature algorithm is run (0).
81
     *
82
     * When a full sigalg is run (1), this currently affects the following
83
     * other flags, which are to remain untouched after their initialization:
84
     *
85
     * - flag_allow_md (initialized to 0)
86
     */
87
    unsigned int flag_sigalg : 1;
88
    /*
89
     * Flag to determine if the hash function can be changed (1) or not (0)
90
     * Because it's dangerous to change during a DigestSign or DigestVerify
91
     * operation, this flag is cleared by their Init function, and set again
92
     * by their Final function.
93
     */
94
    unsigned int flag_allow_md : 1;
95
96
    /* If this is set to 1 then the generated k is not random */
97
    unsigned int nonce_type;
98
99
    /* The Algorithm Identifier of the combined signature algorithm */
100
    unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE];
101
    size_t  aid_len;
102
103
    /* main digest */
104
    char mdname[OSSL_MAX_NAME_SIZE];
105
    EVP_MD *md;
106
    EVP_MD_CTX *mdctx;
107
108
    /* Signature, for verification */
109
    unsigned char *sig;
110
    size_t siglen;
111
112
    OSSL_FIPS_IND_DECLARE
113
} PROV_DSA_CTX;
114
115
static size_t dsa_get_md_size(const PROV_DSA_CTX *pdsactx)
116
0
{
117
0
    int md_size;
118
119
0
    if (pdsactx->md != NULL) {
120
0
        md_size = EVP_MD_get_size(pdsactx->md);
121
0
        if (md_size <= 0)
122
0
            return 0;
123
0
        return (size_t)md_size;
124
0
    }
125
0
    return 0;
126
0
}
127
128
static void *dsa_newctx(void *provctx, const char *propq)
129
0
{
130
0
    PROV_DSA_CTX *pdsactx;
131
132
0
    if (!ossl_prov_is_running())
133
0
        return NULL;
134
135
0
    pdsactx = OPENSSL_zalloc(sizeof(PROV_DSA_CTX));
136
0
    if (pdsactx == NULL)
137
0
        return NULL;
138
139
0
    pdsactx->libctx = PROV_LIBCTX_OF(provctx);
140
0
    pdsactx->flag_allow_md = 1;
141
0
    OSSL_FIPS_IND_INIT(pdsactx)
142
0
    if (propq != NULL && (pdsactx->propq = OPENSSL_strdup(propq)) == NULL) {
143
0
        OPENSSL_free(pdsactx);
144
0
        pdsactx = NULL;
145
0
    }
146
0
    return pdsactx;
147
0
}
148
149
static int dsa_setup_md(PROV_DSA_CTX *ctx,
150
                        const char *mdname, const char *mdprops,
151
                        const char *desc)
152
0
{
153
0
    EVP_MD *md = NULL;
154
155
0
    if (mdprops == NULL)
156
0
        mdprops = ctx->propq;
157
158
0
    if (mdname != NULL) {
159
0
        WPACKET pkt;
160
0
        int md_nid;
161
0
        size_t mdname_len = strlen(mdname);
162
0
        unsigned char *aid = NULL;
163
164
0
        md = EVP_MD_fetch(ctx->libctx, mdname, mdprops);
165
0
        md_nid = ossl_digest_get_approved_nid(md);
166
167
0
        if (md == NULL) {
168
0
            ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST,
169
0
                           "%s could not be fetched", mdname);
170
0
            goto err;
171
0
        }
172
0
        if (md_nid == NID_undef) {
173
0
            ERR_raise_data(ERR_LIB_PROV, PROV_R_DIGEST_NOT_ALLOWED,
174
0
                           "digest=%s", mdname);
175
0
            goto err;
176
0
        }
177
0
        if (mdname_len >= sizeof(ctx->mdname)) {
178
0
            ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST,
179
0
                           "%s exceeds name buffer length", mdname);
180
0
            goto err;
181
0
        }
182
        /* XOF digests don't work */
183
0
        if (EVP_MD_xof(md)) {
184
0
            ERR_raise(ERR_LIB_PROV, PROV_R_XOF_DIGESTS_NOT_ALLOWED);
185
0
            goto err;
186
0
        }
187
#ifdef FIPS_MODULE
188
        {
189
            int sha1_allowed
190
                = ((ctx->operation
191
                    & (EVP_PKEY_OP_SIGN | EVP_PKEY_OP_SIGNMSG)) == 0);
192
193
            if (!ossl_fips_ind_digest_sign_check(OSSL_FIPS_IND_GET(ctx),
194
                                                 OSSL_FIPS_IND_SETTABLE1,
195
                                                 ctx->libctx,
196
                                                 md_nid, sha1_allowed, 0, desc,
197
                                                 ossl_fips_config_signature_digest_check))
198
                goto err;
199
        }
200
#endif
201
202
0
        if (!ctx->flag_allow_md) {
203
0
            if (ctx->mdname[0] != '\0'
204
0
                && !EVP_MD_is_a(md, ctx->mdname)) {
205
0
                ERR_raise_data(ERR_LIB_PROV, PROV_R_DIGEST_NOT_ALLOWED,
206
0
                               "digest %s != %s", mdname, ctx->mdname);
207
0
                goto err;
208
0
            }
209
0
            EVP_MD_free(md);
210
0
            return 1;
211
0
        }
212
213
0
        EVP_MD_CTX_free(ctx->mdctx);
214
0
        EVP_MD_free(ctx->md);
215
216
        /*
217
         * We do not care about DER writing errors.
218
         * All it really means is that for some reason, there's no
219
         * AlgorithmIdentifier to be had, but the operation itself is
220
         * still valid, just as long as it's not used to construct
221
         * anything that needs an AlgorithmIdentifier.
222
         */
223
0
        ctx->aid_len = 0;
224
0
        if (WPACKET_init_der(&pkt, ctx->aid_buf, sizeof(ctx->aid_buf))
225
0
            && ossl_DER_w_algorithmIdentifier_DSA_with_MD(&pkt, -1, ctx->dsa,
226
0
                                                          md_nid)
227
0
            && WPACKET_finish(&pkt)) {
228
0
            WPACKET_get_total_written(&pkt, &ctx->aid_len);
229
0
            aid = WPACKET_get_curr(&pkt);
230
0
        }
231
0
        WPACKET_cleanup(&pkt);
232
0
        if (aid != NULL && ctx->aid_len != 0)
233
0
            memmove(ctx->aid_buf, aid, ctx->aid_len);
234
235
0
        ctx->mdctx = NULL;
236
0
        ctx->md = md;
237
0
        OPENSSL_strlcpy(ctx->mdname, mdname, sizeof(ctx->mdname));
238
0
    }
239
240
0
    return 1;
241
0
 err:
242
0
    EVP_MD_free(md);
243
0
    return 0;
244
0
}
245
246
#ifdef FIPS_MODULE
247
248
static int dsa_sign_check_approved(PROV_DSA_CTX *ctx, int signing,
249
                                   const char *desc)
250
{
251
    /* DSA Signing is not approved in FIPS 140-3 */
252
    if (signing
253
        && !OSSL_FIPS_IND_ON_UNAPPROVED(ctx, OSSL_FIPS_IND_SETTABLE2,
254
                                        ctx->libctx, desc, "DSA",
255
                                        ossl_fips_config_dsa_sign_disallowed))
256
        return 0;
257
    return 1;
258
}
259
260
static int dsa_check_key(PROV_DSA_CTX *ctx, int sign, const char *desc)
261
{
262
    int approved = ossl_dsa_check_key(ctx->dsa, sign);
263
264
    if (!approved) {
265
        if (!OSSL_FIPS_IND_ON_UNAPPROVED(ctx, OSSL_FIPS_IND_SETTABLE0,
266
                                         ctx->libctx, desc, "DSA Key",
267
                                         ossl_fips_config_signature_digest_check)) {
268
            ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
269
            return 0;
270
        }
271
    }
272
    return 1;
273
}
274
#endif
275
276
static int
277
dsa_signverify_init(void *vpdsactx, void *vdsa,
278
                    OSSL_FUNC_signature_set_ctx_params_fn *set_ctx_params,
279
                    const OSSL_PARAM params[], int operation,
280
                    const char *desc)
281
0
{
282
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
283
284
0
    if (!ossl_prov_is_running()
285
0
            || pdsactx == NULL)
286
0
        return 0;
287
288
0
    if (vdsa == NULL && pdsactx->dsa == NULL) {
289
0
        ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET);
290
0
        return 0;
291
0
    }
292
293
0
    if (vdsa != NULL) {
294
0
        if (!DSA_up_ref(vdsa))
295
0
            return 0;
296
0
        DSA_free(pdsactx->dsa);
297
0
        pdsactx->dsa = vdsa;
298
0
    }
299
300
0
    pdsactx->operation = operation;
301
302
0
    OSSL_FIPS_IND_SET_APPROVED(pdsactx)
303
0
    if (!set_ctx_params(pdsactx, params))
304
0
        return 0;
305
#ifdef FIPS_MODULE
306
    {
307
        int operation_is_sign
308
            = (operation & (EVP_PKEY_OP_SIGN | EVP_PKEY_OP_SIGNMSG)) != 0;
309
310
        if (!dsa_sign_check_approved(pdsactx, operation_is_sign, desc))
311
            return 0;
312
        if (!dsa_check_key(pdsactx, operation_is_sign, desc))
313
            return 0;
314
    }
315
#endif
316
0
    return 1;
317
0
}
318
319
static int dsa_sign_init(void *vpdsactx, void *vdsa, const OSSL_PARAM params[])
320
0
{
321
0
    return dsa_signverify_init(vpdsactx, vdsa, dsa_set_ctx_params, params,
322
0
                               EVP_PKEY_OP_SIGN, "DSA Sign Init");
323
0
}
324
325
/*
326
 * Sign tbs without digesting it first.  This is suitable for "primitive"
327
 * signing and signing the digest of a message, i.e. should be used with
328
 * implementations of the keytype related algorithms.
329
 */
330
static int dsa_sign_directly(void *vpdsactx,
331
                             unsigned char *sig, size_t *siglen, size_t sigsize,
332
                             const unsigned char *tbs, size_t tbslen)
333
0
{
334
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
335
0
    int ret;
336
0
    unsigned int sltmp;
337
0
    size_t dsasize = DSA_size(pdsactx->dsa);
338
0
    size_t mdsize = dsa_get_md_size(pdsactx);
339
340
0
    if (!ossl_prov_is_running())
341
0
        return 0;
342
343
#ifdef FIPS_MODULE
344
    if (!dsa_sign_check_approved(pdsactx, 1, "Sign"))
345
        return 0;
346
#endif
347
348
0
    if (sig == NULL) {
349
0
        *siglen = dsasize;
350
0
        return 1;
351
0
    }
352
353
0
    if (sigsize < dsasize)
354
0
        return 0;
355
356
0
    if (mdsize != 0 && tbslen != mdsize)
357
0
        return 0;
358
359
0
    ret = ossl_dsa_sign_int(0, tbs, (int)tbslen, sig, &sltmp, pdsactx->dsa,
360
0
                            pdsactx->nonce_type, pdsactx->mdname,
361
0
                            pdsactx->libctx, pdsactx->propq);
362
0
    if (ret <= 0)
363
0
        return 0;
364
365
0
    *siglen = sltmp;
366
0
    return 1;
367
0
}
368
369
static int dsa_signverify_message_update(void *vpdsactx,
370
                                         const unsigned char *data,
371
                                         size_t datalen)
372
0
{
373
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
374
375
0
    if (pdsactx == NULL)
376
0
        return 0;
377
378
0
    return EVP_DigestUpdate(pdsactx->mdctx, data, datalen);
379
0
}
380
381
static int dsa_sign_message_final(void *vpdsactx, unsigned char *sig,
382
                                  size_t *siglen, size_t sigsize)
383
0
{
384
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
385
0
    unsigned char digest[EVP_MAX_MD_SIZE];
386
0
    unsigned int dlen = 0;
387
388
0
    if (!ossl_prov_is_running() || pdsactx == NULL || pdsactx->mdctx == NULL)
389
0
        return 0;
390
    /*
391
     * If sig is NULL then we're just finding out the sig size. Other fields
392
     * are ignored. Defer to dsa_sign.
393
     */
394
0
    if (sig != NULL) {
395
        /*
396
         * When this function is used through dsa_digest_sign_final(),
397
         * there is the possibility that some externally provided digests
398
         * exceed EVP_MAX_MD_SIZE. We should probably handle that
399
         * somehow but that problem is much larger than just in DSA.
400
         */
401
0
        if (!EVP_DigestFinal_ex(pdsactx->mdctx, digest, &dlen))
402
0
            return 0;
403
0
    }
404
405
0
    return dsa_sign_directly(vpdsactx, sig, siglen, sigsize, digest, dlen);
406
0
}
407
408
/*
409
 * If signing a message, digest tbs and sign the result.
410
 * Otherwise, sign tbs directly.
411
 */
412
static int dsa_sign(void *vpdsactx, unsigned char *sig, size_t *siglen,
413
                    size_t sigsize, const unsigned char *tbs, size_t tbslen)
414
0
{
415
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
416
417
0
    if (pdsactx->operation == EVP_PKEY_OP_SIGNMSG) {
418
        /*
419
         * If |sig| is NULL, the caller is only looking for the sig length.
420
         * DO NOT update the input in this case.
421
         */
422
0
        if (sig == NULL)
423
0
            return dsa_sign_message_final(pdsactx, sig, siglen, sigsize);
424
425
0
        if (dsa_signverify_message_update(pdsactx, tbs, tbslen) <= 0)
426
0
            return 0;
427
0
        return dsa_sign_message_final(pdsactx, sig, siglen, sigsize);
428
0
    }
429
0
    return dsa_sign_directly(pdsactx, sig, siglen, sigsize, tbs, tbslen);
430
0
}
431
432
static int dsa_verify_init(void *vpdsactx, void *vdsa,
433
                           const OSSL_PARAM params[])
434
0
{
435
0
    return dsa_signverify_init(vpdsactx, vdsa, dsa_set_ctx_params, params,
436
0
                               EVP_PKEY_OP_VERIFY, "DSA Verify Init");
437
0
}
438
439
static int dsa_verify_directly(void *vpdsactx,
440
                               const unsigned char *sig, size_t siglen,
441
                               const unsigned char *tbs, size_t tbslen)
442
0
{
443
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
444
0
    size_t mdsize = dsa_get_md_size(pdsactx);
445
446
0
    if (!ossl_prov_is_running() || (mdsize != 0 && tbslen != mdsize))
447
0
        return 0;
448
449
0
    return DSA_verify(0, tbs, (int)tbslen, sig, (int)siglen, pdsactx->dsa);
450
0
}
451
452
static int dsa_verify_set_sig(void *vpdsactx,
453
                              const unsigned char *sig, size_t siglen)
454
0
{
455
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
456
0
    OSSL_PARAM params[2];
457
458
0
    params[0] =
459
0
        OSSL_PARAM_construct_octet_string(OSSL_SIGNATURE_PARAM_SIGNATURE,
460
0
                                          (unsigned char *)sig, siglen);
461
0
    params[1] = OSSL_PARAM_construct_end();
462
0
    return dsa_sigalg_set_ctx_params(pdsactx, params);
463
0
}
464
465
static int dsa_verify_message_final(void *vpdsactx)
466
0
{
467
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
468
0
    unsigned char digest[EVP_MAX_MD_SIZE];
469
0
    unsigned int dlen = 0;
470
471
0
    if (!ossl_prov_is_running())
472
0
        return 0;
473
474
0
    if (pdsactx == NULL || pdsactx->mdctx == NULL)
475
0
        return 0;
476
477
    /*
478
     * The digests used here are all known (see dsa_get_md_nid()), so they
479
     * should not exceed the internal buffer size of EVP_MAX_MD_SIZE.
480
     */
481
0
    if (!EVP_DigestFinal_ex(pdsactx->mdctx, digest, &dlen))
482
0
        return 0;
483
484
0
    return dsa_verify_directly(vpdsactx, pdsactx->sig, pdsactx->siglen,
485
0
                               digest, dlen);
486
0
}
487
488
/*
489
 * If verifying a message, digest tbs and verify the result.
490
 * Otherwise, verify tbs directly.
491
 */
492
static int dsa_verify(void *vpdsactx,
493
                      const unsigned char *sig, size_t siglen,
494
                      const unsigned char *tbs, size_t tbslen)
495
0
{
496
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
497
498
0
    if (pdsactx->operation == EVP_PKEY_OP_VERIFYMSG) {
499
0
        if (dsa_verify_set_sig(pdsactx, sig, siglen) <= 0)
500
0
            return 0;
501
0
        if (dsa_signverify_message_update(pdsactx, tbs, tbslen) <= 0)
502
0
            return 0;
503
0
        return dsa_verify_message_final(pdsactx);
504
0
    }
505
0
    return dsa_verify_directly(pdsactx, sig, siglen, tbs, tbslen);
506
0
}
507
508
/* DigestSign/DigestVerify wrappers */
509
510
static int dsa_digest_signverify_init(void *vpdsactx, const char *mdname,
511
                                      void *vdsa, const OSSL_PARAM params[],
512
                                      int operation, const char *desc)
513
0
{
514
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
515
516
0
    if (!ossl_prov_is_running())
517
0
        return 0;
518
519
0
    if (!dsa_signverify_init(vpdsactx, vdsa, dsa_set_ctx_params, params,
520
0
                             operation, desc))
521
0
        return 0;
522
523
0
    if (mdname != NULL
524
        /* was dsa_setup_md already called in dsa_signverify_init()? */
525
0
        && (mdname[0] == '\0' || OPENSSL_strcasecmp(pdsactx->mdname, mdname) != 0)
526
0
        && !dsa_setup_md(pdsactx, mdname, NULL, desc))
527
0
        return 0;
528
529
0
    pdsactx->flag_allow_md = 0;
530
531
0
    if (pdsactx->mdctx == NULL) {
532
0
        pdsactx->mdctx = EVP_MD_CTX_new();
533
0
        if (pdsactx->mdctx == NULL)
534
0
            goto error;
535
0
    }
536
537
0
    if (!EVP_DigestInit_ex2(pdsactx->mdctx, pdsactx->md, params))
538
0
        goto error;
539
540
0
    return 1;
541
542
0
 error:
543
0
    EVP_MD_CTX_free(pdsactx->mdctx);
544
0
    pdsactx->mdctx = NULL;
545
0
    return 0;
546
0
}
547
548
static int dsa_digest_sign_init(void *vpdsactx, const char *mdname,
549
                                void *vdsa, const OSSL_PARAM params[])
550
0
{
551
0
    return dsa_digest_signverify_init(vpdsactx, mdname, vdsa, params,
552
0
                                      EVP_PKEY_OP_SIGNMSG,
553
0
                                      "DSA Digest Sign Init");
554
0
}
555
556
static int dsa_digest_signverify_update(void *vpdsactx, const unsigned char *data,
557
                                        size_t datalen)
558
0
{
559
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
560
561
0
    if (pdsactx == NULL)
562
0
        return 0;
563
    /* Sigalg implementations shouldn't do digest_sign */
564
0
    if (pdsactx->flag_sigalg)
565
0
        return 0;
566
567
0
    return dsa_signverify_message_update(vpdsactx, data, datalen);
568
0
}
569
570
static int dsa_digest_sign_final(void *vpdsactx, unsigned char *sig,
571
                                 size_t *siglen, size_t sigsize)
572
0
{
573
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
574
0
    int ok = 0;
575
576
0
    if (pdsactx == NULL)
577
0
        return 0;
578
    /* Sigalg implementations shouldn't do digest_sign */
579
0
    if (pdsactx->flag_sigalg)
580
0
        return 0;
581
582
0
    ok = dsa_sign_message_final(pdsactx, sig, siglen, sigsize);
583
584
0
    pdsactx->flag_allow_md = 1;
585
586
0
    return ok;
587
0
}
588
589
static int dsa_digest_verify_init(void *vpdsactx, const char *mdname,
590
                                  void *vdsa, const OSSL_PARAM params[])
591
0
{
592
0
    return dsa_digest_signverify_init(vpdsactx, mdname, vdsa, params,
593
0
                                      EVP_PKEY_OP_VERIFYMSG,
594
0
                                      "DSA Digest Verify Init");
595
0
}
596
597
int dsa_digest_verify_final(void *vpdsactx, const unsigned char *sig,
598
                            size_t siglen)
599
0
{
600
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
601
0
    int ok = 0;
602
603
0
    if (pdsactx == NULL)
604
0
        return 0;
605
    /* Sigalg implementations shouldn't do digest_verify */
606
0
    if (pdsactx->flag_sigalg)
607
0
        return 0;
608
609
0
    if (dsa_verify_set_sig(pdsactx, sig, siglen))
610
0
        ok = dsa_verify_message_final(vpdsactx);
611
612
0
    pdsactx->flag_allow_md = 1;
613
614
0
    return ok;
615
0
}
616
617
static void dsa_freectx(void *vpdsactx)
618
0
{
619
0
    PROV_DSA_CTX *ctx = (PROV_DSA_CTX *)vpdsactx;
620
621
0
    EVP_MD_CTX_free(ctx->mdctx);
622
0
    EVP_MD_free(ctx->md);
623
0
    OPENSSL_free(ctx->sig);
624
0
    OPENSSL_free(ctx->propq);
625
0
    DSA_free(ctx->dsa);
626
0
    OPENSSL_free(ctx);
627
0
}
628
629
static void *dsa_dupctx(void *vpdsactx)
630
0
{
631
0
    PROV_DSA_CTX *srcctx = (PROV_DSA_CTX *)vpdsactx;
632
0
    PROV_DSA_CTX *dstctx;
633
634
0
    if (!ossl_prov_is_running())
635
0
        return NULL;
636
637
0
    dstctx = OPENSSL_zalloc(sizeof(*srcctx));
638
0
    if (dstctx == NULL)
639
0
        return NULL;
640
641
0
    *dstctx = *srcctx;
642
0
    dstctx->dsa = NULL;
643
0
    dstctx->propq = NULL;
644
645
0
    if (srcctx->dsa != NULL && !DSA_up_ref(srcctx->dsa))
646
0
        goto err;
647
0
    dstctx->dsa = srcctx->dsa;
648
649
0
    if (srcctx->md != NULL && !EVP_MD_up_ref(srcctx->md))
650
0
        goto err;
651
0
    dstctx->md = srcctx->md;
652
653
0
    if (srcctx->mdctx != NULL) {
654
0
        dstctx->mdctx = EVP_MD_CTX_new();
655
0
        if (dstctx->mdctx == NULL
656
0
                || !EVP_MD_CTX_copy_ex(dstctx->mdctx, srcctx->mdctx))
657
0
            goto err;
658
0
    }
659
660
0
    if (srcctx->propq != NULL) {
661
0
        dstctx->propq = OPENSSL_strdup(srcctx->propq);
662
0
        if (dstctx->propq == NULL)
663
0
            goto err;
664
0
    }
665
666
0
    return dstctx;
667
0
 err:
668
0
    dsa_freectx(dstctx);
669
0
    return NULL;
670
0
}
671
672
struct dsa_all_set_ctx_params_st {
673
    OSSL_PARAM *digest;     /* dsa_set_ctx_params */
674
    OSSL_PARAM *propq;      /* dsa_set_ctx_params */
675
#ifdef FIPS_MODULE
676
    OSSL_PARAM *ind_d;
677
    OSSL_PARAM *ind_k;
678
    OSSL_PARAM *ind_sign;
679
#endif
680
    OSSL_PARAM *nonce;
681
    OSSL_PARAM *sig;        /* dsa_sigalg_set_ctx_params */
682
};
683
684
#define dsa_set_ctx_params_st dsa_all_set_ctx_params_st
685
#define dsa_sigalg_set_ctx_params_st dsa_all_set_ctx_params_st
686
687
#include "providers/implementations/signature/dsa_sig.inc"
688
689
static int dsa_get_ctx_params(void *vpdsactx, OSSL_PARAM *params)
690
0
{
691
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
692
0
    struct dsa_get_ctx_params_st p;
693
694
0
    if (pdsactx == NULL || !dsa_get_ctx_params_decoder(params, &p))
695
0
        return 0;
696
697
0
    if (p.algid != NULL
698
0
        && !OSSL_PARAM_set_octet_string(p.algid,
699
0
                                        pdsactx->aid_len == 0 ? NULL : pdsactx->aid_buf,
700
0
                                        pdsactx->aid_len))
701
0
        return 0;
702
703
0
    if (p.digest != NULL && !OSSL_PARAM_set_utf8_string(p.digest, pdsactx->mdname))
704
0
        return 0;
705
706
0
    if (p.nonce != NULL && !OSSL_PARAM_set_uint(p.nonce, pdsactx->nonce_type))
707
0
        return 0;
708
709
0
    if (!OSSL_FIPS_IND_GET_CTX_FROM_PARAM(pdsactx, p.ind))
710
0
        return 0;
711
712
0
    return 1;
713
0
}
714
715
static const OSSL_PARAM *dsa_gettable_ctx_params(ossl_unused void *ctx,
716
                                                 ossl_unused void *provctx)
717
0
{
718
0
    return dsa_get_ctx_params_list;
719
0
}
720
721
/**
722
 * @brief Setup common params for dsa_set_ctx_params and dsa_sigalg_set_ctx_params
723
 * The caller is responsible for checking |vpdsactx| is not NULL and |params|
724
 * is not empty.
725
 */
726
static int dsa_common_set_ctx_params(PROV_DSA_CTX *pdsactx,
727
                                     const struct dsa_all_set_ctx_params_st *p)
728
0
{
729
0
    if (!OSSL_FIPS_IND_SET_CTX_FROM_PARAM(pdsactx, OSSL_FIPS_IND_SETTABLE0,
730
0
                                          p->ind_k))
731
0
        return 0;
732
0
    if (!OSSL_FIPS_IND_SET_CTX_FROM_PARAM(pdsactx, OSSL_FIPS_IND_SETTABLE1,
733
0
                                          p->ind_d))
734
0
        return 0;
735
0
    if (!OSSL_FIPS_IND_SET_CTX_FROM_PARAM(pdsactx, OSSL_FIPS_IND_SETTABLE2,
736
0
                                          p->ind_sign))
737
0
        return 0;
738
739
0
    if (p->nonce != NULL
740
0
        && !OSSL_PARAM_get_uint(p->nonce, &pdsactx->nonce_type))
741
0
        return 0;
742
0
    return 1;
743
0
}
744
745
static int dsa_set_ctx_params(void *vpdsactx, const OSSL_PARAM params[])
746
0
{
747
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
748
0
    struct dsa_all_set_ctx_params_st p;
749
0
    int ret;
750
751
0
    if (pdsactx == NULL || !dsa_set_ctx_params_decoder(params, &p))
752
0
        return 0;
753
754
0
    if ((ret = dsa_common_set_ctx_params(pdsactx, &p)) <= 0)
755
0
        return ret;
756
757
0
    if (p.digest != NULL) {
758
0
        char mdname[OSSL_MAX_NAME_SIZE] = "", *pmdname = mdname;
759
0
        char mdprops[OSSL_MAX_PROPQUERY_SIZE] = "", *pmdprops = mdprops;
760
761
0
        if (!OSSL_PARAM_get_utf8_string(p.digest, &pmdname, sizeof(mdname)))
762
0
            return 0;
763
0
        if (p.propq != NULL
764
0
            && !OSSL_PARAM_get_utf8_string(p.propq, &pmdprops, sizeof(mdprops)))
765
0
            return 0;
766
0
        if (!dsa_setup_md(pdsactx, mdname, mdprops, "DSA Set Ctx"))
767
0
            return 0;
768
0
    }
769
0
    return 1;
770
0
}
771
772
static const OSSL_PARAM settable_ctx_params_no_digest[] = {
773
    OSSL_PARAM_END
774
};
775
776
static const OSSL_PARAM *dsa_settable_ctx_params(void *vpdsactx,
777
                                                 ossl_unused void *provctx)
778
0
{
779
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
780
781
0
    if (pdsactx != NULL && !pdsactx->flag_allow_md)
782
0
        return settable_ctx_params_no_digest;
783
0
    return dsa_set_ctx_params_list;
784
0
}
785
786
static int dsa_get_ctx_md_params(void *vpdsactx, OSSL_PARAM *params)
787
0
{
788
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
789
790
0
    if (pdsactx->mdctx == NULL)
791
0
        return 0;
792
793
0
    return EVP_MD_CTX_get_params(pdsactx->mdctx, params);
794
0
}
795
796
static const OSSL_PARAM *dsa_gettable_ctx_md_params(void *vpdsactx)
797
0
{
798
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
799
800
0
    if (pdsactx->md == NULL)
801
0
        return 0;
802
803
0
    return EVP_MD_gettable_ctx_params(pdsactx->md);
804
0
}
805
806
static int dsa_set_ctx_md_params(void *vpdsactx, const OSSL_PARAM params[])
807
0
{
808
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
809
810
0
    if (pdsactx->mdctx == NULL)
811
0
        return 0;
812
813
0
    return EVP_MD_CTX_set_params(pdsactx->mdctx, params);
814
0
}
815
816
static const OSSL_PARAM *dsa_settable_ctx_md_params(void *vpdsactx)
817
0
{
818
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
819
820
0
    if (pdsactx->md == NULL)
821
0
        return 0;
822
823
0
    return EVP_MD_settable_ctx_params(pdsactx->md);
824
0
}
825
826
const OSSL_DISPATCH ossl_dsa_signature_functions[] = {
827
    { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))dsa_newctx },
828
    { OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))dsa_sign_init },
829
    { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))dsa_sign },
830
    { OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))dsa_verify_init },
831
    { OSSL_FUNC_SIGNATURE_VERIFY, (void (*)(void))dsa_verify },
832
    { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT,
833
      (void (*)(void))dsa_digest_sign_init },
834
    { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE,
835
      (void (*)(void))dsa_digest_signverify_update },
836
    { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL,
837
      (void (*)(void))dsa_digest_sign_final },
838
    { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT,
839
      (void (*)(void))dsa_digest_verify_init },
840
    { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE,
841
      (void (*)(void))dsa_digest_signverify_update },
842
    { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL,
843
      (void (*)(void))dsa_digest_verify_final },
844
    { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))dsa_freectx },
845
    { OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))dsa_dupctx },
846
    { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void (*)(void))dsa_get_ctx_params },
847
    { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS,
848
      (void (*)(void))dsa_gettable_ctx_params },
849
    { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, (void (*)(void))dsa_set_ctx_params },
850
    { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS,
851
      (void (*)(void))dsa_settable_ctx_params },
852
    { OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS,
853
      (void (*)(void))dsa_get_ctx_md_params },
854
    { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS,
855
      (void (*)(void))dsa_gettable_ctx_md_params },
856
    { OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS,
857
      (void (*)(void))dsa_set_ctx_md_params },
858
    { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS,
859
      (void (*)(void))dsa_settable_ctx_md_params },
860
    OSSL_DISPATCH_END
861
};
862
863
/* ------------------------------------------------------------------ */
864
865
/*
866
 * So called sigalgs (composite DSA+hash) implemented below.  They
867
 * are pretty much hard coded.
868
 */
869
870
static OSSL_FUNC_signature_query_key_types_fn dsa_sigalg_query_key_types;
871
static OSSL_FUNC_signature_settable_ctx_params_fn dsa_sigalg_settable_ctx_params;
872
static OSSL_FUNC_signature_set_ctx_params_fn dsa_sigalg_set_ctx_params;
873
874
/*
875
 * dsa_sigalg_signverify_init() is almost like dsa_digest_signverify_init(),
876
 * just doesn't allow fetching an MD from whatever the user chooses.
877
 */
878
static int dsa_sigalg_signverify_init(void *vpdsactx, void *vdsa,
879
                                      OSSL_FUNC_signature_set_ctx_params_fn *set_ctx_params,
880
                                      const OSSL_PARAM params[],
881
                                      const char *mdname,
882
                                      int operation, const char *desc)
883
0
{
884
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
885
886
0
    if (!ossl_prov_is_running())
887
0
        return 0;
888
889
0
    if (!dsa_signverify_init(vpdsactx, vdsa, set_ctx_params, params, operation,
890
0
                             desc))
891
0
        return 0;
892
893
0
    if (!dsa_setup_md(pdsactx, mdname, NULL, desc))
894
0
        return 0;
895
896
0
    pdsactx->flag_sigalg = 1;
897
0
    pdsactx->flag_allow_md = 0;
898
899
0
    if (pdsactx->mdctx == NULL) {
900
0
        pdsactx->mdctx = EVP_MD_CTX_new();
901
0
        if (pdsactx->mdctx == NULL)
902
0
            goto error;
903
0
    }
904
905
0
    if (!EVP_DigestInit_ex2(pdsactx->mdctx, pdsactx->md, params))
906
0
        goto error;
907
908
0
    return 1;
909
910
0
 error:
911
0
    EVP_MD_CTX_free(pdsactx->mdctx);
912
0
    pdsactx->mdctx = NULL;
913
0
    return 0;
914
0
}
915
916
static const char **dsa_sigalg_query_key_types(void)
917
0
{
918
0
    static const char *keytypes[] = { "DSA", NULL };
919
920
0
    return keytypes;
921
0
}
922
923
static const OSSL_PARAM *dsa_sigalg_settable_ctx_params(void *vpdsactx,
924
                                                        ossl_unused void *provctx)
925
0
{
926
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
927
928
0
    if (pdsactx != NULL && pdsactx->operation == EVP_PKEY_OP_VERIFYMSG)
929
0
        return dsa_sigalg_set_ctx_params_list;
930
0
    return NULL;
931
0
}
932
933
static int dsa_sigalg_set_ctx_params(void *vpdsactx, const OSSL_PARAM params[])
934
0
{
935
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
936
0
    struct dsa_all_set_ctx_params_st p;
937
0
    int ret;
938
939
0
    if (pdsactx == NULL || !dsa_sigalg_set_ctx_params_decoder(params, &p))
940
0
        return 0;
941
942
0
    if ((ret = dsa_common_set_ctx_params(pdsactx, &p)) <= 0)
943
0
        return ret;
944
945
0
    if (pdsactx->operation == EVP_PKEY_OP_VERIFYMSG) {
946
0
        if (p.sig != NULL) {
947
0
            OPENSSL_free(pdsactx->sig);
948
0
            pdsactx->sig = NULL;
949
0
            pdsactx->siglen = 0;
950
0
            if (!OSSL_PARAM_get_octet_string(p.sig, (void **)&pdsactx->sig,
951
0
                                             0, &pdsactx->siglen))
952
0
                return 0;
953
0
        }
954
0
    }
955
0
    return 1;
956
0
}
957
958
#define IMPL_DSA_SIGALG(md, MD)                                         \
959
    static OSSL_FUNC_signature_sign_init_fn dsa_##md##_sign_init;       \
960
    static OSSL_FUNC_signature_sign_message_init_fn                     \
961
        dsa_##md##_sign_message_init;                                   \
962
    static OSSL_FUNC_signature_verify_init_fn dsa_##md##_verify_init;   \
963
    static OSSL_FUNC_signature_verify_message_init_fn                   \
964
        dsa_##md##_verify_message_init;                                 \
965
                                                                        \
966
    static int                                                          \
967
    dsa_##md##_sign_init(void *vpdsactx, void *vdsa,                    \
968
                         const OSSL_PARAM params[])                     \
969
0
    {                                                                   \
970
0
        static const char desc[] = "DSA-" MD " Sign Init";             \
971
0
                                                                        \
972
0
        return dsa_sigalg_signverify_init(vpdsactx, vdsa,               \
973
0
                                          dsa_sigalg_set_ctx_params,    \
974
0
                                          params, MD,                  \
975
0
                                          EVP_PKEY_OP_SIGN,             \
976
0
                                          desc);                        \
977
0
    }                                                                   \
Unexecuted instantiation: dsa_sig.c:dsa_sha1_sign_init
Unexecuted instantiation: dsa_sig.c:dsa_sha224_sign_init
Unexecuted instantiation: dsa_sig.c:dsa_sha256_sign_init
Unexecuted instantiation: dsa_sig.c:dsa_sha384_sign_init
Unexecuted instantiation: dsa_sig.c:dsa_sha512_sign_init
Unexecuted instantiation: dsa_sig.c:dsa_sha3_224_sign_init
Unexecuted instantiation: dsa_sig.c:dsa_sha3_256_sign_init
Unexecuted instantiation: dsa_sig.c:dsa_sha3_384_sign_init
Unexecuted instantiation: dsa_sig.c:dsa_sha3_512_sign_init
978
                                                                        \
979
    static int                                                          \
980
    dsa_##md##_sign_message_init(void *vpdsactx, void *vdsa,            \
981
                                 const OSSL_PARAM params[])             \
982
0
    {                                                                   \
983
0
        static const char desc[] = "DSA-" MD " Sign Message Init";     \
984
0
                                                                        \
985
0
        return dsa_sigalg_signverify_init(vpdsactx, vdsa,               \
986
0
                                          dsa_sigalg_set_ctx_params,    \
987
0
                                          params, MD,                  \
988
0
                                          EVP_PKEY_OP_SIGNMSG,          \
989
0
                                          desc);                        \
990
0
    }                                                                   \
Unexecuted instantiation: dsa_sig.c:dsa_sha1_sign_message_init
Unexecuted instantiation: dsa_sig.c:dsa_sha224_sign_message_init
Unexecuted instantiation: dsa_sig.c:dsa_sha256_sign_message_init
Unexecuted instantiation: dsa_sig.c:dsa_sha384_sign_message_init
Unexecuted instantiation: dsa_sig.c:dsa_sha512_sign_message_init
Unexecuted instantiation: dsa_sig.c:dsa_sha3_224_sign_message_init
Unexecuted instantiation: dsa_sig.c:dsa_sha3_256_sign_message_init
Unexecuted instantiation: dsa_sig.c:dsa_sha3_384_sign_message_init
Unexecuted instantiation: dsa_sig.c:dsa_sha3_512_sign_message_init
991
                                                                        \
992
    static int                                                          \
993
    dsa_##md##_verify_init(void *vpdsactx, void *vdsa,                  \
994
                           const OSSL_PARAM params[])                   \
995
0
    {                                                                   \
996
0
        static const char desc[] = "DSA-" MD " Verify Init";           \
997
0
                                                                        \
998
0
        return dsa_sigalg_signverify_init(vpdsactx, vdsa,               \
999
0
                                          dsa_sigalg_set_ctx_params,    \
1000
0
                                          params, MD,                  \
1001
0
                                          EVP_PKEY_OP_VERIFY,           \
1002
0
                                          desc);                        \
1003
0
    }                                                                   \
Unexecuted instantiation: dsa_sig.c:dsa_sha1_verify_init
Unexecuted instantiation: dsa_sig.c:dsa_sha224_verify_init
Unexecuted instantiation: dsa_sig.c:dsa_sha256_verify_init
Unexecuted instantiation: dsa_sig.c:dsa_sha384_verify_init
Unexecuted instantiation: dsa_sig.c:dsa_sha512_verify_init
Unexecuted instantiation: dsa_sig.c:dsa_sha3_224_verify_init
Unexecuted instantiation: dsa_sig.c:dsa_sha3_256_verify_init
Unexecuted instantiation: dsa_sig.c:dsa_sha3_384_verify_init
Unexecuted instantiation: dsa_sig.c:dsa_sha3_512_verify_init
1004
                                                                        \
1005
    static int                                                          \
1006
    dsa_##md##_verify_message_init(void *vpdsactx, void *vdsa,          \
1007
                                   const OSSL_PARAM params[])           \
1008
0
    {                                                                   \
1009
0
        static const char desc[] = "DSA-" MD " Verify Message Init";   \
1010
0
                                                                        \
1011
0
        return dsa_sigalg_signverify_init(vpdsactx, vdsa,               \
1012
0
                                          dsa_sigalg_set_ctx_params,    \
1013
0
                                          params, MD,                  \
1014
0
                                          EVP_PKEY_OP_VERIFYMSG,        \
1015
0
                                          desc);                        \
1016
0
    }                                                                   \
Unexecuted instantiation: dsa_sig.c:dsa_sha1_verify_message_init
Unexecuted instantiation: dsa_sig.c:dsa_sha224_verify_message_init
Unexecuted instantiation: dsa_sig.c:dsa_sha256_verify_message_init
Unexecuted instantiation: dsa_sig.c:dsa_sha384_verify_message_init
Unexecuted instantiation: dsa_sig.c:dsa_sha512_verify_message_init
Unexecuted instantiation: dsa_sig.c:dsa_sha3_224_verify_message_init
Unexecuted instantiation: dsa_sig.c:dsa_sha3_256_verify_message_init
Unexecuted instantiation: dsa_sig.c:dsa_sha3_384_verify_message_init
Unexecuted instantiation: dsa_sig.c:dsa_sha3_512_verify_message_init
1017
                                                                        \
1018
    const OSSL_DISPATCH ossl_dsa_##md##_signature_functions[] = {       \
1019
        { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))dsa_newctx },     \
1020
        { OSSL_FUNC_SIGNATURE_SIGN_INIT,                                \
1021
          (void (*)(void))dsa_##md##_sign_init },                       \
1022
        { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))dsa_sign },         \
1023
        { OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_INIT,                        \
1024
          (void (*)(void))dsa_##md##_sign_message_init },               \
1025
        { OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_UPDATE,                      \
1026
          (void (*)(void))dsa_signverify_message_update },              \
1027
        { OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_FINAL,                       \
1028
          (void (*)(void))dsa_sign_message_final },                     \
1029
        { OSSL_FUNC_SIGNATURE_VERIFY_INIT,                              \
1030
          (void (*)(void))dsa_##md##_verify_init },                     \
1031
        { OSSL_FUNC_SIGNATURE_VERIFY,                                   \
1032
          (void (*)(void))dsa_verify },                                 \
1033
        { OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_INIT,                      \
1034
          (void (*)(void))dsa_##md##_verify_message_init },             \
1035
        { OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_UPDATE,                    \
1036
          (void (*)(void))dsa_signverify_message_update },              \
1037
        { OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_FINAL,                     \
1038
          (void (*)(void))dsa_verify_message_final },                   \
1039
        { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))dsa_freectx },   \
1040
        { OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))dsa_dupctx },     \
1041
        { OSSL_FUNC_SIGNATURE_QUERY_KEY_TYPES,                          \
1042
          (void (*)(void))dsa_sigalg_query_key_types },                 \
1043
        { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS,                           \
1044
          (void (*)(void))dsa_get_ctx_params },                         \
1045
        { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS,                      \
1046
          (void (*)(void))dsa_gettable_ctx_params },                    \
1047
        { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS,                           \
1048
          (void (*)(void))dsa_sigalg_set_ctx_params },                  \
1049
        { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS,                      \
1050
          (void (*)(void))dsa_sigalg_settable_ctx_params },             \
1051
        OSSL_DISPATCH_END                                               \
1052
    }
1053
1054
IMPL_DSA_SIGALG(sha1, "SHA1");
1055
IMPL_DSA_SIGALG(sha224, "SHA2-224");
1056
IMPL_DSA_SIGALG(sha256, "SHA2-256");
1057
IMPL_DSA_SIGALG(sha384, "SHA2-384");
1058
IMPL_DSA_SIGALG(sha512, "SHA2-512");
1059
IMPL_DSA_SIGALG(sha3_224, "SHA3-224");
1060
IMPL_DSA_SIGALG(sha3_256, "SHA3-256");
1061
IMPL_DSA_SIGALG(sha3_384, "SHA3-384");
1062
IMPL_DSA_SIGALG(sha3_512, "SHA3-512");