Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ec/ec_key.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* | - | ||||||||||||||||||||||||
2 | * Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||||||||||||||||||||
3 | * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved | - | ||||||||||||||||||||||||
4 | * | - | ||||||||||||||||||||||||
5 | * Licensed under the OpenSSL license (the "License"). You may not use | - | ||||||||||||||||||||||||
6 | * this file except in compliance with the License. You can obtain a copy | - | ||||||||||||||||||||||||
7 | * in the file LICENSE in the source distribution or at | - | ||||||||||||||||||||||||
8 | * https://www.openssl.org/source/license.html | - | ||||||||||||||||||||||||
9 | */ | - | ||||||||||||||||||||||||
10 | - | |||||||||||||||||||||||||
11 | #include "internal/cryptlib.h" | - | ||||||||||||||||||||||||
12 | #include <string.h> | - | ||||||||||||||||||||||||
13 | #include "ec_lcl.h" | - | ||||||||||||||||||||||||
14 | #include "internal/refcount.h" | - | ||||||||||||||||||||||||
15 | #include <openssl/err.h> | - | ||||||||||||||||||||||||
16 | #include <openssl/engine.h> | - | ||||||||||||||||||||||||
17 | - | |||||||||||||||||||||||||
18 | EC_KEY *EC_KEY_new(void) | - | ||||||||||||||||||||||||
19 | { | - | ||||||||||||||||||||||||
20 | return EC_KEY_new_method(NULL); executed 40669 times by 2 tests: return EC_KEY_new_method( ((void *)0) ); Executed by:
| 40669 | ||||||||||||||||||||||||
21 | } | - | ||||||||||||||||||||||||
22 | - | |||||||||||||||||||||||||
23 | EC_KEY *EC_KEY_new_by_curve_name(int nid) | - | ||||||||||||||||||||||||
24 | { | - | ||||||||||||||||||||||||
25 | EC_KEY *ret = EC_KEY_new(); | - | ||||||||||||||||||||||||
26 | if (ret == NULL)
| 0-4 | ||||||||||||||||||||||||
27 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
28 | ret->group = EC_GROUP_new_by_curve_name(nid); | - | ||||||||||||||||||||||||
29 | if (ret->group == NULL) {
| 0-4 | ||||||||||||||||||||||||
30 | EC_KEY_free(ret); | - | ||||||||||||||||||||||||
31 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
32 | } | - | ||||||||||||||||||||||||
33 | if (ret->meth->set_group != NULL
| 0-4 | ||||||||||||||||||||||||
34 | && ret->meth->set_group(ret, ret->group) == 0) {
| 0 | ||||||||||||||||||||||||
35 | EC_KEY_free(ret); | - | ||||||||||||||||||||||||
36 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
37 | } | - | ||||||||||||||||||||||||
38 | return ret; executed 4 times by 1 test: return ret; Executed by:
| 4 | ||||||||||||||||||||||||
39 | } | - | ||||||||||||||||||||||||
40 | - | |||||||||||||||||||||||||
41 | void EC_KEY_free(EC_KEY *r) | - | ||||||||||||||||||||||||
42 | { | - | ||||||||||||||||||||||||
43 | int i; | - | ||||||||||||||||||||||||
44 | - | |||||||||||||||||||||||||
45 | if (r == NULL)
| 14558-42949 | ||||||||||||||||||||||||
46 | return; executed 14558 times by 1 test: return; Executed by:
| 14558 | ||||||||||||||||||||||||
47 | - | |||||||||||||||||||||||||
48 | CRYPTO_DOWN_REF(&r->references, &i, r->lock); | - | ||||||||||||||||||||||||
49 | REF_PRINT_COUNT("EC_KEY", r); | - | ||||||||||||||||||||||||
50 | if (i > 0)
| 1859-41090 | ||||||||||||||||||||||||
51 | return; executed 1859 times by 1 test: return; Executed by:
| 1859 | ||||||||||||||||||||||||
52 | REF_ASSERT_ISNT(i < 0); | - | ||||||||||||||||||||||||
53 | - | |||||||||||||||||||||||||
54 | if (r->meth != NULL && r->meth->finish != NULL)
| 0-41090 | ||||||||||||||||||||||||
55 | r->meth->finish(r); never executed: r->meth->finish(r); | 0 | ||||||||||||||||||||||||
56 | - | |||||||||||||||||||||||||
57 | #ifndef OPENSSL_NO_ENGINE | - | ||||||||||||||||||||||||
58 | ENGINE_finish(r->engine); | - | ||||||||||||||||||||||||
59 | #endif | - | ||||||||||||||||||||||||
60 | - | |||||||||||||||||||||||||
61 | if (r->group && r->group->meth->keyfinish)
| 0-35746 | ||||||||||||||||||||||||
62 | r->group->meth->keyfinish(r); never executed: r->group->meth->keyfinish(r); | 0 | ||||||||||||||||||||||||
63 | - | |||||||||||||||||||||||||
64 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EC_KEY, r, &r->ex_data); | - | ||||||||||||||||||||||||
65 | CRYPTO_THREAD_lock_free(r->lock); | - | ||||||||||||||||||||||||
66 | EC_GROUP_free(r->group); | - | ||||||||||||||||||||||||
67 | EC_POINT_free(r->pub_key); | - | ||||||||||||||||||||||||
68 | BN_clear_free(r->priv_key); | - | ||||||||||||||||||||||||
69 | - | |||||||||||||||||||||||||
70 | OPENSSL_clear_free((void *)r, sizeof(EC_KEY)); | - | ||||||||||||||||||||||||
71 | } executed 41090 times by 2 tests: end of block Executed by:
| 41090 | ||||||||||||||||||||||||
72 | - | |||||||||||||||||||||||||
73 | EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src) | - | ||||||||||||||||||||||||
74 | { | - | ||||||||||||||||||||||||
75 | if (dest == NULL || src == NULL) {
| 0-421 | ||||||||||||||||||||||||
76 | ECerr(EC_F_EC_KEY_COPY, ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
77 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
78 | } | - | ||||||||||||||||||||||||
79 | if (src->meth != dest->meth) {
| 0-421 | ||||||||||||||||||||||||
80 | if (dest->meth->finish != NULL)
| 0 | ||||||||||||||||||||||||
81 | dest->meth->finish(dest); never executed: dest->meth->finish(dest); | 0 | ||||||||||||||||||||||||
82 | if (dest->group && dest->group->meth->keyfinish)
| 0 | ||||||||||||||||||||||||
83 | dest->group->meth->keyfinish(dest); never executed: dest->group->meth->keyfinish(dest); | 0 | ||||||||||||||||||||||||
84 | #ifndef OPENSSL_NO_ENGINE | - | ||||||||||||||||||||||||
85 | if (ENGINE_finish(dest->engine) == 0)
| 0 | ||||||||||||||||||||||||
86 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
87 | dest->engine = NULL; | - | ||||||||||||||||||||||||
88 | #endif | - | ||||||||||||||||||||||||
89 | } never executed: end of block | 0 | ||||||||||||||||||||||||
90 | /* copy the parameters */ | - | ||||||||||||||||||||||||
91 | if (src->group != NULL) {
| 0-421 | ||||||||||||||||||||||||
92 | const EC_METHOD *meth = EC_GROUP_method_of(src->group); | - | ||||||||||||||||||||||||
93 | /* clear the old group */ | - | ||||||||||||||||||||||||
94 | EC_GROUP_free(dest->group); | - | ||||||||||||||||||||||||
95 | dest->group = EC_GROUP_new(meth); | - | ||||||||||||||||||||||||
96 | if (dest->group == NULL)
| 0-421 | ||||||||||||||||||||||||
97 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
98 | if (!EC_GROUP_copy(dest->group, src->group))
| 0-421 | ||||||||||||||||||||||||
99 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
100 | - | |||||||||||||||||||||||||
101 | /* copy the public key */ | - | ||||||||||||||||||||||||
102 | if (src->pub_key != NULL) {
| 0-421 | ||||||||||||||||||||||||
103 | EC_POINT_free(dest->pub_key); | - | ||||||||||||||||||||||||
104 | dest->pub_key = EC_POINT_new(src->group); | - | ||||||||||||||||||||||||
105 | if (dest->pub_key == NULL)
| 0-421 | ||||||||||||||||||||||||
106 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
107 | if (!EC_POINT_copy(dest->pub_key, src->pub_key))
| 0-421 | ||||||||||||||||||||||||
108 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
109 | } executed 421 times by 1 test: end of block Executed by:
| 421 | ||||||||||||||||||||||||
110 | /* copy the private key */ | - | ||||||||||||||||||||||||
111 | if (src->priv_key != NULL) {
| 0-421 | ||||||||||||||||||||||||
112 | if (dest->priv_key == NULL) {
| 0-421 | ||||||||||||||||||||||||
113 | dest->priv_key = BN_new(); | - | ||||||||||||||||||||||||
114 | if (dest->priv_key == NULL)
| 0-421 | ||||||||||||||||||||||||
115 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
116 | } executed 421 times by 1 test: end of block Executed by:
| 421 | ||||||||||||||||||||||||
117 | if (!BN_copy(dest->priv_key, src->priv_key))
| 0-421 | ||||||||||||||||||||||||
118 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
119 | if (src->group->meth->keycopy
| 0-421 | ||||||||||||||||||||||||
120 | && src->group->meth->keycopy(dest, src) == 0)
| 0 | ||||||||||||||||||||||||
121 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
122 | } executed 421 times by 1 test: end of block Executed by:
| 421 | ||||||||||||||||||||||||
123 | } executed 421 times by 1 test: end of block Executed by:
| 421 | ||||||||||||||||||||||||
124 | - | |||||||||||||||||||||||||
125 | - | |||||||||||||||||||||||||
126 | /* copy the rest */ | - | ||||||||||||||||||||||||
127 | dest->enc_flag = src->enc_flag; | - | ||||||||||||||||||||||||
128 | dest->conv_form = src->conv_form; | - | ||||||||||||||||||||||||
129 | dest->version = src->version; | - | ||||||||||||||||||||||||
130 | dest->flags = src->flags; | - | ||||||||||||||||||||||||
131 | if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_EC_KEY,
| 0-421 | ||||||||||||||||||||||||
132 | &dest->ex_data, &src->ex_data))
| 0-421 | ||||||||||||||||||||||||
133 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
134 | - | |||||||||||||||||||||||||
135 | if (src->meth != dest->meth) {
| 0-421 | ||||||||||||||||||||||||
136 | #ifndef OPENSSL_NO_ENGINE | - | ||||||||||||||||||||||||
137 | if (src->engine != NULL && ENGINE_init(src->engine) == 0)
| 0 | ||||||||||||||||||||||||
138 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
139 | dest->engine = src->engine; | - | ||||||||||||||||||||||||
140 | #endif | - | ||||||||||||||||||||||||
141 | dest->meth = src->meth; | - | ||||||||||||||||||||||||
142 | } never executed: end of block | 0 | ||||||||||||||||||||||||
143 | - | |||||||||||||||||||||||||
144 | if (src->meth->copy != NULL && src->meth->copy(dest, src) == 0)
| 0-421 | ||||||||||||||||||||||||
145 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
146 | - | |||||||||||||||||||||||||
147 | return dest; executed 421 times by 1 test: return dest; Executed by:
| 421 | ||||||||||||||||||||||||
148 | } | - | ||||||||||||||||||||||||
149 | - | |||||||||||||||||||||||||
150 | EC_KEY *EC_KEY_dup(const EC_KEY *ec_key) | - | ||||||||||||||||||||||||
151 | { | - | ||||||||||||||||||||||||
152 | EC_KEY *ret = EC_KEY_new_method(ec_key->engine); | - | ||||||||||||||||||||||||
153 | - | |||||||||||||||||||||||||
154 | if (ret == NULL)
| 0-421 | ||||||||||||||||||||||||
155 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||
157 | if (EC_KEY_copy(ret, ec_key) == NULL) {
| 0-421 | ||||||||||||||||||||||||
158 | EC_KEY_free(ret); | - | ||||||||||||||||||||||||
159 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
160 | } | - | ||||||||||||||||||||||||
161 | return ret; executed 421 times by 1 test: return ret; Executed by:
| 421 | ||||||||||||||||||||||||
162 | } | - | ||||||||||||||||||||||||
163 | - | |||||||||||||||||||||||||
164 | int EC_KEY_up_ref(EC_KEY *r) | - | ||||||||||||||||||||||||
165 | { | - | ||||||||||||||||||||||||
166 | int i; | - | ||||||||||||||||||||||||
167 | - | |||||||||||||||||||||||||
168 | if (CRYPTO_UP_REF(&r->references, &i, r->lock) <= 0)
| 0-1859 | ||||||||||||||||||||||||
169 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
170 | - | |||||||||||||||||||||||||
171 | REF_PRINT_COUNT("EC_KEY", r); | - | ||||||||||||||||||||||||
172 | REF_ASSERT_ISNT(i < 2); | - | ||||||||||||||||||||||||
173 | return ((i > 1) ? 1 : 0); executed 1859 times by 1 test: return ((i > 1) ? 1 : 0); Executed by:
| 0-1859 | ||||||||||||||||||||||||
174 | } | - | ||||||||||||||||||||||||
175 | - | |||||||||||||||||||||||||
176 | ENGINE *EC_KEY_get0_engine(const EC_KEY *eckey) | - | ||||||||||||||||||||||||
177 | { | - | ||||||||||||||||||||||||
178 | return eckey->engine; never executed: return eckey->engine; | 0 | ||||||||||||||||||||||||
179 | } | - | ||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||
181 | int EC_KEY_generate_key(EC_KEY *eckey) | - | ||||||||||||||||||||||||
182 | { | - | ||||||||||||||||||||||||
183 | if (eckey == NULL || eckey->group == NULL) {
| 0-1003 | ||||||||||||||||||||||||
184 | ECerr(EC_F_EC_KEY_GENERATE_KEY, ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
185 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
186 | } | - | ||||||||||||||||||||||||
187 | if (eckey->meth->keygen != NULL)
| 0-1003 | ||||||||||||||||||||||||
188 | return eckey->meth->keygen(eckey); executed 1003 times by 1 test: return eckey->meth->keygen(eckey); Executed by:
| 1003 | ||||||||||||||||||||||||
189 | ECerr(EC_F_EC_KEY_GENERATE_KEY, EC_R_OPERATION_NOT_SUPPORTED); | - | ||||||||||||||||||||||||
190 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
191 | } | - | ||||||||||||||||||||||||
192 | - | |||||||||||||||||||||||||
193 | int ossl_ec_key_gen(EC_KEY *eckey) | - | ||||||||||||||||||||||||
194 | { | - | ||||||||||||||||||||||||
195 | return eckey->group->meth->keygen(eckey); executed 1003 times by 1 test: return eckey->group->meth->keygen(eckey); Executed by:
| 1003 | ||||||||||||||||||||||||
196 | } | - | ||||||||||||||||||||||||
197 | - | |||||||||||||||||||||||||
198 | int ec_key_simple_generate_key(EC_KEY *eckey) | - | ||||||||||||||||||||||||
199 | { | - | ||||||||||||||||||||||||
200 | int ok = 0; | - | ||||||||||||||||||||||||
201 | BN_CTX *ctx = NULL; | - | ||||||||||||||||||||||||
202 | BIGNUM *priv_key = NULL; | - | ||||||||||||||||||||||||
203 | const BIGNUM *order = NULL; | - | ||||||||||||||||||||||||
204 | EC_POINT *pub_key = NULL; | - | ||||||||||||||||||||||||
205 | - | |||||||||||||||||||||||||
206 | if ((ctx = BN_CTX_new()) == NULL)
| 0-1003 | ||||||||||||||||||||||||
207 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
208 | - | |||||||||||||||||||||||||
209 | if (eckey->priv_key == NULL) {
| 0-1003 | ||||||||||||||||||||||||
210 | priv_key = BN_new(); | - | ||||||||||||||||||||||||
211 | if (priv_key == NULL)
| 0-1003 | ||||||||||||||||||||||||
212 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
213 | } else executed 1003 times by 1 test: end of block Executed by:
| 1003 | ||||||||||||||||||||||||
214 | priv_key = eckey->priv_key; never executed: priv_key = eckey->priv_key; | 0 | ||||||||||||||||||||||||
215 | - | |||||||||||||||||||||||||
216 | order = EC_GROUP_get0_order(eckey->group); | - | ||||||||||||||||||||||||
217 | if (order == NULL)
| 0-1003 | ||||||||||||||||||||||||
218 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
219 | - | |||||||||||||||||||||||||
220 | do | - | ||||||||||||||||||||||||
221 | if (!BN_priv_rand_range(priv_key, order))
| 0-1003 | ||||||||||||||||||||||||
222 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
223 | while (BN_is_zero(priv_key)) ;
| 0-1003 | ||||||||||||||||||||||||
224 | - | |||||||||||||||||||||||||
225 | if (eckey->pub_key == NULL) {
| 0-1003 | ||||||||||||||||||||||||
226 | pub_key = EC_POINT_new(eckey->group); | - | ||||||||||||||||||||||||
227 | if (pub_key == NULL)
| 0-1003 | ||||||||||||||||||||||||
228 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
229 | } else executed 1003 times by 1 test: end of block Executed by:
| 1003 | ||||||||||||||||||||||||
230 | pub_key = eckey->pub_key; never executed: pub_key = eckey->pub_key; | 0 | ||||||||||||||||||||||||
231 | - | |||||||||||||||||||||||||
232 | if (!EC_POINT_mul(eckey->group, pub_key, priv_key, NULL, NULL, ctx))
| 0-1003 | ||||||||||||||||||||||||
233 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
234 | - | |||||||||||||||||||||||||
235 | eckey->priv_key = priv_key; | - | ||||||||||||||||||||||||
236 | eckey->pub_key = pub_key; | - | ||||||||||||||||||||||||
237 | - | |||||||||||||||||||||||||
238 | ok = 1; | - | ||||||||||||||||||||||||
239 | - | |||||||||||||||||||||||||
240 | err: code before this statement executed 1003 times by 1 test: err: Executed by:
| 1003 | ||||||||||||||||||||||||
241 | if (eckey->pub_key == NULL)
| 0-1003 | ||||||||||||||||||||||||
242 | EC_POINT_free(pub_key); never executed: EC_POINT_free(pub_key); | 0 | ||||||||||||||||||||||||
243 | if (eckey->priv_key != priv_key)
| 0-1003 | ||||||||||||||||||||||||
244 | BN_free(priv_key); never executed: BN_free(priv_key); | 0 | ||||||||||||||||||||||||
245 | BN_CTX_free(ctx); | - | ||||||||||||||||||||||||
246 | return ok; executed 1003 times by 1 test: return ok; Executed by:
| 1003 | ||||||||||||||||||||||||
247 | } | - | ||||||||||||||||||||||||
248 | - | |||||||||||||||||||||||||
249 | int ec_key_simple_generate_public_key(EC_KEY *eckey) | - | ||||||||||||||||||||||||
250 | { | - | ||||||||||||||||||||||||
251 | return EC_POINT_mul(eckey->group, eckey->pub_key, eckey->priv_key, NULL, executed 399 times by 1 test: return EC_POINT_mul(eckey->group, eckey->pub_key, eckey->priv_key, ((void *)0) , ((void *)0) , ((void *)0) ); Executed by:
| 399 | ||||||||||||||||||||||||
252 | NULL, NULL); executed 399 times by 1 test: return EC_POINT_mul(eckey->group, eckey->pub_key, eckey->priv_key, ((void *)0) , ((void *)0) , ((void *)0) ); Executed by:
| 399 | ||||||||||||||||||||||||
253 | } | - | ||||||||||||||||||||||||
254 | - | |||||||||||||||||||||||||
255 | int EC_KEY_check_key(const EC_KEY *eckey) | - | ||||||||||||||||||||||||
256 | { | - | ||||||||||||||||||||||||
257 | if (eckey == NULL || eckey->group == NULL || eckey->pub_key == NULL) {
| 0-72 | ||||||||||||||||||||||||
258 | ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
259 | return 0; executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||||||||
260 | } | - | ||||||||||||||||||||||||
261 | - | |||||||||||||||||||||||||
262 | if (eckey->group->meth->keycheck == NULL) {
| 0-71 | ||||||||||||||||||||||||
263 | ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
264 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
265 | } | - | ||||||||||||||||||||||||
266 | - | |||||||||||||||||||||||||
267 | return eckey->group->meth->keycheck(eckey); executed 71 times by 1 test: return eckey->group->meth->keycheck(eckey); Executed by:
| 71 | ||||||||||||||||||||||||
268 | } | - | ||||||||||||||||||||||||
269 | - | |||||||||||||||||||||||||
270 | int ec_key_simple_check_key(const EC_KEY *eckey) | - | ||||||||||||||||||||||||
271 | { | - | ||||||||||||||||||||||||
272 | int ok = 0; | - | ||||||||||||||||||||||||
273 | BN_CTX *ctx = NULL; | - | ||||||||||||||||||||||||
274 | const BIGNUM *order = NULL; | - | ||||||||||||||||||||||||
275 | EC_POINT *point = NULL; | - | ||||||||||||||||||||||||
276 | - | |||||||||||||||||||||||||
277 | if (eckey == NULL || eckey->group == NULL || eckey->pub_key == NULL) {
| 0-71 | ||||||||||||||||||||||||
278 | ECerr(EC_F_EC_KEY_SIMPLE_CHECK_KEY, ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
279 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
280 | } | - | ||||||||||||||||||||||||
281 | - | |||||||||||||||||||||||||
282 | if (EC_POINT_is_at_infinity(eckey->group, eckey->pub_key)) {
| 0-71 | ||||||||||||||||||||||||
283 | ECerr(EC_F_EC_KEY_SIMPLE_CHECK_KEY, EC_R_POINT_AT_INFINITY); | - | ||||||||||||||||||||||||
284 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
285 | } | - | ||||||||||||||||||||||||
286 | - | |||||||||||||||||||||||||
287 | if ((ctx = BN_CTX_new()) == NULL)
| 0-71 | ||||||||||||||||||||||||
288 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
289 | if ((point = EC_POINT_new(eckey->group)) == NULL)
| 0-71 | ||||||||||||||||||||||||
290 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
291 | - | |||||||||||||||||||||||||
292 | /* testing whether the pub_key is on the elliptic curve */ | - | ||||||||||||||||||||||||
293 | if (EC_POINT_is_on_curve(eckey->group, eckey->pub_key, ctx) <= 0) {
| 0-71 | ||||||||||||||||||||||||
294 | ECerr(EC_F_EC_KEY_SIMPLE_CHECK_KEY, EC_R_POINT_IS_NOT_ON_CURVE); | - | ||||||||||||||||||||||||
295 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
296 | } | - | ||||||||||||||||||||||||
297 | /* testing whether pub_key * order is the point at infinity */ | - | ||||||||||||||||||||||||
298 | order = eckey->group->order; | - | ||||||||||||||||||||||||
299 | if (BN_is_zero(order)) {
| 0-71 | ||||||||||||||||||||||||
300 | ECerr(EC_F_EC_KEY_SIMPLE_CHECK_KEY, EC_R_INVALID_GROUP_ORDER); | - | ||||||||||||||||||||||||
301 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
302 | } | - | ||||||||||||||||||||||||
303 | if (!EC_POINT_mul(eckey->group, point, NULL, eckey->pub_key, order, ctx)) {
| 0-71 | ||||||||||||||||||||||||
304 | ECerr(EC_F_EC_KEY_SIMPLE_CHECK_KEY, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
305 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
306 | } | - | ||||||||||||||||||||||||
307 | if (!EC_POINT_is_at_infinity(eckey->group, point)) {
| 0-71 | ||||||||||||||||||||||||
308 | ECerr(EC_F_EC_KEY_SIMPLE_CHECK_KEY, EC_R_WRONG_ORDER); | - | ||||||||||||||||||||||||
309 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
310 | } | - | ||||||||||||||||||||||||
311 | /* | - | ||||||||||||||||||||||||
312 | * in case the priv_key is present : check if generator * priv_key == | - | ||||||||||||||||||||||||
313 | * pub_key | - | ||||||||||||||||||||||||
314 | */ | - | ||||||||||||||||||||||||
315 | if (eckey->priv_key != NULL) {
| 1-70 | ||||||||||||||||||||||||
316 | if (BN_cmp(eckey->priv_key, order) >= 0) {
| 0-70 | ||||||||||||||||||||||||
317 | ECerr(EC_F_EC_KEY_SIMPLE_CHECK_KEY, EC_R_WRONG_ORDER); | - | ||||||||||||||||||||||||
318 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
319 | } | - | ||||||||||||||||||||||||
320 | if (!EC_POINT_mul(eckey->group, point, eckey->priv_key,
| 0-70 | ||||||||||||||||||||||||
321 | NULL, NULL, ctx)) {
| 0-70 | ||||||||||||||||||||||||
322 | ECerr(EC_F_EC_KEY_SIMPLE_CHECK_KEY, ERR_R_EC_LIB); | - | ||||||||||||||||||||||||
323 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
324 | } | - | ||||||||||||||||||||||||
325 | if (EC_POINT_cmp(eckey->group, point, eckey->pub_key, ctx) != 0) {
| 0-70 | ||||||||||||||||||||||||
326 | ECerr(EC_F_EC_KEY_SIMPLE_CHECK_KEY, EC_R_INVALID_PRIVATE_KEY); | - | ||||||||||||||||||||||||
327 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
328 | } | - | ||||||||||||||||||||||||
329 | } executed 70 times by 1 test: end of block Executed by:
| 70 | ||||||||||||||||||||||||
330 | ok = 1; | - | ||||||||||||||||||||||||
331 | err: code before this statement executed 71 times by 1 test: err: Executed by:
| 71 | ||||||||||||||||||||||||
332 | BN_CTX_free(ctx); | - | ||||||||||||||||||||||||
333 | EC_POINT_free(point); | - | ||||||||||||||||||||||||
334 | return ok; executed 71 times by 1 test: return ok; Executed by:
| 71 | ||||||||||||||||||||||||
335 | } | - | ||||||||||||||||||||||||
336 | - | |||||||||||||||||||||||||
337 | int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x, | - | ||||||||||||||||||||||||
338 | BIGNUM *y) | - | ||||||||||||||||||||||||
339 | { | - | ||||||||||||||||||||||||
340 | BN_CTX *ctx = NULL; | - | ||||||||||||||||||||||||
341 | BIGNUM *tx, *ty; | - | ||||||||||||||||||||||||
342 | EC_POINT *point = NULL; | - | ||||||||||||||||||||||||
343 | int ok = 0; | - | ||||||||||||||||||||||||
344 | - | |||||||||||||||||||||||||
345 | if (key == NULL || key->group == NULL || x == NULL || y == NULL) {
| 0 | ||||||||||||||||||||||||
346 | ECerr(EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES, | - | ||||||||||||||||||||||||
347 | ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
348 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
349 | } | - | ||||||||||||||||||||||||
350 | ctx = BN_CTX_new(); | - | ||||||||||||||||||||||||
351 | if (ctx == NULL)
| 0 | ||||||||||||||||||||||||
352 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
353 | - | |||||||||||||||||||||||||
354 | BN_CTX_start(ctx); | - | ||||||||||||||||||||||||
355 | point = EC_POINT_new(key->group); | - | ||||||||||||||||||||||||
356 | - | |||||||||||||||||||||||||
357 | if (point == NULL)
| 0 | ||||||||||||||||||||||||
358 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
359 | - | |||||||||||||||||||||||||
360 | tx = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
361 | ty = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
362 | if (ty == NULL)
| 0 | ||||||||||||||||||||||||
363 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
364 | - | |||||||||||||||||||||||||
365 | if (!EC_POINT_set_affine_coordinates(key->group, point, x, y, ctx))
| 0 | ||||||||||||||||||||||||
366 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
367 | if (!EC_POINT_get_affine_coordinates(key->group, point, tx, ty, ctx))
| 0 | ||||||||||||||||||||||||
368 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
369 | - | |||||||||||||||||||||||||
370 | /* | - | ||||||||||||||||||||||||
371 | * Check if retrieved coordinates match originals and are less than field | - | ||||||||||||||||||||||||
372 | * order: if not values are out of range. | - | ||||||||||||||||||||||||
373 | */ | - | ||||||||||||||||||||||||
374 | if (BN_cmp(x, tx) || BN_cmp(y, ty)
| 0 | ||||||||||||||||||||||||
375 | || (BN_cmp(x, key->group->field) >= 0)
| 0 | ||||||||||||||||||||||||
376 | || (BN_cmp(y, key->group->field) >= 0)) {
| 0 | ||||||||||||||||||||||||
377 | ECerr(EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES, | - | ||||||||||||||||||||||||
378 | EC_R_COORDINATES_OUT_OF_RANGE); | - | ||||||||||||||||||||||||
379 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
380 | } | - | ||||||||||||||||||||||||
381 | - | |||||||||||||||||||||||||
382 | if (!EC_KEY_set_public_key(key, point))
| 0 | ||||||||||||||||||||||||
383 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
384 | - | |||||||||||||||||||||||||
385 | if (EC_KEY_check_key(key) == 0)
| 0 | ||||||||||||||||||||||||
386 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
387 | - | |||||||||||||||||||||||||
388 | ok = 1; | - | ||||||||||||||||||||||||
389 | - | |||||||||||||||||||||||||
390 | err: code before this statement never executed: err: | 0 | ||||||||||||||||||||||||
391 | BN_CTX_end(ctx); | - | ||||||||||||||||||||||||
392 | BN_CTX_free(ctx); | - | ||||||||||||||||||||||||
393 | EC_POINT_free(point); | - | ||||||||||||||||||||||||
394 | return ok; never executed: return ok; | 0 | ||||||||||||||||||||||||
395 | - | |||||||||||||||||||||||||
396 | } | - | ||||||||||||||||||||||||
397 | - | |||||||||||||||||||||||||
398 | const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key) | - | ||||||||||||||||||||||||
399 | { | - | ||||||||||||||||||||||||
400 | return key->group; executed 44270 times by 2 tests: return key->group; Executed by:
| 44270 | ||||||||||||||||||||||||
401 | } | - | ||||||||||||||||||||||||
402 | - | |||||||||||||||||||||||||
403 | int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group) | - | ||||||||||||||||||||||||
404 | { | - | ||||||||||||||||||||||||
405 | if (key->meth->set_group != NULL && key->meth->set_group(key, group) == 0)
| 0-33141 | ||||||||||||||||||||||||
406 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
407 | EC_GROUP_free(key->group); | - | ||||||||||||||||||||||||
408 | key->group = EC_GROUP_dup(group); | - | ||||||||||||||||||||||||
409 | return (key->group == NULL) ? 0 : 1; executed 33141 times by 2 tests: return (key->group == ((void *)0) ) ? 0 : 1; Executed by:
| 0-33141 | ||||||||||||||||||||||||
410 | } | - | ||||||||||||||||||||||||
411 | - | |||||||||||||||||||||||||
412 | const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key) | - | ||||||||||||||||||||||||
413 | { | - | ||||||||||||||||||||||||
414 | return key->priv_key; executed 2404 times by 2 tests: return key->priv_key; Executed by:
| 2404 | ||||||||||||||||||||||||
415 | } | - | ||||||||||||||||||||||||
416 | - | |||||||||||||||||||||||||
417 | int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key) | - | ||||||||||||||||||||||||
418 | { | - | ||||||||||||||||||||||||
419 | if (key->group == NULL || key->group->meth == NULL)
| 0-3 | ||||||||||||||||||||||||
420 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
421 | if (key->group->meth->set_private != NULL
| 0-3 | ||||||||||||||||||||||||
422 | && key->group->meth->set_private(key, priv_key) == 0)
| 0 | ||||||||||||||||||||||||
423 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
424 | if (key->meth->set_private != NULL
| 0-3 | ||||||||||||||||||||||||
425 | && key->meth->set_private(key, priv_key) == 0)
| 0 | ||||||||||||||||||||||||
426 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
427 | BN_clear_free(key->priv_key); | - | ||||||||||||||||||||||||
428 | key->priv_key = BN_dup(priv_key); | - | ||||||||||||||||||||||||
429 | return (key->priv_key == NULL) ? 0 : 1; executed 3 times by 1 test: return (key->priv_key == ((void *)0) ) ? 0 : 1; Executed by:
| 0-3 | ||||||||||||||||||||||||
430 | } | - | ||||||||||||||||||||||||
431 | - | |||||||||||||||||||||||||
432 | const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key) | - | ||||||||||||||||||||||||
433 | { | - | ||||||||||||||||||||||||
434 | return key->pub_key; executed 7589 times by 2 tests: return key->pub_key; Executed by:
| 7589 | ||||||||||||||||||||||||
435 | } | - | ||||||||||||||||||||||||
436 | - | |||||||||||||||||||||||||
437 | int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub_key) | - | ||||||||||||||||||||||||
438 | { | - | ||||||||||||||||||||||||
439 | if (key->meth->set_public != NULL
| 0-3 | ||||||||||||||||||||||||
440 | && key->meth->set_public(key, pub_key) == 0)
| 0 | ||||||||||||||||||||||||
441 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
442 | EC_POINT_free(key->pub_key); | - | ||||||||||||||||||||||||
443 | key->pub_key = EC_POINT_dup(pub_key, key->group); | - | ||||||||||||||||||||||||
444 | return (key->pub_key == NULL) ? 0 : 1; executed 3 times by 1 test: return (key->pub_key == ((void *)0) ) ? 0 : 1; Executed by:
| 0-3 | ||||||||||||||||||||||||
445 | } | - | ||||||||||||||||||||||||
446 | - | |||||||||||||||||||||||||
447 | unsigned int EC_KEY_get_enc_flags(const EC_KEY *key) | - | ||||||||||||||||||||||||
448 | { | - | ||||||||||||||||||||||||
449 | return key->enc_flag; executed 5 times by 1 test: return key->enc_flag; Executed by:
| 5 | ||||||||||||||||||||||||
450 | } | - | ||||||||||||||||||||||||
451 | - | |||||||||||||||||||||||||
452 | void EC_KEY_set_enc_flags(EC_KEY *key, unsigned int flags) | - | ||||||||||||||||||||||||
453 | { | - | ||||||||||||||||||||||||
454 | key->enc_flag = flags; | - | ||||||||||||||||||||||||
455 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||||||||
456 | - | |||||||||||||||||||||||||
457 | point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key) | - | ||||||||||||||||||||||||
458 | { | - | ||||||||||||||||||||||||
459 | return key->conv_form; executed 1145 times by 1 test: return key->conv_form; Executed by:
| 1145 | ||||||||||||||||||||||||
460 | } | - | ||||||||||||||||||||||||
461 | - | |||||||||||||||||||||||||
462 | void EC_KEY_set_conv_form(EC_KEY *key, point_conversion_form_t cform) | - | ||||||||||||||||||||||||
463 | { | - | ||||||||||||||||||||||||
464 | key->conv_form = cform; | - | ||||||||||||||||||||||||
465 | if (key->group != NULL)
| 0 | ||||||||||||||||||||||||
466 | EC_GROUP_set_point_conversion_form(key->group, cform); never executed: EC_GROUP_set_point_conversion_form(key->group, cform); | 0 | ||||||||||||||||||||||||
467 | } never executed: end of block | 0 | ||||||||||||||||||||||||
468 | - | |||||||||||||||||||||||||
469 | void EC_KEY_set_asn1_flag(EC_KEY *key, int flag) | - | ||||||||||||||||||||||||
470 | { | - | ||||||||||||||||||||||||
471 | if (key->group != NULL)
| 0 | ||||||||||||||||||||||||
472 | EC_GROUP_set_asn1_flag(key->group, flag); never executed: EC_GROUP_set_asn1_flag(key->group, flag); | 0 | ||||||||||||||||||||||||
473 | } never executed: end of block | 0 | ||||||||||||||||||||||||
474 | - | |||||||||||||||||||||||||
475 | int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx) | - | ||||||||||||||||||||||||
476 | { | - | ||||||||||||||||||||||||
477 | if (key->group == NULL)
| 0 | ||||||||||||||||||||||||
478 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
479 | return EC_GROUP_precompute_mult(key->group, ctx); never executed: return EC_GROUP_precompute_mult(key->group, ctx); | 0 | ||||||||||||||||||||||||
480 | } | - | ||||||||||||||||||||||||
481 | - | |||||||||||||||||||||||||
482 | int EC_KEY_get_flags(const EC_KEY *key) | - | ||||||||||||||||||||||||
483 | { | - | ||||||||||||||||||||||||
484 | return key->flags; executed 1218 times by 1 test: return key->flags; Executed by:
| 1218 | ||||||||||||||||||||||||
485 | } | - | ||||||||||||||||||||||||
486 | - | |||||||||||||||||||||||||
487 | void EC_KEY_set_flags(EC_KEY *key, int flags) | - | ||||||||||||||||||||||||
488 | { | - | ||||||||||||||||||||||||
489 | key->flags |= flags; | - | ||||||||||||||||||||||||
490 | } executed 421 times by 1 test: end of block Executed by:
| 421 | ||||||||||||||||||||||||
491 | - | |||||||||||||||||||||||||
492 | void EC_KEY_clear_flags(EC_KEY *key, int flags) | - | ||||||||||||||||||||||||
493 | { | - | ||||||||||||||||||||||||
494 | key->flags &= ~flags; | - | ||||||||||||||||||||||||
495 | } never executed: end of block | 0 | ||||||||||||||||||||||||
496 | - | |||||||||||||||||||||||||
497 | size_t EC_KEY_key2buf(const EC_KEY *key, point_conversion_form_t form, | - | ||||||||||||||||||||||||
498 | unsigned char **pbuf, BN_CTX *ctx) | - | ||||||||||||||||||||||||
499 | { | - | ||||||||||||||||||||||||
500 | if (key == NULL || key->pub_key == NULL || key->group == NULL)
| 0-1195 | ||||||||||||||||||||||||
501 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
502 | return EC_POINT_point2buf(key->group, key->pub_key, form, pbuf, ctx); executed 1195 times by 1 test: return EC_POINT_point2buf(key->group, key->pub_key, form, pbuf, ctx); Executed by:
| 1195 | ||||||||||||||||||||||||
503 | } | - | ||||||||||||||||||||||||
504 | - | |||||||||||||||||||||||||
505 | int EC_KEY_oct2key(EC_KEY *key, const unsigned char *buf, size_t len, | - | ||||||||||||||||||||||||
506 | BN_CTX *ctx) | - | ||||||||||||||||||||||||
507 | { | - | ||||||||||||||||||||||||
508 | if (key == NULL || key->group == NULL)
| 0-33906 | ||||||||||||||||||||||||
509 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
510 | if (key->pub_key == NULL)
| 2644-31262 | ||||||||||||||||||||||||
511 | key->pub_key = EC_POINT_new(key->group); executed 31262 times by 1 test: key->pub_key = EC_POINT_new(key->group); Executed by:
| 31262 | ||||||||||||||||||||||||
512 | if (key->pub_key == NULL)
| 0-33906 | ||||||||||||||||||||||||
513 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
514 | if (EC_POINT_oct2point(key->group, key->pub_key, buf, len, ctx) == 0)
| 7088-26818 | ||||||||||||||||||||||||
515 | return 0; executed 7088 times by 1 test: return 0; Executed by:
| 7088 | ||||||||||||||||||||||||
516 | /* | - | ||||||||||||||||||||||||
517 | * Save the point conversion form. | - | ||||||||||||||||||||||||
518 | * For non-custom curves the first octet of the buffer (excluding | - | ||||||||||||||||||||||||
519 | * the last significant bit) contains the point conversion form. | - | ||||||||||||||||||||||||
520 | * EC_POINT_oct2point() has already performed sanity checking of | - | ||||||||||||||||||||||||
521 | * the buffer so we know it is valid. | - | ||||||||||||||||||||||||
522 | */ | - | ||||||||||||||||||||||||
523 | if ((key->group->meth->flags & EC_FLAGS_CUSTOM_CURVE) == 0)
| 0-26818 | ||||||||||||||||||||||||
524 | key->conv_form = (point_conversion_form_t)(buf[0] & ~0x01); executed 26818 times by 1 test: key->conv_form = (point_conversion_form_t)(buf[0] & ~0x01); Executed by:
| 26818 | ||||||||||||||||||||||||
525 | return 1; executed 26818 times by 1 test: return 1; Executed by:
| 26818 | ||||||||||||||||||||||||
526 | } | - | ||||||||||||||||||||||||
527 | - | |||||||||||||||||||||||||
528 | size_t EC_KEY_priv2oct(const EC_KEY *eckey, | - | ||||||||||||||||||||||||
529 | unsigned char *buf, size_t len) | - | ||||||||||||||||||||||||
530 | { | - | ||||||||||||||||||||||||
531 | if (eckey->group == NULL || eckey->group->meth == NULL)
| 0-964 | ||||||||||||||||||||||||
532 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
533 | if (eckey->group->meth->priv2oct == NULL) {
| 0-964 | ||||||||||||||||||||||||
534 | ECerr(EC_F_EC_KEY_PRIV2OCT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
535 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
536 | } | - | ||||||||||||||||||||||||
537 | - | |||||||||||||||||||||||||
538 | return eckey->group->meth->priv2oct(eckey, buf, len); executed 964 times by 1 test: return eckey->group->meth->priv2oct(eckey, buf, len); Executed by:
| 964 | ||||||||||||||||||||||||
539 | } | - | ||||||||||||||||||||||||
540 | - | |||||||||||||||||||||||||
541 | size_t ec_key_simple_priv2oct(const EC_KEY *eckey, | - | ||||||||||||||||||||||||
542 | unsigned char *buf, size_t len) | - | ||||||||||||||||||||||||
543 | { | - | ||||||||||||||||||||||||
544 | size_t buf_len; | - | ||||||||||||||||||||||||
545 | - | |||||||||||||||||||||||||
546 | buf_len = (EC_GROUP_order_bits(eckey->group) + 7) / 8; | - | ||||||||||||||||||||||||
547 | if (eckey->priv_key == NULL)
| 0-964 | ||||||||||||||||||||||||
548 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
549 | if (buf == NULL)
| 482 | ||||||||||||||||||||||||
550 | return buf_len; executed 482 times by 1 test: return buf_len; Executed by:
| 482 | ||||||||||||||||||||||||
551 | else if (len < buf_len)
| 0-482 | ||||||||||||||||||||||||
552 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
553 | - | |||||||||||||||||||||||||
554 | /* Octetstring may need leading zeros if BN is to short */ | - | ||||||||||||||||||||||||
555 | - | |||||||||||||||||||||||||
556 | if (BN_bn2binpad(eckey->priv_key, buf, buf_len) == -1) {
| 78-404 | ||||||||||||||||||||||||
557 | ECerr(EC_F_EC_KEY_SIMPLE_PRIV2OCT, EC_R_BUFFER_TOO_SMALL); | - | ||||||||||||||||||||||||
558 | return 0; executed 78 times by 1 test: return 0; Executed by:
| 78 | ||||||||||||||||||||||||
559 | } | - | ||||||||||||||||||||||||
560 | - | |||||||||||||||||||||||||
561 | return buf_len; executed 404 times by 1 test: return buf_len; Executed by:
| 404 | ||||||||||||||||||||||||
562 | } | - | ||||||||||||||||||||||||
563 | - | |||||||||||||||||||||||||
564 | int EC_KEY_oct2priv(EC_KEY *eckey, const unsigned char *buf, size_t len) | - | ||||||||||||||||||||||||
565 | { | - | ||||||||||||||||||||||||
566 | if (eckey->group == NULL || eckey->group->meth == NULL)
| 0-3016 | ||||||||||||||||||||||||
567 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
568 | if (eckey->group->meth->oct2priv == NULL) {
| 0-3016 | ||||||||||||||||||||||||
569 | ECerr(EC_F_EC_KEY_OCT2PRIV, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
570 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
571 | } | - | ||||||||||||||||||||||||
572 | return eckey->group->meth->oct2priv(eckey, buf, len); executed 3016 times by 1 test: return eckey->group->meth->oct2priv(eckey, buf, len); Executed by:
| 3016 | ||||||||||||||||||||||||
573 | } | - | ||||||||||||||||||||||||
574 | - | |||||||||||||||||||||||||
575 | int ec_key_simple_oct2priv(EC_KEY *eckey, const unsigned char *buf, size_t len) | - | ||||||||||||||||||||||||
576 | { | - | ||||||||||||||||||||||||
577 | if (eckey->priv_key == NULL)
| 0-3016 | ||||||||||||||||||||||||
578 | eckey->priv_key = BN_secure_new(); executed 3016 times by 1 test: eckey->priv_key = BN_secure_new(); Executed by:
| 3016 | ||||||||||||||||||||||||
579 | if (eckey->priv_key == NULL) {
| 0-3016 | ||||||||||||||||||||||||
580 | ECerr(EC_F_EC_KEY_SIMPLE_OCT2PRIV, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
581 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
582 | } | - | ||||||||||||||||||||||||
583 | eckey->priv_key = BN_bin2bn(buf, len, eckey->priv_key); | - | ||||||||||||||||||||||||
584 | if (eckey->priv_key == NULL) {
| 0-3016 | ||||||||||||||||||||||||
585 | ECerr(EC_F_EC_KEY_SIMPLE_OCT2PRIV, ERR_R_BN_LIB); | - | ||||||||||||||||||||||||
586 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
587 | } | - | ||||||||||||||||||||||||
588 | return 1; executed 3016 times by 1 test: return 1; Executed by:
| 3016 | ||||||||||||||||||||||||
589 | } | - | ||||||||||||||||||||||||
590 | - | |||||||||||||||||||||||||
591 | size_t EC_KEY_priv2buf(const EC_KEY *eckey, unsigned char **pbuf) | - | ||||||||||||||||||||||||
592 | { | - | ||||||||||||||||||||||||
593 | size_t len; | - | ||||||||||||||||||||||||
594 | unsigned char *buf; | - | ||||||||||||||||||||||||
595 | - | |||||||||||||||||||||||||
596 | len = EC_KEY_priv2oct(eckey, NULL, 0); | - | ||||||||||||||||||||||||
597 | if (len == 0)
| 0-482 | ||||||||||||||||||||||||
598 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
599 | if ((buf = OPENSSL_malloc(len)) == NULL) {
| 0-482 | ||||||||||||||||||||||||
600 | ECerr(EC_F_EC_KEY_PRIV2BUF, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
601 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
602 | } | - | ||||||||||||||||||||||||
603 | len = EC_KEY_priv2oct(eckey, buf, len); | - | ||||||||||||||||||||||||
604 | if (len == 0) {
| 78-404 | ||||||||||||||||||||||||
605 | OPENSSL_free(buf); | - | ||||||||||||||||||||||||
606 | return 0; executed 78 times by 1 test: return 0; Executed by:
| 78 | ||||||||||||||||||||||||
607 | } | - | ||||||||||||||||||||||||
608 | *pbuf = buf; | - | ||||||||||||||||||||||||
609 | return len; executed 404 times by 1 test: return len; Executed by:
| 404 | ||||||||||||||||||||||||
610 | } | - | ||||||||||||||||||||||||
611 | - | |||||||||||||||||||||||||
612 | int EC_KEY_can_sign(const EC_KEY *eckey) | - | ||||||||||||||||||||||||
613 | { | - | ||||||||||||||||||||||||
614 | if (eckey->group == NULL || eckey->group->meth == NULL
| 0-3354 | ||||||||||||||||||||||||
615 | || (eckey->group->meth->flags & EC_FLAGS_NO_SIGN))
| 0-3354 | ||||||||||||||||||||||||
616 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
617 | return 1; executed 3354 times by 1 test: return 1; Executed by:
| 3354 | ||||||||||||||||||||||||
618 | } | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |