Coverage Report

Created: 2025-12-31 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl34/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
2.47k
{
117
2.47k
    int md_size;
118
119
2.47k
    if (pdsactx->md != NULL) {
120
2.47k
        md_size = EVP_MD_get_size(pdsactx->md);
121
2.47k
        if (md_size <= 0)
122
0
            return 0;
123
2.47k
        return (size_t)md_size;
124
2.47k
    }
125
0
    return 0;
126
2.47k
}
127
128
static void *dsa_newctx(void *provctx, const char *propq)
129
3.26k
{
130
3.26k
    PROV_DSA_CTX *pdsactx;
131
132
3.26k
    if (!ossl_prov_is_running())
133
0
        return NULL;
134
135
3.26k
    pdsactx = OPENSSL_zalloc(sizeof(PROV_DSA_CTX));
136
3.26k
    if (pdsactx == NULL)
137
0
        return NULL;
138
139
3.26k
    pdsactx->libctx = PROV_LIBCTX_OF(provctx);
140
3.26k
    pdsactx->flag_allow_md = 1;
141
3.26k
    OSSL_FIPS_IND_INIT(pdsactx)
142
3.26k
    if (propq != NULL && (pdsactx->propq = OPENSSL_strdup(propq)) == NULL) {
143
0
        OPENSSL_free(pdsactx);
144
0
        pdsactx = NULL;
145
0
    }
146
3.26k
    return pdsactx;
147
3.26k
}
148
149
static int dsa_setup_md(PROV_DSA_CTX *ctx,
150
    const char *mdname, const char *mdprops,
151
    const char *desc)
152
2.47k
{
153
2.47k
    EVP_MD *md = NULL;
154
155
2.47k
    if (mdprops == NULL)
156
2.47k
        mdprops = ctx->propq;
157
158
2.47k
    if (mdname != NULL) {
159
2.47k
        WPACKET pkt;
160
2.47k
        int md_nid;
161
2.47k
        size_t mdname_len = strlen(mdname);
162
2.47k
        unsigned char *aid = NULL;
163
164
2.47k
        md = EVP_MD_fetch(ctx->libctx, mdname, mdprops);
165
2.47k
        md_nid = ossl_digest_get_approved_nid(md);
166
167
2.47k
        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
2.47k
        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
2.47k
        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
2.47k
        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))
192
                    == 0);
193
194
            if (!ossl_fips_ind_digest_sign_check(OSSL_FIPS_IND_GET(ctx),
195
                    OSSL_FIPS_IND_SETTABLE1,
196
                    ctx->libctx,
197
                    md_nid, sha1_allowed, desc,
198
                    ossl_fips_config_signature_digest_check))
199
                goto err;
200
        }
201
#endif
202
203
2.47k
        if (!ctx->flag_allow_md) {
204
0
            if (ctx->mdname[0] != '\0'
205
0
                && !EVP_MD_is_a(md, ctx->mdname)) {
206
0
                ERR_raise_data(ERR_LIB_PROV, PROV_R_DIGEST_NOT_ALLOWED,
207
0
                    "digest %s != %s", mdname, ctx->mdname);
208
0
                goto err;
209
0
            }
210
0
            EVP_MD_free(md);
211
0
            return 1;
212
0
        }
213
214
2.47k
        EVP_MD_CTX_free(ctx->mdctx);
215
2.47k
        EVP_MD_free(ctx->md);
216
217
        /*
218
         * We do not care about DER writing errors.
219
         * All it really means is that for some reason, there's no
220
         * AlgorithmIdentifier to be had, but the operation itself is
221
         * still valid, just as long as it's not used to construct
222
         * anything that needs an AlgorithmIdentifier.
223
         */
224
2.47k
        ctx->aid_len = 0;
225
2.47k
        if (WPACKET_init_der(&pkt, ctx->aid_buf, sizeof(ctx->aid_buf))
226
2.47k
            && ossl_DER_w_algorithmIdentifier_DSA_with_MD(&pkt, -1, ctx->dsa,
227
2.47k
                md_nid)
228
2.47k
            && WPACKET_finish(&pkt)) {
229
2.47k
            WPACKET_get_total_written(&pkt, &ctx->aid_len);
230
2.47k
            aid = WPACKET_get_curr(&pkt);
231
2.47k
        }
232
2.47k
        WPACKET_cleanup(&pkt);
233
2.47k
        if (aid != NULL && ctx->aid_len != 0)
234
2.47k
            memmove(ctx->aid_buf, aid, ctx->aid_len);
235
236
2.47k
        ctx->mdctx = NULL;
237
2.47k
        ctx->md = md;
238
2.47k
        OPENSSL_strlcpy(ctx->mdname, mdname, sizeof(ctx->mdname));
239
2.47k
    }
240
241
2.47k
    return 1;
242
0
err:
243
0
    EVP_MD_free(md);
244
0
    return 0;
245
2.47k
}
246
247
#ifdef FIPS_MODULE
248
249
static int dsa_sign_check_approved(PROV_DSA_CTX *ctx, int signing,
250
    const char *desc)
251
{
252
    /* DSA Signing is not approved in FIPS 140-3 */
253
    if (signing
254
        && !OSSL_FIPS_IND_ON_UNAPPROVED(ctx, OSSL_FIPS_IND_SETTABLE2,
255
            ctx->libctx, desc, "DSA",
256
            ossl_fips_config_dsa_sign_disallowed))
257
        return 0;
258
    return 1;
259
}
260
261
static int dsa_check_key(PROV_DSA_CTX *ctx, int sign, const char *desc)
262
{
263
    int approved = ossl_dsa_check_key(ctx->dsa, sign);
264
265
    if (!approved) {
266
        if (!OSSL_FIPS_IND_ON_UNAPPROVED(ctx, OSSL_FIPS_IND_SETTABLE0,
267
                ctx->libctx, desc, "DSA Key",
268
                ossl_fips_config_signature_digest_check)) {
269
            ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
270
            return 0;
271
        }
272
    }
273
    return 1;
274
}
275
#endif
276
277
static int
278
dsa_signverify_init(void *vpdsactx, void *vdsa,
279
    OSSL_FUNC_signature_set_ctx_params_fn *set_ctx_params,
280
    const OSSL_PARAM params[], int operation,
281
    const char *desc)
282
2.47k
{
283
2.47k
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
284
285
2.47k
    if (!ossl_prov_is_running()
286
2.47k
        || pdsactx == NULL)
287
0
        return 0;
288
289
2.47k
    if (vdsa == NULL && pdsactx->dsa == NULL) {
290
0
        ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET);
291
0
        return 0;
292
0
    }
293
294
2.47k
    if (vdsa != NULL) {
295
2.47k
        if (!DSA_up_ref(vdsa))
296
0
            return 0;
297
2.47k
        DSA_free(pdsactx->dsa);
298
2.47k
        pdsactx->dsa = vdsa;
299
2.47k
    }
300
301
2.47k
    pdsactx->operation = operation;
302
303
2.47k
    OSSL_FIPS_IND_SET_APPROVED(pdsactx)
304
2.47k
    if (!set_ctx_params(pdsactx, params))
305
0
        return 0;
306
#ifdef FIPS_MODULE
307
    {
308
        int operation_is_sign
309
            = (operation & (EVP_PKEY_OP_SIGN | EVP_PKEY_OP_SIGNMSG)) != 0;
310
311
        if (!dsa_sign_check_approved(pdsactx, operation_is_sign, desc))
312
            return 0;
313
        if (!dsa_check_key(pdsactx, operation_is_sign, desc))
314
            return 0;
315
    }
316
#endif
317
2.47k
    return 1;
318
2.47k
}
319
320
static int dsa_sign_init(void *vpdsactx, void *vdsa, const OSSL_PARAM params[])
321
0
{
322
0
    return dsa_signverify_init(vpdsactx, vdsa, dsa_set_ctx_params, params,
323
0
        EVP_PKEY_OP_SIGN, "DSA Sign Init");
324
0
}
325
326
/*
327
 * Sign tbs without digesting it first.  This is suitable for "primitive"
328
 * signing and signing the digest of a message, i.e. should be used with
329
 * implementations of the keytype related algorithms.
330
 */
331
static int dsa_sign_directly(void *vpdsactx,
332
    unsigned char *sig, size_t *siglen, size_t sigsize,
333
    const unsigned char *tbs, size_t tbslen)
334
0
{
335
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
336
0
    int ret;
337
0
    unsigned int sltmp;
338
0
    size_t dsasize = DSA_size(pdsactx->dsa);
339
0
    size_t mdsize = dsa_get_md_size(pdsactx);
340
341
0
    if (!ossl_prov_is_running())
342
0
        return 0;
343
344
#ifdef FIPS_MODULE
345
    if (!dsa_sign_check_approved(pdsactx, 1, "Sign"))
346
        return 0;
347
#endif
348
349
0
    if (sig == NULL) {
350
0
        *siglen = dsasize;
351
0
        return 1;
352
0
    }
353
354
0
    if (sigsize < dsasize)
355
0
        return 0;
356
357
0
    if (mdsize != 0 && tbslen != mdsize)
358
0
        return 0;
359
360
0
    ret = ossl_dsa_sign_int(0, tbs, tbslen, sig, &sltmp, pdsactx->dsa,
361
0
        pdsactx->nonce_type, pdsactx->mdname,
362
0
        pdsactx->libctx, pdsactx->propq);
363
0
    if (ret <= 0)
364
0
        return 0;
365
366
0
    *siglen = sltmp;
367
0
    return 1;
368
0
}
369
370
static int dsa_signverify_message_update(void *vpdsactx,
371
    const unsigned char *data,
372
    size_t datalen)
