Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/ecdh/ech_key.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | static int ecdh_compute_key(void *out, size_t len, const EC_POINT *pub_key, | - | ||||||||||||
6 | EC_KEY *ecdh, | - | ||||||||||||
7 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)); | - | ||||||||||||
8 | static int | - | ||||||||||||
9 | ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, | - | ||||||||||||
10 | EC_KEY *ecdh, | - | ||||||||||||
11 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)) | - | ||||||||||||
12 | { | - | ||||||||||||
13 | BN_CTX *ctx; | - | ||||||||||||
14 | EC_POINT *tmp = | - | ||||||||||||
15 | ((void *)0) | - | ||||||||||||
16 | ; | - | ||||||||||||
17 | BIGNUM *x = | - | ||||||||||||
18 | ((void *)0) | - | ||||||||||||
19 | , *y = | - | ||||||||||||
20 | ((void *)0) | - | ||||||||||||
21 | ; | - | ||||||||||||
22 | const BIGNUM *priv_key; | - | ||||||||||||
23 | const EC_GROUP* group; | - | ||||||||||||
24 | int ret = -1; | - | ||||||||||||
25 | size_t buflen, len; | - | ||||||||||||
26 | unsigned char *buf = | - | ||||||||||||
27 | ((void *)0) | - | ||||||||||||
28 | ; | - | ||||||||||||
29 | - | |||||||||||||
30 | if (outlen > 0x7fffffff
| 0-82 | ||||||||||||
31 | - | |||||||||||||
32 | ERR_put_error(43,(0xfff),((1|64)),__FILE__,109); | - | ||||||||||||
33 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||
34 | } | - | ||||||||||||
35 | - | |||||||||||||
36 | if ((
| 0-82 | ||||||||||||
37 | ((void *)0)
| 0-82 | ||||||||||||
38 | ) | - | ||||||||||||
39 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
40 | BN_CTX_start(ctx); | - | ||||||||||||
41 | if ((
| 0-82 | ||||||||||||
42 | ((void *)0)
| 0-82 | ||||||||||||
43 | ) | - | ||||||||||||
44 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
45 | if ((
| 0-82 | ||||||||||||
46 | ((void *)0)
| 0-82 | ||||||||||||
47 | ) | - | ||||||||||||
48 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
49 | - | |||||||||||||
50 | priv_key = EC_KEY_get0_private_key(ecdh); | - | ||||||||||||
51 | if (priv_key ==
| 0-82 | ||||||||||||
52 | ((void *)0)
| 0-82 | ||||||||||||
53 | ) { | - | ||||||||||||
54 | ERR_put_error(43,(0xfff),(100),__FILE__,123); | - | ||||||||||||
55 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
56 | } | - | ||||||||||||
57 | - | |||||||||||||
58 | group = EC_KEY_get0_group(ecdh); | - | ||||||||||||
59 | - | |||||||||||||
60 | if (!EC_POINT_is_on_curve(group, pub_key, ctx)
| 0-82 | ||||||||||||
61 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
62 | - | |||||||||||||
63 | if ((
| 0-82 | ||||||||||||
64 | ((void *)0)
| 0-82 | ||||||||||||
65 | ) { | - | ||||||||||||
66 | ERR_put_error(43,(0xfff),((1|64)),__FILE__,133); | - | ||||||||||||
67 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
68 | } | - | ||||||||||||
69 | - | |||||||||||||
70 | if (!EC_POINT_mul(group, tmp,
| 0-82 | ||||||||||||
71 | ((void *)0)
| 0-82 | ||||||||||||
72 | , pub_key, priv_key, ctx)
| 0-82 | ||||||||||||
73 | ERR_put_error(43,(0xfff),(101),__FILE__,138); | - | ||||||||||||
74 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
75 | } | - | ||||||||||||
76 | - | |||||||||||||
77 | if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) ==
| 20-62 | ||||||||||||
78 | 406
| 20-62 | ||||||||||||
79 | if (!EC_POINT_get_affine_coordinates_GFp(group, tmp, x, y,
| 0-62 | ||||||||||||
80 | ctx)
| 0-62 | ||||||||||||
81 | ERR_put_error(43,(0xfff),(101),__FILE__,146); | - | ||||||||||||
82 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
83 | } | - | ||||||||||||
84 | } executed 62 times by 2 tests: end of block Executed by:
| 62 | ||||||||||||
85 | - | |||||||||||||
86 | else { | - | ||||||||||||
87 | if (!EC_POINT_get_affine_coordinates_GF2m(group, tmp, x, y,
| 0-20 | ||||||||||||
88 | ctx)
| 0-20 | ||||||||||||
89 | ERR_put_error(43,(0xfff),(101),__FILE__,154); | - | ||||||||||||
90 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
91 | } | - | ||||||||||||
92 | } executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||
93 | - | |||||||||||||
94 | - | |||||||||||||
95 | buflen = ECDH_size(ecdh); | - | ||||||||||||
96 | len = ((BN_num_bits(x)+7)/8); | - | ||||||||||||
97 | if (len > buflen
| 0-82 | ||||||||||||
98 | ERR_put_error(43,(0xfff),((4|64)),__FILE__,163); | - | ||||||||||||
99 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
100 | } | - | ||||||||||||
101 | if (KDF ==
| 30-52 | ||||||||||||
102 | ((void *)0)
| 30-52 | ||||||||||||
103 | && outlen < buflen
| 0-52 | ||||||||||||
104 | - | |||||||||||||
105 | ERR_put_error(43,(0xfff),(104),__FILE__,168); | - | ||||||||||||
106 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
107 | } | - | ||||||||||||
108 | if ((
| 0-82 | ||||||||||||
109 | ((void *)0)
| 0-82 | ||||||||||||
110 | ) { | - | ||||||||||||
111 | ERR_put_error(43,(0xfff),((1|64)),__FILE__,172); | - | ||||||||||||
112 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
113 | } | - | ||||||||||||
114 | - | |||||||||||||
115 | memset(buf, 0, buflen - len); | - | ||||||||||||
116 | if (len != (size_t)BN_bn2bin(x, buf + buflen - len)
| 0-82 | ||||||||||||
117 | ERR_put_error(43,(0xfff),(3),__FILE__,178); | - | ||||||||||||
118 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
119 | } | - | ||||||||||||
120 | - | |||||||||||||
121 | if (KDF !=
| 30-52 | ||||||||||||
122 | ((void *)0)
| 30-52 | ||||||||||||
123 | ) { | - | ||||||||||||
124 | if (KDF(buf, buflen, out, &outlen) ==
| 0-30 | ||||||||||||
125 | ((void *)0)
| 0-30 | ||||||||||||
126 | ) { | - | ||||||||||||
127 | ERR_put_error(43,(0xfff),(102),__FILE__,184); | - | ||||||||||||
128 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
129 | } | - | ||||||||||||
130 | ret = outlen; | - | ||||||||||||
131 | } executed 30 times by 1 test: else {end of block Executed by:
| 30 | ||||||||||||
132 | - | |||||||||||||
133 | if (outlen > buflen
| 0-52 | ||||||||||||
134 | memset((void *)((uintptr_t)out + buflen), 0, outlen - buflen); | - | ||||||||||||
135 | outlen = buflen; | - | ||||||||||||
136 | } never executed: end of block | 0 | ||||||||||||
137 | memcpy(out, buf, outlen); | - | ||||||||||||
138 | ret = outlen; | - | ||||||||||||
139 | } executed 52 times by 2 tests: end of block Executed by:
| 52 | ||||||||||||
140 | - | |||||||||||||
141 | err: code before this statement executed 82 times by 2 tests: err: Executed by:
| 82 | ||||||||||||
142 | EC_POINT_free(tmp); | - | ||||||||||||
143 | if (ctx
| 0-82 | ||||||||||||
144 | BN_CTX_end(ctx); executed 82 times by 2 tests: BN_CTX_end(ctx); Executed by:
| 82 | ||||||||||||
145 | BN_CTX_free(ctx); | - | ||||||||||||
146 | free(buf); | - | ||||||||||||
147 | return executed 82 times by 2 tests: (ret);return (ret); Executed by:
executed 82 times by 2 tests: return (ret); Executed by:
| 82 | ||||||||||||
148 | } | - | ||||||||||||
149 | - | |||||||||||||
150 | static ECDH_METHOD openssl_ecdh_meth = { | - | ||||||||||||
151 | .name = "OpenSSL ECDH method", | - | ||||||||||||
152 | .compute_key = ecdh_compute_key | - | ||||||||||||
153 | }; | - | ||||||||||||
154 | - | |||||||||||||
155 | const ECDH_METHOD * | - | ||||||||||||
156 | ECDH_OpenSSL(void) | - | ||||||||||||
157 | { | - | ||||||||||||
158 | return executed 24 times by 2 tests: &openssl_ecdh_meth;return &openssl_ecdh_meth; Executed by:
executed 24 times by 2 tests: return &openssl_ecdh_meth; Executed by:
| 24 | ||||||||||||
159 | } | - | ||||||||||||
160 | - | |||||||||||||
161 | int | - | ||||||||||||
162 | ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, | - | ||||||||||||
163 | EC_KEY *eckey, | - | ||||||||||||
164 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)) | - | ||||||||||||
165 | { | - | ||||||||||||
166 | ECDH_DATA *ecdh = ecdh_check(eckey); | - | ||||||||||||
167 | if (ecdh ==
| 0-82 | ||||||||||||
168 | ((void *)0)
| 0-82 | ||||||||||||
169 | ) | - | ||||||||||||
170 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
171 | return executed 82 times by 2 tests: ecdh->meth->compute_key(out, outlen, pub_key, eckey, KDF);return ecdh->meth->compute_key(out, outlen, pub_key, eckey, KDF); Executed by:
executed 82 times by 2 tests: return ecdh->meth->compute_key(out, outlen, pub_key, eckey, KDF); Executed by:
| 82 | ||||||||||||
172 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |