Coverage Report

Created: 2025-08-28 07:07

/src/openssl34/providers/implementations/signature/dsa_sig.c
Line
Count
Source (jump to first uncovered line)
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
1.57k
{
117
1.57k
    int md_size;
118
119
1.57k
    if (pdsactx->md != NULL) {
120
1.57k
        md_size = EVP_MD_get_size(pdsactx->md);
121
1.57k
        if (md_size <= 0)
122
0
            return 0;
123
1.57k
        return (size_t)md_size;
124
1.57k
    }
125
0
    return 0;
126
1.57k
}
127
128
static void *dsa_newctx(void *provctx, const char *propq)
129
2.55k
{
130
2.55k
    PROV_DSA_CTX *pdsactx;
131
132
2.55k
    if (!ossl_prov_is_running())
133
0
        return NULL;
134
135
2.55k
    pdsactx = OPENSSL_zalloc(sizeof(PROV_DSA_CTX));
136
2.55k
    if (pdsactx == NULL)
137
0
        return NULL;
138
139
2.55k
    pdsactx->libctx = PROV_LIBCTX_OF(provctx);
140
2.55k
    pdsactx->flag_allow_md = 1;
141
2.55k
    OSSL_FIPS_IND_INIT(pdsactx)
142
2.55k
    if (propq != NULL && (pdsactx->propq = OPENSSL_strdup(propq)) == NULL) {
143
0
        OPENSSL_free(pdsactx);
144
0
        pdsactx = NULL;
145
0
    }
146
2.55k
    return pdsactx;
147
2.55k
}
148
149
static int dsa_setup_md(PROV_DSA_CTX *ctx,
150
                        const char *mdname, const char *mdprops,
151
                        const char *desc)
152
1.57k
{
153
1.57k
    EVP_MD *md = NULL;
154
155
1.57k
    if (mdprops == NULL)
156
1.57k
        mdprops = ctx->propq;
157
158
1.57k
    if (mdname != NULL) {
159
1.57k
        WPACKET pkt;
160
1.57k
        int md_nid;
161
1.57k
        size_t mdname_len = strlen(mdname);
162
1.57k
        unsigned char *aid = NULL;
163
164
1.57k
        md = EVP_MD_fetch(ctx->libctx, mdname, mdprops);
165
1.57k
        md_nid = ossl_digest_get_approved_nid(md);
166
167
1.57k
        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
1.57k
        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
1.57k
        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
1.57k
        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, desc,
197
                                                 ossl_fips_config_signature_digest_check))
198
                goto err;
199
        }
200
#endif
201
202
1.57k
        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
1.57k
        EVP_MD_CTX_free(ctx->mdctx);
214
1.57k
        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
1.57k
        ctx->aid_len = 0;
224
1.57k
        if (WPACKET_init_der(&pkt, ctx->aid_buf, sizeof(ctx->aid_buf))
225
1.57k
            && ossl_DER_w_algorithmIdentifier_DSA_with_MD(&pkt, -1, ctx->dsa,
226
1.57k
                                                          md_nid)
227
1.57k
            && WPACKET_finish(&pkt)) {
228
1.57k
            WPACKET_get_total_written(&pkt, &ctx->aid_len);
229
1.57k
            aid = WPACKET_get_curr(&pkt);
230
1.57k
        }
231
1.57k
        WPACKET_cleanup(&pkt);
232
1.57k
        if (aid != NULL && ctx->aid_len != 0)
233
1.57k
            memmove(ctx->aid_buf, aid, ctx->aid_len);
234
235
1.57k
        ctx->mdctx = NULL;
236
1.57k
        ctx->md = md;
237
1.57k
        OPENSSL_strlcpy(ctx->mdname, mdname, sizeof(ctx->mdname));
238
1.57k
    }
239
240
1.57k
    return 1;
241
0
 err:
242
0
    EVP_MD_free(md);
243
0
    return 0;
244
1.57k
}
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
1.57k
{
282
1.57k
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
283
284
1.57k
    if (!ossl_prov_is_running()
285
1.57k
            || pdsactx == NULL)
286
0
        return 0;
287
288
1.57k
    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
1.57k
    if (vdsa != NULL) {
294
1.57k
        if (!DSA_up_ref(vdsa))
295
0
            return 0;
296
1.57k
        DSA_free(pdsactx->dsa);
297
1.57k
        pdsactx->dsa = vdsa;
298
1.57k
    }
299
300
1.57k
    pdsactx->operation = operation;
301
302
1.57k
    OSSL_FIPS_IND_SET_APPROVED(pdsactx)
303
1.57k
    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
1.57k
    return 1;
317
1.57k
}
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, 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
1.57k
{
373
1.57k
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
374
375
1.57k
    if (pdsactx == NULL)
376
0
        return 0;
377
378
1.57k
    return EVP_DigestUpdate(pdsactx->mdctx, data, datalen);
379
1.57k
}
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
1.57k
{
443
1.57k
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
444
1.57k
    size_t mdsize = dsa_get_md_size(pdsactx);
445
446
1.57k
    if (!ossl_prov_is_running() || (mdsize != 0 && tbslen != mdsize))
447
0
        return 0;
448
449
1.57k
    return DSA_verify(0, tbs, tbslen, sig, siglen, pdsactx->dsa);
450
1.57k
}
451
452
static int dsa_verify_set_sig(void *vpdsactx,
453
                              const unsigned char *sig, size_t siglen)
454
1.57k
{
455
1.57k
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
456
1.57k
    OSSL_PARAM params[2];
457
458
1.57k
    params[0] =
459
1.57k
        OSSL_PARAM_construct_octet_string(OSSL_SIGNATURE_PARAM_SIGNATURE,
460
1.57k
                                          (unsigned char *)sig, siglen);
461
1.57k
    params[1] = OSSL_PARAM_construct_end();
462
1.57k
    return dsa_sigalg_set_ctx_params(pdsactx, params);
463
1.57k
}
464
465
static int dsa_verify_message_final(void *vpdsactx)
466
1.57k
{
467
1.57k
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
468
1.57k
    unsigned char digest[EVP_MAX_MD_SIZE];
469
1.57k
    unsigned int dlen = 0;
470
471
1.57k
    if (!ossl_prov_is_running())
472
0
        return 0;
473
474
1.57k
    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
1.57k
    if (!EVP_DigestFinal_ex(pdsactx->mdctx, digest, &dlen))
482
0
        return 0;
483
484
1.57k
    return dsa_verify_directly(vpdsactx, pdsactx->sig, pdsactx->siglen,
485
1.57k
                               digest, dlen);
486
1.57k
}
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
1.57k
{
514
1.57k
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
515
516
1.57k
    if (!ossl_prov_is_running())
517
0
        return 0;
518
519
1.57k
    if (!dsa_signverify_init(vpdsactx, vdsa, dsa_set_ctx_params, params,
520
1.57k
                             operation, desc))
521
0
        return 0;
522
523
1.57k
    if (mdname != NULL
524
        /* was dsa_setup_md already called in dsa_signverify_init()? */
525
1.57k
        && (mdname[0] == '\0' || OPENSSL_strcasecmp(pdsactx->mdname, mdname) != 0)
526
1.57k
        && !dsa_setup_md(pdsactx, mdname, NULL, desc))
527
0
        return 0;
528
529
1.57k
    pdsactx->flag_allow_md = 0;
530
531
1.57k
    if (pdsactx->mdctx == NULL) {
532
1.57k
        pdsactx->mdctx = EVP_MD_CTX_new();
533
1.57k
        if (pdsactx->mdctx == NULL)
534
0
            goto error;
535
1.57k
    }
536
537
1.57k
    if (!EVP_DigestInit_ex2(pdsactx->mdctx, pdsactx->md, params))
538
0
        goto error;
539
540
1.57k
    return 1;
541
542
0
 error:
543
0
    EVP_MD_CTX_free(pdsactx->mdctx);
544
0
    pdsactx->mdctx = NULL;
545
0
    return 0;
546
1.57k
}
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
1.57k
{
559
1.57k
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
560
561
1.57k
    if (pdsactx == NULL)
562
0
        return 0;
563
    /* Sigalg implementations shouldn't do digest_sign */
564
1.57k
    if (pdsactx->flag_sigalg)
565
0
        return 0;
566
567
1.57k
    return dsa_signverify_message_update(vpdsactx, data, datalen);
568
1.57k
}
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
2.55k
{
592
2.55k
    return dsa_digest_signverify_init(vpdsactx, mdname, vdsa, params,
593
2.55k
                                      EVP_PKEY_OP_VERIFYMSG,
594
2.55k
                                      "DSA Digest Verify Init");
595
2.55k
}
596
597
int dsa_digest_verify_final(void *vpdsactx, const unsigned char *sig,
598
                            size_t siglen)
