Coverage Report

Created: 2025-04-22 06:18

/src/openssl/crypto/dsa/dsa_meth.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2016-2020 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 "dsa_local.h"
17
#include <string.h>
18
#include <openssl/err.h>
19
20
#ifndef OPENSSL_NO_DEPRECATED_3_0
21
DSA_METHOD *DSA_meth_new(const char *name, int flags)
22
0
{
23
0
    DSA_METHOD *dsam = OPENSSL_zalloc(sizeof(*dsam));
24
25
0
    if (dsam != NULL) {
26
0
        dsam->flags = flags;
27
28
0
        dsam->name = OPENSSL_strdup(name);
29
0
        if (dsam->name != NULL)
30
0
            return dsam;
31
32
0
        OPENSSL_free(dsam);
33
0
    }
34
35
0
    ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE);
36
0
    return NULL;
37
0
}
38
39
void DSA_meth_free(DSA_METHOD *dsam)
40
0
{
41
0
    if (dsam != NULL) {
42
0
        OPENSSL_free(dsam->name);
43
0
        OPENSSL_free(dsam);
44
0
    }
45
0
}
46
47
DSA_METHOD *DSA_meth_dup(const DSA_METHOD *dsam)
48
0
{
49
0
    DSA_METHOD *ret = OPENSSL_malloc(sizeof(*ret));
50
51
0
    if (ret != NULL) {
52
0
        memcpy(ret, dsam, sizeof(*dsam));
53
54
0
        ret->name = OPENSSL_strdup(dsam->name);
55
0
        if (ret->name != NULL)
56
0
            return ret;
57
58
0
        OPENSSL_free(ret);
59
0
    }
60
61
0
    ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE);
62
0
    return NULL;
63
0
}
64
65
const char *DSA_meth_get0_name(const DSA_METHOD *dsam)
66
0
{
67
0
    return dsam->name;
68
0
}
69
70
int DSA_meth_set1_name(DSA_METHOD *dsam, const char *name)
71
0
{
72
0
    char *tmpname = OPENSSL_strdup(name);
73
74
0
    if (tmpname == NULL) {
75
0
        ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE);
76
0
        return 0;
77
0
    }
78
79
0
    OPENSSL_free(dsam->name);
80
0
    dsam->name = tmpname;
81
82
0
    return 1;
83
0
}
84
85
int DSA_meth_get_flags(const DSA_METHOD *dsam)
86
0
{
87
0
    return dsam->flags;
88
0
}
89
90
int DSA_meth_set_flags(DSA_METHOD *dsam, int flags)
91
0
{
92
0
    dsam->flags = flags;
93
0
    return 1;
94
0
}
95
96
void *DSA_meth_get0_app_data(const DSA_METHOD *dsam)
97
0
{
98
0
    return dsam->app_data;
99
0
}
100
101
int DSA_meth_set0_app_data(DSA_METHOD *dsam, void *app_data)
102
0
{
103
0
    dsam->app_data = app_data;
104
0
    return 1;
105
0
}
106
107
DSA_SIG *(*DSA_meth_get_sign(const DSA_METHOD *dsam))
108
        (const unsigned char *, int, DSA *)
109
0
{
110
0
    return dsam->dsa_do_sign;
111
0
}
112
113
int DSA_meth_set_sign(DSA_METHOD *dsam,
114
                       DSA_SIG *(*sign) (const unsigned char *, int, DSA *))
115
0
{
116
0
    dsam->dsa_do_sign = sign;
117
0
    return 1;
118
0
}
119
120
int (*DSA_meth_get_sign_setup(const DSA_METHOD *dsam))
121
        (DSA *, BN_CTX *, BIGNUM **, BIGNUM **)
122
0
{
123
0
    return dsam->dsa_sign_setup;
124
0
}
125
126
int DSA_meth_set_sign_setup(DSA_METHOD *dsam,
127
        int (*sign_setup) (DSA *, BN_CTX *, BIGNUM **, BIGNUM **))
128
0
{
129
0
    dsam->dsa_sign_setup = sign_setup;
130
0
    return 1;
131
0
}
132
133
int (*DSA_meth_get_verify(const DSA_METHOD *dsam))
134
        (const unsigned char *, int, DSA_SIG *, DSA *)
135
0
{
136
0
    return dsam->dsa_do_verify;
137
0
}
138
139
int DSA_meth_set_verify(DSA_METHOD *dsam,
140
    int (*verify) (const unsigned char *, int, DSA_SIG *, DSA *))
141
0
{
142
0
    dsam->dsa_do_verify = verify;
143
0
    return 1;
144
0
}
145
146
int (*DSA_meth_get_mod_exp(const DSA_METHOD *dsam))
147
        (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
148
         const BIGNUM *, const BIGNUM *, BN_CTX *, BN_MONT_CTX *)
149
0
{
150
0
    return dsam->dsa_mod_exp;
151
0
}
152
153
int DSA_meth_set_mod_exp(DSA_METHOD *dsam,
154
    int (*mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *,
155
                    const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *,
156
                    BN_MONT_CTX *))
157
0
{
158
0
    dsam->dsa_mod_exp = mod_exp;
159
0
    return 1;
160
0
}
161
162
int (*DSA_meth_get_bn_mod_exp(const DSA_METHOD *dsam))
163
    (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *,
164
     BN_MONT_CTX *)
165
0
{
166
0
    return dsam->bn_mod_exp;
167
0
}
168
169
int DSA_meth_set_bn_mod_exp(DSA_METHOD *dsam,
170
    int (*bn_mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *,
171
                       const BIGNUM *, BN_CTX *, BN_MONT_CTX *))
172
0
{
173
0
    dsam->bn_mod_exp = bn_mod_exp;
174
0
    return 1;
175
0
}
176
177
int (*DSA_meth_get_init(const DSA_METHOD *dsam))(DSA *)
178
0
{
179
0
    return dsam->init;
180
0
}
181
182
int DSA_meth_set_init(DSA_METHOD *dsam, int (*init)(DSA *))
183
0
{
184
0
    dsam->init = init;
185
0
    return 1;
186
0
}
187
188
int (*DSA_meth_get_finish(const DSA_METHOD *dsam)) (DSA *)
189
0
{
190
0
    return dsam->finish;
191
0
}
192
193
int DSA_meth_set_finish(DSA_METHOD *dsam, int (*finish) (DSA *))
194
0
{
195
0
    dsam->finish = finish;
196
0
    return 1;
197
0
}
198
199
int (*DSA_meth_get_paramgen(const DSA_METHOD *dsam))
200
        (DSA *, int, const unsigned char *, int, int *, unsigned long *,
201
         BN_GENCB *)
202
0
{
203
0
    return dsam->dsa_paramgen;
204
0
}
205
206
int DSA_meth_set_paramgen(DSA_METHOD *dsam,
207
        int (*paramgen) (DSA *, int, const unsigned char *, int, int *,
208
                         unsigned long *, BN_GENCB *))
209
0
{
210
0
    dsam->dsa_paramgen = paramgen;
211
0
    return 1;
212
0
}
213
214
int (*DSA_meth_get_keygen(const DSA_METHOD *dsam)) (DSA *)
215
0
{
216
0
    return dsam->dsa_keygen;
217
0
}
218
219
int DSA_meth_set_keygen(DSA_METHOD *dsam, int (*keygen) (DSA *))
220
0
{
221
0
    dsam->dsa_keygen = keygen;
222
0
    return 1;
223
0
}
224
#endif