373
2.47k
{
374
2.47k
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
375
376
2.47k
    if (pdsactx == NULL)
377
0
        return 0;
378
379
2.47k
    return EVP_DigestUpdate(pdsactx->mdctx, data, datalen);
380
2.47k
}
381
382
static int dsa_sign_message_final(void *vpdsactx, unsigned char *sig,
383
    size_t *siglen, size_t sigsize)
384
0
{
385
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
386
0
    unsigned char digest[EVP_MAX_MD_SIZE];
387
0
    unsigned int dlen = 0;
388
389
0
    if (!ossl_prov_is_running() || pdsactx == NULL || pdsactx->mdctx == NULL)
390
0
        return 0;
391
    /*
392
     * If sig is NULL then we're just finding out the sig size. Other fields
393
     * are ignored. Defer to dsa_sign.
394
     */
395
0
    if (sig != NULL) {
396
        /*
397
         * When this function is used through dsa_digest_sign_final(),
398
         * there is the possibility that some externally provided digests
399
         * exceed EVP_MAX_MD_SIZE. We should probably handle that
400
         * somehow but that problem is much larger than just in DSA.
401
         */
402
0
        if (!EVP_DigestFinal_ex(pdsactx->mdctx, digest, &dlen))
403
0
            return 0;
404
0
    }
405
406
0
    return dsa_sign_directly(vpdsactx, sig, siglen, sigsize, digest, dlen);
407
0
}
408
409
/*
410
 * If signing a message, digest tbs and sign the result.
411
 * Otherwise, sign tbs directly.
412
 */
413
static int dsa_sign(void *vpdsactx, unsigned char *sig, size_t *siglen,
414
    size_t sigsize, const unsigned char *tbs, size_t tbslen)
415
0
{
416
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
417
418
0
    if (pdsactx->operation == EVP_PKEY_OP_SIGNMSG) {
419
        /*
420
         * If |sig| is NULL, the caller is only looking for the sig length.
421
         * DO NOT update the input in this case.
422
         */
423
0
        if (sig == NULL)
424
0
            return dsa_sign_message_final(pdsactx, sig, siglen, sigsize);
425
426
0
        if (dsa_signverify_message_update(pdsactx, tbs, tbslen) <= 0)
427
0
            return 0;
428
0
        return dsa_sign_message_final(pdsactx, sig, siglen, sigsize);
429
0
    }
430
0
    return dsa_sign_directly(pdsactx, sig, siglen, sigsize, tbs, tbslen);
431
0
}
432
433
static int dsa_verify_init(void *vpdsactx, void *vdsa,
434
    const OSSL_PARAM params[])
435
0
{
436
0
    return dsa_signverify_init(vpdsactx, vdsa, dsa_set_ctx_params, params,
437
0
        EVP_PKEY_OP_VERIFY, "DSA Verify Init");
438
0
}
439
440
static int dsa_verify_directly(void *vpdsactx,
441
    const unsigned char *sig, size_t siglen,
442
    const unsigned char *tbs, size_t tbslen)
443
2.47k
{
444
2.47k
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
445
2.47k
    size_t mdsize = dsa_get_md_size(pdsactx);
446
447
2.47k
    if (!ossl_prov_is_running() || (mdsize != 0 && tbslen != mdsize))
448
0
        return 0;
449
450
2.47k
    return DSA_verify(0, tbs, tbslen, sig, siglen, pdsactx->dsa);
451
2.47k
}
452
453
static int dsa_verify_set_sig(void *vpdsactx,
454
    const unsigned char *sig, size_t siglen)
455
2.47k
{
456
2.47k
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
457
2.47k
    OSSL_PARAM params[2];
458
459
2.47k
    params[0] = OSSL_PARAM_construct_octet_string(OSSL_SIGNATURE_PARAM_SIGNATURE,
460
2.47k
        (unsigned char *)sig, siglen);
461
2.47k
    params[1] = OSSL_PARAM_construct_end();
462
2.47k
    return dsa_sigalg_set_ctx_params(pdsactx, params);
463
2.47k
}
464
465
static int dsa_verify_message_final(void *vpdsactx)
466
2.47k
{
467
2.47k
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
468
2.47k
    unsigned char digest[EVP_MAX_MD_SIZE];
469
2.47k
    unsigned int dlen = 0;
470
471
2.47k
    if (!ossl_prov_is_running())
472
0
        return 0;
473
474
2.47k
    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
2.47k
    if (!EVP_DigestFinal_ex(pdsactx->mdctx, digest, &dlen))
482
0
        return 0;
483
484
2.47k
    return dsa_verify_directly(vpdsactx, pdsactx->sig, pdsactx->siglen,
485
2.47k
        digest, dlen);
486
2.47k
}
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
2.47k
{
514
2.47k
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
515
516
2.47k
    if (!ossl_prov_is_running())
517
0
        return 0;
518
519
2.47k
    if (!dsa_signverify_init(vpdsactx, vdsa, dsa_set_ctx_params, params,
520
2.47k
            operation, desc))
521
0
        return 0;
522
523
2.47k
    if (mdname != NULL
524
        /* was dsa_setup_md already called in dsa_signverify_init()? */
525
2.47k
        && (mdname[0] == '\0' || OPENSSL_strcasecmp(pdsactx->mdname, mdname) != 0)
526
2.47k
        && !dsa_setup_md(pdsactx, mdname, NULL, desc))
527
0
        return 0;
528
529
2.47k
    pdsactx->flag_allow_md = 0;
530
531
2.47k
    if (pdsactx->mdctx == NULL) {
532
2.47k
        pdsactx->mdctx = EVP_MD_CTX_new();
533
2.47k
        if (pdsactx->mdctx == NULL)
534
0
            goto error;
535
2.47k
    }
536
537
2.47k
    if (!EVP_DigestInit_ex2(pdsactx->mdctx, pdsactx->md, params))
538
0
        goto error;
539
540
2.47k
    return 1;
541
542
0
error:
543
0
    EVP_MD_CTX_free(pdsactx->mdctx);
544
0
    pdsactx->mdctx = NULL;
545
0
    return 0;
546
2.47k
}
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
2.47k
{
559
2.47k
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
560
561
2.47k
    if (pdsactx == NULL)
562
0
        return 0;
563
    /* Sigalg implementations shouldn't do digest_sign */
564
2.47k
    if (pdsactx->flag_sigalg)
565
0
        return 0;
566
567
2.47k
    return dsa_signverify_message_update(vpdsactx, data, datalen);
568
2.47k
}
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
3.26k
{
592
3.26k
    return dsa_digest_signverify_init(vpdsactx, mdname, vdsa, params,
593
3.26k
        EVP_PKEY_OP_VERIFYMSG,
594
3.26k
        "DSA Digest Verify Init");
595
3.26k
}
596
597
int dsa_digest_verify_final(void *vpdsactx, const unsigned char *sig,
598
    size_t siglen)
599
2.47k
{
600
2.47k
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
601
2.47k
    int ok = 0;
602
603
2.47k
    if (pdsactx == NULL)
604
0
        return 0;
605
    /* Sigalg implementations shouldn't do digest_verify */
606
2.47k
    if (pdsactx->flag_sigalg)
607
0
        return 0;
608
609
2.47k
    if (dsa_verify_set_sig(pdsactx, sig, siglen))
610
2.47k
        ok = dsa_verify_message_final(vpdsactx);
611
612
2.47k
    pdsactx->flag_allow_md = 1;
613
614
2.47k
    return ok;
615
2.47k
}
616
617
static void dsa_freectx(void *vpdsactx)
618
6.53k
{
619
6.53k
    PROV_DSA_CTX *ctx = (PROV_DSA_CTX *)vpdsactx;
620
621
6.53k
    EVP_MD_CTX_free(ctx->mdctx);
622
6.53k
    EVP_MD_free(ctx->md);
623
6.53k
    OPENSSL_free(ctx->sig);
624
6.53k
    OPENSSL_free(ctx->propq);
625
6.53k
    DSA_free(ctx->dsa);
626
6.53k
    OPENSSL_free(ctx);
627
6.53k
}
628
629
static void *dsa_dupctx(void *vpdsactx)
630
3.26k
{
631
3.26k
    PROV_DSA_CTX *srcctx = (PROV_DSA_CTX *)vpdsactx;
632
3.26k
    PROV_DSA_CTX *dstctx;
633
634
3.26k
    if (!ossl_prov_is_running())
635
0
        return NULL;
636
637
3.26k
    dstctx = OPENSSL_zalloc(sizeof(*srcctx));
638
3.26k
    if (dstctx == NULL)
639
0
        return NULL;
640
641
3.26k
    *dstctx = *srcctx;
642
3.26k
    dstctx->dsa = NULL;
643
3.26k
    dstctx->propq = NULL;
644
645
3.26k
    if (srcctx->dsa != NULL && !DSA_up_ref(srcctx->dsa))
646
0
        goto err;
647
3.26k
    dstctx->dsa = srcctx->dsa;
648
649
3.26k
    if (srcctx->md != NULL && !EVP_MD_up_ref(srcctx->md))
650
0
        goto err;
651
3.26k
    dstctx->md = srcctx->md;
652
653
3.26k
    if (srcctx->mdctx != NULL) {
654
3.26k
        dstctx->mdctx = EVP_MD_CTX_new();
655
3.26k
        if (dstctx->mdctx == NULL
656
3.26k
            || !EVP_MD_CTX_copy_ex(dstctx->mdctx, srcctx->mdctx))
657
0
            goto err;
658
3.26k
    }
659
660
3.26k
    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
3.26k
    return dstctx;
667
0
err:
668
0
    dsa_freectx(dstctx);
669
0
    return NULL;
670
3.26k
}
671
672
static int dsa_get_ctx_params(void *vpdsactx, OSSL_PARAM *params)
673
0
{
674
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
675
0
    OSSL_PARAM *p;
676
677
0
    if (pdsactx == NULL)
678
0
        return 0;
679
680
0
    p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
681
0
    if (p != NULL
682
0
        && !OSSL_PARAM_set_octet_string(p,
683
0
            pdsactx->aid_len == 0 ? NULL : pdsactx->aid_buf,
684
0
            pdsactx->aid_len))
685
0
        return 0;
686
687
0
    p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST);
688
0
    if (p != NULL && !OSSL_PARAM_set_utf8_string(p, pdsactx->mdname))
689
0
        return 0;
690
691
0
    p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_NONCE_TYPE);
692
0
    if (p != NULL && !OSSL_PARAM_set_uint(p, pdsactx->nonce_type))
693
0
        return 0;
694
0
    if (!OSSL_FIPS_IND_GET_CTX_PARAM(pdsactx, params))
695
0
        return 0;
696
697
0
    return 1;
698
0
}
699
700
static const OSSL_PARAM known_gettable_ctx_params[] = {
701
    OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_ALGORITHM_ID, NULL, 0),
702
    OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
703
    OSSL_PARAM_uint(OSSL_SIGNATURE_PARAM_NONCE_TYPE, NULL),
704
    OSSL_FIPS_IND_GETTABLE_CTX_PARAM()
705
        OSSL_PARAM_END
706
};
707
708
static const OSSL_PARAM *dsa_gettable_ctx_params(ossl_unused void *ctx,
709
    ossl_unused void *provctx)
710
0
{
711
0
    return known_gettable_ctx_params;
712
0
}
713
714
/* The common params for dsa_set_ctx_params and dsa_sigalg_set_ctx_params */
715
static int dsa_common_set_ctx_params(void *vpdsactx, const OSSL_PARAM params[])
716
864
{
717
864
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
718
864
    const OSSL_PARAM *p;
719
720
864
    if (pdsactx == NULL)
721
0
        return 0;
722
864
    if (params == NULL)
723
432
        return 1;
724
725
432
    if (!OSSL_FIPS_IND_SET_CTX_PARAM(pdsactx, OSSL_FIPS_IND_SETTABLE0, params,
726
432
            OSSL_SIGNATURE_PARAM_FIPS_KEY_CHECK))
727
0
        return 0;
728
432
    if (!OSSL_FIPS_IND_SET_CTX_PARAM(pdsactx, OSSL_FIPS_IND_SETTABLE1, params,
729
432
            OSSL_SIGNATURE_PARAM_FIPS_DIGEST_CHECK))
730
0
        return 0;
731
432
    if (!OSSL_FIPS_IND_SET_CTX_PARAM(pdsactx, OSSL_FIPS_IND_SETTABLE2, params,
732
432
            OSSL_SIGNATURE_PARAM_FIPS_SIGN_CHECK))
733
0
        return 0;
734
735
432
    p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_NONCE_TYPE);
736
432
    if (p != NULL
737
0
        && !OSSL_PARAM_get_uint(p, &pdsactx->nonce_type))
738
0
        return 0;
739
432
    return 1;
740
432
}
741
742
#define DSA_COMMON_SETTABLE_CTX_PARAMS                                                 \
743
    OSSL_PARAM_uint(OSSL_SIGNATURE_PARAM_NONCE_TYPE, NULL),                            \
744
        OSSL_FIPS_IND_SETTABLE_CTX_PARAM(OSSL_SIGNATURE_PARAM_FIPS_KEY_CHECK)          \
745
            OSSL_FIPS_IND_SETTABLE_CTX_PARAM(OSSL_SIGNATURE_PARAM_FIPS_DIGEST_CHECK)   \
746
                OSSL_FIPS_IND_SETTABLE_CTX_PARAM(OSSL_SIGNATURE_PARAM_FIPS_SIGN_CHECK) \
747
                    OSSL_PARAM_END
748
749
static int dsa_set_ctx_params(void *vpdsactx, const OSSL_PARAM params[])
750
432
{
751
432
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
752
432
    const OSSL_PARAM *p;
753
432
    int ret;
754
755
432
    if ((ret = dsa_common_set_ctx_params(pdsactx, params)) <= 0)
756
0
        return ret;
757
758
432
    if (params == NULL)
759
432
        return 1;
760
761
0
    p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST);
