| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bn/bn_sqr.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx) | - | ||||||||||||
| 7 | { | - | ||||||||||||
| 8 | int ret = bn_sqr_fixed_top(r, a, ctx); | - | ||||||||||||
| 9 | - | |||||||||||||
| 10 | bn_correct_top(r); | - | ||||||||||||
| 11 | ; | - | ||||||||||||
| 12 | - | |||||||||||||
| 13 | return executed 3893302 times by 2 tests: ret;return ret;Executed by:
executed 3893302 times by 2 tests: return ret;Executed by:
| 3893302 | ||||||||||||
| 14 | } | - | ||||||||||||
| 15 | - | |||||||||||||
| 16 | int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx) | - | ||||||||||||
| 17 | { | - | ||||||||||||
| 18 | int max, al; | - | ||||||||||||
| 19 | int ret = 0; | - | ||||||||||||
| 20 | BIGNUM *tmp, *rr; | - | ||||||||||||
| 21 | - | |||||||||||||
| 22 | ; | - | ||||||||||||
| 23 | - | |||||||||||||
| 24 | al = a->top; | - | ||||||||||||
| 25 | if (al <= 0
| 13300-3946758 | ||||||||||||
| 26 | r->top = 0; | - | ||||||||||||
| 27 | r->neg = 0; | - | ||||||||||||
| 28 | return executed 13300 times by 1 test: 1;return 1;Executed by:
executed 13300 times by 1 test: return 1;Executed by:
| 13300 | ||||||||||||
| 29 | } | - | ||||||||||||
| 30 | - | |||||||||||||
| 31 | BN_CTX_start(ctx); | - | ||||||||||||
| 32 | rr = (
| 63434-3883324 | ||||||||||||
| 33 | tmp = BN_CTX_get(ctx); | - | ||||||||||||
| 34 | if (rr ==
| 0-3946758 | ||||||||||||
| 35 | ((void *)0)
| 0-3946758 | ||||||||||||
| 36 | || tmp ==
| 0-3946758 | ||||||||||||
| 37 | ((void *)0)
| 0-3946758 | ||||||||||||
| 38 | ) | - | ||||||||||||
| 39 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 40 | - | |||||||||||||
| 41 | max = 2 * al; | - | ||||||||||||
| 42 | if (bn_wexpand(rr, max) ==
| 0-3946758 | ||||||||||||
| 43 | ((void *)0)
| 0-3946758 | ||||||||||||
| 44 | ) | - | ||||||||||||
| 45 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 46 | - | |||||||||||||
| 47 | if (al == 4
| 361243-3585515 | ||||||||||||
| 48 | - | |||||||||||||
| 49 | - | |||||||||||||
| 50 | - | |||||||||||||
| 51 | - | |||||||||||||
| 52 | bn_sqr_comba4(rr->d, a->d); | - | ||||||||||||
| 53 | - | |||||||||||||
| 54 | } executed 3585515 times by 2 tests: else if (al == 8end of blockExecuted by:
| 126176-3585515 | ||||||||||||
| 55 | - | |||||||||||||
| 56 | - | |||||||||||||
| 57 | - | |||||||||||||
| 58 | - | |||||||||||||
| 59 | bn_sqr_comba8(rr->d, a->d); | - | ||||||||||||
| 60 | - | |||||||||||||
| 61 | } executed 126176 times by 1 test: else {end of blockExecuted by:
| 126176 | ||||||||||||
| 62 | - | |||||||||||||
| 63 | if (al < (16)
| 53910-181157 | ||||||||||||
| 64 | unsigned long t[(16) * 2]; | - | ||||||||||||
| 65 | bn_sqr_normal(rr->d, a->d, al, t); | - | ||||||||||||
| 66 | } executed 181157 times by 1 test: else {end of blockExecuted by:
| 181157 | ||||||||||||
| 67 | int j, k; | - | ||||||||||||
| 68 | - | |||||||||||||
| 69 | j = BN_num_bits_word((unsigned long)al); | - | ||||||||||||
| 70 | j = 1 << (j - 1); | - | ||||||||||||
| 71 | k = j + j; | - | ||||||||||||
| 72 | if (al == j
| 21270-32640 | ||||||||||||
| 73 | if (bn_wexpand(tmp, k * 2) ==
| 0-21270 | ||||||||||||
| 74 | ((void *)0)
| 0-21270 | ||||||||||||
| 75 | ) | - | ||||||||||||
| 76 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 77 | bn_sqr_recursive(rr->d, a->d, al, tmp->d); | - | ||||||||||||
| 78 | } executed 21270 times by 1 test: else {end of blockExecuted by:
| 21270 | ||||||||||||
| 79 | if (bn_wexpand(tmp, max) ==
| 0-32640 | ||||||||||||
| 80 | ((void *)0)
| 0-32640 | ||||||||||||
| 81 | ) | - | ||||||||||||
| 82 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 83 | bn_sqr_normal(rr->d, a->d, al, tmp->d); | - | ||||||||||||
| 84 | } executed 32640 times by 1 test: end of blockExecuted by:
| 32640 | ||||||||||||
| 85 | } | - | ||||||||||||
| 86 | - | |||||||||||||
| 87 | - | |||||||||||||
| 88 | - | |||||||||||||
| 89 | - | |||||||||||||
| 90 | - | |||||||||||||
| 91 | } | - | ||||||||||||
| 92 | - | |||||||||||||
| 93 | rr->neg = 0; | - | ||||||||||||
| 94 | rr->top = max; | - | ||||||||||||
| 95 | rr->flags |= 0; | - | ||||||||||||
| 96 | if (r != rr
| 0-3883324 | ||||||||||||
| 97 | ((void *)0)
| 0-63434 | ||||||||||||
| 98 | ) | - | ||||||||||||
| 99 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 100 | - | |||||||||||||
| 101 | ret = 1; | - | ||||||||||||
| 102 | err: code before this statement executed 3946758 times by 2 tests: err:Executed by:
| 3946758 | ||||||||||||
| 103 | ; | - | ||||||||||||
| 104 | ; | - | ||||||||||||
| 105 | BN_CTX_end(ctx); | - | ||||||||||||
| 106 | return executed 3946758 times by 2 tests: ret;return ret;Executed by:
executed 3946758 times by 2 tests: return ret;Executed by:
| 3946758 | ||||||||||||
| 107 | } | - | ||||||||||||
| 108 | - | |||||||||||||
| 109 | - | |||||||||||||
| 110 | void bn_sqr_normal(unsigned long *r, const unsigned long *a, int n, unsigned long *tmp) | - | ||||||||||||
| 111 | { | - | ||||||||||||
| 112 | int i, j, max; | - | ||||||||||||
| 113 | const unsigned long *ap; | - | ||||||||||||
| 114 | unsigned long *rp; | - | ||||||||||||
| 115 | - | |||||||||||||
| 116 | max = n * 2; | - | ||||||||||||
| 117 | ap = a; | - | ||||||||||||
| 118 | rp = r; | - | ||||||||||||
| 119 | rp[0] = rp[max - 1] = 0; | - | ||||||||||||
| 120 | rp++; | - | ||||||||||||
| 121 | j = n; | - | ||||||||||||
| 122 | - | |||||||||||||
| 123 | if (--
| 96661-117136 | ||||||||||||
| 124 | ap++; | - | ||||||||||||
| 125 | rp[j] = bn_mul_words(rp, ap, j, ap[-1]); | - | ||||||||||||
| 126 | rp += 2; | - | ||||||||||||
| 127 | } executed 117136 times by 1 test: end of blockExecuted by:
| 117136 | ||||||||||||
| 128 | - | |||||||||||||
| 129 | for (i = n - 2; i > 0
| 213797-1646505 | ||||||||||||
| 130 | j--; | - | ||||||||||||
| 131 | ap++; | - | ||||||||||||
| 132 | rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]); | - | ||||||||||||
| 133 | rp += 2; | - | ||||||||||||
| 134 | } executed 1646505 times by 1 test: end of blockExecuted by:
| 1646505 | ||||||||||||
| 135 | - | |||||||||||||
| 136 | bn_add_words(r, r, r, max); | - | ||||||||||||
| 137 | - | |||||||||||||
| 138 | - | |||||||||||||
| 139 | - | |||||||||||||
| 140 | bn_sqr_words(tmp, a, n); | - | ||||||||||||
| 141 | - | |||||||||||||
| 142 | bn_add_words(r, r, tmp, max); | - | ||||||||||||
| 143 | } executed 213797 times by 1 test: end of blockExecuted by:
| 213797 | ||||||||||||
| 144 | void bn_sqr_recursive(unsigned long *r, const unsigned long *a, int n2, unsigned long *t) | - | ||||||||||||
| 145 | { | - | ||||||||||||
| 146 | int n = n2 / 2; | - | ||||||||||||
| 147 | int zero, c1; | - | ||||||||||||
| 148 | unsigned long ln, lo, *p; | - | ||||||||||||
| 149 | - | |||||||||||||
| 150 | if (n2 == 4
| 0-155914 | ||||||||||||
| 151 | - | |||||||||||||
| 152 | - | |||||||||||||
| 153 | - | |||||||||||||
| 154 | bn_sqr_comba4(r, a); | - | ||||||||||||
| 155 | - | |||||||||||||
| 156 | return; never executed: return; | 0 | ||||||||||||
| 157 | } else if (n2 == 8
| 44972-110942 | ||||||||||||
| 158 | - | |||||||||||||
| 159 | - | |||||||||||||
| 160 | - | |||||||||||||
| 161 | bn_sqr_comba8(r, a); | - | ||||||||||||
| 162 | - | |||||||||||||
| 163 | return; executed 110942 times by 1 test: return;Executed by:
| 110942 | ||||||||||||
| 164 | } | - | ||||||||||||
| 165 | if (n2 < (16)
| 0-44972 | ||||||||||||
| 166 | bn_sqr_normal(r, a, n2, t); | - | ||||||||||||
| 167 | return; never executed: return; | 0 | ||||||||||||
| 168 | } | - | ||||||||||||
| 169 | - | |||||||||||||
| 170 | c1 = bn_cmp_words(a, &(a[n]), n); | - | ||||||||||||
| 171 | zero = 0; | - | ||||||||||||
| 172 | if (c1 > 0
| 15570-29402 | ||||||||||||
| 173 | bn_sub_words(t, a, &(a[n]), n); executed 29402 times by 1 test: bn_sub_words(t, a, &(a[n]), n);Executed by:
| 29402 | ||||||||||||
| 174 | else if (c1 < 0
| 272-15298 | ||||||||||||
| 175 | bn_sub_words(t, &(a[n]), a, n); executed 15298 times by 1 test: bn_sub_words(t, &(a[n]), a, n);Executed by:
| 15298 | ||||||||||||
| 176 | else | - | ||||||||||||
| 177 | zero = 1; executed 272 times by 1 test: zero = 1;Executed by:
| 272 | ||||||||||||
| 178 | - | |||||||||||||
| 179 | - | |||||||||||||
| 180 | p = &(t[n2 * 2]); | - | ||||||||||||
| 181 | - | |||||||||||||
| 182 | if (!zero
| 272-44700 | ||||||||||||
| 183 | bn_sqr_recursive(&(t[n2]), t, n, p); executed 44700 times by 1 test: bn_sqr_recursive(&(t[n2]), t, n, p);Executed by:
| 44700 | ||||||||||||
| 184 | else | - | ||||||||||||
| 185 | memset(&t[n2], 0, sizeof(*t) * n2); executed 272 times by 1 test: memset(&t[n2], 0, sizeof(*t) * n2);Executed by:
| 272 | ||||||||||||
| 186 | bn_sqr_recursive(r, a, n, p); | - | ||||||||||||
| 187 | bn_sqr_recursive(&(r[n2]), &(a[n]), n, p); | - | ||||||||||||
| 188 | - | |||||||||||||
| 189 | - | |||||||||||||
| 190 | - | |||||||||||||
| 191 | - | |||||||||||||
| 192 | - | |||||||||||||
| 193 | - | |||||||||||||
| 194 | - | |||||||||||||
| 195 | c1 = (int)(bn_add_words(t, r, &(r[n2]), n2)); | - | ||||||||||||
| 196 | - | |||||||||||||
| 197 | - | |||||||||||||
| 198 | c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2)); | - | ||||||||||||
| 199 | - | |||||||||||||
| 200 | - | |||||||||||||
| 201 | - | |||||||||||||
| 202 | - | |||||||||||||
| 203 | - | |||||||||||||
| 204 | - | |||||||||||||
| 205 | - | |||||||||||||
| 206 | c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2)); | - | ||||||||||||
| 207 | if (c1
| 12652-32320 | ||||||||||||
| 208 | p = &(r[n + n2]); | - | ||||||||||||
| 209 | lo = *p; | - | ||||||||||||
| 210 | ln = (lo + c1) & (0xffffffffffffffffL); | - | ||||||||||||
| 211 | *p = ln; | - | ||||||||||||
| 212 | - | |||||||||||||
| 213 | - | |||||||||||||
| 214 | - | |||||||||||||
| 215 | - | |||||||||||||
| 216 | - | |||||||||||||
| 217 | if (ln < (unsigned long)c1
| 321-12331 | ||||||||||||
| 218 | do { | - | ||||||||||||
| 219 | p++; | - | ||||||||||||
| 220 | lo = *p; | - | ||||||||||||
| 221 | ln = (lo + 1) & (0xffffffffffffffffL); | - | ||||||||||||
| 222 | *p = ln; | - | ||||||||||||
| 223 | } executed 644 times by 1 test: while (ln == 0end of blockExecuted by:
| 321-644 | ||||||||||||
| 224 | } executed 321 times by 1 test: end of blockExecuted by:
| 321 | ||||||||||||
| 225 | } executed 12652 times by 1 test: end of blockExecuted by:
| 12652 | ||||||||||||
| 226 | } executed 44972 times by 1 test: end of blockExecuted by:
| 44972 | ||||||||||||
| Switch to Source code | Preprocessed file |