| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bn/bn_div.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, | - | ||||||||||||||||||||||||||||||||||||
| 2 | BN_CTX *ctx) | - | ||||||||||||||||||||||||||||||||||||
| 3 | { | - | ||||||||||||||||||||||||||||||||||||
| 4 | int norm_shift, i, loop; | - | ||||||||||||||||||||||||||||||||||||
| 5 | BIGNUM *tmp, wnum, *snum, *sdiv, *res; | - | ||||||||||||||||||||||||||||||||||||
| 6 | unsigned long *resp, *wnump; | - | ||||||||||||||||||||||||||||||||||||
| 7 | unsigned long d0, d1; | - | ||||||||||||||||||||||||||||||||||||
| 8 | int num_n, div_n; | - | ||||||||||||||||||||||||||||||||||||
| 9 | int no_branch = 0; | - | ||||||||||||||||||||||||||||||||||||
| 10 | - | |||||||||||||||||||||||||||||||||||||
| 11 | - | |||||||||||||||||||||||||||||||||||||
| 12 | - | |||||||||||||||||||||||||||||||||||||
| 13 | - | |||||||||||||||||||||||||||||||||||||
| 14 | - | |||||||||||||||||||||||||||||||||||||
| 15 | - | |||||||||||||||||||||||||||||||||||||
| 16 | if ((num->top > 0
| 0-7089159 | ||||||||||||||||||||||||||||||||||||
| 17 | (divisor->top > 0
| 0-7098495 | ||||||||||||||||||||||||||||||||||||
| 18 | ERR_put_error(3,(107),(107),__FILE__,154); | - | ||||||||||||||||||||||||||||||||||||
| 19 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
| 20 | } | - | ||||||||||||||||||||||||||||||||||||
| 21 | - | |||||||||||||||||||||||||||||||||||||
| 22 | ; | - | ||||||||||||||||||||||||||||||||||||
| 23 | ; | - | ||||||||||||||||||||||||||||||||||||
| 24 | - | |||||||||||||||||||||||||||||||||||||
| 25 | if ((
| 2422072-4676426 | ||||||||||||||||||||||||||||||||||||
| 26 | || (
| 24686-4651740 | ||||||||||||||||||||||||||||||||||||
| 27 | no_branch = 1; | - | ||||||||||||||||||||||||||||||||||||
| 28 | } executed 2446758 times by 2 tests: end of blockExecuted by:
| 2446758 | ||||||||||||||||||||||||||||||||||||
| 29 | - | |||||||||||||||||||||||||||||||||||||
| 30 | ; | - | ||||||||||||||||||||||||||||||||||||
| 31 | ; | - | ||||||||||||||||||||||||||||||||||||
| 32 | - | |||||||||||||||||||||||||||||||||||||
| 33 | - | |||||||||||||||||||||||||||||||||||||
| 34 | - | |||||||||||||||||||||||||||||||||||||
| 35 | - | |||||||||||||||||||||||||||||||||||||
| 36 | - | |||||||||||||||||||||||||||||||||||||
| 37 | - | |||||||||||||||||||||||||||||||||||||
| 38 | - | |||||||||||||||||||||||||||||||||||||
| 39 | if (BN_is_zero(divisor)
| 3-7098495 | ||||||||||||||||||||||||||||||||||||
| 40 | ERR_put_error(3,(107),(103),__FILE__,176); | - | ||||||||||||||||||||||||||||||||||||
| 41 | return executed 3 times by 1 test: 0;return 0;Executed by:
executed 3 times by 1 test: return 0;Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||
| 42 | } | - | ||||||||||||||||||||||||||||||||||||
| 43 | - | |||||||||||||||||||||||||||||||||||||
| 44 | if (!no_branch
| 230043-4651737 | ||||||||||||||||||||||||||||||||||||
| 45 | if (rm !=
| 1-230042 | ||||||||||||||||||||||||||||||||||||
| 46 | ((void *)0)
| 1-230042 | ||||||||||||||||||||||||||||||||||||
| 47 | ) { | - | ||||||||||||||||||||||||||||||||||||
| 48 | if (BN_copy(rm, num) ==
| 0-230042 | ||||||||||||||||||||||||||||||||||||
| 49 | ((void *)0)
| 0-230042 | ||||||||||||||||||||||||||||||||||||
| 50 | ) | - | ||||||||||||||||||||||||||||||||||||
| 51 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
| 52 | } executed 230042 times by 2 tests: end of blockExecuted by:
| 230042 | ||||||||||||||||||||||||||||||||||||
| 53 | if (dv !=
| 96-229947 | ||||||||||||||||||||||||||||||||||||
| 54 | ((void *)0)
| 96-229947 | ||||||||||||||||||||||||||||||||||||
| 55 | ) | - | ||||||||||||||||||||||||||||||||||||
| 56 | ( executed 96 times by 1 test: BN_set_word((dv),0));(BN_set_word((dv),0));Executed by:
executed 96 times by 1 test: (BN_set_word((dv),0));Executed by:
| 96 | ||||||||||||||||||||||||||||||||||||
| 57 | return executed 230043 times by 2 tests: 1;return 1;Executed by:
executed 230043 times by 2 tests: return 1;Executed by:
| 230043 | ||||||||||||||||||||||||||||||||||||
| 58 | } | - | ||||||||||||||||||||||||||||||||||||
| 59 | - | |||||||||||||||||||||||||||||||||||||
| 60 | BN_CTX_start(ctx); | - | ||||||||||||||||||||||||||||||||||||
| 61 | res = (
| 2507737-4360715 | ||||||||||||||||||||||||||||||||||||
| 62 | ((void *)0)
| 2507737-4360715 | ||||||||||||||||||||||||||||||||||||
| 63 | )
| 2507737-4360715 | ||||||||||||||||||||||||||||||||||||
| 64 | tmp = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||||||||||||||
| 65 | snum = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||||||||||||||
| 66 | sdiv = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||||||||||||||
| 67 | if (sdiv ==
| 0-6868452 | ||||||||||||||||||||||||||||||||||||
| 68 | ((void *)0)
| 0-6868452 | ||||||||||||||||||||||||||||||||||||
| 69 | ) | - | ||||||||||||||||||||||||||||||||||||
| 70 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||
| 71 | - | |||||||||||||||||||||||||||||||||||||
| 72 | - | |||||||||||||||||||||||||||||||||||||
| 73 | norm_shift = (8 * 8) - ((BN_num_bits(divisor)) % (8 * 8)); | - | ||||||||||||||||||||||||||||||||||||
| 74 | if (!(BN_lshift(sdiv, divisor, norm_shift))
| 0-6868452 | ||||||||||||||||||||||||||||||||||||
| 75 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||
| 76 | sdiv->neg = 0; | - | ||||||||||||||||||||||||||||||||||||
| 77 | norm_shift += (8 * 8); | - | ||||||||||||||||||||||||||||||||||||
| 78 | if (!(BN_lshift(snum, num, norm_shift))
| 0-6868452 | ||||||||||||||||||||||||||||||||||||
| 79 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||
| 80 | snum->neg = 0; | - | ||||||||||||||||||||||||||||||||||||
| 81 | - | |||||||||||||||||||||||||||||||||||||
| 82 | if (no_branch
| 2446758-4421694 | ||||||||||||||||||||||||||||||||||||
| 83 | - | |||||||||||||||||||||||||||||||||||||
| 84 | - | |||||||||||||||||||||||||||||||||||||
| 85 | - | |||||||||||||||||||||||||||||||||||||
| 86 | - | |||||||||||||||||||||||||||||||||||||
| 87 | if (snum->top <= sdiv->top + 1
| 532746-1914012 | ||||||||||||||||||||||||||||||||||||
| 88 | if (bn_wexpand(snum, sdiv->top + 2) ==
| 0-532746 | ||||||||||||||||||||||||||||||||||||
| 89 | ((void *)0)
| 0-532746 | ||||||||||||||||||||||||||||||||||||
| 90 | ) | - | ||||||||||||||||||||||||||||||||||||
| 91 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||
| 92 | for (i = snum->top; i < sdiv->top + 2
| 532746-532814 | ||||||||||||||||||||||||||||||||||||
| 93 | snum->d[i] = 0; executed 532814 times by 1 test: snum->d[i] = 0;Executed by:
| 532814 | ||||||||||||||||||||||||||||||||||||
| 94 | snum->top = sdiv->top + 2; | - | ||||||||||||||||||||||||||||||||||||
| 95 | } executed 532746 times by 1 test: else {end of blockExecuted by:
| 532746 | ||||||||||||||||||||||||||||||||||||
| 96 | if (bn_wexpand(snum, snum->top + 1) ==
| 0-1914012 | ||||||||||||||||||||||||||||||||||||
| 97 | ((void *)0)
| 0-1914012 | ||||||||||||||||||||||||||||||||||||
| 98 | ) | - | ||||||||||||||||||||||||||||||||||||
| 99 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||
| 100 | snum->d[snum->top] = 0; | - | ||||||||||||||||||||||||||||||||||||
| 101 | snum->top++; | - | ||||||||||||||||||||||||||||||||||||
| 102 | } executed 1914012 times by 2 tests: end of blockExecuted by:
| 1914012 | ||||||||||||||||||||||||||||||||||||
| 103 | } | - | ||||||||||||||||||||||||||||||||||||
| 104 | - | |||||||||||||||||||||||||||||||||||||
| 105 | div_n = sdiv->top; | - | ||||||||||||||||||||||||||||||||||||
| 106 | num_n = snum->top; | - | ||||||||||||||||||||||||||||||||||||
| 107 | loop = num_n - div_n; | - | ||||||||||||||||||||||||||||||||||||
| 108 | - | |||||||||||||||||||||||||||||||||||||
| 109 | - | |||||||||||||||||||||||||||||||||||||
| 110 | - | |||||||||||||||||||||||||||||||||||||
| 111 | - | |||||||||||||||||||||||||||||||||||||
| 112 | wnum.neg = 0; | - | ||||||||||||||||||||||||||||||||||||
| 113 | wnum.d = &(snum->d[loop]); | - | ||||||||||||||||||||||||||||||||||||
| 114 | wnum.top = div_n; | - | ||||||||||||||||||||||||||||||||||||
| 115 | wnum.flags = 0x02; | - | ||||||||||||||||||||||||||||||||||||
| 116 | - | |||||||||||||||||||||||||||||||||||||
| 117 | - | |||||||||||||||||||||||||||||||||||||
| 118 | - | |||||||||||||||||||||||||||||||||||||
| 119 | wnum.dmax = snum->dmax - loop; | - | ||||||||||||||||||||||||||||||||||||
| 120 | - | |||||||||||||||||||||||||||||||||||||
| 121 | - | |||||||||||||||||||||||||||||||||||||
| 122 | - | |||||||||||||||||||||||||||||||||||||
| 123 | d0 = sdiv->d[div_n - 1]; | - | ||||||||||||||||||||||||||||||||||||
| 124 | d1 = (
| 534748-6333704 | ||||||||||||||||||||||||||||||||||||
| 125 | - | |||||||||||||||||||||||||||||||||||||
| 126 | - | |||||||||||||||||||||||||||||||||||||
| 127 | wnump = &(snum->d[num_n - 1]); | - | ||||||||||||||||||||||||||||||||||||
| 128 | - | |||||||||||||||||||||||||||||||||||||
| 129 | - | |||||||||||||||||||||||||||||||||||||
| 130 | if (!bn_wexpand(res, (loop + 1))
| 0-6868452 | ||||||||||||||||||||||||||||||||||||
| 131 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||
| 132 | res->neg = (num->neg ^ divisor->neg); | - | ||||||||||||||||||||||||||||||||||||
| 133 | res->top = loop - no_branch; | - | ||||||||||||||||||||||||||||||||||||
| 134 | resp = &(res->d[loop - 1]); | - | ||||||||||||||||||||||||||||||||||||
| 135 | - | |||||||||||||||||||||||||||||||||||||
| 136 | - | |||||||||||||||||||||||||||||||||||||
| 137 | if (!bn_wexpand(tmp, (div_n + 1))
| 0-6868452 | ||||||||||||||||||||||||||||||||||||
| 138 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||
| 139 | - | |||||||||||||||||||||||||||||||||||||
| 140 | if (!no_branch
| 2446758-4421694 | ||||||||||||||||||||||||||||||||||||
| 141 | if (BN_ucmp(&wnum, sdiv) >= 0
| 32266-4389428 | ||||||||||||||||||||||||||||||||||||
| 142 | - | |||||||||||||||||||||||||||||||||||||
| 143 | - | |||||||||||||||||||||||||||||||||||||
| 144 | - | |||||||||||||||||||||||||||||||||||||
| 145 | - | |||||||||||||||||||||||||||||||||||||
| 146 | - | |||||||||||||||||||||||||||||||||||||
| 147 | ; | - | ||||||||||||||||||||||||||||||||||||
| 148 | bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n); | - | ||||||||||||||||||||||||||||||||||||
| 149 | *resp = 1; | - | ||||||||||||||||||||||||||||||||||||
| 150 | } executed 32266 times by 2 tests: elseend of blockExecuted by:
| 32266 | ||||||||||||||||||||||||||||||||||||
| 151 | res->top--; executed 4389428 times by 2 tests: res->top--;Executed by:
| 4389428 | ||||||||||||||||||||||||||||||||||||
| 152 | } | - | ||||||||||||||||||||||||||||||||||||
| 153 | - | |||||||||||||||||||||||||||||||||||||
| 154 | - | |||||||||||||||||||||||||||||||||||||
| 155 | resp++; | - | ||||||||||||||||||||||||||||||||||||
| 156 | - | |||||||||||||||||||||||||||||||||||||
| 157 | - | |||||||||||||||||||||||||||||||||||||
| 158 | - | |||||||||||||||||||||||||||||||||||||
| 159 | - | |||||||||||||||||||||||||||||||||||||
| 160 | - | |||||||||||||||||||||||||||||||||||||
| 161 | if (res->top == 0
| 0-6868452 | ||||||||||||||||||||||||||||||||||||
| 162 | res->neg = 0; never executed: res->neg = 0; | 0 | ||||||||||||||||||||||||||||||||||||
| 163 | else | - | ||||||||||||||||||||||||||||||||||||
| 164 | resp--; executed 6868452 times by 2 tests: resp--;Executed by:
| 6868452 | ||||||||||||||||||||||||||||||||||||
| 165 | - | |||||||||||||||||||||||||||||||||||||
| 166 | for (i = 0; i < loop - 1
| 6868452-22741823 | ||||||||||||||||||||||||||||||||||||
| 167 | unsigned long q, l0; | - | ||||||||||||||||||||||||||||||||||||
| 168 | unsigned long n0, n1, rem = 0; | - | ||||||||||||||||||||||||||||||||||||
| 169 | - | |||||||||||||||||||||||||||||||||||||
| 170 | n0 = wnump[0]; | - | ||||||||||||||||||||||||||||||||||||
| 171 | n1 = wnump[-1]; | - | ||||||||||||||||||||||||||||||||||||
| 172 | if (n0 == d0
| 90174-22651649 | ||||||||||||||||||||||||||||||||||||
| 173 | q = (0xffffffffffffffffL); executed 90174 times by 1 test: q = (0xffffffffffffffffL);Executed by:
| 90174 | ||||||||||||||||||||||||||||||||||||
| 174 | else { | - | ||||||||||||||||||||||||||||||||||||
| 175 | unsigned long t2l, t2h; | - | ||||||||||||||||||||||||||||||||||||
| 176 | - | |||||||||||||||||||||||||||||||||||||
| 177 | q = ({ asm volatile ( "divq %4" : "=a"(q), "=d"(rem) : "a"(n1), "d"(n0), "r"(d0) : "cc"); q; }); | - | ||||||||||||||||||||||||||||||||||||
| 178 | - | |||||||||||||||||||||||||||||||||||||
| 179 | - | |||||||||||||||||||||||||||||||||||||
| 180 | - | |||||||||||||||||||||||||||||||||||||
| 181 | - | |||||||||||||||||||||||||||||||||||||
| 182 | - | |||||||||||||||||||||||||||||||||||||
| 183 | ({ __uint128_t ret=(__uint128_t)(d1)*(q); (t2h)=ret>>64; (t2l)=ret; }); | - | ||||||||||||||||||||||||||||||||||||
| 184 | for (;;) { | - | ||||||||||||||||||||||||||||||||||||
| 185 | if ((
| 78657-16235308 | ||||||||||||||||||||||||||||||||||||
| 186 | break; executed 16568745 times by 2 tests: break;Executed by:
| 16568745 | ||||||||||||||||||||||||||||||||||||
| 187 | q--; | - | ||||||||||||||||||||||||||||||||||||
| 188 | rem += d0; | - | ||||||||||||||||||||||||||||||||||||
| 189 | if (rem < d0
| 470532-6082904 | ||||||||||||||||||||||||||||||||||||
| 190 | break; executed 6082904 times by 2 tests: break;Executed by:
| 6082904 | ||||||||||||||||||||||||||||||||||||
| 191 | if (t2l < d1
| 168517-302015 | ||||||||||||||||||||||||||||||||||||
| 192 | t2h--; executed 302015 times by 2 tests: t2h--;Executed by:
| 302015 | ||||||||||||||||||||||||||||||||||||
| 193 | t2l -= d1; | - | ||||||||||||||||||||||||||||||||||||
| 194 | } executed 470532 times by 2 tests: end of blockExecuted by:
| 470532 | ||||||||||||||||||||||||||||||||||||
| 195 | - | |||||||||||||||||||||||||||||||||||||
| 196 | } executed 22651649 times by 2 tests: end of blockExecuted by:
| 22651649 | ||||||||||||||||||||||||||||||||||||
| 197 | - | |||||||||||||||||||||||||||||||||||||
| 198 | - | |||||||||||||||||||||||||||||||||||||
| 199 | l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q); | - | ||||||||||||||||||||||||||||||||||||
| 200 | tmp->d[div_n] = l0; | - | ||||||||||||||||||||||||||||||||||||
| 201 | wnum.d--; | - | ||||||||||||||||||||||||||||||||||||
| 202 | - | |||||||||||||||||||||||||||||||||||||
| 203 | - | |||||||||||||||||||||||||||||||||||||
| 204 | - | |||||||||||||||||||||||||||||||||||||
| 205 | - | |||||||||||||||||||||||||||||||||||||
| 206 | if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)
| 78007-22663816 | ||||||||||||||||||||||||||||||||||||
| 207 | - | |||||||||||||||||||||||||||||||||||||
| 208 | - | |||||||||||||||||||||||||||||||||||||
| 209 | - | |||||||||||||||||||||||||||||||||||||
| 210 | - | |||||||||||||||||||||||||||||||||||||
| 211 | - | |||||||||||||||||||||||||||||||||||||
| 212 | q--; | - | ||||||||||||||||||||||||||||||||||||
| 213 | if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n)
| 0-78007 | ||||||||||||||||||||||||||||||||||||
| 214 | - | |||||||||||||||||||||||||||||||||||||
| 215 | - | |||||||||||||||||||||||||||||||||||||
| 216 | - | |||||||||||||||||||||||||||||||||||||
| 217 | - | |||||||||||||||||||||||||||||||||||||
| 218 | (* executed 78007 times by 1 test: wnump)++;(*wnump)++;Executed by:
executed 78007 times by 1 test: (*wnump)++;Executed by:
| 78007 | ||||||||||||||||||||||||||||||||||||
| 219 | } executed 78007 times by 1 test: end of blockExecuted by:
| 78007 | ||||||||||||||||||||||||||||||||||||
| 220 | - | |||||||||||||||||||||||||||||||||||||
| 221 | resp--; | - | ||||||||||||||||||||||||||||||||||||
| 222 | *resp = q; | - | ||||||||||||||||||||||||||||||||||||
| 223 | } executed 22741823 times by 2 tests: end of blockExecuted by:
| 22741823 | ||||||||||||||||||||||||||||||||||||
| 224 | bn_correct_top(snum); | - | ||||||||||||||||||||||||||||||||||||
| 225 | if (rm !=
| 84287-6784165 | ||||||||||||||||||||||||||||||||||||
| 226 | ((void *)0)
| 84287-6784165 | ||||||||||||||||||||||||||||||||||||
| 227 | ) { | - | ||||||||||||||||||||||||||||||||||||
| 228 | - | |||||||||||||||||||||||||||||||||||||
| 229 | - | |||||||||||||||||||||||||||||||||||||
| 230 | - | |||||||||||||||||||||||||||||||||||||
| 231 | - | |||||||||||||||||||||||||||||||||||||
| 232 | int neg = num->neg; | - | ||||||||||||||||||||||||||||||||||||
| 233 | BN_rshift(rm, snum, norm_shift); | - | ||||||||||||||||||||||||||||||||||||
| 234 | if (!BN_is_zero(rm)
| 32906-6751259 | ||||||||||||||||||||||||||||||||||||
| 235 | rm->neg = neg; executed 6751259 times by 2 tests: rm->neg = neg;Executed by:
| 6751259 | ||||||||||||||||||||||||||||||||||||
| 236 | ; | - | ||||||||||||||||||||||||||||||||||||
| 237 | } executed 6784165 times by 2 tests: end of blockExecuted by:
| 6784165 | ||||||||||||||||||||||||||||||||||||
| 238 | if (no_branch
| 2446758-4421694 | ||||||||||||||||||||||||||||||||||||
| 239 | bn_correct_top(res); executed 2446758 times by 2 tests: bn_correct_top(res);Executed by:
| 2446758 | ||||||||||||||||||||||||||||||||||||
| 240 | BN_CTX_end(ctx); | - | ||||||||||||||||||||||||||||||||||||
| 241 | return executed 6868452 times by 2 tests: 1;return 1;Executed by:
executed 6868452 times by 2 tests: return 1;Executed by:
| 6868452 | ||||||||||||||||||||||||||||||||||||
| 242 | err: | - | ||||||||||||||||||||||||||||||||||||
| 243 | ; | - | ||||||||||||||||||||||||||||||||||||
| 244 | BN_CTX_end(ctx); | - | ||||||||||||||||||||||||||||||||||||
| 245 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
| 246 | } | - | ||||||||||||||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |