OpenCoverage

dsa_ameth.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/dsa/dsa_ameth.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.-
3 *-
4 * Licensed under the OpenSSL license (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#include <stdio.h>-
11#include "internal/cryptlib.h"-
12#include <openssl/x509.h>-
13#include <openssl/asn1.h>-
14#include "dsa_locl.h"-
15#include <openssl/bn.h>-
16#include <openssl/cms.h>-
17#include "internal/asn1_int.h"-
18#include "internal/evp_int.h"-
19-
20static int dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)-
21{-
22 const unsigned char *p, *pm;-
23 int pklen, pmlen;-
24 int ptype;-
25 const void *pval;-
26 const ASN1_STRING *pstr;-
27 X509_ALGOR *palg;-
28 ASN1_INTEGER *public_key = NULL;-
29-
30 DSA *dsa = NULL;-
31-
32 if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, &palg, pubkey))
!X509_PUBKEY_g...&palg, pubkey)Description
TRUEnever evaluated
FALSEevaluated 4251 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4251
33 return 0;
never executed: return 0;
0
34 X509_ALGOR_get0(NULL, &ptype, &pval, palg);-
35-
36 if (ptype == V_ASN1_SEQUENCE) {
ptype == 16Description
TRUEevaluated 4122 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 129 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
129-4122
37 pstr = pval;-
38 pm = pstr->data;-
39 pmlen = pstr->length;-
40-
41 if ((dsa = d2i_DSAparams(NULL, &pm, pmlen)) == NULL) {
(dsa = d2i_DSA...== ((void *)0)Description
TRUEevaluated 1666 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2456 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1666-2456
42 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_DECODE_ERROR);-
43 goto err;
executed 1666 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
1666
44 }-
45-
46 } else if ((ptype == V_ASN1_NULL) || (ptype == V_ASN1_UNDEF)) {
executed 2456 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
(ptype == 5)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 124 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(ptype == -1)Description
TRUEevaluated 42 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 82 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5-2456
47 if ((dsa = DSA_new()) == NULL) {
(dsa = DSA_new...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 47 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-47
48 DSAerr(DSA_F_DSA_PUB_DECODE, ERR_R_MALLOC_FAILURE);-
49 goto err;
never executed: goto err;
0
50 }-
51 } else {
executed 47 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
47
52 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_PARAMETER_ENCODING_ERROR);-
53 goto err;
executed 82 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
82
54 }-
55-
56 if ((public_key = d2i_ASN1_INTEGER(NULL, &p, pklen)) == NULL) {
(public_key = ...== ((void *)0)Description
TRUEevaluated 125 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2378 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
125-2378
57 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_DECODE_ERROR);-
58 goto err;
executed 125 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
125
59 }-
60-
61 if ((dsa->pub_key = ASN1_INTEGER_to_BN(public_key, NULL)) == NULL) {
(dsa->pub_key ...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2378 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2378
62 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_BN_DECODE_ERROR);-
63 goto err;
never executed: goto err;
0
64 }-
65-
66 ASN1_INTEGER_free(public_key);-
67 EVP_PKEY_assign_DSA(pkey, dsa);-
68 return 1;
executed 2378 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2378
69-
70 err:-
71 ASN1_INTEGER_free(public_key);-
72 DSA_free(dsa);-
73 return 0;
executed 1873 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
1873
74-
75}-
76-
77static int dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)-
78{-
79 DSA *dsa;-
80 int ptype;-
81 unsigned char *penc = NULL;-
82 int penclen;-
83 ASN1_STRING *str = NULL;-
84 ASN1_INTEGER *pubint = NULL;-
85 ASN1_OBJECT *aobj;-
86-
87 dsa = pkey->pkey.dsa;-
88 if (pkey->save_parameters && dsa->p && dsa->q && dsa->g) {
pkey->save_parametersDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
dsa->pDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
dsa->qDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
dsa->gDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-18
89 str = ASN1_STRING_new();-
90 if (str == NULL) {
str == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-18
91 DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE);-
92 goto err;
never executed: goto err;
0
93 }-
94 str->length = i2d_DSAparams(dsa, &str->data);-
95 if (str->length <= 0) {
str->length <= 0Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-18
96 DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE);-
97 goto err;
never executed: goto err;
0
98 }-
99 ptype = V_ASN1_SEQUENCE;-
100 } else
executed 18 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
18
101 ptype = V_ASN1_UNDEF;
never executed: ptype = -1;
0
102-
103 pubint = BN_to_ASN1_INTEGER(dsa->pub_key, NULL);-
104-
105 if (pubint == NULL) {
pubint == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-18
106 DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE);-
107 goto err;
never executed: goto err;
0
108 }-
109-
110 penclen = i2d_ASN1_INTEGER(pubint, &penc);-
111 ASN1_INTEGER_free(pubint);-
112-
113 if (penclen <= 0) {
penclen <= 0Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-18
114 DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE);-
115 goto err;
never executed: goto err;
0
116 }-
117-
118 aobj = OBJ_nid2obj(EVP_PKEY_DSA);-
119 if (aobj == NULL)
aobj == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-18
120 goto err;
never executed: goto err;
0
121-
122 if (X509_PUBKEY_set0_param(pk, aobj, ptype, str, penc, penclen))
X509_PUBKEY_se...penc, penclen)Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-18
123 return 1;
executed 18 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
18
124-
125 err:
code before this statement never executed: err:
0
126 OPENSSL_free(penc);-
127 ASN1_STRING_free(str);-
128-
129 return 0;
never executed: return 0;
0
130}-
131-
132/*-
133 * In PKCS#8 DSA: you just get a private key integer and parameters in the-
134 * AlgorithmIdentifier the pubkey must be recalculated.-
135 */-
136-
137static int dsa_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8)-
138{-
139 const unsigned char *p, *pm;-
140 int pklen, pmlen;-
141 int ptype;-
142 const void *pval;-
143 const ASN1_STRING *pstr;-
144 const X509_ALGOR *palg;-
145 ASN1_INTEGER *privkey = NULL;-
146 BN_CTX *ctx = NULL;-
147-
148 DSA *dsa = NULL;-
149-
150 int ret = 0;-
151-
152 if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8))
!PKCS8_pkey_ge...en, &palg, p8)Description
TRUEnever evaluated
FALSEevaluated 50 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-50
153 return 0;
never executed: return 0;
0
154 X509_ALGOR_get0(NULL, &ptype, &pval, palg);-
155-
156 if ((privkey = d2i_ASN1_INTEGER(NULL, &p, pklen)) == NULL)
(privkey = d2i...== ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 49 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-49
157 goto decerr;
executed 1 time by 1 test: goto decerr;
Executed by:
  • libcrypto.so.1.1
1
158 if (privkey->type == V_ASN1_NEG_INTEGER || ptype != V_ASN1_SEQUENCE)
privkey->type == (2 | 0x100)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 48 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
ptype != 16Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 47 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-48
159 goto decerr;
executed 2 times by 1 test: goto decerr;
Executed by:
  • libcrypto.so.1.1
2
160-
161 pstr = pval;-
162 pm = pstr->data;-
163 pmlen = pstr->length;-
164 if ((dsa = d2i_DSAparams(NULL, &pm, pmlen)) == NULL)
(dsa = d2i_DSA...== ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 46 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-46
165 goto decerr;
executed 1 time by 1 test: goto decerr;
Executed by:
  • libcrypto.so.1.1
1
166 /* We have parameters now set private key */-
167 if ((dsa->priv_key = BN_secure_new()) == NULL
(dsa->priv_key...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 46 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-46
168 || !ASN1_INTEGER_to_BN(privkey, dsa->priv_key)) {
!ASN1_INTEGER_...dsa->priv_key)Description
TRUEnever evaluated
FALSEevaluated 46 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-46
169 DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_BN_ERROR);-
170 goto dsaerr;
never executed: goto dsaerr;
0
171 }-
172 /* Calculate public key */-
173 if ((dsa->pub_key = BN_new()) == NULL) {
(dsa->pub_key ...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 46 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-46
174 DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);-
175 goto dsaerr;
never executed: goto dsaerr;
0
176 }-
177 if ((ctx = BN_CTX_new()) == NULL) {
(ctx = BN_CTX_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 46 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-46
178 DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);-
179 goto dsaerr;
never executed: goto dsaerr;
0
180 }-
181-
182 BN_set_flags(dsa->priv_key, BN_FLG_CONSTTIME);-
183 if (!BN_mod_exp(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx)) {
!BN_mod_exp(ds..., dsa->p, ctx)Description
TRUEnever evaluated
FALSEevaluated 46 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-46
184 DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_BN_ERROR);-
185 goto dsaerr;
never executed: goto dsaerr;
0
186 }-
187-
188 EVP_PKEY_assign_DSA(pkey, dsa);-
189-
190 ret = 1;-
191 goto done;
executed 46 times by 1 test: goto done;
Executed by:
  • libcrypto.so.1.1
46
192-
193 decerr:-
194 DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_DECODE_ERROR);-
195 dsaerr:
code before this statement executed 4 times by 1 test: dsaerr:
Executed by:
  • libcrypto.so.1.1
4
196 DSA_free(dsa);-
197 done:
code before this statement executed 4 times by 1 test: done:
Executed by:
  • libcrypto.so.1.1
4
198 BN_CTX_free(ctx);-
199 ASN1_STRING_clear_free(privkey);-
200 return ret;
executed 50 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
50
201}-
202-
203static int dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)-
204{-
205 ASN1_STRING *params = NULL;-
206 ASN1_INTEGER *prkey = NULL;-
207 unsigned char *dp = NULL;-
208 int dplen;-
209-
210 if (!pkey->pkey.dsa || !pkey->pkey.dsa->priv_key) {
!pkey->pkey.dsaDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!pkey->pkey.dsa->priv_keyDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
211 DSAerr(DSA_F_DSA_PRIV_ENCODE, DSA_R_MISSING_PARAMETERS);-
212 goto err;
never executed: goto err;
0
213 }-
214-
215 params = ASN1_STRING_new();-
216-
217 if (params == NULL) {
params == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
218 DSAerr(DSA_F_DSA_PRIV_ENCODE, ERR_R_MALLOC_FAILURE);-
219 goto err;
never executed: goto err;
0
220 }-
221-
222 params->length = i2d_DSAparams(pkey->pkey.dsa, &params->data);-
223 if (params->length <= 0) {
params->length <= 0Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
224 DSAerr(DSA_F_DSA_PRIV_ENCODE, ERR_R_MALLOC_FAILURE);-
225 goto err;
never executed: goto err;
0
226 }-
227 params->type = V_ASN1_SEQUENCE;-
228-
229 /* Get private key into integer */-
230 prkey = BN_to_ASN1_INTEGER(pkey->pkey.dsa->priv_key, NULL);-
231-
232 if (!prkey) {
!prkeyDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
233 DSAerr(DSA_F_DSA_PRIV_ENCODE, DSA_R_BN_ERROR);-
234 goto err;
never executed: goto err;
0
235 }-
236-
237 dplen = i2d_ASN1_INTEGER(prkey, &dp);-
238-
239 ASN1_STRING_clear_free(prkey);-
240 prkey = NULL;-
241-
242 if (!PKCS8_pkey_set0(p8, OBJ_nid2obj(NID_dsa), 0,
!PKCS8_pkey_se...ms, dp, dplen)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
243 V_ASN1_SEQUENCE, params, dp, dplen))
!PKCS8_pkey_se...ms, dp, dplen)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
244 goto err;
never executed: goto err;
0
245-
246 return 1;
executed 4 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
4
247-
248 err:-
249 OPENSSL_free(dp);-
250 ASN1_STRING_free(params);-
251 ASN1_STRING_clear_free(prkey);-
252 return 0;
never executed: return 0;
0
253}-
254-
255static int int_dsa_size(const EVP_PKEY *pkey)-
256{-
257 return DSA_size(pkey->pkey.dsa);
executed 368 times by 1 test: return DSA_size(pkey->pkey.dsa);
Executed by:
  • libcrypto.so.1.1
368
258}-
259-
260static int dsa_bits(const EVP_PKEY *pkey)-
261{-
262 return DSA_bits(pkey->pkey.dsa);
executed 18 times by 1 test: return DSA_bits(pkey->pkey.dsa);
Executed by:
  • libcrypto.so.1.1
18
263}-
264-
265static int dsa_security_bits(const EVP_PKEY *pkey)-
266{-
267 return DSA_security_bits(pkey->pkey.dsa);
executed 2017 times by 1 test: return DSA_security_bits(pkey->pkey.dsa);
Executed by:
  • libcrypto.so.1.1
2017
268}-
269-
270static int dsa_missing_parameters(const EVP_PKEY *pkey)-
271{-
272 DSA *dsa;-
273 dsa = pkey->pkey.dsa;-
274 if (dsa == NULL || dsa->p == NULL || dsa->q == NULL || dsa->g == NULL)
dsa == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4546 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
dsa->p == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4546 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
dsa->q == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4546 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
dsa->g == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4546 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4546
275 return 1;
never executed: return 1;
0
276 return 0;
executed 4546 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
4546
277}-
278-
279static int dsa_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)-
280{-
281 BIGNUM *a;-
282-
283 if (to->pkey.dsa == NULL) {
to->pkey.dsa == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
284 to->pkey.dsa = DSA_new();-
285 if (to->pkey.dsa == NULL)
to->pkey.dsa == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
286 return 0;
never executed: return 0;
0
287 }
never executed: end of block
0
288-
289 if ((a = BN_dup(from->pkey.dsa->p)) == NULL)
(a = BN_dup(fr...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
290 return 0;
never executed: return 0;
0
291 BN_free(to->pkey.dsa->p);-
292 to->pkey.dsa->p = a;-
293-
294 if ((a = BN_dup(from->pkey.dsa->q)) == NULL)
(a = BN_dup(fr...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
295 return 0;
never executed: return 0;
0
296 BN_free(to->pkey.dsa->q);-
297 to->pkey.dsa->q = a;-
298-
299 if ((a = BN_dup(from->pkey.dsa->g)) == NULL)
(a = BN_dup(fr...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
300 return 0;
never executed: return 0;
0
301 BN_free(to->pkey.dsa->g);-
302 to->pkey.dsa->g = a;-
303 return 1;
never executed: return 1;
0
304}-
305-
306static int dsa_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)-
307{-
308 if (BN_cmp(a->pkey.dsa->p, b->pkey.dsa->p) ||
BN_cmp(a->pkey...->pkey.dsa->p)Description
TRUEnever evaluated
FALSEevaluated 4036 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4036
309 BN_cmp(a->pkey.dsa->q, b->pkey.dsa->q) ||
BN_cmp(a->pkey...->pkey.dsa->q)Description
TRUEnever evaluated
FALSEevaluated 4036 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4036
310 BN_cmp(a->pkey.dsa->g, b->pkey.dsa->g))
BN_cmp(a->pkey...->pkey.dsa->g)Description
TRUEnever evaluated
FALSEevaluated 4036 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4036
311 return 0;
never executed: return 0;
0
312 else-
313 return 1;
executed 4036 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
4036
314}-
315-
316static int dsa_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b)-
317{-
318 if (BN_cmp(b->pkey.dsa->pub_key, a->pkey.dsa->pub_key) != 0)
BN_cmp(b->pkey...>pub_key) != 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2037 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-2037
319 return 0;
executed 2 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
2
320 else-
321 return 1;
executed 2037 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2037
322}-
323-
324static void int_dsa_free(EVP_PKEY *pkey)-
325{-
326 DSA_free(pkey->pkey.dsa);-
327}
executed 8190 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
8190
328-
329static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype)-
330{-
331 int ret = 0;-
332 const char *ktype = NULL;-
333 const BIGNUM *priv_key, *pub_key;-
334-
335 if (ptype == 2)
ptype == 2Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 21 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
12-21
336 priv_key = x->priv_key;
executed 12 times by 1 test: priv_key = x->priv_key;
Executed by:
  • libcrypto.so.1.1
12
337 else-
338 priv_key = NULL;
executed 21 times by 1 test: priv_key = ((void *)0) ;
Executed by:
  • libcrypto.so.1.1
21
339-
340 if (ptype > 0)
ptype > 0Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 13 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
13-20
341 pub_key = x->pub_key;
executed 20 times by 1 test: pub_key = x->pub_key;
Executed by:
  • libcrypto.so.1.1
20
342 else-
343 pub_key = NULL;
executed 13 times by 1 test: pub_key = ((void *)0) ;
Executed by:
  • libcrypto.so.1.1
13
344-
345 if (ptype == 2)
ptype == 2Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 21 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
12-21
346 ktype = "Private-Key";
executed 12 times by 1 test: ktype = "Private-Key";
Executed by:
  • libcrypto.so.1.1
12
347 else if (ptype == 1)
ptype == 1Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 13 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
8-13
348 ktype = "Public-Key";
executed 8 times by 1 test: ktype = "Public-Key";
Executed by:
  • libcrypto.so.1.1
8
349 else-
350 ktype = "DSA-Parameters";
executed 13 times by 1 test: ktype = "DSA-Parameters";
Executed by:
  • libcrypto.so.1.1
13
351-
352 if (priv_key) {
priv_keyDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 24 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
9-24
353 if (!BIO_indent(bp, off, 128))
!BIO_indent(bp, off, 128)Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-9
354 goto err;
never executed: goto err;
0
355 if (BIO_printf(bp, "%s: (%d bit)\n", ktype, BN_num_bits(x->p))
BIO_printf(bp,...ts(x->p)) <= 0Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-9
356 <= 0)
BIO_printf(bp,...ts(x->p)) <= 0Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-9
357 goto err;
never executed: goto err;
0
358 }
executed 9 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
9
359-
360 if (!ASN1_bn_print(bp, "priv:", priv_key, NULL, off))
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 33 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-33
361 goto err;
never executed: goto err;
0
362 if (!ASN1_bn_print(bp, "pub: ", pub_key, NULL, off))
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 33 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-33
363 goto err;
never executed: goto err;
0
364 if (!ASN1_bn_print(bp, "P: ", x->p, NULL, off))
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 33 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-33
365 goto err;
never executed: goto err;
0
366 if (!ASN1_bn_print(bp, "Q: ", x->q, NULL, off))
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 33 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-33
367 goto err;
never executed: goto err;
0
368 if (!ASN1_bn_print(bp, "G: ", x->g, NULL, off))
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 33 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-33
369 goto err;
never executed: goto err;
0
370 ret = 1;-
371 err:
code before this statement executed 33 times by 1 test: err:
Executed by:
  • libcrypto.so.1.1
33
372 return ret;
executed 33 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
33
373}-
374-
375static int dsa_param_decode(EVP_PKEY *pkey,-
376 const unsigned char **pder, int derlen)-
377{-
378 DSA *dsa;-
379-
380 if ((dsa = d2i_DSAparams(NULL, pder, derlen)) == NULL) {
(dsa = d2i_DSA...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
381 DSAerr(DSA_F_DSA_PARAM_DECODE, ERR_R_DSA_LIB);-
382 return 0;
never executed: return 0;
0
383 }-
384 EVP_PKEY_assign_DSA(pkey, dsa);-
385 return 1;
never executed: return 1;
0
386}-
387-
388static int dsa_param_encode(const EVP_PKEY *pkey, unsigned char **pder)-
389{-
390 return i2d_DSAparams(pkey->pkey.dsa, pder);
never executed: return i2d_DSAparams(pkey->pkey.dsa, pder);
0
391}-
392-
393static int dsa_param_print(BIO *bp, const EVP_PKEY *pkey, int indent,-
394 ASN1_PCTX *ctx)-
395{-
396 return do_dsa_print(bp, pkey->pkey.dsa, indent, 0);
executed 13 times by 1 test: return do_dsa_print(bp, pkey->pkey.dsa, indent, 0);
Executed by:
  • libcrypto.so.1.1
13
397}-
398-
399static int dsa_pub_print(BIO *bp, const EVP_PKEY *pkey, int indent,-
400 ASN1_PCTX *ctx)-
401{-
402 return do_dsa_print(bp, pkey->pkey.dsa, indent, 1);
executed 8 times by 1 test: return do_dsa_print(bp, pkey->pkey.dsa, indent, 1);
Executed by:
  • libcrypto.so.1.1
8
403}-
404-
405static int dsa_priv_print(BIO *bp, const EVP_PKEY *pkey, int indent,-
406 ASN1_PCTX *ctx)-
407{-
408 return do_dsa_print(bp, pkey->pkey.dsa, indent, 2);
executed 12 times by 1 test: return do_dsa_print(bp, pkey->pkey.dsa, indent, 2);
Executed by:
  • libcrypto.so.1.1
12
409}-
410-
411static int old_dsa_priv_decode(EVP_PKEY *pkey,-
412 const unsigned char **pder, int derlen)-
413{-
414 DSA *dsa;-
415-
416 if ((dsa = d2i_DSAPrivateKey(NULL, pder, derlen)) == NULL) {
(dsa = d2i_DSA...== ((void *)0)Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2008 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
29-2008
417 DSAerr(DSA_F_OLD_DSA_PRIV_DECODE, ERR_R_DSA_LIB);-
418 return 0;
executed 29 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
29
419 }-
420 EVP_PKEY_assign_DSA(pkey, dsa);-
421 return 1;
executed 2008 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2008
422}-
423-
424static int old_dsa_priv_encode(const EVP_PKEY *pkey, unsigned char **pder)-
425{-
426 return i2d_DSAPrivateKey(pkey->pkey.dsa, pder);
executed 7 times by 1 test: return i2d_DSAPrivateKey(pkey->pkey.dsa, pder);
Executed by:
  • libcrypto.so.1.1
7
427}-
428-
429static int dsa_sig_print(BIO *bp, const X509_ALGOR *sigalg,-
430 const ASN1_STRING *sig, int indent, ASN1_PCTX *pctx)-
431{-
432 DSA_SIG *dsa_sig;-
433 const unsigned char *p;-
434-
435 if (!sig) {
!sigDescription
TRUEevaluated 46 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 64 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
46-64
436 if (BIO_puts(bp, "\n") <= 0)
BIO_puts(bp, "\n") <= 0Description
TRUEnever evaluated
FALSEevaluated 46 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-46
437 return 0;
never executed: return 0;
0
438 else-
439 return 1;
executed 46 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
46
440 }-
441 p = sig->data;-
442 dsa_sig = d2i_DSA_SIG(NULL, &p, sig->length);-
443 if (dsa_sig) {
dsa_sigDescription
TRUEevaluated 21 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 43 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
21-43
444 int rv = 0;-
445 const BIGNUM *r, *s;-
446-
447 DSA_SIG_get0(dsa_sig, &r, &s);-
448-
449 if (BIO_write(bp, "\n", 1) != 1)
BIO_write(bp, "\n", 1) != 1Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-21
450 goto err;
never executed: goto err;
0
451-
452 if (!ASN1_bn_print(bp, "r: ", r, NULL, indent))
!ASN1_bn_print...*)0) , indent)Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-21
453 goto err;
never executed: goto err;
0
454 if (!ASN1_bn_print(bp, "s: ", s, NULL, indent))
!ASN1_bn_print...*)0) , indent)Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-21
455 goto err;
never executed: goto err;
0
456 rv = 1;-
457 err:
code before this statement executed 21 times by 1 test: err:
Executed by:
  • libcrypto.so.1.1
21
458 DSA_SIG_free(dsa_sig);-
459 return rv;
executed 21 times by 1 test: return rv;
Executed by:
  • libcrypto.so.1.1
21
460 }-
461 return X509_signature_dump(bp, sig, indent);
executed 43 times by 1 test: return X509_signature_dump(bp, sig, indent);
Executed by:
  • libcrypto.so.1.1
