| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/rsa/rsa_crpt.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | - | |||||||||||||
| 9 | int | - | ||||||||||||
| 10 | RSA_bits(const RSA *r) | - | ||||||||||||
| 11 | { | - | ||||||||||||
| 12 | return never executed: BN_num_bits(r->n);return BN_num_bits(r->n);never executed: return BN_num_bits(r->n); | 0 | ||||||||||||
| 13 | } | - | ||||||||||||
| 14 | - | |||||||||||||
| 15 | int | - | ||||||||||||
| 16 | RSA_size(const RSA *r) | - | ||||||||||||
| 17 | { | - | ||||||||||||
| 18 | return executed 443 times by 5 tests: ((BN_num_bits(r->n)+7)/8);return ((BN_num_bits(r->n)+7)/8);Executed by:
executed 443 times by 5 tests: return ((BN_num_bits(r->n)+7)/8);Executed by:
| 443 | ||||||||||||
| 19 | } | - | ||||||||||||
| 20 | - | |||||||||||||
| 21 | int | - | ||||||||||||
| 22 | RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to, | - | ||||||||||||
| 23 | RSA *rsa, int padding) | - | ||||||||||||
| 24 | { | - | ||||||||||||
| 25 | return executed 21 times by 3 tests: rsa->meth->rsa_pub_enc(flen, from, to, rsa, padding);return rsa->meth->rsa_pub_enc(flen, from, to, rsa, padding);Executed by:
executed 21 times by 3 tests: return rsa->meth->rsa_pub_enc(flen, from, to, rsa, padding);Executed by:
| 21 | ||||||||||||
| 26 | } | - | ||||||||||||
| 27 | - | |||||||||||||
| 28 | int | - | ||||||||||||
| 29 | RSA_private_encrypt(int flen, const unsigned char *from, unsigned char *to, | - | ||||||||||||
| 30 | RSA *rsa, int padding) | - | ||||||||||||
| 31 | { | - | ||||||||||||
| 32 | return executed 51 times by 5 tests: rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding);return rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding);Executed by:
executed 51 times by 5 tests: return rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding);Executed by:
| 51 | ||||||||||||
| 33 | } | - | ||||||||||||
| 34 | - | |||||||||||||
| 35 | int | - | ||||||||||||
| 36 | RSA_private_decrypt(int flen, const unsigned char *from, unsigned char *to, | - | ||||||||||||
| 37 | RSA *rsa, int padding) | - | ||||||||||||
| 38 | { | - | ||||||||||||
| 39 | return executed 511 times by 3 tests: rsa->meth->rsa_priv_dec(flen, from, to, rsa, padding);return rsa->meth->rsa_priv_dec(flen, from, to, rsa, padding);Executed by:
executed 511 times by 3 tests: return rsa->meth->rsa_priv_dec(flen, from, to, rsa, padding);Executed by:
| 511 | ||||||||||||
| 40 | } | - | ||||||||||||
| 41 | - | |||||||||||||
| 42 | int | - | ||||||||||||
| 43 | RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to, | - | ||||||||||||
| 44 | RSA *rsa, int padding) | - | ||||||||||||
| 45 | { | - | ||||||||||||
| 46 | return executed 120 times by 3 tests: rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding);return rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding);Executed by:
executed 120 times by 3 tests: return rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding);Executed by:
| 120 | ||||||||||||
| 47 | } | - | ||||||||||||
| 48 | - | |||||||||||||
| 49 | int | - | ||||||||||||
| 50 | RSA_flags(const RSA *r) | - | ||||||||||||
| 51 | { | - | ||||||||||||
| 52 | return executed 63 times by 3 tests: r == return r == ((void *)0) ? 0 : r->meth->flags;Executed by:
executed 63 times by 3 tests: return r == ((void *)0) ? 0 : r->meth->flags;Executed by:
| 0-63 | ||||||||||||
| 53 | ((void *)0)
executed 63 times by 3 tests: return r == ((void *)0) ? 0 : r->meth->flags;Executed by:
| 0-63 | ||||||||||||
| 54 | ? 0 : r->meth->flags; executed 63 times by 3 tests: return r == ((void *)0) ? 0 : r->meth->flags;Executed by:
| 63 | ||||||||||||
| 55 | } | - | ||||||||||||
| 56 | - | |||||||||||||
| 57 | void | - | ||||||||||||
| 58 | RSA_blinding_off(RSA *rsa) | - | ||||||||||||
| 59 | { | - | ||||||||||||
| 60 | BN_BLINDING_free(rsa->blinding); | - | ||||||||||||
| 61 | rsa->blinding = | - | ||||||||||||
| 62 | ((void *)0) | - | ||||||||||||
| 63 | ; | - | ||||||||||||
| 64 | rsa->flags |= 0x0080; | - | ||||||||||||
| 65 | } never executed: end of block | 0 | ||||||||||||
| 66 | - | |||||||||||||
| 67 | int | - | ||||||||||||
| 68 | RSA_blinding_on(RSA *rsa, BN_CTX *ctx) | - | ||||||||||||
| 69 | { | - | ||||||||||||
| 70 | int ret = 0; | - | ||||||||||||
| 71 | - | |||||||||||||
| 72 | if (rsa->blinding !=
| 0 | ||||||||||||
| 73 | ((void *)0)
| 0 | ||||||||||||
| 74 | ) | - | ||||||||||||
| 75 | RSA_blinding_off(rsa); never executed: RSA_blinding_off(rsa); | 0 | ||||||||||||
| 76 | - | |||||||||||||
| 77 | rsa->blinding = RSA_setup_blinding(rsa, ctx); | - | ||||||||||||
| 78 | if (rsa->blinding ==
| 0 | ||||||||||||
| 79 | ((void *)0)
| 0 | ||||||||||||
| 80 | ) | - | ||||||||||||
| 81 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 82 | - | |||||||||||||
| 83 | rsa->flags &= ~0x0080; | - | ||||||||||||
| 84 | ret = 1; | - | ||||||||||||
| 85 | err: code before this statement never executed: err: | 0 | ||||||||||||
| 86 | return never executed: (ret);return (ret);never executed: return (ret); | 0 | ||||||||||||
| 87 | } | - | ||||||||||||
| 88 | - | |||||||||||||
| 89 | static BIGNUM * | - | ||||||||||||
| 90 | rsa_get_public_exp(const BIGNUM *d, const BIGNUM *p, const BIGNUM *q, | - | ||||||||||||
| 91 | BN_CTX *ctx) | - | ||||||||||||
| 92 | { | - | ||||||||||||
| 93 | BIGNUM *ret = | - | ||||||||||||
| 94 | ((void *)0) | - | ||||||||||||
| 95 | , *r0, *r1, *r2; | - | ||||||||||||
| 96 | - | |||||||||||||
| 97 | if (d ==
| 0 | ||||||||||||
| 98 | ((void *)0)
| 0 | ||||||||||||
| 99 | || p ==
| 0 | ||||||||||||
| 100 | ((void *)0)
| 0 | ||||||||||||
| 101 | || q ==
| 0 | ||||||||||||
| 102 | ((void *)0)
| 0 | ||||||||||||
| 103 | ) | - | ||||||||||||
| 104 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||
| 105 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
| 106 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 107 | - | |||||||||||||
| 108 | BN_CTX_start(ctx); | - | ||||||||||||
| 109 | if ((
| 0 | ||||||||||||
| 110 | ((void *)0)
| 0 | ||||||||||||
| 111 | ) | - | ||||||||||||
| 112 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 113 | if ((
| 0 | ||||||||||||
| 114 | ((void *)0)
| 0 | ||||||||||||
| 115 | ) | - | ||||||||||||
| 116 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 117 | if ((
| 0 | ||||||||||||
| 118 | ((void *)0)
| 0 | ||||||||||||
| 119 | ) | - | ||||||||||||
| 120 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 121 | - | |||||||||||||
| 122 | if (!BN_sub(r1, p, BN_value_one())
| 0 | ||||||||||||
| 123 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 124 | if (!BN_sub(r2, q, BN_value_one())
| 0 | ||||||||||||
| 125 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 126 | if (!BN_mul(r0, r1, r2, ctx)
| 0 | ||||||||||||
| 127 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 128 | - | |||||||||||||
| 129 | ret = BN_mod_inverse_ct( | - | ||||||||||||
| 130 | ((void *)0) | - | ||||||||||||
| 131 | , d, r0, ctx); | - | ||||||||||||
| 132 | err: code before this statement never executed: err: | 0 | ||||||||||||
| 133 | BN_CTX_end(ctx); | - | ||||||||||||
| 134 | return never executed: ret;return ret;never executed: return ret; | 0 | ||||||||||||
| 135 | } | - | ||||||||||||
| 136 | - | |||||||||||||
| 137 | BN_BLINDING * | - | ||||||||||||
| 138 | RSA_setup_blinding(RSA *rsa, BN_CTX *in_ctx) | - | ||||||||||||
| 139 | { | - | ||||||||||||
| 140 | BIGNUM *e; | - | ||||||||||||
| 141 | BIGNUM n; | - | ||||||||||||
| 142 | BN_CTX *ctx; | - | ||||||||||||
| 143 | BN_BLINDING *ret = | - | ||||||||||||
| 144 | ((void *)0) | - | ||||||||||||
| 145 | ; | - | ||||||||||||
| 146 | - | |||||||||||||
| 147 | if (in_ctx ==
| 0-67 | ||||||||||||
| 148 | ((void *)0)
| 0-67 | ||||||||||||
| 149 | ) { | - | ||||||||||||
| 150 | if ((
| 0 | ||||||||||||
| 151 | ((void *)0)
| 0 | ||||||||||||
| 152 | ) | - | ||||||||||||
| 153 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 154 | } never executed: elseend of block | 0 | ||||||||||||
| 155 | ctx = in_ctx; executed 67 times by 6 tests: ctx = in_ctx;Executed by:
| 67 | ||||||||||||
| 156 | - | |||||||||||||
| 157 | BN_CTX_start(ctx); | - | ||||||||||||
| 158 | - | |||||||||||||
| 159 | if (rsa->e ==
| 0-67 | ||||||||||||
| 160 | ((void *)0)
| 0-67 | ||||||||||||
| 161 | ) { | - | ||||||||||||
| 162 | e = rsa_get_public_exp(rsa->d, rsa->p, rsa->q, ctx); | - | ||||||||||||
| 163 | if (e ==
| 0 | ||||||||||||
| 164 | ((void *)0)
| 0 | ||||||||||||
| 165 | ) { | - | ||||||||||||
| 166 | ERR_put_error(4,(0xfff),(140),__FILE__,196); | - | ||||||||||||
| 167 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 168 | } | - | ||||||||||||
| 169 | } never executed: elseend of block | 0 | ||||||||||||
| 170 | e = rsa->e; executed 67 times by 6 tests: e = rsa->e;Executed by:
| 67 | ||||||||||||
| 171 | - | |||||||||||||
| 172 | BN_init(&n); | - | ||||||||||||
| 173 | ((&n)->d=(rsa->n)->d, (&n)->top=(rsa->n)->top, (&n)->dmax=(rsa->n)->dmax, (&n)->neg=(rsa->n)->neg, (&n)->flags=(((&n)->flags & 0x01) | ((rsa->n)->flags & ~0x01) | 0x02 | (0x04))); | - | ||||||||||||
| 174 | - | |||||||||||||
| 175 | ret = BN_BLINDING_create_param( | - | ||||||||||||
| 176 | ((void *)0) | - | ||||||||||||
| 177 | , e, &n, ctx, rsa->meth->bn_mod_exp, | - | ||||||||||||
| 178 | rsa->_method_mod_n); | - | ||||||||||||
| 179 | - | |||||||||||||
| 180 | if (ret ==
| 0-67 | ||||||||||||
| 181 | ((void *)0)
| 0-67 | ||||||||||||
| 182 | ) { | - | ||||||||||||
| 183 | ERR_put_error(4,(0xfff),(3),__FILE__,209); | - | ||||||||||||
| 184 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 185 | } | - | ||||||||||||
| 186 | CRYPTO_THREADID_current(BN_BLINDING_thread_id(ret)); | - | ||||||||||||
| 187 | err: code before this statement executed 67 times by 6 tests: err:Executed by:
| 67 | ||||||||||||
| 188 | BN_CTX_end(ctx); | - | ||||||||||||
| 189 | if (in_ctx ==
| 0-67 | ||||||||||||
| 190 | ((void *)0)
| 0-67 | ||||||||||||
| 191 | ) | - | ||||||||||||
| 192 | BN_CTX_free(ctx); never executed: BN_CTX_free(ctx); | 0 | ||||||||||||
| 193 | if (rsa->e ==
| 0-67 | ||||||||||||
| 194 | ((void *)0)
| 0-67 | ||||||||||||
| 195 | ) | - | ||||||||||||
| 196 | BN_free(e); never executed: BN_free(e); | 0 | ||||||||||||
| 197 | - | |||||||||||||
| 198 | return executed 67 times by 6 tests: ret;return ret;Executed by:
executed 67 times by 6 tests: return ret;Executed by:
| 67 | ||||||||||||
| 199 | } | - | ||||||||||||
| Switch to Source code | Preprocessed file |