OpenCoverage

ec_ameth.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/ec/ec_ameth.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6static int-
7eckey_param2type(int *pptype, void **ppval, EC_KEY * ec_key)-
8{-
9 const EC_GROUP *group;-
10 int nid;-
11 if (ec_key ==
ec_key == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
12 ((void *)0)
ec_key == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
13 || (
(group = EC_KE...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
group = EC_KEY_get0_group(ec_key)) ==
(group = EC_KE...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
14 ((void *)0)
(group = EC_KE...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
15 ) {-
16 ERR_put_error(16,(0xfff),(124),__FILE__,77);-
17 return
never executed: return 0;
0;
never executed: return 0;
0
18 }-
19 if (EC_GROUP_get_asn1_flag(group)
EC_GROUP_get_asn1_flag(group)Description
TRUEnever evaluated
FALSEnever evaluated
&&
0
20 (
(nid = EC_GROU...e_name(group))Description
TRUEnever evaluated
FALSEnever evaluated
nid = EC_GROUP_get_curve_name(group))
(nid = EC_GROU...e_name(group))Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
21-
22 *ppval = OBJ_nid2obj(nid);-
23 *pptype = 6;-
24 }
never executed: end of block
else {
0
25-
26 ASN1_STRING *pstr = -
27 ((void *)0)-
28 ;-
29 pstr = ASN1_STRING_new();-
30 if (!pstr
!pstrDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
31 return
never executed: return 0;
0;
never executed: return 0;
0
32 pstr->length = i2d_ECParameters(ec_key, &pstr->data);-
33 if (pstr->length <= 0
pstr->length <= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
34 ASN1_STRING_free(pstr);-
35 ERR_put_error(16,(0xfff),(16),__FILE__,94);-
36 return
never executed: return 0;
0;
never executed: return 0;
0
37 }-
38 *ppval = pstr;-
39 *pptype = 16;-
40 }
never executed: end of block
0
41 return
never executed: return 1;
1;
never executed: return 1;
0
42}-
43-
44static int-
45eckey_pub_encode(X509_PUBKEY * pk, const EVP_PKEY * pkey)-
46{-
47 EC_KEY *ec_key = pkey->pkey.ec;-
48 void *pval = -
49 ((void *)0)-
50 ;-
51 int ptype;-
52 unsigned char *penc = -
53 ((void *)0)-
54 , *p;-
55 int penclen;-
56-
57 if (!eckey_param2type(&ptype, &pval, ec_key)
!eckey_param2t...&pval, ec_key)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
58 ERR_put_error(16,(0xfff),(16),__FILE__,113);-
59 return
never executed: return 0;
0;
never executed: return 0;
0
60 }-
61 penclen = i2o_ECPublicKey(ec_key, -
62 ((void *)0)-
63 );-
64 if (penclen <= 0
penclen <= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
65 goto
never executed: goto err;
err;
never executed: goto err;
0
66 penc = malloc(penclen);-
67 if (!penc
!pencDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
68 goto
never executed: goto err;
err;
never executed: goto err;
0
69 p = penc;-
70 penclen = i2o_ECPublicKey(ec_key, &p);-
71 if (penclen <= 0
penclen <= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
72 goto
never executed: goto err;
err;
never executed: goto err;
0
73 if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(408),
X509_PUBKEY_se...penc, penclen)Description
TRUEnever evaluated
FALSEnever evaluated
0
74 ptype, pval, penc, penclen)
X509_PUBKEY_se...penc, penclen)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
75 return
never executed: return 1;
1;
never executed: return 1;
0
76 err:
code before this statement never executed: err:
0
77 if (ptype == 6
ptype == 6Description
TRUEnever evaluated
FALSEnever evaluated
)
0
78 ASN1_OBJECT_free(pval);
never executed: ASN1_OBJECT_free(pval);
0
79 else-
80 ASN1_STRING_free(pval);
never executed: ASN1_STRING_free(pval);
0
81 free(penc);-
82 return
never executed: return 0;
0;
never executed: return 0;
0
83}-
84-
85static EC_KEY *-
86eckey_type2param(int ptype, const void *pval)-
87{-
88 EC_KEY *eckey = -
89 ((void *)0)-
90 ;-
91-
92 if (ptype == 16
ptype == 16Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
93 const ASN1_STRING *pstr = pval;-
94 const unsigned char *pm = -
95 ((void *)0)-
96 ;-
97 int pmlen;-
98-
99 pm = pstr->data;-
100 pmlen = pstr->length;-
101 if (!(eckey = d2i_ECParameters(
!(eckey = d2i_..., &pm, pmlen))Description
TRUEnever evaluated
FALSEnever evaluated
0
102 ((void *)0)
!(eckey = d2i_..., &pm, pmlen))Description
TRUEnever evaluated
FALSEnever evaluated
0
103 , &pm, pmlen))
!(eckey = d2i_..., &pm, pmlen))Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
104 ERR_put_error(16,(0xfff),(142),__FILE__,151);-
105 goto
never executed: goto ecerr;
ecerr;
never executed: goto ecerr;
0
106 }-
107 }
never executed: end of block
else if (ptype == 6
ptype == 6Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
108 const ASN1_OBJECT *poid = pval;-
109 EC_GROUP *group;-
110-
111-
112-
113-
114-
115 if ((
(eckey = EC_KE...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
eckey = EC_KEY_new()) ==
(eckey = EC_KE...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
116 ((void *)0)
(eckey = EC_KE...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
117 ) {-
118 ERR_put_error(16,(0xfff),((1|64)),__FILE__,163);-
119 goto
never executed: goto ecerr;
ecerr;
never executed: goto ecerr;
0
120 }-
121 group = EC_GROUP_new_by_curve_name(OBJ_obj2nid(poid));-
122 if (group ==
group == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
123 ((void *)0)
group == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
124 )-
125 goto
never executed: goto ecerr;
ecerr;
never executed: goto ecerr;
0
126 EC_GROUP_set_asn1_flag(group, 0x001);-
127 if (EC_KEY_set_group(eckey, group) == 0
EC_KEY_set_gro...y, group) == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
128 goto
never executed: goto ecerr;
ecerr;
never executed: goto ecerr;
0
129 EC_GROUP_free(group);-
130 }
never executed: end of block
else {
0
131 ERR_put_error(16,(0xfff),(142),__FILE__,174);-
132 goto
never executed: goto ecerr;
ecerr;
never executed: goto ecerr;
0
133 }-
134-
135 return
never executed: return eckey;
eckey;
never executed: return eckey;
0
136-
137 ecerr:-
138 if (eckey
eckeyDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
139 EC_KEY_free(eckey);
never executed: EC_KEY_free(eckey);
0
140 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
141 ((void *)0)
never executed: return ((void *)0) ;
0
142 ;
never executed: return ((void *)0) ;
0
143}-
144-
145static int-
146eckey_pub_decode(EVP_PKEY * pkey, X509_PUBKEY * pubkey)-
147{-
148 const unsigned char *p = -
149 ((void *)0)-
150 ;-
151 const void *pval;-
152 int ptype, pklen;-
153 EC_KEY *eckey = -
154 ((void *)0)-
155 ;-
156 X509_ALGOR *palg;-
157-
158 if (!X509_PUBKEY_get0_param(
!X509_PUBKEY_g...&palg, pubkey)Description
TRUEnever evaluated
FALSEnever evaluated
0
159 ((void *)0)
!X509_PUBKEY_g...&palg, pubkey)Description
TRUEnever evaluated
FALSEnever evaluated
0
160 , &p, &pklen, &palg, pubkey)
!X509_PUBKEY_g...&palg, pubkey)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
161 return
never executed: return 0;
0;
never executed: return 0;
0
162 X509_ALGOR_get0(-
163 ((void *)0)-
164 , &ptype, &pval, palg);-
165-
166 eckey = eckey_type2param(ptype, pval);-
167-
168 if (!eckey
!eckeyDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
169 ERR_put_error(16,(0xfff),(16),__FILE__,202);-
170 return
never executed: return 0;
0;
never executed: return 0;
0
171 }-
172-
173 if (!o2i_ECPublicKey(&eckey, &p, pklen)
!o2i_ECPublicK...ey, &p, pklen)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
174 ERR_put_error(16,(0xfff),(142),__FILE__,207);-
175 goto
never executed: goto ecerr;
ecerr;
never executed: goto ecerr;
0
176 }-
177 EVP_PKEY_assign((pkey),408, (char *)(eckey));-
178 return
never executed: return 1;
1;
never executed: return 1;
0
179-
180 ecerr:-
181 if (eckey
eckeyDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
182 EC_KEY_free(eckey);
never executed: EC_KEY_free(eckey);
0
183 return
never executed: return 0;
0;
never executed: return 0;
0
184}-
185-
186static int-
187eckey_pub_cmp(const EVP_PKEY * a, const EVP_PKEY * b)-
188{-
189 int r;-
190 const EC_GROUP *group = EC_KEY_get0_group(b->pkey.ec);-
191 const EC_POINT *pa = EC_KEY_get0_public_key(a->pkey.ec), *pb = EC_KEY_get0_public_key(b->pkey.ec);-
192-
193 r = EC_POINT_cmp(group, pa, pb, -
194 ((void *)0)-
195 );-
196 if (r == 0
r == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
197 return
never executed: return 1;
1;
never executed: return 1;
0
198 if (r == 1
r == 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
199 return
never executed: return 0;
0;
never executed: return 0;
0
200 return
never executed: return -2;
-2;
never executed: return -2;
0
201}-
202-
203static int-
204eckey_priv_decode(EVP_PKEY * pkey, const PKCS8_PRIV_KEY_INFO * p8)-
205{-
206 const unsigned char *p = -
207 ((void *)0)-
208 ;-
209 const void *pval;-
210 int ptype, pklen;-
211 EC_KEY *eckey = -
212 ((void *)0)-
213 ;-
214 const X509_ALGOR *palg;-
215-
216 if (!PKCS8_pkey_get0(
!PKCS8_pkey_ge...en, &palg, p8)Description
TRUEnever evaluated
FALSEnever evaluated
0
217 ((void *)0)
!PKCS8_pkey_ge...en, &palg, p8)Description
TRUEnever evaluated
FALSEnever evaluated
0
218 , &p, &pklen, &palg, p8)
!PKCS8_pkey_ge...en, &palg, p8)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
219 return
never executed: return 0;
0;
never executed: return 0;
0
220 X509_ALGOR_get0(-
221 ((void *)0)-
222 , &ptype, &pval, palg);-
223-
224 eckey = eckey_type2param(ptype, pval);-
225-
226 if (!eckey
!eckeyDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
227 goto
never executed: goto ecliberr;
ecliberr;
never executed: goto ecliberr;
0
228-
229-
230 if (!d2i_ECPrivateKey(&eckey, &p, pklen)
!d2i_ECPrivate...ey, &p, pklen)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
231 ERR_put_error(16,(0xfff),(142),__FILE__,254);-
232 goto
never executed: goto ecerr;
ecerr;
never executed: goto ecerr;
0
233 }-
234-
235 if (EC_KEY_get0_public_key(eckey) ==
EC_KEY_get0_pu...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
236 ((void *)0)
EC_KEY_get0_pu...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
237 ) {-
238 const BIGNUM *priv_key;-
239 const EC_GROUP *group;-
240 EC_POINT *pub_key;-
241-
242-
243-
244-
245 group = EC_KEY_get0_group(eckey);-
246 pub_key = EC_POINT_new(group);-
247 if (pub_key ==
pub_key == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
248 ((void *)0)
pub_key == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
249 ) {-
250 ERR_put_error(16,(0xfff),(16),__FILE__,269);-
251 goto
never executed: goto ecliberr;
ecliberr;
never executed: goto ecliberr;
0
252 }-
253 if (!EC_POINT_copy(pub_key, EC_GROUP_get0_generator(group))
!EC_POINT_copy...erator(group))Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
254 EC_POINT_free(pub_key);-
255 ERR_put_error(16,(0xfff),(16),__FILE__,274);-
256 goto
never executed: goto ecliberr;
ecliberr;
never executed: goto ecliberr;
0
257 }-
258 priv_key = EC_KEY_get0_private_key(eckey);-
259 if (!EC_POINT_mul(group, pub_key, priv_key,
!EC_POINT_mul(... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
260 ((void *)0)
!EC_POINT_mul(... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
261 ,
!EC_POINT_mul(... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
262 ((void *)0)
!EC_POINT_mul(... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
263 ,
!EC_POINT_mul(... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
264 ((void *)0)
!EC_POINT_mul(... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
265 )
!EC_POINT_mul(... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
266 EC_POINT_free(pub_key);-
267 ERR_put_error(16,(0xfff),(16),__FILE__,280);-
268 goto
never executed: goto ecliberr;
ecliberr;
never executed: goto ecliberr;
0
269 }-
270 if (EC_KEY_set_public_key(eckey, pub_key) == 0
EC_KEY_set_pub... pub_key) == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
271 EC_POINT_free(pub_key);-
272 ERR_put_error(16,(0xfff),(16),__FILE__,285);-
273 goto
never executed: goto ecliberr;
ecliberr;
never executed: goto ecliberr;
0
274 }-
275 EC_POINT_free(pub_key);-
276 }
never executed: end of block
0
277 EVP_PKEY_assign((pkey),408, (char *)(eckey));-
278 return
never executed: return 1;
1;
never executed: return 1;
0
279-
280 ecliberr:-
281 ERR_put_error(16,(0xfff),(16),__FILE__,294);-
282 ecerr:
code before this statement never executed: ecerr:
0
283 if (eckey
eckeyDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
284 EC_KEY_free(eckey);
never executed: EC_KEY_free(eckey);
0
285 return
never executed: return 0;
0;
never executed: return 0;
0
286}-
287-
288static int-
289eckey_priv_encode(PKCS8_PRIV_KEY_INFO * p8, const EVP_PKEY * pkey)-
290{-
291 EC_KEY *ec_key;-
292 unsigned char *ep, *p;-
293 int eplen, ptype;-
294 void *pval;-
295 unsigned int tmp_flags, old_flags;-
296-
297 ec_key = pkey->pkey.ec;-
298-
299 if (!eckey_param2type(&ptype, &pval, ec_key)
!eckey_param2t...&pval, ec_key)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
300 ERR_put_error(16,(0xfff),(142),__FILE__,313);-
301 return
never executed: return 0;
0;
never executed: return 0;
0
302 }-
303-
304-
305-
306-
307-
308-
309 old_flags = EC_KEY_get_enc_flags(ec_key);-
310 tmp_flags = old_flags | 0x001;-
311 EC_KEY_set_enc_flags(ec_key, tmp_flags);-
312 eplen = i2d_ECPrivateKey(ec_key, -
313 ((void *)0)-
314 );-
315 if (!eplen
!eplenDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
316 EC_KEY_set_enc_flags(ec_key, old_flags);-
317 ERR_put_error(16,(0xfff),(16),__FILE__,328);-
318 return
never executed: return 0;
0;
never executed: return 0;
0
319 }-
320 ep = malloc(eplen);-
321 if (!ep
!epDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
322 EC_KEY_set_enc_flags(ec_key, old_flags);-
323 ERR_put_error(16,(0xfff),((1|64)),__FILE__,334);-
324 return
never executed: return 0;
0;
never executed: return 0;
0
325 }-
326 p = ep;-
327 if (!i2d_ECPrivateKey(ec_key, &p)
!i2d_ECPrivateKey(ec_key, &p)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
328 EC_KEY_set_enc_flags(ec_key, old_flags);-
329 free(ep);-
330 ERR_put_error(16,(0xfff),(16),__FILE__,341);-
331 return
never executed: return 0;
0;
never executed: return 0;
0
332 }-
333-
334 EC_KEY_set_enc_flags(ec_key, old_flags);-
335-
336 if (!PKCS8_pkey_set0(p8, OBJ_nid2obj(408), 0,
!PKCS8_pkey_se...al, ep, eplen)Description
TRUEnever evaluated
FALSEnever evaluated
0
337 ptype, pval, ep, eplen)
!PKCS8_pkey_se...al, ep, eplen)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
338 return
never executed: return 0;
0;
never executed: return 0;
0
339-
340 return
never executed: return 1;
1;
never executed: return 1;
0
341}-
342-
343static int-
344int_ec_size(const EVP_PKEY * pkey)-
345{-
346 return
never executed: return ECDSA_size(pkey->pkey.ec);
ECDSA_size(pkey->pkey.ec);
never executed: return ECDSA_size(pkey->pkey.ec);
0
347}-
348-
349static int-
350ec_bits(const EVP_PKEY * pkey)-
351{-
352 BIGNUM *order = BN_new();-
353 const EC_GROUP *group;-
354 int ret;-
355-
356 if (!order
!orderDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
357 ERR_clear_error();-
358 return
never executed: return 0;
0;
never executed: return 0;
0
359 }-
360 group = EC_KEY_get0_group(pkey->pkey.ec);-
361 if (!EC_GROUP_get_order(group, order,
!EC_GROUP_get_... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
362 ((void *)0)
!EC_GROUP_get_... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
363 )
!EC_GROUP_get_... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
364 BN_free(order);-
365 ERR_clear_error();-
366 return
never executed: return 0;
0;
never executed: return 0;
0
367 }-
368 ret = BN_num_bits(order);-
369 BN_free(order);-
370 return
never executed: return ret;
ret;
never executed: return ret;
0
371}-
372-
373static int-
374ec_missing_parameters(const EVP_PKEY * pkey)-
375{-
376 if (EC_KEY_get0_group(pkey->pkey.ec) ==
EC_KEY_get0_gr...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
377 ((void *)0)
EC_KEY_get0_gr...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
378 )-
379 return
never executed: return 1;
1;
never executed: return 1;
0
380 return
never executed: return 0;
0;
never executed: return 0;
0
381}-
382-
383static int-
384ec_copy_parameters(EVP_PKEY * to, const EVP_PKEY * from)-
385{-
386 return
never executed: return EC_KEY_set_group(to->pkey.ec, EC_KEY_get0_group(from->pkey.ec));
EC_KEY_set_group(to->pkey.ec, EC_KEY_get0_group(from->pkey.ec));
never executed: return EC_KEY_set_group(to->pkey.ec, EC_KEY_get0_group(from->pkey.ec));
0
387}-
388-
389static int-
390ec_cmp_parameters(const EVP_PKEY * a, const EVP_PKEY * b)-
391{-
392 const EC_GROUP *group_a = EC_KEY_get0_group(a->pkey.ec), *group_b = EC_KEY_get0_group(b->pkey.ec);-
393 if (EC_GROUP_cmp(group_a, group_b,
EC_GROUP_cmp(g... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
394 ((void *)0)
EC_GROUP_cmp(g... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
395 )
EC_GROUP_cmp(g... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
)
0
396 return
never executed: return 0;
0;
never executed: return 0;
0
397 else-
398 return
never executed: return 1;
1;
never executed: return 1;
0
399}-
400-
401static void-
402int_ec_free(EVP_PKEY * pkey)-
403{-
404 EC_KEY_free(pkey->pkey.ec);-
405}
never executed: end of block
0
406-
407static int-
408do_EC_KEY_print(BIO * bp, const EC_KEY * x, int off, int ktype)-
409{-
410 unsigned char *buffer = -
411 ((void *)0)-
412 ;-
413 const char *ecstr;-
414 size_t buf_len = 0, i;-
415 int ret = 0, reason = 32;-
416 BIGNUM *pub_key = -
417 ((void *)0)-
418 , *order = -
419 ((void *)0)-
420 ;-
421 BN_CTX *ctx = -
422 ((void *)0)-
423 ;-
424 const EC_GROUP *group;-
425 const EC_POINT *public_key;-
426 const BIGNUM *priv_key;-
427-
428 if (x ==
x == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
429 ((void *)0)
x == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
430 || (
(group = EC_KE...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
group = EC_KEY_get0_group(x)) ==
(group = EC_KE...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
431 ((void *)0)
(group = EC_KE...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
432 ) {-
433 reason = (3|64);-
434 goto
never executed: goto err;
err;
never executed: goto err;
0
435 }-
436 ctx = BN_CTX_new();-
437 if (ctx ==
ctx == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
438 ((void *)0)
ctx == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
439 ) {-
440 reason = (1|64);-
441 goto
never executed: goto err;
err;
never executed: goto err;
0
442 }-
443 if (ktype > 0
ktype > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
444 public_key = EC_KEY_get0_public_key(x);-
445 if (public_key !=
public_key != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
446 ((void *)0)
public_key != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
447 ) {-
448 if ((
(pub_key = EC_...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
pub_key = EC_POINT_point2bn(group, public_key,
(pub_key = EC_...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
449 EC_KEY_get_conv_form(x),
(pub_key = EC_...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
450 ((void *)0)
(pub_key = EC_...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
451 , ctx)) ==
(pub_key = EC_...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
452 ((void *)0)
(pub_key = EC_...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
453 ) {-
454 reason = 16;-
455 goto
never executed: goto err;
err;
never executed: goto err;
0
456 }-
457 if (pub_key
pub_keyDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
458 buf_len = (size_t) ((BN_num_bits(pub_key)+7)/8);
never executed: buf_len = (size_t) ((BN_num_bits(pub_key)+7)/8);
0
459 }
never executed: end of block
0
460 }
never executed: end of block
0
461 if (ktype == 2
ktype == 2Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
462 priv_key = EC_KEY_get0_private_key(x);-
463 if (priv_key
priv_keyDescription
TRUEnever evaluated
FALSEnever evaluated
&& (
(i = (size_t) .../8)) > buf_lenDescription
TRUEnever evaluated
FALSEnever evaluated
i = (size_t) ((BN_num_bits(priv_key)+7)/8)) > buf_len
(i = (size_t) .../8)) > buf_lenDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
464 buf_len = i;
never executed: buf_len = i;
0
465 }
never executed: end of block
else
0
466 priv_key =
never executed: priv_key = ((void *)0) ;
0
467 ((void *)0)
never executed: priv_key = ((void *)0) ;
0
468 ;
never executed: priv_key = ((void *)0) ;
0
469-
470 if (ktype > 0
ktype > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
471 buf_len += 10;-
472 if ((
(buffer = mall...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
buffer = malloc(buf_len)) ==
(buffer = mall...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
473 ((void *)0)
(buffer = mall...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
474 ) {-
475 reason = (1|64);-
476 goto
never executed: goto err;
err;
never executed: goto err;
0
477 }-
478 }
never executed: end of block
0
479 if (ktype == 2
ktype == 2Description
TRUEnever evaluated
FALSEnever evaluated
)
0
480 ecstr = "Private-Key";
never executed: ecstr = "Private-Key";
0
481 else if (ktype == 1
ktype == 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
482 ecstr = "Public-Key";
never executed: ecstr = "Public-Key";
0
483 else-
484 ecstr = "ECDSA-Parameters";
never executed: ecstr = "ECDSA-Parameters";
0
485-
486 if (!BIO_indent(bp, off, 128)
!BIO_indent(bp, off, 128)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
487 goto
never executed: goto err;
err;
never executed: goto err;
0
488 if ((
(order = BN_ne...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
order = BN_new()) ==
(order = BN_ne...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
489 ((void *)0)
(order = BN_ne...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
490 )-
491 goto
never executed: goto err;
err;
never executed: goto err;
0
492 if (!EC_GROUP_get_order(group, order,
!EC_GROUP_get_... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
493 ((void *)0)
!EC_GROUP_get_... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
494 )
!EC_GROUP_get_... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
)
0
495 goto
never executed: goto err;
err;
never executed: goto err;
0
496 if (BIO_printf(bp, "%s: (%d bit)\n", ecstr,
BIO_printf(bp,...s(order)) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
497 BN_num_bits(order)) <= 0
BIO_printf(bp,...s(order)) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
498 goto
never executed: goto err;
err;
never executed: goto err;
0
499-
500 if ((
(priv_key != ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
priv_key !=
(priv_key != ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
501 ((void *)0)
(priv_key != ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
502 )
(priv_key != ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
&& !ASN1_bn_print(bp, "priv:", priv_key,
!ASN1_bn_print..., buffer, off)Description
TRUEnever evaluated
FALSEnever evaluated
0
503 buffer, off)
!ASN1_bn_print..., buffer, off)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
504 goto
never executed: goto err;
err;
never executed: goto err;
0
505 if ((
(pub_key != ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
pub_key !=
(pub_key != ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
506 ((void *)0)
(pub_key != ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
507 )
(pub_key != ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
&& !ASN1_bn_print(bp, "pub: ", pub_key,
!ASN1_bn_print..., buffer, off)Description
TRUEnever evaluated
FALSEnever evaluated
0
508 buffer, off)
!ASN1_bn_print..., buffer, off)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
509 goto
never executed: goto err;
err;
never executed: goto err;
0
510 if (!ECPKParameters_print(bp, group, off)
!ECPKParameter...p, group, off)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
511 goto
never executed: goto err;
err;
never executed: goto err;
0
512 ret = 1;-
513 err:
code before this statement never executed: err:
0
514 if (!ret
!retDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
515 ERR_put_error(16,(0xfff),(reason),__FILE__,488);
never executed: ERR_put_error(16,(0xfff),(reason),__FILE__,488);
0
516 BN_free(pub_key);-
517 BN_free(order);-
518 BN_CTX_free(ctx);-
519 free(buffer);-
520 return
never executed: return (ret);
(ret);
never executed: return (ret);
0
521}-
522-
523static int-
524eckey_param_decode(EVP_PKEY * pkey,-
525 const unsigned char **pder, int derlen)-
526{-
527 EC_KEY *eckey;-
528 if (!(eckey = d2i_ECParameters(
!(eckey = d2i_...pder, derlen))Description
TRUEnever evaluated
FALSEnever evaluated
0
529 ((void *)0)
!(eckey = d2i_...pder, derlen))Description
TRUEnever evaluated
FALSEnever evaluated
0
530 , pder, derlen))
!(eckey = d2i_...pder, derlen))Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
531 ERR_put_error(16,(0xfff),(16),__FILE__,502);-
532 return
never executed: return 0;
0;
never executed: return 0;
0
533 }-
534 EVP_PKEY_assign((pkey),408, (char *)(eckey));-
535 return
never executed: return 1;
1;
never executed: return 1;
0
536}-
537-
538static int-
539eckey_param_encode(const EVP_PKEY * pkey, unsigned char **pder)-
540{-
541 return
never executed: return i2d_ECParameters(pkey->pkey.ec, pder);
i2d_ECParameters(pkey->pkey.ec, pder);
never executed: return i2d_ECParameters(pkey->pkey.ec, pder);
0
542}-
543-
544static int-
545eckey_param_print(BIO * bp, const EVP_PKEY * pkey, int indent,-
546 ASN1_PCTX * ctx)-
547{-
548 return
never executed: return do_EC_KEY_print(bp, pkey->pkey.ec, indent, 0);
do_EC_KEY_print(bp, pkey->pkey.ec, indent, 0);
never executed: return do_EC_KEY_print(bp, pkey->pkey.ec, indent, 0);
0
549}-
550-
551static int-
552eckey_pub_print(BIO * bp, const EVP_PKEY * pkey, int indent,-
553 ASN1_PCTX * ctx)-
554{-
555 return
never executed: return do_EC_KEY_print(bp, pkey->pkey.ec, indent, 1);
do_EC_KEY_print(bp, pkey->pkey.ec, indent, 1);
never executed: return do_EC_KEY_print(bp, pkey->pkey.ec, indent, 1);
0
556}-
557-
558-
559static int-
560eckey_priv_print(BIO * bp, const EVP_PKEY * pkey, int indent,-
561 ASN1_PCTX * ctx)-
562{-
563 return
never executed: return do_EC_KEY_print(bp, pkey->pkey.ec, indent, 2);
do_EC_KEY_print(bp, pkey->pkey.ec, indent, 2);
never executed: return do_EC_KEY_print(bp, pkey->pkey.ec, indent, 2);
0
564}-
565-
566static int-
567old_ec_priv_decode(EVP_PKEY * pkey,-
568 const unsigned char **pder, int derlen)-
569{-
570 EC_KEY *ec;-
571 if (!(ec = d2i_ECPrivateKey(
!(ec = d2i_ECP...pder, derlen))Description
TRUEnever evaluated
FALSEnever evaluated
0
572 ((void *)0)
!(ec = d2i_ECP...pder, derlen))Description
TRUEnever evaluated
FALSEnever evaluated
0
573 , pder, derlen))
!(ec = d2i_ECP...pder, derlen))Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
574 ERR_put_error(16,(0xfff),(142),__FILE__,543);-
575 return
never executed: return 0;
0;
never executed: return 0;
0
576 }-
577 EVP_PKEY_assign((pkey),408, (char *)(ec));-
578 return
never executed: return 1;
1;
never executed: return 1;
0
579}-
580-
581static int-
582old_ec_priv_encode(const EVP_PKEY * pkey, unsigned char **pder)-
583{-
584 return
never executed: return i2d_ECPrivateKey(pkey->pkey.ec, pder);
i2d_ECPrivateKey(pkey->pkey.ec, pder);
never executed: return i2d_ECPrivateKey(pkey->pkey.ec, pder);
0
585}-
586-
587static int-
588ec_pkey_ctrl(EVP_PKEY * pkey, int op, long arg1, void *arg2)-
589{-
590 switch (op) {-
591 case
never executed: case 0x1:
0x1:
never executed: case 0x1:
0
592 if (arg1 == 0
arg1 == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
593 int snid, hnid;-
594 X509_ALGOR *alg1, *alg2;-
595 PKCS7_SIGNER_INFO_get0_algs(arg2, -
596 ((void *)0)-
597 , &alg1, &alg2);-
598 if (alg1 ==
alg1 == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
599 ((void *)0)
alg1 == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
600 || alg1->algorithm ==
alg1->algorithm == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
601 ((void *)0)
alg1->algorithm == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
602 )-
603 return
never executed: return -1;
-1;
never executed: return -1;
0
604 hnid = OBJ_obj2nid(alg1->algorithm);-
605 if (hnid == 0
hnid == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
606 return
never executed: return -1;
-1;
never executed: return -1;
0
607 if (!OBJ_find_sigid_by_algs(&snid, hnid, EVP_PKEY_id(pkey))
!OBJ_find_sigi...PKEY_id(pkey))Description
TRUEnever evaluated
FALSEnever evaluated
)
0
608 return
never executed: return -1;
-1;
never executed: return -1;
0
609 X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), -1, 0);-
610 }
never executed: end of block
0
611 return
never executed: return 1;
1;
never executed: return 1;
0
612-
613 case
never executed: case 0x3:
0x3:
never executed: case 0x3:
0
614 *(int *) arg2 = 64;-
615 return
never executed: return 2;
2;
never executed: return 2;
0
616-
617 default
never executed: default:
:
never executed: default:
0
618 return
never executed: return -2;
-2;
never executed: return -2;
0
619-
620 }-
621-
622}-
623-
624const EVP_PKEY_ASN1_METHOD eckey_asn1_meth = {-
625 .pkey_id = 408,-
626 .pkey_base_id = 408,-
627-
628 .pem_str = "EC",-
629 .info = "OpenSSL EC algorithm",-
630-
631 .pub_decode = eckey_pub_decode,-
632 .pub_encode = eckey_pub_encode,-
633 .pub_cmp = eckey_pub_cmp,-
634 .pub_print = eckey_pub_print,-
635-
636 .priv_decode = eckey_priv_decode,-
637 .priv_encode = eckey_priv_encode,-
638 .priv_print = eckey_priv_print,-
639-
640 .pkey_size = int_ec_size,-
641 .pkey_bits = ec_bits,-
642-
643 .param_decode = eckey_param_decode,-
644 .param_encode = eckey_param_encode,-
645 .param_missing = ec_missing_parameters,-
646 .param_copy = ec_copy_parameters,-
647 .param_cmp = ec_cmp_parameters,-
648 .param_print = eckey_param_print,-
649-
650 .pkey_free = int_ec_free,-
651 .pkey_ctrl = ec_pkey_ctrl,-
652 .old_priv_decode = old_ec_priv_decode,-
653 .old_priv_encode = old_ec_priv_encode-
654};-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2