762
0
    if (p != NULL) {
763
0
        char mdname[OSSL_MAX_NAME_SIZE] = "", *pmdname = mdname;
764
0
        char mdprops[OSSL_MAX_PROPQUERY_SIZE] = "", *pmdprops = mdprops;
765
0
        const OSSL_PARAM *propsp = OSSL_PARAM_locate_const(params,
766
0
            OSSL_SIGNATURE_PARAM_PROPERTIES);
767
768
0
        if (!OSSL_PARAM_get_utf8_string(p, &pmdname, sizeof(mdname)))
769
0
            return 0;
770
0
        if (propsp != NULL
771
0
            && !OSSL_PARAM_get_utf8_string(propsp, &pmdprops, sizeof(mdprops)))
772
0
            return 0;
773
0
        if (!dsa_setup_md(pdsactx, mdname, mdprops, "DSA Set Ctx"))
774
0
            return 0;
775
0
    }
776
0
    return 1;
777
0
}
778
779
static const OSSL_PARAM settable_ctx_params[] = {
780
    OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
781
    OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_PROPERTIES, NULL, 0),
782
    DSA_COMMON_SETTABLE_CTX_PARAMS
783
};
784
785
static const OSSL_PARAM settable_ctx_params_no_digest[] = {
786
    OSSL_PARAM_END
787
};
788
789
static const OSSL_PARAM *dsa_settable_ctx_params(void *vpdsactx,
790
    ossl_unused void *provctx)
791
7
{
792
7
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
793
794
7
    if (pdsactx != NULL && !pdsactx->flag_allow_md)
795
0
        return settable_ctx_params_no_digest;
796
7
    return settable_ctx_params;
797
7
}
798
799
static int dsa_get_ctx_md_params(void *vpdsactx, OSSL_PARAM *params)
800
0
{
801
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
802
803
0
    if (pdsactx->mdctx == NULL)
804
0
        return 0;
805
806
0
    return EVP_MD_CTX_get_params(pdsactx->mdctx, params);
807
0
}
808
809
static const OSSL_PARAM *dsa_gettable_ctx_md_params(void *vpdsactx)
810
0
{
811
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
812
813
0
    if (pdsactx->md == NULL)
814
0
        return 0;
815
816
0
    return EVP_MD_gettable_ctx_params(pdsactx->md);
817
0
}
818
819
static int dsa_set_ctx_md_params(void *vpdsactx, const OSSL_PARAM params[])
820
0
{
821
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
822
823
0
    if (pdsactx->mdctx == NULL)
824
0
        return 0;
825
826
0
    return EVP_MD_CTX_set_params(pdsactx->mdctx, params);
827
0
}
828
829
static const OSSL_PARAM *dsa_settable_ctx_md_params(void *vpdsactx)
830
0
{
831
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
832
833
0
    if (pdsactx->md == NULL)
834
0
        return 0;
835
836
0
    return EVP_MD_settable_ctx_params(pdsactx->md);
837
0
}
838
839
const OSSL_DISPATCH ossl_dsa_signature_functions[] = {
840
    { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))dsa_newctx },
841
    { OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))dsa_sign_init },
842
    { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))dsa_sign },
843
    { OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))dsa_verify_init },
844
    { OSSL_FUNC_SIGNATURE_VERIFY, (void (*)(void))dsa_verify },
845
    { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT,
846
        (void (*)(void))dsa_digest_sign_init },
847
    { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE,
848
        (void (*)(void))dsa_digest_signverify_update },
849
    { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL,
850
        (void (*)(void))dsa_digest_sign_final },
851
    { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT,
852
        (void (*)(void))dsa_digest_verify_init },
853
    { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE,
854
        (void (*)(void))dsa_digest_signverify_update },
855
    { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL,
856
        (void (*)(void))dsa_digest_verify_final },
857
    { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))dsa_freectx },
858
    { OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))dsa_dupctx },
859
    { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void (*)(void))dsa_get_ctx_params },
860
    { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS,
861
        (void (*)(void))dsa_gettable_ctx_params },
862
    { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, (void (*)(void))dsa_set_ctx_params },
863
    { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS,
864
        (void (*)(void))dsa_settable_ctx_params },
865
    { OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS,
866
        (void (*)(void))dsa_get_ctx_md_params },
867
    { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS,
868
        (void (*)(void))dsa_gettable_ctx_md_params },
869
    { OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS,
870
        (void (*)(void))dsa_set_ctx_md_params },
871
    { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS,
872
        (void (*)(void))dsa_settable_ctx_md_params },
873
    OSSL_DISPATCH_END
874
};
875
876
/* ------------------------------------------------------------------ */
877
878
/*
879
 * So called sigalgs (composite DSA+hash) implemented below.  They
880
 * are pretty much hard coded.
881
 */
