OpenCoverage

bn_sqrt.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bn/bn_sqrt.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2000-2018 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 "internal/cryptlib.h"-
11#include "bn_lcl.h"-
12-
13BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)-
14/*-
15 * Returns 'ret' such that ret^2 == a (mod p), using the Tonelli/Shanks-
16 * algorithm (cf. Henri Cohen, "A Course in Algebraic Computational Number-
17 * Theory", algorithm 1.5.1). 'p' must be prime!-
18 */-
19{-
20 BIGNUM *ret = in;-
21 int err = 1;-
22 int r;-
23 BIGNUM *A, *b, *q, *t, *x, *y;-
24 int e, i, j;-
25-
26 if (!BN_is_odd(p) || BN_abs_is_word(p, 1)) {
!BN_is_odd(p)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4601 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
BN_abs_is_word(p, 1)Description
TRUEnever evaluated
FALSEevaluated 4601 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4601
27 if (BN_abs_is_word(p, 2)) {
BN_abs_is_word(p, 2)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-5
28 if (ret == NULL)
ret == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5
29 ret = BN_new();
never executed: ret = BN_new();
0
30 if (ret == NULL)
ret == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5
31 goto end;
never executed: goto end;
0
32 if (!BN_set_word(ret, BN_is_bit_set(a, 0))) {
!BN_set_word(r...bit_set(a, 0))Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5
33 if (ret != in)
ret != inDescription
TRUEnever evaluated
FALSEnever evaluated
0
34 BN_free(ret);
never executed: BN_free(ret);
0
35 return NULL;
never executed: return ((void *)0) ;
0
36 }-
37 bn_check_top(ret);-
38 return ret;
executed 5 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
5
39 }-
40-
41 BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);-
42 return NULL;
never executed: return ((void *)0) ;
0
43 }-
44-
45 if (BN_is_zero(a) || BN_is_one(a)) {
BN_is_zero(a)Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4594 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
BN_is_one(a)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4593 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-4594
46 if (ret == NULL)
ret == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-8
47 ret = BN_new();
never executed: ret = BN_new();
0
48 if (ret == NULL)
ret == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-8
49 goto end;
never executed: goto end;
0
50 if (!BN_set_word(ret, BN_is_one(a))) {
!BN_set_word(r... BN_is_one(a))Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-8
51 if (ret != in)
ret != inDescription
TRUEnever evaluated
FALSEnever evaluated
0
52 BN_free(ret);
never executed: BN_free(ret);
0
53 return NULL;
never executed: return ((void *)0) ;
0
54 }-
55 bn_check_top(ret);-
56 return ret;
executed 8 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
8
57 }-
58-
59 BN_CTX_start(ctx);-
60 A = BN_CTX_get(ctx);-
61 b = BN_CTX_get(ctx);-
62 q = BN_CTX_get(ctx);-
63 t = BN_CTX_get(ctx);-
64 x = BN_CTX_get(ctx);-
65 y = BN_CTX_get(ctx);-
66 if (y == NULL)
y == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4593 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4593
67 goto end;
never executed: goto end;
0
68-
69 if (ret == NULL)
ret == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4593 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4593
70 ret = BN_new();
never executed: ret = BN_new();
0
71 if (ret == NULL)
ret == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4593 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4593
72 goto end;
never executed: goto end;
0
73-
74 /* A = a mod p */-
75 if (!BN_nnmod(A, a, p, ctx))
!BN_nnmod(A, a, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 4593 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4593
76 goto end;
never executed: goto end;
0
77-
78 /* now write |p| - 1 as 2^e*q where q is odd */-
79 e = 1;-
80 while (!BN_is_bit_set(p, e))
!BN_is_bit_set(p, e)Description
TRUEevaluated 195180 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4593 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4593-195180
81 e++;
executed 195180 times by 1 test: e++;
Executed by:
  • libcrypto.so.1.1
195180
82 /* we'll set q later (if needed) */-
83-
84 if (e == 1) {
e == 1Description
TRUEevaluated 1894 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2699 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1894-2699
85 /*--
86 * The easy case: (|p|-1)/2 is odd, so 2 has an inverse-
87 * modulo (|p|-1)/2, and square roots can be computed-
88 * directly by modular exponentiation.-
89 * We have-
90 * 2 * (|p|+1)/4 == 1 (mod (|p|-1)/2),-
91 * so we can use exponent (|p|+1)/4, i.e. (|p|-3)/4 + 1.-
92 */-
93 if (!BN_rshift(q, p, 2))
!BN_rshift(q, p, 2)Description
TRUEnever evaluated
FALSEevaluated 1894 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1894
94 goto end;
never executed: goto end;
0
95 q->neg = 0;-
96 if (!BN_add_word(q, 1))
!BN_add_word(q, 1)Description
TRUEnever evaluated
FALSEevaluated 1894 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1894
97 goto end;
never executed: goto end;
0
98 if (!BN_mod_exp(ret, A, q, p, ctx))
!BN_mod_exp(ret, A, q, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 1894 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1894
99 goto end;
never executed: goto end;
0
100 err = 0;-
101 goto vrfy;
executed 1894 times by 1 test: goto vrfy;
Executed by:
  • libcrypto.so.1.1
1894
102 }-
103-
104 if (e == 2) {
e == 2Description
TRUEevaluated 595 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2104 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
595-2104
105 /*--
106 * |p| == 5 (mod 8)-
107 *-
108 * In this case 2 is always a non-square since-
109 * Legendre(2,p) = (-1)^((p^2-1)/8) for any odd prime.-
110 * So if a really is a square, then 2*a is a non-square.-
111 * Thus for-
112 * b := (2*a)^((|p|-5)/8),-
113 * i := (2*a)*b^2-
114 * we have-
115 * i^2 = (2*a)^((1 + (|p|-5)/4)*2)-
116 * = (2*a)^((p-1)/2)-
117 * = -1;-
118 * so if we set-
119 * x := a*b*(i-1),-
120 * then-
121 * x^2 = a^2 * b^2 * (i^2 - 2*i + 1)-
122 * = a^2 * b^2 * (-2*i)-
123 * = a*(-i)*(2*a*b^2)-
124 * = a*(-i)*i-
125 * = a.-
126 *-
127 * (This is due to A.O.L. Atkin,-
128 * <URL: http://listserv.nodak.edu/scripts/wa.exe?A2=ind9211&L=nmbrthry&O=T&P=562>,-
129 * November 1992.)-
130 */-
131-
132 /* t := 2*a */-
133 if (!BN_mod_lshift1_quick(t, A, p))
!BN_mod_lshift1_quick(t, A, p)Description
TRUEnever evaluated
FALSEevaluated 595 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-595
134 goto end;
never executed: goto end;
0
135-
136 /* b := (2*a)^((|p|-5)/8) */-
137 if (!BN_rshift(q, p, 3))
!BN_rshift(q, p, 3)Description
TRUEnever evaluated
FALSEevaluated 595 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-595
138 goto end;
never executed: goto end;
0
139 q->neg = 0;-
140 if (!BN_mod_exp(b, t, q, p, ctx))
!BN_mod_exp(b, t, q, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 595 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-595
141 goto end;
never executed: goto end;
0
142-
143 /* y := b^2 */-
144 if (!BN_mod_sqr(y, b, p, ctx))
!BN_mod_sqr(y, b, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 595 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-595
145 goto end;
never executed: goto end;
0
146-
147 /* t := (2*a)*b^2 - 1 */-
148 if (!BN_mod_mul(t, t, y, p, ctx))
!BN_mod_mul(t, t, y, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 595 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-595
149 goto end;
never executed: goto end;
0
150 if (!BN_sub_word(t, 1))
!BN_sub_word(t, 1)Description
TRUEnever evaluated
FALSEevaluated 595 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-595
151 goto end;
never executed: goto end;
0
152-
153 /* x = a*b*t */-
154 if (!BN_mod_mul(x, A, b, p, ctx))
!BN_mod_mul(x, A, b, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 595 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-595
155 goto end;
never executed: goto end;
0
156 if (!BN_mod_mul(x, x, t, p, ctx))
!BN_mod_mul(x, x, t, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 595 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-595
157 goto end;
never executed: goto end;
0
158-
159 if (!BN_copy(ret, x))
!BN_copy(ret, x)Description
TRUEnever evaluated
FALSEevaluated 595 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-595
160 goto end;
never executed: goto end;
0
161 err = 0;-
162 goto vrfy;
executed 595 times by 1 test: goto vrfy;
Executed by:
  • libcrypto.so.1.1
595
163 }-
164-
165 /*-
166 * e > 2, so we really have to use the Tonelli/Shanks algorithm. First,-
167 * find some y that is not a square.-
168 */-
169 if (!BN_copy(q, p))
!BN_copy(q, p)Description
TRUEnever evaluated
FALSEevaluated 2104 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2104
170 goto end; /* use 'q' as temp */
never executed: goto end;
0
171 q->neg = 0;-
172 i = 2;-
173 do {-
174 /*-
175 * For efficiency, try small numbers first; if this fails, try random-
176 * numbers.-
177 */-
178 if (i < 22) {
i < 22Description
TRUEevaluated 20474 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 550 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
550-20474
179 if (!BN_set_word(y, i))
!BN_set_word(y, i)Description
TRUEnever evaluated
FALSEevaluated 20474 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-20474
180 goto end;
never executed: goto end;
0
181 } else {
executed 20474 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
20474
182 if (!BN_priv_rand(y, BN_num_bits(p), 0, 0))
!BN_priv_rand(...bits(p), 0, 0)Description
TRUEnever evaluated
FALSEevaluated 550 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-550
183 goto end;
never executed: goto end;
0
184 if (BN_ucmp(y, p) >= 0) {
BN_ucmp(y, p) >= 0Description
TRUEevaluated 123 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 427 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
123-427
185 if (!(p->neg ? BN_add : BN_sub) (y, y, p))
!(p->neg ? BN_...sub) (y, y, p)Description
TRUEnever evaluated
FALSEevaluated 123 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
p->negDescription
TRUEnever evaluated
FALSEevaluated 123 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-123
186 goto end;
never executed: goto end;
0
187 }
executed 123 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
123
188 /* now 0 <= y < |p| */-
189 if (BN_is_zero(y))
BN_is_zero(y)Description
TRUEnever evaluated
FALSEevaluated 550 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-550
190 if (!BN_set_word(y, i))
!BN_set_word(y, i)Description
TRUEnever evaluated
FALSEnever evaluated
0
191 goto end;
never executed: goto end;
0
192 }
executed 550 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
550
193-
194 r = BN_kronecker(y, q, ctx); /* here 'q' is |p| */-
195 if (r < -1)
r < -1Description
TRUEnever evaluated
FALSEevaluated 21024 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-21024
196 goto end;
never executed: goto end;
0
197 if (r == 0) {
r == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 21019 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5-21019
198 /* m divides p */-
199 BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);-
200 goto end;
executed 5 times by 1 test: goto end;
Executed by:
  • libcrypto.so.1.1
5
201 }-
202 }
executed 21019 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
21019
203 while (r == 1 && ++i < 82);
r == 1Description
TRUEevaluated 18929 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2090 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
++i < 82Description
TRUEevaluated 18920 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
9-18929
204-
205 if (r != -1) {
r != -1Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2090 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
9-2090
206 /*-
207 * Many rounds and still no non-square -- this is more likely a bug-
208 * than just bad luck. Even if p is not prime, we should have found-
209 * some y such that r == -1.-
210 */-
211 BNerr(BN_F_BN_MOD_SQRT, BN_R_TOO_MANY_ITERATIONS);-
212 goto end;
executed 9 times by 1 test: goto end;
Executed by:
  • libcrypto.so.1.1
9
213 }-
214-
215 /* Here's our actual 'q': */-
216 if (!BN_rshift(q, q, e))
!BN_rshift(q, q, e)Description
TRUEnever evaluated
FALSEevaluated 2090 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2090
217 goto end;
never executed: goto end;
0
218-
219 /*-
220 * Now that we have some non-square, we can find an element of order 2^e-
221 * by computing its q'th power.-
222 */-
223 if (!BN_mod_exp(y, y, q, p, ctx))
!BN_mod_exp(y, y, q, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 2090 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2090
224 goto end;
never executed: goto end;
0
225 if (BN_is_one(y)) {
BN_is_one(y)Description
TRUEnever evaluated
FALSEevaluated 2090 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2090
226 BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);-
227 goto end;
never executed: goto end;
0
228 }-
229-
230 /*--
231 * Now we know that (if p is indeed prime) there is an integer-
232 * k, 0 <= k < 2^e, such that-
233 *-
234 * a^q * y^k == 1 (mod p).-
235 *-
236 * As a^q is a square and y is not, k must be even.-
237 * q+1 is even, too, so there is an element-
238 *-
239 * X := a^((q+1)/2) * y^(k/2),-
240 *-
241 * and it satisfies-
242 *-
243 * X^2 = a^q * a * y^k-
244 * = a,-
245 *-
246 * so it is the square root that we are looking for.-
247 */-
248-
249 /* t := (q-1)/2 (note that q is odd) */-
250 if (!BN_rshift1(t, q))
!BN_rshift1(t, q)Description
TRUEnever evaluated
FALSEevaluated 2090 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2090
251 goto end;
never executed: goto end;
0
252-
253 /* x := a^((q-1)/2) */-
254 if (BN_is_zero(t)) { /* special case: p = 2^e + 1 */
BN_is_zero(t)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2085 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5-2085
255 if (!BN_nnmod(t, A, p, ctx))
!BN_nnmod(t, A, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5
256 goto end;
never executed: goto end;
0
257 if (BN_is_zero(t)) {
BN_is_zero(t)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5
258 /* special case: a == 0 (mod p) */-
259 BN_zero(ret);-
260 err = 0;-
261 goto end;
never executed: goto end;
0
262 } else if (!BN_one(x))
!(BN_set_word((x),1))Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5
263 goto end;
never executed: goto end;
0
264 } else {
executed 5 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
5
265 if (!BN_mod_exp(x, A, t, p, ctx))
!BN_mod_exp(x, A, t, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 2085 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2085
266 goto end;
never executed: goto end;
0
267 if (BN_is_zero(x)) {
BN_is_zero(x)Description
TRUEnever evaluated
FALSEevaluated 2085 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2085
268 /* special case: a == 0 (mod p) */-
269 BN_zero(ret);-
270 err = 0;-
271 goto end;
never executed: goto end;
0
272 }-
273 }
executed 2085 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2085
274-
275 /* b := a*x^2 (= a^q) */-
276 if (!BN_mod_sqr(b, x, p, ctx))
!BN_mod_sqr(b, x, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 2090 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2090
277 goto end;
never executed: goto end;
0
278 if (!BN_mod_mul(b, b, A, p, ctx))
!BN_mod_mul(b, b, A, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 2090 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2090
279 goto end;
never executed: goto end;
0
280-
281 /* x := a*x (= a^((q+1)/2)) */-
282 if (!BN_mod_mul(x, x, A, p, ctx))
!BN_mod_mul(x, x, A, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 2090 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2090
283 goto end;
never executed: goto end;
0
284-
285 while (1) {-
286 /*--
287 * Now b is a^q * y^k for some even k (0 <= k < 2^E-
288 * where E refers to the original value of e, which we-
289 * don't keep in a variable), and x is a^((q+1)/2) * y^(k/2).-
290 *-
291 * We have a*b = x^2,-
292 * y^2^(e-1) = -1,-
293 * b^2^(e-1) = 1.-
294 */-
295-
296 if (BN_is_one(b)) {
BN_is_one(b)Description
TRUEevaluated 1491 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 71682 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1491-71682
297 if (!BN_copy(ret, x))
!BN_copy(ret, x)Description
TRUEnever evaluated
FALSEevaluated 1491 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1491
298 goto end;
never executed: goto end;
0
299 err = 0;-
300 goto vrfy;
executed 1491 times by 1 test: goto vrfy;
Executed by:
  • libcrypto.so.1.1
1491
301 }-
302-
303 /* find smallest i such that b^(2^i) = 1 */-
304 i = 1;-
305 if (!BN_mod_sqr(t, b, p, ctx))
!BN_mod_sqr(t, b, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 71682 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-71682
306 goto end;
never executed: goto end;
0
307 while (!BN_is_one(t)) {
!BN_is_one(t)Description
TRUEevaluated 3365412 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 71083 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
71083-3365412
308 i++;-
309 if (i == e) {
i == eDescription
TRUEevaluated 599 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3364813 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
599-3364813
310 BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);-
311 goto end;
executed 599 times by 1 test: goto end;
Executed by:
  • libcrypto.so.1.1
599
312 }-
313 if (!BN_mod_mul(t, t, t, p, ctx))
!BN_mod_mul(t, t, t, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 3364813 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3364813
314 goto end;
never executed: goto end;
0
315 }
executed 3364813 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
3364813
316-
317 /* t := y^2^(e - i - 1) */-
318 if (!BN_copy(t, y))
!BN_copy(t, y)Description
TRUEnever evaluated
FALSEevaluated 71083 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-71083
319 goto end;
never executed: goto end;
0
320 for (j = e - i - 1; j > 0; j--) {
j > 0Description
TRUEevaluated 63419 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 71083 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
63419-71083
321 if (!BN_mod_sqr(t, t, p, ctx))
!BN_mod_sqr(t, t, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 63419 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-63419
322 goto end;
never executed: goto end;
0
323 }
executed 63419 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
63419
324 if (!BN_mod_mul(y, t, t, p, ctx))
!BN_mod_mul(y, t, t, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 71083 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-71083
325 goto end;
never executed: goto end;
0
326 if (!BN_mod_mul(x, x, t, p, ctx))
!BN_mod_mul(x, x, t, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 71083 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-71083
327 goto end;
never executed: goto end;
0
328 if (!BN_mod_mul(b, b, y, p, ctx))
!BN_mod_mul(b, b, y, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 71083 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-71083
329 goto end;
never executed: goto end;
0
330 e = i;-
331 }
executed 71083 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
71083
332-
333 vrfy:
code before this statement never executed: vrfy:
0
334 if (!err) {
!errDescription
TRUEevaluated 3980 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-3980
335 /*-
336 * verify the result -- the input might have been not a square (test-
337 * added in 0.9.8)-
338 */-
339-
340 if (!BN_mod_sqr(x, ret, p, ctx))
!BN_mod_sqr(x, ret, p, ctx)Description
TRUEnever evaluated
FALSEevaluated 3980 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3980
341 err = 1;
never executed: err = 1;
0
342-
343 if (!err && 0 != BN_cmp(x, A)) {
!errDescription
TRUEevaluated 3980 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0 != BN_cmp(x, A)Description
TRUEevaluated 666 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3314 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3980
344 BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);-
345 err = 1;-
346 }
executed 666 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
666
347 }
executed 3980 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
3980
348-
349 end:
code before this statement executed 3980 times by 1 test: end:
Executed by:
  • libcrypto.so.1.1
3980
350 if (err) {
errDescription
TRUEevaluated 1279 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3314 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1279-3314
351 if (ret != in)
ret != inDescription
TRUEnever evaluated
FALSEevaluated 1279 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1279
352 BN_clear_free(ret);
never executed: BN_clear_free(ret);
0
353 ret = NULL;-
354 }
executed 1279 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1279
355 BN_CTX_end(ctx);-
356 bn_check_top(ret);-
357 return ret;
executed 4593 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
4593
358}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2