OpenCoverage

dsa_key.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/dsa/dsa_key.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 1995-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 <time.h>-
12#include "internal/cryptlib.h"-
13#include <openssl/bn.h>-
14#include "dsa_locl.h"-
15-
16static int dsa_builtin_keygen(DSA *dsa);-
17-
18int DSA_generate_key(DSA *dsa)-
19{-
20 if (dsa->meth->dsa_keygen)
dsa->meth->dsa_keygenDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3
21 return dsa->meth->dsa_keygen(dsa);
never executed: return dsa->meth->dsa_keygen(dsa);
0
22 return dsa_builtin_keygen(dsa);
executed 3 times by 1 test: return dsa_builtin_keygen(dsa);
Executed by:
  • libcrypto.so.1.1
3
23}-
24-
25static int dsa_builtin_keygen(DSA *dsa)-
26{-
27 int ok = 0;-
28 BN_CTX *ctx = NULL;-
29 BIGNUM *pub_key = NULL, *priv_key = NULL;-
30-
31 if ((ctx = BN_CTX_new()) == NULL)
(ctx = BN_CTX_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3
32 goto err;
never executed: goto err;
0
33-
34 if (dsa->priv_key == NULL) {
dsa->priv_key == ((void *)0)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-3
35 if ((priv_key = BN_secure_new()) == NULL)
(priv_key = BN...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3
36 goto err;
never executed: goto err;
0
37 } else
executed 3 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
3
38 priv_key = dsa->priv_key;
never executed: priv_key = dsa->priv_key;
0
39-
40 do-
41 if (!BN_priv_rand_range(priv_key, dsa->q))
!BN_priv_rand_...v_key, dsa->q)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3
42 goto err;
never executed: goto err;
0
43 while (BN_is_zero(priv_key)) ;
BN_is_zero(priv_key)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3
44-
45 if (dsa->pub_key == NULL) {
dsa->pub_key == ((void *)0)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-3
46 if ((pub_key = BN_new()) == NULL)
(pub_key = BN_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3
47 goto err;
never executed: goto err;
0
48 } else
executed 3 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
3
49 pub_key = dsa->pub_key;
never executed: pub_key = dsa->pub_key;
0
50-
51 {-
52 BIGNUM *prk = BN_new();-
53-
54 if (prk == NULL)
prk == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3
55 goto err;
never executed: goto err;
0
56 BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME);-
57-
58 if (!BN_mod_exp(pub_key, dsa->g, prk, dsa->p, ctx)) {
!BN_mod_exp(pu..., dsa->p, ctx)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3
59 BN_free(prk);-
60 goto err;
never executed: goto err;
0
61 }-
62 /* We MUST free prk before any further use of priv_key */-
63 BN_free(prk);-
64 }-
65-
66 dsa->priv_key = priv_key;-
67 dsa->pub_key = pub_key;-
68 ok = 1;-
69-
70 err:
code before this statement executed 3 times by 1 test: err:
Executed by:
  • libcrypto.so.1.1
3
71 if (pub_key != dsa->pub_key)
pub_key != dsa->pub_keyDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3
72 BN_free(pub_key);
never executed: BN_free(pub_key);
0
73 if (priv_key != dsa->priv_key)
priv_key != dsa->priv_keyDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3
74 BN_free(priv_key);
never executed: BN_free(priv_key);
0
75 BN_CTX_free(ctx);-
76 return ok;
executed 3 times by 1 test: return ok;
Executed by:
  • libcrypto.so.1.1
3
77}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2