43
462}-
463-
464static int dsa_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)-
465{-
466 switch (op) {-
467 case ASN1_PKEY_CTRL_PKCS7_SIGN:
executed 11 times by 1 test: case 0x1:
Executed by:
  • libcrypto.so.1.1
11
468 if (arg1 == 0) {
arg1 == 0Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-11
469 int snid, hnid;-
470 X509_ALGOR *alg1, *alg2;-
471 PKCS7_SIGNER_INFO_get0_algs(arg2, NULL, &alg1, &alg2);-
472 if (alg1 == NULL || alg1->algorithm == NULL)
alg1 == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
alg1->algorithm == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-11
473 return -1;
never executed: return -1;
0
474 hnid = OBJ_obj2nid(alg1->algorithm);-
475 if (hnid == NID_undef)
hnid == 0Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-11
476 return -1;
never executed: return -1;
0
477 if (!OBJ_find_sigid_by_algs(&snid, hnid, EVP_PKEY_id(pkey)))
!OBJ_find_sigi...PKEY_id(pkey))Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-11
478 return -1;
never executed: return -1;
0
479 X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF, 0);-
480 }
executed 11 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
11
481 return 1;
executed 11 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
11
482#ifndef OPENSSL_NO_CMS-
483 case ASN1_PKEY_CTRL_CMS_SIGN:
executed 54 times by 1 test: case 0x5:
Executed by:
  • libcrypto.so.1.1
