| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bn/bn_recp.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | void BN_RECP_CTX_init(BN_RECP_CTX *recp) | - | ||||||||||||
| 3 | { | - | ||||||||||||
| 4 | memset(recp, 0, sizeof(*recp)); | - | ||||||||||||
| 5 | bn_init(&(recp->N)); | - | ||||||||||||
| 6 | bn_init(&(recp->Nr)); | - | ||||||||||||
| 7 | } executed 577 times by 1 test: end of blockExecuted by:
| 577 | ||||||||||||
| 8 | - | |||||||||||||
| 9 | BN_RECP_CTX *BN_RECP_CTX_new(void) | - | ||||||||||||
| 10 | { | - | ||||||||||||
| 11 | BN_RECP_CTX *ret; | - | ||||||||||||
| 12 | - | |||||||||||||
| 13 | if ((
| 0-1 | ||||||||||||
| 14 | ((void *)0)
| 0-1 | ||||||||||||
| 15 | ) { | - | ||||||||||||
| 16 | ERR_put_error(3,(150),((1|64)),__FILE__,25); | - | ||||||||||||
| 17 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||
| 18 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
| 19 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 20 | } | - | ||||||||||||
| 21 | - | |||||||||||||
| 22 | bn_init(&(ret->N)); | - | ||||||||||||
| 23 | bn_init(&(ret->Nr)); | - | ||||||||||||
| 24 | ret->flags = 0x01; | - | ||||||||||||
| 25 | return executed 1 time by 1 test: ret;return ret;Executed by:
executed 1 time by 1 test: return ret;Executed by:
| 1 | ||||||||||||
| 26 | } | - | ||||||||||||
| 27 | - | |||||||||||||
| 28 | void BN_RECP_CTX_free(BN_RECP_CTX *recp) | - | ||||||||||||
| 29 | { | - | ||||||||||||
| 30 | if (recp ==
| 0-578 | ||||||||||||
| 31 | ((void *)0)
| 0-578 | ||||||||||||
| 32 | ) | - | ||||||||||||
| 33 | return; never executed: return; | 0 | ||||||||||||
| 34 | BN_free(&recp->N); | - | ||||||||||||
| 35 | BN_free(&recp->Nr); | - | ||||||||||||
| 36 | if (recp->flags & 0x01
| 1-577 | ||||||||||||
| 37 | CRYPTO_free(recp, __FILE__, 42); executed 1 time by 1 test: CRYPTO_free(recp, __FILE__, 42);Executed by:
| 1 | ||||||||||||
| 38 | } executed 578 times by 1 test: end of blockExecuted by:
| 578 | ||||||||||||
| 39 | - | |||||||||||||
| 40 | int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx) | - | ||||||||||||
| 41 | { | - | ||||||||||||
| 42 | if (!BN_copy(&(recp->N), d)
| 0-727 | ||||||||||||
| 43 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 44 | (BN_set_word((&(recp->Nr)),0)); | - | ||||||||||||
| 45 | recp->num_bits = BN_num_bits(d); | - | ||||||||||||
| 46 | recp->shift = 0; | - | ||||||||||||
| 47 | return executed 727 times by 1 test: 1;return 1;Executed by:
executed 727 times by 1 test: return 1;Executed by:
| 727 | ||||||||||||
| 48 | } | - | ||||||||||||
| 49 | - | |||||||||||||
| 50 | int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y, | - | ||||||||||||
| 51 | BN_RECP_CTX *recp, BN_CTX *ctx) | - | ||||||||||||
| 52 | { | - | ||||||||||||
| 53 | int ret = 0; | - | ||||||||||||
| 54 | BIGNUM *a; | - | ||||||||||||
| 55 | const BIGNUM *ca; | - | ||||||||||||
| 56 | - | |||||||||||||
| 57 | BN_CTX_start(ctx); | - | ||||||||||||
| 58 | if ((
| 0-172764 | ||||||||||||
| 59 | ((void *)0)
| 0-172764 | ||||||||||||
| 60 | ) | - | ||||||||||||
| 61 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 62 | if (y !=
| 0-172764 | ||||||||||||
| 63 | ((void *)0)
| 0-172764 | ||||||||||||
| 64 | ) { | - | ||||||||||||
| 65 | if (x == y
| 29341-143423 | ||||||||||||
| 66 | if (!BN_sqr(a, x, ctx)
| 0-143423 | ||||||||||||
| 67 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 68 | } executed 143423 times by 1 test: else {end of blockExecuted by:
| 143423 | ||||||||||||
| 69 | if (!BN_mul(a, x, y, ctx)
| 0-29341 | ||||||||||||
| 70 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 71 | } executed 29341 times by 1 test: end of blockExecuted by:
| 29341 | ||||||||||||
| 72 | ca = a; | - | ||||||||||||
| 73 | } executed 172764 times by 1 test: elseend of blockExecuted by:
| 172764 | ||||||||||||
| 74 | ca = x; never executed: ca = x; | 0 | ||||||||||||
| 75 | - | |||||||||||||
| 76 | ret = BN_div_recp( | - | ||||||||||||
| 77 | ((void *)0) | - | ||||||||||||
| 78 | , r, ca, recp, ctx); | - | ||||||||||||
| 79 | err: code before this statement executed 172764 times by 1 test: err:Executed by:
| 172764 | ||||||||||||
| 80 | BN_CTX_end(ctx); | - | ||||||||||||
| 81 | ; | - | ||||||||||||
| 82 | return executed 172764 times by 1 test: ret;return ret;Executed by:
executed 172764 times by 1 test: return ret;Executed by:
| 172764 | ||||||||||||
| 83 | } | - | ||||||||||||
| 84 | - | |||||||||||||
| 85 | int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, | - | ||||||||||||
| 86 | BN_RECP_CTX *recp, BN_CTX *ctx) | - | ||||||||||||
| 87 | { | - | ||||||||||||
| 88 | int i, j, ret = 0; | - | ||||||||||||
| 89 | BIGNUM *a, *b, *d, *r; | - | ||||||||||||
| 90 | - | |||||||||||||
| 91 | BN_CTX_start(ctx); | - | ||||||||||||
| 92 | d = (
| 150-172764 | ||||||||||||
| 93 | ((void *)0)
| 150-172764 | ||||||||||||
| 94 | )
| 150-172764 | ||||||||||||
| 95 | r = (
| 0-172914 | ||||||||||||
| 96 | ((void *)0)
| 0-172914 | ||||||||||||
| 97 | )
| 0-172914 | ||||||||||||
| 98 | a = BN_CTX_get(ctx); | - | ||||||||||||
| 99 | b = BN_CTX_get(ctx); | - | ||||||||||||
| 100 | if (b ==
| 0-172914 | ||||||||||||
| 101 | ((void *)0)
| 0-172914 | ||||||||||||
| 102 | ) | - | ||||||||||||
| 103 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 104 | - | |||||||||||||
| 105 | if (BN_ucmp(m, &(recp->N)) < 0
| 9160-163754 | ||||||||||||
| 106 | (BN_set_word((d),0)); | - | ||||||||||||
| 107 | if (!BN_copy(r, m)
| 0-9160 | ||||||||||||
| 108 | BN_CTX_end(ctx); | - | ||||||||||||
| 109 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 110 | } | - | ||||||||||||
| 111 | BN_CTX_end(ctx); | - | ||||||||||||
| 112 | return executed 9160 times by 1 test: 1;return 1;Executed by:
executed 9160 times by 1 test: return 1;Executed by:
| 9160 | ||||||||||||
| 113 | } | - | ||||||||||||
| 114 | - | |||||||||||||
| 115 | - | |||||||||||||
| 116 | - | |||||||||||||
| 117 | - | |||||||||||||
| 118 | - | |||||||||||||
| 119 | - | |||||||||||||
| 120 | - | |||||||||||||
| 121 | i = BN_num_bits(m); | - | ||||||||||||
| 122 | j = recp->num_bits << 1; | - | ||||||||||||
| 123 | if (j > i
| 12209-151545 | ||||||||||||
| 124 | i = j; executed 151545 times by 1 test: i = j;Executed by:
| 151545 | ||||||||||||
| 125 | - | |||||||||||||
| 126 | - | |||||||||||||
| 127 | if (i != recp->shift
| 717-163037 | ||||||||||||
| 128 | recp->shift = BN_reciprocal(&(recp->Nr), &(recp->N), i, ctx); executed 717 times by 1 test: recp->shift = BN_reciprocal(&(recp->Nr), &(recp->N), i, ctx);Executed by:
| 717 | ||||||||||||
| 129 | - | |||||||||||||
| 130 | if (recp->shift == -1
| 0-163754 | ||||||||||||
| 131 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 132 | - | |||||||||||||
| 133 | - | |||||||||||||
| 134 | - | |||||||||||||
| 135 | - | |||||||||||||
| 136 | - | |||||||||||||
| 137 | - | |||||||||||||
| 138 | - | |||||||||||||
| 139 | if (!BN_rshift(a, m, recp->num_bits)
| 0-163754 | ||||||||||||
| 140 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 141 | if (!BN_mul(b, a, &(recp->Nr), ctx)
| 0-163754 | ||||||||||||
| 142 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 143 | if (!BN_rshift(d, b, i - recp->num_bits)
| 0-163754 | ||||||||||||
| 144 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 145 | d->neg = 0; | - | ||||||||||||
| 146 | - | |||||||||||||
| 147 | if (!BN_mul(b, &(recp->N), d, ctx)
| 0-163754 | ||||||||||||
| 148 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 149 | if (!BN_usub(r, m, b)
| 0-163754 | ||||||||||||
| 150 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 151 | r->neg = 0; | - | ||||||||||||
| 152 | - | |||||||||||||
| 153 | j = 0; | - | ||||||||||||
| 154 | while (BN_ucmp(r, &(recp->N)) >= 0
| 122656-163754 | ||||||||||||
| 155 | if (j++ > 2
| 0-122656 | ||||||||||||
| 156 | ERR_put_error(3,(130),(101),__FILE__,149); | - | ||||||||||||
| 157 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 158 | } | - | ||||||||||||
| 159 | if (!BN_usub(r, r, &(recp->N))
| 0-122656 | ||||||||||||
| 160 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 161 | if (!BN_add_word(d, 1)
| 0-122656 | ||||||||||||
| 162 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 163 | } executed 122656 times by 1 test: end of blockExecuted by:
| 122656 | ||||||||||||
| 164 | - | |||||||||||||
| 165 | r->neg = BN_is_zero(r)
| 9-163745 | ||||||||||||
| 166 | d->neg = m->neg ^ recp->N.neg; | - | ||||||||||||
| 167 | ret = 1; | - | ||||||||||||
| 168 | err: code before this statement executed 163754 times by 1 test: err:Executed by:
| 163754 | ||||||||||||
| 169 | BN_CTX_end(ctx); | - | ||||||||||||
| 170 | ; | - | ||||||||||||
| 171 | ; | - | ||||||||||||
| 172 | return executed 163754 times by 1 test: ret;return ret;Executed by:
executed 163754 times by 1 test: return ret;Executed by:
| 163754 | ||||||||||||
| 173 | } | - | ||||||||||||
| 174 | - | |||||||||||||
| 175 | - | |||||||||||||
| 176 | - | |||||||||||||
| 177 | - | |||||||||||||
| 178 | - | |||||||||||||
| 179 | - | |||||||||||||
| 180 | - | |||||||||||||
| 181 | int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx) | - | ||||||||||||
| 182 | { | - | ||||||||||||
| 183 | int ret = -1; | - | ||||||||||||
| 184 | BIGNUM *t; | - | ||||||||||||
| 185 | - | |||||||||||||
| 186 | BN_CTX_start(ctx); | - | ||||||||||||
| 187 | if ((
| 0-717 | ||||||||||||
| 188 | ((void *)0)
| 0-717 | ||||||||||||
| 189 | ) | - | ||||||||||||
| 190 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 191 | - | |||||||||||||
| 192 | if (!BN_set_bit(t, len)
| 0-717 | ||||||||||||
| 193 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 194 | - | |||||||||||||
| 195 | if (!BN_div(r,
| 0-717 | ||||||||||||
| 196 | ((void *)0)
| 0-717 | ||||||||||||
| 197 | , t, m, ctx)
| 0-717 | ||||||||||||
| 198 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 199 | - | |||||||||||||
| 200 | ret = len; | - | ||||||||||||
| 201 | err: code before this statement executed 717 times by 1 test: err:Executed by:
| 717 | ||||||||||||
| 202 | ; | - | ||||||||||||
| 203 | BN_CTX_end(ctx); | - | ||||||||||||
| 204 | return executed 717 times by 1 test: ret;return ret;Executed by:
executed 717 times by 1 test: return ret;Executed by:
| 717 | ||||||||||||
| 205 | } | - | ||||||||||||
| Switch to Source code | Preprocessed file |