| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ec/ecdh_ossl.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | int ossl_ecdh_compute_key(unsigned char **psec, size_t *pseclen, | - | ||||||||||||
| 6 | const EC_POINT *pub_key, const EC_KEY *ecdh) | - | ||||||||||||
| 7 | { | - | ||||||||||||
| 8 | if (ecdh->group->meth->ecdh_compute_key ==
| 0-1213 | ||||||||||||
| 9 | ((void *)0)
| 0-1213 | ||||||||||||
| 10 | ) { | - | ||||||||||||
| 11 | ERR_put_error(16,(247),(160),__FILE__,26); | - | ||||||||||||
| 12 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 13 | } | - | ||||||||||||
| 14 | - | |||||||||||||
| 15 | return executed 1213 times by 1 test: ecdh->group->meth->ecdh_compute_key(psec, pseclen, pub_key, ecdh);return ecdh->group->meth->ecdh_compute_key(psec, pseclen, pub_key, ecdh);Executed by:
executed 1213 times by 1 test: return ecdh->group->meth->ecdh_compute_key(psec, pseclen, pub_key, ecdh);Executed by:
| 1213 | ||||||||||||
| 16 | } | - | ||||||||||||
| 17 | - | |||||||||||||
| 18 | - | |||||||||||||
| 19 | - | |||||||||||||
| 20 | - | |||||||||||||
| 21 | - | |||||||||||||
| 22 | - | |||||||||||||
| 23 | int ecdh_simple_compute_key(unsigned char **pout, size_t *poutlen, | - | ||||||||||||
| 24 | const EC_POINT *pub_key, const EC_KEY *ecdh) | - | ||||||||||||
| 25 | { | - | ||||||||||||
| 26 | BN_CTX *ctx; | - | ||||||||||||
| 27 | EC_POINT *tmp = | - | ||||||||||||
| 28 | ((void *)0) | - | ||||||||||||
| 29 | ; | - | ||||||||||||
| 30 | BIGNUM *x = | - | ||||||||||||
| 31 | ((void *)0) | - | ||||||||||||
| 32 | ; | - | ||||||||||||
| 33 | const BIGNUM *priv_key; | - | ||||||||||||
| 34 | const EC_GROUP *group; | - | ||||||||||||
| 35 | int ret = 0; | - | ||||||||||||
| 36 | size_t buflen, len; | - | ||||||||||||
| 37 | unsigned char *buf = | - | ||||||||||||
| 38 | ((void *)0) | - | ||||||||||||
| 39 | ; | - | ||||||||||||
| 40 | - | |||||||||||||
| 41 | if ((
| 0-1213 | ||||||||||||
| 42 | ((void *)0)
| 0-1213 | ||||||||||||
| 43 | ) | - | ||||||||||||
| 44 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 45 | BN_CTX_start(ctx); | - | ||||||||||||
| 46 | x = BN_CTX_get(ctx); | - | ||||||||||||
| 47 | if (x ==
| 0-1213 | ||||||||||||
| 48 | ((void *)0)
| 0-1213 | ||||||||||||
| 49 | ) { | - | ||||||||||||
| 50 | ERR_put_error(16,(257),((1|64)),__FILE__,55); | - | ||||||||||||
| 51 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 52 | } | - | ||||||||||||
| 53 | - | |||||||||||||
| 54 | priv_key = EC_KEY_get0_private_key(ecdh); | - | ||||||||||||
| 55 | if (priv_key ==
| 0-1213 | ||||||||||||
| 56 | ((void *)0)
| 0-1213 | ||||||||||||
| 57 | ) { | - | ||||||||||||
| 58 | ERR_put_error(16,(257),(154),__FILE__,61); | - | ||||||||||||
| 59 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 60 | } | - | ||||||||||||
| 61 | - | |||||||||||||
| 62 | group = EC_KEY_get0_group(ecdh); | - | ||||||||||||
| 63 | - | |||||||||||||
| 64 | if (EC_KEY_get_flags(ecdh) & 0x1000
| 421-792 | ||||||||||||
| 65 | if (!EC_GROUP_get_cofactor(group, x,
| 0-421 | ||||||||||||
| 66 | ((void *)0)
| 0-421 | ||||||||||||
| 67 | )
| 0-421 | ||||||||||||
| 68 | !BN_mul(x, x, priv_key, ctx)
| 0-421 | ||||||||||||
| 69 | ERR_put_error(16,(257),((1|64)),__FILE__,70); | - | ||||||||||||
| 70 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 71 | } | - | ||||||||||||
| 72 | priv_key = x; | - | ||||||||||||
| 73 | } executed 421 times by 1 test: end of blockExecuted by:
| 421 | ||||||||||||
| 74 | - | |||||||||||||
| 75 | if ((
| 0-1213 | ||||||||||||
| 76 | ((void *)0)
| 0-1213 | ||||||||||||
| 77 | ) { | - | ||||||||||||
| 78 | ERR_put_error(16,(257),((1|64)),__FILE__,77); | - | ||||||||||||
| 79 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 80 | } | - | ||||||||||||
| 81 | - | |||||||||||||
| 82 | if (!EC_POINT_mul(group, tmp,
| 0-1213 | ||||||||||||
| 83 | ((void *)0)
| 0-1213 | ||||||||||||
| 84 | , pub_key, priv_key, ctx)
| 0-1213 | ||||||||||||
| 85 | ERR_put_error(16,(257),(155),__FILE__,82); | - | ||||||||||||
| 86 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 87 | } | - | ||||||||||||
| 88 | - | |||||||||||||
| 89 | if (!EC_POINT_get_affine_coordinates(group, tmp, x,
| 93-1120 | ||||||||||||
| 90 | ((void *)0)
| 93-1120 | ||||||||||||
| 91 | , ctx)
| 93-1120 | ||||||||||||
| 92 | ERR_put_error(16,(257),(155),__FILE__,87); | - | ||||||||||||
| 93 | goto executed 93 times by 1 test: err;goto err;Executed by:
executed 93 times by 1 test: goto err;Executed by:
| 93 | ||||||||||||
| 94 | } | - | ||||||||||||
| 95 | - | |||||||||||||
| 96 | buflen = (EC_GROUP_get_degree(group) + 7) / 8; | - | ||||||||||||
| 97 | len = ((BN_num_bits(x)+7)/8); | - | ||||||||||||
| 98 | if (len > buflen
| 0-1120 | ||||||||||||
| 99 | ERR_put_error(16,(257),((4|64)),__FILE__,94); | - | ||||||||||||
| 100 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 101 | } | - | ||||||||||||
| 102 | if ((
| 0-1120 | ||||||||||||
| 103 | ((void *)0)
| 0-1120 | ||||||||||||
| 104 | ) { | - | ||||||||||||
| 105 | ERR_put_error(16,(257),((1|64)),__FILE__,98); | - | ||||||||||||
| 106 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 107 | } | - | ||||||||||||
| 108 | - | |||||||||||||
| 109 | memset(buf, 0, buflen - len); | - | ||||||||||||
| 110 | if (len != (size_t)BN_bn2bin(x, buf + buflen - len)
| 0-1120 | ||||||||||||
| 111 | ERR_put_error(16,(257),(3),__FILE__,104); | - | ||||||||||||
| 112 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 113 | } | - | ||||||||||||
| 114 | - | |||||||||||||
| 115 | *pout = buf; | - | ||||||||||||
| 116 | *poutlen = buflen; | - | ||||||||||||
| 117 | buf = | - | ||||||||||||
| 118 | ((void *)0) | - | ||||||||||||
| 119 | ; | - | ||||||||||||
| 120 | - | |||||||||||||
| 121 | ret = 1; | - | ||||||||||||
| 122 | - | |||||||||||||
| 123 | err: code before this statement executed 1120 times by 1 test: err:Executed by:
| 1120 | ||||||||||||
| 124 | EC_POINT_free(tmp); | - | ||||||||||||
| 125 | if (ctx
| 0-1213 | ||||||||||||
| 126 | BN_CTX_end(ctx); executed 1213 times by 1 test: BN_CTX_end(ctx);Executed by:
| 1213 | ||||||||||||
| 127 | BN_CTX_free(ctx); | - | ||||||||||||
| 128 | CRYPTO_free(buf, __FILE__, 119); | - | ||||||||||||
| 129 | return executed 1213 times by 1 test: ret;return ret;Executed by:
executed 1213 times by 1 test: return ret;Executed by:
| 1213 | ||||||||||||
| 130 | } | - | ||||||||||||
| Switch to Source code | Preprocessed file |