54
484 if (arg1 == 0) {
arg1 == 0Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 28 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
26-28
485 int snid, hnid;-
486 X509_ALGOR *alg1, *alg2;-
487 CMS_SignerInfo_get0_algs(arg2, NULL, NULL, &alg1, &alg2);-
488 if (alg1 == NULL || alg1->algorithm == NULL)
alg1 == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
alg1->algorithm == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-26
489 return -1;
never executed: return -1;
0
490 hnid = OBJ_obj2nid(alg1->algorithm);-
491 if (hnid == NID_undef)
hnid == 0Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-26
492 return -1;
never executed: return -1;
0
493 if (!OBJ_find_sigid_by_algs(&snid, hnid, EVP_PKEY_id(pkey)))
!OBJ_find_sigi...PKEY_id(pkey))Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-26
494 return -1;
never executed: return -1;
0
495 X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF, 0);-
496 }
executed 26 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
26
497 return 1;
executed 54 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
54
498-
499 case ASN1_PKEY_CTRL_CMS_RI_TYPE:
never executed: case 0x8:
0
500 *(int *)arg2 = CMS_RECIPINFO_NONE;-
501 return 1;
never executed: return 1;
0
502#endif-
503-
504 case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
executed 38 times by 1 test: case 0x3:
Executed by:
  • libcrypto.so.1.1
