OpenCoverage

rsa_mp.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/rsa/rsa_mp.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.-
3 * Copyright 2017 BaishanCloud. All rights reserved.-
4 *-
5 * Licensed under the OpenSSL license (the "License"). You may not use-
6 * this file except in compliance with the License. You can obtain a copy-
7 * in the file LICENSE in the source distribution or at-
8 * https://www.openssl.org/source/license.html-
9 */-
10-
11#include <openssl/bn.h>-
12#include <openssl/err.h>-
13#include "rsa_locl.h"-
14-
15void rsa_multip_info_free_ex(RSA_PRIME_INFO *pinfo)-
16{-
17 /* free pp and pinfo only */-
18 BN_clear_free(pinfo->pp);-
19 OPENSSL_free(pinfo);-
20}
executed 8639 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
8639
21-
22void rsa_multip_info_free(RSA_PRIME_INFO *pinfo)-
23{-
24 /* free a RSA_PRIME_INFO structure */-
25 BN_clear_free(pinfo->r);-
26 BN_clear_free(pinfo->d);-
27 BN_clear_free(pinfo->t);-
28 rsa_multip_info_free_ex(pinfo);-
29}
executed 8639 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
8639
30-
31RSA_PRIME_INFO *rsa_multip_info_new(void)-
32{-
33 RSA_PRIME_INFO *pinfo;-
34-
35 /* create a RSA_PRIME_INFO structure */-
36 if ((pinfo = OPENSSL_zalloc(sizeof(RSA_PRIME_INFO))) == NULL) {
(pinfo = CRYPT...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 13 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-13
37 RSAerr(RSA_F_RSA_MULTIP_INFO_NEW, ERR_R_MALLOC_FAILURE);-
38 return NULL;
never executed: return ((void *)0) ;
0
39 }-
40 if ((pinfo->r = BN_secure_new()) == NULL)
(pinfo->r = BN...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 13 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-13
41 goto err;
never executed: goto err;
0
42 if ((pinfo->d = BN_secure_new()) == NULL)
(pinfo->d = BN...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 13 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-13
43 goto err;
never executed: goto err;
0
44 if ((pinfo->t = BN_secure_new()) == NULL)
(pinfo->t = BN...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 13 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-13
45 goto err;
never executed: goto err;
0
46 if ((pinfo->pp = BN_secure_new()) == NULL)
(pinfo->pp = B...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 13 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-13
47 goto err;
never executed: goto err;
0
48-
49 return pinfo;
executed 13 times by 1 test: return pinfo;
Executed by:
  • libcrypto.so.1.1
13
50-
51 err:-
52 BN_free(pinfo->r);-
53 BN_free(pinfo->d);-
54 BN_free(pinfo->t);-
55 BN_free(pinfo->pp);-
56 OPENSSL_free(pinfo);-
57 return NULL;
never executed: return ((void *)0) ;
0
58}-
59-
60/* Refill products of primes */-
61int rsa_multip_calc_product(RSA *rsa)-
62{-
63 RSA_PRIME_INFO *pinfo;-
64 BIGNUM *p1 = NULL, *p2 = NULL;-
65 BN_CTX *ctx = NULL;-
66 int i, rv = 0, ex_primes;-
67-
68 if ((ex_primes = sk_RSA_PRIME_INFO_num(rsa->prime_infos)) <= 0) {
(ex_primes = s...e_infos)) <= 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 167 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-167
69 /* invalid */-
70 goto err;
executed 2 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
2
71 }-
72-
73 if ((ctx = BN_CTX_new()) == NULL)
(ctx = BN_CTX_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 167 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-167
74 goto err;
never executed: goto err;
0
75-
76 /* calculate pinfo->pp = p * q for first 'extra' prime */-
77 p1 = rsa->p;-
78 p2 = rsa->q;-
79-
80 for (i = 0; i < ex_primes; i++) {
i < ex_primesDescription
TRUEevaluated 3947 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 167 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
167-3947
81 pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i);-
82 if (pinfo->pp == NULL) {
pinfo->pp == ((void *)0)Description
TRUEevaluated 3946 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-3946
83 pinfo->pp = BN_secure_new();-
84 if (pinfo->pp == NULL)
pinfo->pp == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 3946 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3946
85 goto err;
never executed: goto err;
0
86 }
executed 3946 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
3946
87 if (!BN_mul(pinfo->pp, p1, p2, ctx))
!BN_mul(pinfo-..., p1, p2, ctx)Description
TRUEnever evaluated
FALSEevaluated 3947 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3947
88 goto err;
never executed: goto err;
0
89 /* save previous one */-
90 p1 = pinfo->pp;-
91 p2 = pinfo->r;-
92 }
executed 3947 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
3947
93-
94 rv = 1;-
95 err:
code before this statement executed 167 times by 1 test: err:
Executed by:
  • libcrypto.so.1.1
167
96 BN_CTX_free(ctx);-
97 return rv;
executed 169 times by 1 test: return rv;
Executed by:
  • libcrypto.so.1.1
169
98}-
99-
100int rsa_multip_cap(int bits)-
101{-
102 int cap = 5;-
103-
104 if (bits < 1024)
bits < 1024Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 23 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
3-23
105 cap = 2;
executed 3 times by 1 test: cap = 2;
Executed by:
  • libcrypto.so.1.1
3
106 else if (bits < 4096)
bits < 4096Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
8-15
107 cap = 3;
executed 15 times by 1 test: cap = 3;
Executed by:
  • libcrypto.so.1.1
15
108 else if (bits < 8192)
bits < 8192Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4
109 cap = 4;
executed 4 times by 1 test: cap = 4;
Executed by:
  • libcrypto.so.1.1
4
110-
111 if (cap > RSA_MAX_PRIME_NUM)
cap > 5Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-26
112 cap = RSA_MAX_PRIME_NUM;
never executed: cap = 5;
0
113-
114 return cap;
executed 26 times by 1 test: return cap;
Executed by:
  • libcrypto.so.1.1
26
115}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2