882
883
static OSSL_FUNC_signature_query_key_types_fn dsa_sigalg_query_key_types;
884
static OSSL_FUNC_signature_settable_ctx_params_fn dsa_sigalg_settable_ctx_params;
885
static OSSL_FUNC_signature_set_ctx_params_fn dsa_sigalg_set_ctx_params;
886
887
/*
888
 * dsa_sigalg_signverify_init() is almost like dsa_digest_signverify_init(),
889
 * just doesn't allow fetching an MD from whatever the user chooses.
890
 */
891
static int dsa_sigalg_signverify_init(void *vpdsactx, void *vdsa,
892
    OSSL_FUNC_signature_set_ctx_params_fn *set_ctx_params,
893
    const OSSL_PARAM params[],
894
    const char *mdname,
895
    int operation, const char *desc)
896
0
{
897
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
898
899
0
    if (!ossl_prov_is_running())
900
0
        return 0;
901
902
0
    if (!dsa_signverify_init(vpdsactx, vdsa, set_ctx_params, params, operation,
903
0
            desc))
904
0
        return 0;
905
906
0
    if (!dsa_setup_md(pdsactx, mdname, NULL, desc))
907
0
        return 0;
908
909
0
    pdsactx->flag_sigalg = 1;
910
0
    pdsactx->flag_allow_md = 0;
911
912
0
    if (pdsactx->mdctx == NULL) {
913
0
        pdsactx->mdctx = EVP_MD_CTX_new();
914
0
        if (pdsactx->mdctx == NULL)
915
0
            goto error;
916
0
    }
917
918
0
    if (!EVP_DigestInit_ex2(pdsactx->mdctx, pdsactx->md, params))
919
0
        goto error;
920
921
0
    return 1;
922
923
0
error:
924
0
    EVP_MD_CTX_free(pdsactx->mdctx);
925
0
    pdsactx->mdctx = NULL;
926
0
    return 0;
927
0
}
928
929
static const char **dsa_sigalg_query_key_types(void)
930
0
{
931
0
    static const char *keytypes[] = { "DSA", NULL };
932
933
0
    return keytypes;
934
0
}
935
936
static const OSSL_PARAM settable_sigalg_ctx_params[] = {
937
    OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_SIGNATURE, NULL, 0),
938
    DSA_COMMON_SETTABLE_CTX_PARAMS
939
};
940
941
static const OSSL_PARAM *dsa_sigalg_settable_ctx_params(void *vpdsactx,
942
    ossl_unused void *provctx)
943
4
{
944
4
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
945
946
4
    if (pdsactx != NULL && pdsactx->operation == EVP_PKEY_OP_VERIFYMSG)
947
0
        return settable_sigalg_ctx_params;
948
4
    return NULL;
949
4
}
950
951
static int dsa_sigalg_set_ctx_params(void *vpdsactx, const OSSL_PARAM params[])
952
432
{
953
432
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
954
432
    const OSSL_PARAM *p;
955
432
    int ret;
956
957
432
    if ((ret = dsa_common_set_ctx_params(pdsactx, params)) <= 0)
958
0
        return ret;
959
960
432
    if (params == NULL)
961
0
        return 1;
962
963
432
    if (pdsactx->operation == EVP_PKEY_OP_VERIFYMSG) {
964
432
        p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_SIGNATURE);
965
432
        if (p != NULL) {
966
432
            OPENSSL_free(pdsactx->sig);
967
432
            pdsactx->sig = NULL;
968
432
            pdsactx->siglen = 0;
969
432
            if (!OSSL_PARAM_get_octet_string(p, (void **)&pdsactx->sig,
970
432
                    0, &pdsactx->siglen))
971
0
                return 0;
972
432
        }
973
432
    }
974
432
    return 1;
975
432
}
976
977
#define IMPL_DSA_SIGALG(md, MD)                                       \
978
    static OSSL_FUNC_signature_sign_init_fn dsa_##md##_sign_init;     \
979
    static OSSL_FUNC_signature_sign_message_init_fn                   \
980
        dsa_##md##_sign_message_init;                                 \
981
    static OSSL_FUNC_signature_verify_init_fn dsa_##md##_verify_init; \
982
    static OSSL_FUNC_signature_verify_message_init_fn                 \
983
        dsa_##md##_verify_message_init;                               \
984
                                                                      \
985
    static int                                                        \
986
    dsa_##md##_sign_init(void *vpdsactx, void *vdsa,                  \
987
        const OSSL_PARAM params[])                                    \
988
0
    {                                                                 \
989
0
        static const char desc[] = "DSA-" #MD " Sign Init";           \
990
0
                                                                      \
991
0
        return dsa_sigalg_signverify_init(vpdsactx, vdsa,             \
992
0
            dsa_sigalg_set_ctx_params,                                \
993
0
            params, #MD,                                              \
994
0
            EVP_PKEY_OP_SIGN,                                         \
995
0
            desc);                                                    \
996
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
997
                                                                      \
998
    static int                                                        \
999
    dsa_##md##_sign_message_init(void *vpdsactx, void *vdsa,          \
1000
        const OSSL_PARAM params[])                                    \