599
1.57k
{
600
1.57k
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
601
1.57k
    int ok = 0;
602
603
1.57k
    if (pdsactx == NULL)
604
0
        return 0;
605
    /* Sigalg implementations shouldn't do digest_verify */
606
1.57k
    if (pdsactx->flag_sigalg)
607
0
        return 0;
608
609
1.57k
    if (dsa_verify_set_sig(pdsactx, sig, siglen))
610
1.57k
        ok = dsa_verify_message_final(vpdsactx);
611
612
1.57k
    pdsactx->flag_allow_md = 1;
613
614
1.57k
    return ok;
615
1.57k
}
616
617
static void dsa_freectx(void *vpdsactx)
618
5.11k
{
619
5.11k
    PROV_DSA_CTX *ctx = (PROV_DSA_CTX *)vpdsactx;
620
621
5.11k
    EVP_MD_CTX_free(ctx->mdctx);
622
5.11k
    EVP_MD_free(ctx->md);
623
5.11k
    OPENSSL_free(ctx->sig);
624
5.11k
    OPENSSL_free(ctx->propq);
625
5.11k
    DSA_free(ctx->dsa);
626
5.11k
    OPENSSL_free(ctx);
627
5.11k
}
628
629
static void *dsa_dupctx(void *vpdsactx)
630
2.55k
{
631
2.55k
    PROV_DSA_CTX *srcctx = (PROV_DSA_CTX *)vpdsactx;
632
2.55k
    PROV_DSA_CTX *dstctx;
633
634
2.55k
    if (!ossl_prov_is_running())
635
0
        return NULL;
636
637
2.55k
    dstctx = OPENSSL_zalloc(sizeof(*srcctx));
638
2.55k
    if (dstctx == NULL)
639
0
        return NULL;
640
641
2.55k
    *dstctx = *srcctx;
642
2.55k
    dstctx->dsa = NULL;
643
2.55k
    dstctx->propq = NULL;
644
645
2.55k
    if (srcctx->dsa != NULL && !DSA_up_ref(srcctx->dsa))
646
0
        goto err;
647
2.55k
    dstctx->dsa = srcctx->dsa;
648
649
2.55k
    if (srcctx->md != NULL && !EVP_MD_up_ref(srcctx->md))
650
0
        goto err;
651
2.55k
    dstctx->md = srcctx->md;
652
653
2.55k
    if (srcctx->mdctx != NULL) {
654
2.55k
        dstctx->mdctx = EVP_MD_CTX_new();
655
2.55k
        if (dstctx->mdctx == NULL
656
2.55k
                || !EVP_MD_CTX_copy_ex(dstctx->mdctx, srcctx->mdctx))
657
0
            goto err;
658
2.55k
    }
659
660
2.55k
    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
2.55k
    return dstctx;
667
0
 err:
668
0
    dsa_freectx(dstctx);
669
0
    return NULL;
670
2.55k
}
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
836
{
717
836
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
718
836
    const OSSL_PARAM *p;
719
720
836
    if (pdsactx == NULL)
721
0
        return 0;
722
836
    if (params == NULL)
723
418
        return 1;
724
725
418
    if (!OSSL_FIPS_IND_SET_CTX_PARAM(pdsactx, OSSL_FIPS_IND_SETTABLE0, params,
726
418
                                     OSSL_SIGNATURE_PARAM_FIPS_KEY_CHECK))
727
0
        return 0;
728
418
    if (!OSSL_FIPS_IND_SET_CTX_PARAM(pdsactx, OSSL_FIPS_IND_SETTABLE1, params,
729
418
                                     OSSL_SIGNATURE_PARAM_FIPS_DIGEST_CHECK))
730
0
        return 0;
731
418
    if (!OSSL_FIPS_IND_SET_CTX_PARAM(pdsactx, OSSL_FIPS_IND_SETTABLE2, params,
732
418
                                     OSSL_SIGNATURE_PARAM_FIPS_SIGN_CHECK))
733
0
        return 0;
734
735
418
    p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_NONCE_TYPE);
736
418
    if (p != NULL
737
418
        && !OSSL_PARAM_get_uint(p, &pdsactx->nonce_type))
738
0
        return 0;
739
418
    return 1;
740
418
}
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
418
{
751
418
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
752
418
    const OSSL_PARAM *p;
753
418
    int ret;
754
755
418
    if ((ret = dsa_common_set_ctx_params(pdsactx, params)) <= 0)
756
0
        return ret;
757
758
418
    if (params == NULL)
759
418
        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 =
766
0
            OSSL_PARAM_locate_const(params,
767
0
                                    OSSL_SIGNATURE_PARAM_PROPERTIES);
768
769
0
        if (!OSSL_PARAM_get_utf8_string(p, &pmdname, sizeof(mdname)))
770
0
            return 0;
771
0
        if (propsp != NULL
772
0
            && !OSSL_PARAM_get_utf8_string(propsp, &pmdprops, sizeof(mdprops)))
773
0
            return 0;
774
0
        if (!dsa_setup_md(pdsactx, mdname, mdprops, "DSA Set Ctx"))
775
0
            return 0;
776
0
    }
777
0
    return 1;
778
0
}
779
780
static const OSSL_PARAM settable_ctx_params[] = {
781
    OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
782
    OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_PROPERTIES, NULL, 0),
783
    DSA_COMMON_SETTABLE_CTX_PARAMS
784
};
785
786
static const OSSL_PARAM settable_ctx_params_no_digest[] = {
787
    OSSL_PARAM_END
788
};
789
790
static const OSSL_PARAM *dsa_settable_ctx_params(void *vpdsactx,
791
                                                 ossl_unused void *provctx)
792
3
{
793
3
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
794
795
3
    if (pdsactx != NULL && !pdsactx->flag_allow_md)
796
0
        return settable_ctx_params_no_digest;
797
3
    return settable_ctx_params;
798
3
}
799
800
static int dsa_get_ctx_md_params(void *vpdsactx, OSSL_PARAM *params)
801
0
{
802
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
803
804
0
    if (pdsactx->mdctx == NULL)
805
0
        return 0;
806
807
0
    return EVP_MD_CTX_get_params(pdsactx->mdctx, params);
808
0
}
809
810
static const OSSL_PARAM *dsa_gettable_ctx_md_params(void *vpdsactx)
811
0
{
812
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
813
814
0
    if (pdsactx->md == NULL)
815
0
        return 0;
816
817
0
    return EVP_MD_gettable_ctx_params(pdsactx->md);
818
0
}
819
820
static int dsa_set_ctx_md_params(void *vpdsactx, const OSSL_PARAM params[])
821
0
{
822
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
823
824
0
    if (pdsactx->mdctx == NULL)
825
0
        return 0;
826
827
0
    return EVP_MD_CTX_set_params(pdsactx->mdctx, params);
828
0
}
829
830
static const OSSL_PARAM *dsa_settable_ctx_md_params(void *vpdsactx)
831
0
{
832
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
833
834
0
    if (pdsactx->md == NULL)
835
0
        return 0;
836
837
0
    return EVP_MD_settable_ctx_params(pdsactx->md);
838
0
}
839
840
const OSSL_DISPATCH ossl_dsa_signature_functions[] = {
841
    { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))dsa_newctx },