38
505 *(int *)arg2 = NID_sha256;-
506 return 2;
executed 38 times by 1 test: return 2;
Executed by:
  • libcrypto.so.1.1
38
507-
508 default:
never executed: default:
0
509 return -2;
never executed: return -2;
0
510-
511 }-
512-
513}-
514-
515/* NB these are sorted in pkey_id order, lowest first */-
516-
517const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[5] = {-
518-
519 {-
520 EVP_PKEY_DSA2,-
521 EVP_PKEY_DSA,-
522 ASN1_PKEY_ALIAS},-
523-
524 {-
525 EVP_PKEY_DSA1,-
526 EVP_PKEY_DSA,-
527 ASN1_PKEY_ALIAS},-
528-
529 {-
530 EVP_PKEY_DSA4,-
531 EVP_PKEY_DSA,-
532 ASN1_PKEY_ALIAS},-
533-
534 {-
535 EVP_PKEY_DSA3,-
536 EVP_PKEY_DSA,-
537 ASN1_PKEY_ALIAS},-
538-
539 {-
540 EVP_PKEY_DSA,-
541 EVP_PKEY_DSA,-
542 0,-
543-
544 "DSA",-
545 "OpenSSL DSA method",-
546-
547 dsa_pub_decode,-
548 dsa_pub_encode,-
549 dsa_pub_cmp,-
550 dsa_pub_print,-
551-
552 dsa_priv_decode,-
553 dsa_priv_encode,-
554 dsa_priv_print,-
555-
556 int_dsa_size,-
557 dsa_bits,-
558 dsa_security_bits,-
559-
560 dsa_param_decode,-
561 dsa_param_encode,-
562 dsa_missing_parameters,-
563 dsa_copy_parameters,-
564 dsa_cmp_parameters,-
565 dsa_param_print,-
566 dsa_sig_print,-
567-
568 int_dsa_free,-
569 dsa_pkey_ctrl,-
570 old_dsa_priv_decode,-
571 old_dsa_priv_encode}-
572};-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2