1001
0
    {                                                                 \
1002
0
        static const char desc[] = "DSA-" #MD " Sign Message Init";   \
1003
0
                                                                      \
1004
0
        return dsa_sigalg_signverify_init(vpdsactx, vdsa,             \
1005
0
            dsa_sigalg_set_ctx_params,                                \
1006
0
            params, #MD,                                              \
1007
0
            EVP_PKEY_OP_SIGNMSG,                                      \
1008
0
            desc);                                                    \
1009
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
1010
                                                                      \
1011
    static int                                                        \
1012
    dsa_##md##_verify_init(void *vpdsactx, void *vdsa,                \
1013
        const OSSL_PARAM params[])                                    \
1014
0
    {                                                                 \
1015
0
        static const char desc[] = "DSA-" #MD " Verify Init";         \
1016
0
                                                                      \
1017
0
        return dsa_sigalg_signverify_init(vpdsactx, vdsa,             \
1018
0
            dsa_sigalg_set_ctx_params,                                \
1019
0
            params, #MD,                                              \
1020
0
            EVP_PKEY_OP_VERIFY,                                       \
1021
0
            desc);                                                    \
1022
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
1023
                                                                      \
1024
    static int                                                        \
1025
    dsa_##md##_verify_message_init(void *vpdsactx, void *vdsa,        \
1026
        const OSSL_PARAM params[])                                    \
1027
0
    {                                                                 \
1028
0
        static const char desc[] = "DSA-" #MD " Verify Message Init"; \
1029
0
                                                                      \
1030
0
        return dsa_sigalg_signverify_init(vpdsactx, vdsa,             \
1031
0
            dsa_sigalg_set_ctx_params,                                \
1032
0
            params, #MD,                                              \
1033
0
            EVP_PKEY_OP_VERIFYMSG,                                    \
1034
0
            desc);                                                    \
1035
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
1036
                                                                      \
1037
    const OSSL_DISPATCH ossl_dsa_##md##_signature_functions[] = {     \
1038
        { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))dsa_newctx },   \
1039
        { OSSL_FUNC_SIGNATURE_SIGN_INIT,                              \
1040
            (void (*)(void))dsa_##md##_sign_init },                   \
1041
        { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))dsa_sign },       \
1042
        { OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_INIT,                      \
1043
            (void (*)(void))dsa_##md##_sign_message_init },           \
1044
        { OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_UPDATE,                    \
1045
            (void (*)(void))dsa_signverify_message_update },          \
1046
        { OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_FINAL,                     \
1047
            (void (*)(void))dsa_sign_message_final },                 \
1048
        { OSSL_FUNC_SIGNATURE_VERIFY_INIT,                            \
1049
            (void (*)(void))dsa_##md##_verify_init },                 \
1050
        { OSSL_FUNC_SIGNATURE_VERIFY,                                 \
1051
            (void (*)(void))dsa_verify },                             \
1052
        { OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_INIT,                    \
1053
            (void (*)(void))dsa_##md##_verify_message_init },         \
1054
        { OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_UPDATE,                  \
1055
            (void (*)(void))dsa_signverify_message_update },          \
1056
        { OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_FINAL,                   \
1057
            (void (*)(void))dsa_verify_message_final },               \
1058
        { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))dsa_freectx }, \
1059
        { OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))dsa_dupctx },   \
1060
        { OSSL_FUNC_SIGNATURE_QUERY_KEY_TYPES,                        \
1061
            (void (*)(void))dsa_sigalg_query_key_types },             \
1062
        { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS,                         \
1063
            (void (*)(void))dsa_get_ctx_params },                     \
1064
        { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS,                    \
1065
            (void (*)(void))dsa_gettable_ctx_params },                \
1066
        { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS,                         \
1067
            (void (*)(void))dsa_sigalg_set_ctx_params },              \
1068
        { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS,                    \
1069
            (void (*)(void))dsa_sigalg_settable_ctx_params },         \
1070
        OSSL_DISPATCH_END                                             \
1071
    }
1072
1073
/* clang-format off */
1074
IMPL_DSA_SIGALG(sha1, SHA1);
1075
IMPL_DSA_SIGALG(sha224, SHA2-224);
1076
IMPL_DSA_SIGALG(sha256, SHA2-256);
1077
IMPL_DSA_SIGALG(sha384, SHA2-384);
1078
IMPL_DSA_SIGALG(sha512, SHA2-512);
1079
IMPL_DSA_SIGALG(sha3_224, SHA3-224);
1080
IMPL_DSA_SIGALG(sha3_256, SHA3-256);
1081
IMPL_DSA_SIGALG(sha3_384, SHA3-384);
1082
IMPL_DSA_SIGALG(sha3_512, SHA3-512);
1083
/* clang-format on */