842
    { OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))dsa_sign_init },
843
    { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))dsa_sign },
844
    { OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))dsa_verify_init },
845
    { OSSL_FUNC_SIGNATURE_VERIFY, (void (*)(void))dsa_verify },
846
    { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT,
847
      (void (*)(void))dsa_digest_sign_init },
848
    { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE,
849
      (void (*)(void))dsa_digest_signverify_update },
850
    { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL,
851
      (void (*)(void))dsa_digest_sign_final },
852
    { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT,
853
      (void (*)(void))dsa_digest_verify_init },
854
    { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE,
855
      (void (*)(void))dsa_digest_signverify_update },
856
    { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL,
857
      (void (*)(void))dsa_digest_verify_final },
858
    { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))dsa_freectx },
859
    { OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))dsa_dupctx },
860
    { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void (*)(void))dsa_get_ctx_params },
861
    { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS,
862
      (void (*)(void))dsa_gettable_ctx_params },
863
    { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, (void (*)(void))dsa_set_ctx_params },
864
    { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS,
865
      (void (*)(void))dsa_settable_ctx_params },
866
    { OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS,
867
      (void (*)(void))dsa_get_ctx_md_params },
868
    { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS,
869
      (void (*)(void))dsa_gettable_ctx_md_params },
870
    { OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS,
871
      (void (*)(void))dsa_set_ctx_md_params },
872
    { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS,
873
      (void (*)(void))dsa_settable_ctx_md_params },
874
    OSSL_DISPATCH_END
875
};
876
877
/* ------------------------------------------------------------------ */
878
879
/*
880
 * So called sigalgs (composite DSA+hash) implemented below.  They
881
 * are pretty much hard coded.
882
 */
883
884
static OSSL_FUNC_signature_query_key_types_fn dsa_sigalg_query_key_types;
885
static OSSL_FUNC_signature_settable_ctx_params_fn dsa_sigalg_settable_ctx_params;
886
static OSSL_FUNC_signature_set_ctx_params_fn dsa_sigalg_set_ctx_params;
887
888
/*
889
 * dsa_sigalg_signverify_init() is almost like dsa_digest_signverify_init(),
890
 * just doesn't allow fetching an MD from whatever the user chooses.
891
 */
892
static int dsa_sigalg_signverify_init(void *vpdsactx, void *vdsa,
893
                                      OSSL_FUNC_signature_set_ctx_params_fn *set_ctx_params,
894
                                      const OSSL_PARAM params[],
895
                                      const char *mdname,
896
                                      int operation, const char *desc)
