| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bn/bn_sqrt.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 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 | - | |||||||||||||
| 13 | BIGNUM *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)) {
| 0-4601 | ||||||||||||
| 27 | if (BN_abs_is_word(p, 2)) {
| 0-5 | ||||||||||||
| 28 | if (ret == NULL)
| 0-5 | ||||||||||||
| 29 | ret = BN_new(); never executed: ret = BN_new(); | 0 | ||||||||||||
| 30 | if (ret == NULL)
| 0-5 | ||||||||||||
| 31 | goto end; never executed: goto end; | 0 | ||||||||||||
| 32 | if (!BN_set_word(ret, BN_is_bit_set(a, 0))) {
| 0-5 | ||||||||||||
| 33 | if (ret != in)
| 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:
| 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)) {
| 1-4594 | ||||||||||||
| 46 | if (ret == NULL)
| 0-8 | ||||||||||||
| 47 | ret = BN_new(); never executed: ret = BN_new(); | 0 | ||||||||||||
| 48 | if (ret == NULL)
| 0-8 | ||||||||||||
| 49 | goto end; never executed: goto end; | 0 | ||||||||||||
| 50 | if (!BN_set_word(ret, BN_is_one(a))) {
| 0-8 | ||||||||||||
| 51 | if (ret != in)
| 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:
| 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)
| 0-4593 | ||||||||||||
| 67 | goto end; never executed: goto end; | 0 | ||||||||||||
| 68 | - | |||||||||||||
| 69 | if (ret == NULL)
| 0-4593 | ||||||||||||
| 70 | ret = BN_new(); never executed: ret = BN_new(); | 0 | ||||||||||||
| 71 | if (ret == NULL)
| 0-4593 | ||||||||||||
| 72 | goto end; never executed: goto end; | 0 | ||||||||||||
| 73 | - | |||||||||||||
| 74 | /* A = a mod p */ | - | ||||||||||||
| 75 | if (!BN_nnmod(A, a, p, ctx))
| 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))
| 4593-195180 | ||||||||||||
| 81 | e++; executed 195180 times by 1 test: e++;Executed by:
| 195180 | ||||||||||||
| 82 | /* we'll set q later (if needed) */ | - | ||||||||||||
| 83 | - | |||||||||||||
| 84 | if (e == 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))
| 0-1894 | ||||||||||||
| 94 | goto end; never executed: goto end; | 0 | ||||||||||||
| 95 | q->neg = 0; | - | ||||||||||||
| 96 | if (!BN_add_word(q, 1))
| 0-1894 | ||||||||||||
| 97 | goto end; never executed: goto end; | 0 | ||||||||||||
| 98 | if (!BN_mod_exp(ret, A, q, p, ctx))
| 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:
| 1894 | ||||||||||||
| 102 | } | - | ||||||||||||
| 103 | - | |||||||||||||
| 104 | if (e == 2) {
| 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))
| 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))
| 0-595 | ||||||||||||
| 138 | goto end; never executed: goto end; | 0 | ||||||||||||
| 139 | q->neg = 0; | - | ||||||||||||
| 140 | if (!BN_mod_exp(b, t, q, p, ctx))
| 0-595 | ||||||||||||
| 141 | goto end; never executed: goto end; | 0 | ||||||||||||
| 142 | - | |||||||||||||
| 143 | /* y := b^2 */ | - | ||||||||||||
| 144 | if (!BN_mod_sqr(y, b, p, ctx))
| 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))
| 0-595 | ||||||||||||
| 149 | goto end; never executed: goto end; | 0 | ||||||||||||
| 150 | if (!BN_sub_word(t, 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))
| 0-595 | ||||||||||||
| 155 | goto end; never executed: goto end; | 0 | ||||||||||||
| 156 | if (!BN_mod_mul(x, x, t, p, ctx))
| 0-595 | ||||||||||||
| 157 | goto end; never executed: goto end; | 0 | ||||||||||||
| 158 | - | |||||||||||||
| 159 | if (!BN_copy(ret, x))
| 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:
| 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))
| 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) {
| 550-20474 | ||||||||||||
| 179 | if (!BN_set_word(y, i))
| 0-20474 | ||||||||||||
| 180 | goto end; never executed: goto end; | 0 | ||||||||||||
| 181 | } else { executed 20474 times by 1 test: end of blockExecuted by:
| 20474 | ||||||||||||
| 182 | if (!BN_priv_rand(y, BN_num_bits(p), 0, 0))
| 0-550 | ||||||||||||
| 183 | goto end; never executed: goto end; | 0 | ||||||||||||
| 184 | if (BN_ucmp(y, p) >= 0) {
| 123-427 | ||||||||||||
| 185 | if (!(p->neg ? BN_add : BN_sub) (y, y, p))
| 0-123 | ||||||||||||
| 186 | goto end; never executed: goto end; | 0 | ||||||||||||
| 187 | } executed 123 times by 1 test: end of blockExecuted by:
| 123 | ||||||||||||
| 188 | /* now 0 <= y < |p| */ | - | ||||||||||||
| 189 | if (BN_is_zero(y))
| 0-550 | ||||||||||||
| 190 | if (!BN_set_word(y, i))
| 0 | ||||||||||||
| 191 | goto end; never executed: goto end; | 0 | ||||||||||||
| 192 | } executed 550 times by 1 test: end of blockExecuted by:
| 550 | ||||||||||||
| 193 | - | |||||||||||||
| 194 | r = BN_kronecker(y, q, ctx); /* here 'q' is |p| */ | - | ||||||||||||
| 195 | if (r < -1)
| 0-21024 | ||||||||||||
| 196 | goto end; never executed: goto end; | 0 | ||||||||||||
| 197 | if (r == 0) {
| 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:
| 5 | ||||||||||||
| 201 | } | - | ||||||||||||
| 202 | } executed 21019 times by 1 test: end of blockExecuted by:
| 21019 | ||||||||||||
| 203 | while (r == 1 && ++i < 82);
| 9-18929 | ||||||||||||
| 204 | - | |||||||||||||
| 205 | if (r != -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:
| 9 | ||||||||||||
| 213 | } | - | ||||||||||||
| 214 | - | |||||||||||||
| 215 | /* Here's our actual 'q': */ | - | ||||||||||||
| 216 | if (!BN_rshift(q, q, e))
| 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))
| 0-2090 | ||||||||||||
| 224 | goto end; never executed: goto end; | 0 | ||||||||||||
| 225 | if (BN_is_one(y)) {
| 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))
| 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 */
| 5-2085 | ||||||||||||
| 255 | if (!BN_nnmod(t, A, p, ctx))
| 0-5 | ||||||||||||
| 256 | goto end; never executed: goto end; | 0 | ||||||||||||
| 257 | if (BN_is_zero(t)) {
| 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))
| 0-5 | ||||||||||||
| 263 | goto end; never executed: goto end; | 0 | ||||||||||||
| 264 | } else { executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||
| 265 | if (!BN_mod_exp(x, A, t, p, ctx))
| 0-2085 | ||||||||||||
| 266 | goto end; never executed: goto end; | 0 | ||||||||||||
| 267 | if (BN_is_zero(x)) {
| 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 blockExecuted by:
| 2085 | ||||||||||||
| 274 | - | |||||||||||||
| 275 | /* b := a*x^2 (= a^q) */ | - | ||||||||||||
| 276 | if (!BN_mod_sqr(b, x, p, ctx))
| 0-2090 | ||||||||||||
| 277 | goto end; never executed: goto end; | 0 | ||||||||||||
| 278 | if (!BN_mod_mul(b, b, A, p, ctx))
| 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))
| 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)) {
| 1491-71682 | ||||||||||||
| 297 | if (!BN_copy(ret, x))
| 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:
| 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))
| 0-71682 | ||||||||||||
| 306 | goto end; never executed: goto end; | 0 | ||||||||||||
| 307 | while (!BN_is_one(t)) {
| 71083-3365412 | ||||||||||||
| 308 | i++; | - | ||||||||||||
| 309 | if (i == e) {
| 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:
| 599 | ||||||||||||
| 312 | } | - | ||||||||||||
| 313 | if (!BN_mod_mul(t, t, t, p, ctx))
| 0-3364813 | ||||||||||||
| 314 | goto end; never executed: goto end; | 0 | ||||||||||||
| 315 | } executed 3364813 times by 1 test: end of blockExecuted by:
| 3364813 | ||||||||||||
| 316 | - | |||||||||||||
| 317 | /* t := y^2^(e - i - 1) */ | - | ||||||||||||
| 318 | if (!BN_copy(t, y))
| 0-71083 | ||||||||||||
| 319 | goto end; never executed: goto end; | 0 | ||||||||||||
| 320 | for (j = e - i - 1; j > 0; j--) {
| 63419-71083 | ||||||||||||
| 321 | if (!BN_mod_sqr(t, t, p, ctx))
| 0-63419 | ||||||||||||
| 322 | goto end; never executed: goto end; | 0 | ||||||||||||
| 323 | } executed 63419 times by 1 test: end of blockExecuted by:
| 63419 | ||||||||||||
| 324 | if (!BN_mod_mul(y, t, t, p, ctx))
| 0-71083 | ||||||||||||
| 325 | goto end; never executed: goto end; | 0 | ||||||||||||
| 326 | if (!BN_mod_mul(x, x, t, p, ctx))
| 0-71083 | ||||||||||||
| 327 | goto end; never executed: goto end; | 0 | ||||||||||||
| 328 | if (!BN_mod_mul(b, b, y, p, ctx))
| 0-71083 | ||||||||||||
| 329 | goto end; never executed: goto end; | 0 | ||||||||||||
| 330 | e = i; | - | ||||||||||||
| 331 | } executed 71083 times by 1 test: end of blockExecuted by:
| 71083 | ||||||||||||
| 332 | - | |||||||||||||
| 333 | vrfy: code before this statement never executed: vrfy: | 0 | ||||||||||||
| 334 | if (!err) {
| 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))
| 0-3980 | ||||||||||||
| 341 | err = 1; never executed: err = 1; | 0 | ||||||||||||
| 342 | - | |||||||||||||
| 343 | if (!err && 0 != BN_cmp(x, A)) {
| 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 blockExecuted by:
| 666 | ||||||||||||
| 347 | } executed 3980 times by 1 test: end of blockExecuted by:
| 3980 | ||||||||||||
| 348 | - | |||||||||||||
| 349 | end: code before this statement executed 3980 times by 1 test: end:Executed by:
| 3980 | ||||||||||||
| 350 | if (err) {
| 1279-3314 | ||||||||||||
| 351 | if (ret != in)
| 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 blockExecuted by:
| 1279 | ||||||||||||
| 355 | BN_CTX_end(ctx); | - | ||||||||||||
| 356 | bn_check_top(ret); | - | ||||||||||||
| 357 | return ret; executed 4593 times by 1 test: return ret;Executed by:
| 4593 | ||||||||||||
| 358 | } | - | ||||||||||||
| Source code | Switch to Preprocessed file |