Coverage Report

Created: 2025-06-13 06:56

/src/openssl/crypto/dsa/dsa_gen.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 1995-2021 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 <openssl/opensslconf.h>
17
#include <stdio.h>
18
#include "internal/cryptlib.h"
19
#include <openssl/evp.h>
20
#include <openssl/bn.h>
21
#include <openssl/rand.h>
22
#include <openssl/sha.h>
23
#include "crypto/dsa.h"
24
#include "dsa_local.h"
25
26
int ossl_dsa_generate_ffc_parameters(DSA *dsa, int type, int pbits, int qbits,
27
                                     BN_GENCB *cb)
28
0
{
29
0
    int ret = 0, res;
30
31
0
#ifndef FIPS_MODULE
32
0
    if (type == DSA_PARAMGEN_TYPE_FIPS_186_2)
33
0
        ret = ossl_ffc_params_FIPS186_2_generate(dsa->libctx, &dsa->params,
34
0
                                                 FFC_PARAM_TYPE_DSA,
35
0
                                                 pbits, qbits, &res, cb);
36
0
    else
37
0
#endif
38
0
        ret = ossl_ffc_params_FIPS186_4_generate(dsa->libctx, &dsa->params,
39
0
                                                 FFC_PARAM_TYPE_DSA,
40
0
                                                 pbits, qbits, &res, cb);
41
0
    if (ret > 0)
42
0
        dsa->dirty_cnt++;
43
0
    return ret;
44
0
}
45
46
#ifndef FIPS_MODULE
47
int DSA_generate_parameters_ex(DSA *dsa, int bits,
48
                               const unsigned char *seed_in, int seed_len,
49
                               int *counter_ret, unsigned long *h_ret,
50
                               BN_GENCB *cb)
51
0
{
52
0
    if (dsa->meth->dsa_paramgen)
53
0
        return dsa->meth->dsa_paramgen(dsa, bits, seed_in, seed_len,
54
0
                                       counter_ret, h_ret, cb);
55
0
    if (seed_in != NULL
56
0
        && !ossl_ffc_params_set_validate_params(&dsa->params, seed_in, seed_len,
57
0
                                                -1))
58
0
        return 0;
59
60
    /* The old code used FIPS 186-2 DSA Parameter generation */
61
0
    if (bits < 2048 && seed_len <= 20) {
62
0
        if (!ossl_dsa_generate_ffc_parameters(dsa, DSA_PARAMGEN_TYPE_FIPS_186_2,
63
0
                                              bits, 160, cb))
64
0
            return 0;
65
0
    } else {
66
0
        if (!ossl_dsa_generate_ffc_parameters(dsa, DSA_PARAMGEN_TYPE_FIPS_186_4,
67
0
                                              bits, 0, cb))
68
0
            return 0;
69
0
    }
70
71
0
    if (counter_ret != NULL)
72
0
        *counter_ret = dsa->params.pcounter;
73
0
    if (h_ret != NULL)
74
0
        *h_ret = dsa->params.h;
75
0
    return 1;
76
0
}
77
#endif