897
0
{
898
0
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
899
900
0
    if (!ossl_prov_is_running())
901
0
        return 0;
902
903
0
    if (!dsa_signverify_init(vpdsactx, vdsa, set_ctx_params, params, operation,
904
0
                             desc))
905
0
        return 0;
906
907
0
    if (!dsa_setup_md(pdsactx, mdname, NULL, desc))
908
0
        return 0;
909
910
0
    pdsactx->flag_sigalg = 1;
911
0
    pdsactx->flag_allow_md = 0;
912
913
0
    if (pdsactx->mdctx == NULL) {
914
0
        pdsactx->mdctx = EVP_MD_CTX_new();
915
0
        if (pdsactx->mdctx == NULL)
916
0
            goto error;
917
0
    }
918
919
0
    if (!EVP_DigestInit_ex2(pdsactx->mdctx, pdsactx->md, params))
920
0
        goto error;
921
922
0
    return 1;
923
924
0
 error:
925
0
    EVP_MD_CTX_free(pdsactx->mdctx);
926
0
    pdsactx->mdctx = NULL;
927
0
    return 0;
928
0
}
929
930
static const char **dsa_sigalg_query_key_types(void)
931
0
{
932
0
    static const char *keytypes[] = { "DSA", NULL };
933
934
0
    return keytypes;
935
0
}
936
937
static const OSSL_PARAM settable_sigalg_ctx_params[] = {
938
    OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_SIGNATURE, NULL, 0),
939
    DSA_COMMON_SETTABLE_CTX_PARAMS
940
};
941
942
static const OSSL_PARAM *dsa_sigalg_settable_ctx_params(void *vpdsactx,
943
                                                        ossl_unused void *provctx)
944
3
{
945
3
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
946
947
3
    if (pdsactx != NULL && pdsactx->operation == EVP_PKEY_OP_VERIFYMSG)
948
0
        return settable_sigalg_ctx_params;
949
3
    return NULL;
950
3
}
951
952
static int dsa_sigalg_set_ctx_params(void *vpdsactx, const OSSL_PARAM params[])
953
418
{
954
418
    PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
955
418
    const OSSL_PARAM *p;
956
418
    int ret;
957
958
418
    if ((ret = dsa_common_set_ctx_params(pdsactx, params)) <= 0)
959
0
        return ret;
960
961
418
    if (params == NULL)
962
0
        return 1;
963
964
418
    if (pdsactx->operation == EVP_PKEY_OP_VERIFYMSG) {
965
418
        p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_SIGNATURE);
966
418
        if (p != NULL) {
967
418
            OPENSSL_free(pdsactx->sig);
968
418
            pdsactx->sig = NULL;
969
418
            pdsactx->siglen = 0;
970
418
            if (!OSSL_PARAM_get_octet_string(p, (void **)&pdsactx->sig,
971
418
                                             0, &pdsactx->siglen))
972
0
                return 0;
973
418
        }
974
418
    }
975
418
    return 1;
976
418
}
977
978
#define IMPL_DSA_SIGALG(md, MD)                                         \
979
    static OSSL_FUNC_signature_sign_init_fn dsa_##md##_sign_init;       \
980
    static OSSL_FUNC_signature_sign_message_init_fn                     \
981
        dsa_##md##_sign_message_init;                                   \
982
    static OSSL_FUNC_signature_verify_init_fn dsa_##md##_verify_init;   \
983
    static OSSL_FUNC_signature_verify_message_init_fn                   \
984
        dsa_##md##_verify_message_init;                                 \
985
                                                                        \
986
    static int                                                          \
987
    dsa_##md##_sign_init(void *vpdsactx, void *vdsa,                    \
988
                         const OSSL_PARAM params[])                     \
989
0
    {                                                                   \
990
0
        static const char desc[] = "DSA-" #MD " Sign Init";             \
991
0
                                                                        \
992
0
        return dsa_sigalg_signverify_init(vpdsactx, vdsa,               \
993
0
                                          dsa_sigalg_set_ctx_params,    \
994
0
                                          params, #MD,                  \
995
0
                                          EVP_PKEY_OP_SIGN,             \
996
0
                                          desc);                        \
997
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
998
                                                                        \
999
    static int                                                          \
1000
    dsa_##md##_sign_message_init(void *vpdsactx, void *vdsa,            \
1001
                                 const OSSL_PARAM params[])             \
