OpenCoverage

bn_intern.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bn/bn_intern.c
Switch to Source codePreprocessed file
LineSourceCount
1signed char *bn_compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)-
2{-
3 int window_val;-
4 signed char *r = -
5 ((void *)0)-
6 ;-
7 int sign = 1;-
8 int bit, next_bit, mask;-
9 size_t len = 0, j;-
10-
11 if (BN_is_zero(scalar)
BN_is_zero(scalar)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2205 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
) {
4-2205
12 r = CRYPTO_malloc(1, __FILE__, 31);-
13 if (r ==
r == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
14 ((void *)0)
r == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
15 ) {-
16 ERR_put_error(3,(142),((1|64)),__FILE__,33);-
17 goto
never executed: goto err;
err;
never executed: goto err;
0
18 }-
19 r[0] = 0;-
20 *ret_len = 1;-
21 return
executed 4 times by 1 test: return r;
Executed by:
  • libcrypto.so.1.1
r;
executed 4 times by 1 test: return r;
Executed by:
  • libcrypto.so.1.1
4
22 }-
23-
24 if (w <= 0
w <= 0Description
TRUEnever evaluated
FALSEevaluated 2205 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
|| w > 7
w > 7Description
TRUEnever evaluated
FALSEevaluated 2205 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
) {
0-2205
25-
26 ERR_put_error(3,(142),((4|64)),__FILE__,43);-
27 goto
never executed: goto err;
err;
never executed: goto err;
0
28 }-
29 bit = 1 << w;-
30 next_bit = bit << 1;-
31 mask = next_bit - 1;-
32-
33 if (BN_is_negative(scalar)
BN_is_negative(scalar)Description
TRUEevaluated 586 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1619 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
) {
586-1619
34 sign = -1;-
35 }
executed 586 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
586
36-
37 if (scalar->d ==
scalar->d == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2205 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-2205
38 ((void *)0)
scalar->d == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2205 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-2205
39 || scalar->top == 0
scalar->top == 0Description
TRUEnever evaluated
FALSEevaluated 2205 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
) {
0-2205
40 ERR_put_error(3,(142),((4|64)),__FILE__,55);-
41 goto
never executed: goto err;
err;
never executed: goto err;
0
42 }-
43-
44 len = BN_num_bits(scalar);-
45 r = CRYPTO_malloc(len + 1, __FILE__, 60);-
46-
47-
48-
49-
50 if (r ==
r == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2205 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-2205
51 ((void *)0)
r == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2205 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-2205
52 ) {-
53 ERR_put_error(3,(142),((1|64)),__FILE__,66);-
54 goto
never executed: goto err;
err;
never executed: goto err;
0
55 }-
56 window_val = scalar->d[0] & mask;-
57 j = 0;-
58 while ((
(window_val != 0)Description
TRUEevaluated 519118 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 93308 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
window_val != 0)
(window_val != 0)Description
TRUEevaluated 519118 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 93308 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
|| (
(j + w + 1 < len)Description
TRUEevaluated 91103 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 2205 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
j + w + 1 < len)
(j + w + 1 < len)Description
TRUEevaluated 91103 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 2205 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
) {
2205-519118
59-
60-
61 int digit = 0;-
62-
63-
64-
65 if (window_val & 1
window_val & 1Description
TRUEevaluated 89410 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 520811 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
) {
89410-520811
66-
67-
68 if (window_val & bit
window_val & bitDescription
TRUEevaluated 43088 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 46322 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
) {
43088-46322
69 digit = window_val - next_bit;-
70-
71-
72 if (j + w + 1 >= len
j + w + 1 >= lenDescription
TRUEevaluated 184 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 42904 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
) {
184-42904
73-
74-
75-
76-
77-
78-
79-
80 digit = window_val & (mask >> 1);-
81 }
executed 184 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
184
82-
83 }
executed 43088 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
else {
43088
84 digit = window_val;-
85 }
executed 46322 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
46322
86-
87 if (digit <= -bit
digit <= -bitDescription
TRUEnever evaluated
FALSEevaluated 89410 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
|| digit >= bit
digit >= bitDescription
TRUEnever evaluated
FALSEevaluated 89410 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
|| !(digit & 1)
!(digit & 1)Description
TRUEnever evaluated
FALSEevaluated 89410 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
) {
0-89410
88 ERR_put_error(3,(142),((4|64)),__FILE__,101);-
89 goto
never executed: goto err;
err;
never executed: goto err;
0
90 }-
91-
92 window_val -= digit;-
93-
94-
95-
96-
97-
98 if (window_val != 0
window_val != 0Description
TRUEevaluated 43088 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 46322 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
&& window_val != next_bit
window_val != next_bitDescription
TRUEevaluated 184 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 42904 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
184-46322
99 && window_val != bit
window_val != bitDescription
TRUEnever evaluated
FALSEevaluated 184 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-184
100 ERR_put_error(3,(142),((4|64)),__FILE__,113);-
101 goto
never executed: goto err;
err;
never executed: goto err;
0
102 }-
103 }
executed 89410 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
89410
104-
105 r[j++] = sign * digit;-
106-
107 window_val >>= 1;-
108 window_val += bit * BN_is_bit_set(scalar, j + w);-
109-
110 if (window_val > next_bit
window_val > next_bitDescription
TRUEnever evaluated
FALSEevaluated 610221 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
) {
0-610221
111 ERR_put_error(3,(142),((4|64)),__FILE__,124);-
112 goto
never executed: goto err;
err;
never executed: goto err;
0
113 }-
114 }
executed 610221 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
610221
115-
116 if (j > len + 1
j > len + 1Description
TRUEnever evaluated
FALSEevaluated 2205 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
) {
0-2205
117 ERR_put_error(3,(142),((4|64)),__FILE__,130);-
118 goto
never executed: goto err;
err;
never executed: goto err;
0
119 }-
120 *ret_len = j;-
121 return
executed 2205 times by 2 tests: return r;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
r;
executed 2205 times by 2 tests: return r;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
2205
122-
123 err:-
124 CRYPTO_free(r, __FILE__, 137);-
125 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
126 ((void *)0)
never executed: return ((void *)0) ;
0
127 ;
never executed: return ((void *)0) ;
0
128}-
129-
130int bn_get_top(const BIGNUM *a)-
131{-
132 return
executed 17493 times by 2 tests: return a->top;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
a->top;
executed 17493 times by 2 tests: return a->top;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
17493
133}-
134-
135int bn_get_dmax(const BIGNUM *a)-
136{-
137 return
never executed: return a->dmax;
a->dmax;
never executed: return a->dmax;
0
138}-
139-
140void bn_set_all_zero(BIGNUM *a)-
141{-
142 int i;-
143-
144 for (i = a->top; i < a->dmax
i < a->dmaxDescription
TRUEevaluated 47286 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 38978 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
; i++)
38978-47286
145 a->d[i] = 0;
executed 47286 times by 1 test: a->d[i] = 0;
Executed by:
  • libcrypto.so.1.1
47286
146}
executed 38978 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
38978
147-
148int bn_copy_words(unsigned long *out, const BIGNUM *in, int size)-
149{-
150 if (in->top > size
in->top > sizeDescription
TRUEnever evaluated
FALSEevaluated 43574 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-43574
151 return
never executed: return 0;
0;
never executed: return 0;
0
152-
153 memset(out, 0, sizeof(*out) * size);-
154 if (in->d !=
in->d != ((void *)0)Description
TRUEevaluated 43572 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-43572
155 ((void *)0)
in->d != ((void *)0)Description
TRUEevaluated 43572 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-43572
156 )-
157 memcpy(out, in->d, sizeof(*out) * in->top);
executed 43572 times by 1 test: memcpy(out, in->d, sizeof(*out) * in->top);
Executed by:
  • libcrypto.so.1.1
43572
158 return
executed 43574 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 43574 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
43574
159}-
160-
161unsigned long *bn_get_words(const BIGNUM *a)-
162{-
163 return
executed 29449 times by 1 test: return a->d;
Executed by:
  • libcrypto.so.1.1
a->d;
executed 29449 times by 1 test: return a->d;
Executed by:
  • libcrypto.so.1.1
29449
164}-
165-
166void bn_set_static_words(BIGNUM *a, const unsigned long *words, int size)-
167{-
168-
169-
170-
171-
172 a->d = (unsigned long *)words;-
173 a->dmax = a->top = size;-
174 a->neg = 0;-
175 a->flags |= 0x02;-
176 bn_correct_top(a);-
177}
never executed: end of block
0
178-
179int bn_set_words(BIGNUM *a, const unsigned long *words, int num_words)-
180{-
181 if (bn_wexpand(a, num_words) ==
bn_wexpand(a, ...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 31069 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-31069
182 ((void *)0)
bn_wexpand(a, ...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 31069 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-31069
183 ) {-
184 ERR_put_error(3,(144),((1|64)),__FILE__,191);-
185 return
never executed: return 0;
0;
never executed: return 0;
0
186 }-
187-
188 memcpy(a->d, words, sizeof(unsigned long) * num_words);-
189 a->top = num_words;-
190 bn_correct_top(a);-
191 return
executed 31069 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 31069 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
31069
192}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2