1002
0
    {                                                                   \
1003
0
        static const char desc[] = "DSA-" #MD " Sign Message Init";     \
1004
0
                                                                        \
1005
0
        return dsa_sigalg_signverify_init(vpdsactx, vdsa,               \
1006
0
                                          dsa_sigalg_set_ctx_params,    \
1007
0
                                          params, #MD,                  \
1008
0
                                          EVP_PKEY_OP_SIGNMSG,          \
1009
0
                                          desc);                        \
1010
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
1011
                                                                        \
1012
    static int                                                          \
1013
    dsa_##md##_verify_init(void *vpdsactx, void *vdsa,                  \
1014
                           const OSSL_PARAM params[])                   \
1015
0
    {                                                                   \
1016
0
        static const char desc[] = "DSA-" #MD " Verify Init";           \
1017
0
                                                                        \
1018
0
        return dsa_sigalg_signverify_init(vpdsactx, vdsa,               \
1019
0
                                          dsa_sigalg_set_ctx_params,    \
1020
0
                                          params, #MD,                  \
1021
0
                                          EVP_PKEY_OP_VERIFY,           \
1022
0
                                          desc);                        \
1023
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
1024
                                                                        \
1025
    static int                                                          \
1026
    dsa_##md##_verify_message_init(void *vpdsactx, void *vdsa,          \
1027
                                   const OSSL_PARAM params[])           \
1028
0
    {                                                                   \
1029
0
        static const char desc[] = "DSA-" #MD " Verify Message Init";   \
1030
0
                                                                        \
1031
0
        return dsa_sigalg_signverify_init(vpdsactx, vdsa,               \
1032
0
                                          dsa_sigalg_set_ctx_params,    \
1033
0
                                          params, #MD,                  \
1034
0
                                          EVP_PKEY_OP_VERIFYMSG,        \
1035
0
                                          desc);                        \
1036
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
1037
                                                                        \
1038
    const OSSL_DISPATCH ossl_dsa_##md##_signature_functions[] = {       \
1039
        { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))dsa_newctx },     \
1040
        { OSSL_FUNC_SIGNATURE_SIGN_INIT,                                \
1041
          (void (*)(void))dsa_##md##_sign_init },                       \
1042
        { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))dsa_sign },         \
1043
        { OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_INIT,                        \
1044
          (void (*)(void))dsa_##md##_sign_message_init },               \
1045
        { OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_UPDATE,                      \
1046
          (void (*)(void))dsa_signverify_message_update },              \
1047
        { OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_FINAL,                       \
1048
          (void (*)(void))dsa_sign_message_final },                     \
1049
        { OSSL_FUNC_SIGNATURE_VERIFY_INIT,                              \
1050
          (void (*)(void))dsa_##md##_verify_init },                     \
1051
        { OSSL_FUNC_SIGNATURE_VERIFY,                                   \
1052
          (void (*)(void))dsa_verify },                                 \
1053
        { OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_INIT,                      \
1054
          (void (*)(void))dsa_##md##_verify_message_init },             \
1055
        { OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_UPDATE,                    \
1056
          (void (*)(void))dsa_signverify_message_update },              \
1057
        { OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_FINAL,                     \
1058
          (void (*)(void))dsa_verify_message_final },                   \
1059
        { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))dsa_freectx },   \
1060
        { OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))dsa_dupctx },     \
1061
        { OSSL_FUNC_SIGNATURE_QUERY_KEY_TYPES,                          \
1062
          (void (*)(void))dsa_sigalg_query_key_types },                 \
1063
        { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS,                           \
1064
          (void (*)(void))dsa_get_ctx_params },                         \
1065
        { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS,                      \
1066
          (void (*)(void))dsa_gettable_ctx_params },                    \
1067
        { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS,                           \
1068
          (void (*)(void))dsa_sigalg_set_ctx_params },                  \
1069
        { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS,                      \
1070
          (void (*)(void))dsa_sigalg_settable_ctx_params },             \
1071
        OSSL_DISPATCH_END                                               \
1072
    }
1073
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);