summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/ec')
-rw-r--r--src/lib/libcrypto/ec/ec2_mult.c11
-rw-r--r--src/lib/libcrypto/ec/ec2_oct.c14
-rw-r--r--src/lib/libcrypto/ec/ec2_smpl.c17
-rw-r--r--src/lib/libcrypto/ec/ec_ameth.c11
-rw-r--r--src/lib/libcrypto/ec/ec_asn1.c45
-rw-r--r--src/lib/libcrypto/ec/ec_check.c8
-rw-r--r--src/lib/libcrypto/ec/ec_curve.c26
-rw-r--r--src/lib/libcrypto/ec/ec_key.c44
-rw-r--r--src/lib/libcrypto/ec/ec_lib.c17
-rw-r--r--src/lib/libcrypto/ec/ec_mult.c20
-rw-r--r--src/lib/libcrypto/ec/ec_pmeth.c8
-rw-r--r--src/lib/libcrypto/ec/eck_prn.c23
-rw-r--r--src/lib/libcrypto/ec/ecp_mont.c57
-rw-r--r--src/lib/libcrypto/ec/ecp_nist.c11
-rw-r--r--src/lib/libcrypto/ec/ecp_nistp224.c20
-rw-r--r--src/lib/libcrypto/ec/ecp_nistp256.c20
-rw-r--r--src/lib/libcrypto/ec/ecp_nistp521.c20
-rw-r--r--src/lib/libcrypto/ec/ecp_oct.c14
-rw-r--r--src/lib/libcrypto/ec/ecp_smpl.c41
19 files changed, 151 insertions, 276 deletions
diff --git a/src/lib/libcrypto/ec/ec2_mult.c b/src/lib/libcrypto/ec/ec2_mult.c
index 6c3a759dc8..c74571f88c 100644
--- a/src/lib/libcrypto/ec/ec2_mult.c
+++ b/src/lib/libcrypto/ec/ec2_mult.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec2_mult.c,v 1.4 2014/07/10 22:45:56 jsing Exp $ */ 1/* $OpenBSD: ec2_mult.c,v 1.5 2014/07/12 16:03:37 miod Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -421,12 +421,9 @@ ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
421 ret = 1; 421 ret = 1;
422 422
423err: 423err:
424 if (p) 424 EC_POINT_free(p);
425 EC_POINT_free(p); 425 EC_POINT_free(acc);
426 if (acc) 426 BN_CTX_free(new_ctx);
427 EC_POINT_free(acc);
428 if (new_ctx != NULL)
429 BN_CTX_free(new_ctx);
430 return ret; 427 return ret;
431} 428}
432 429
diff --git a/src/lib/libcrypto/ec/ec2_oct.c b/src/lib/libcrypto/ec/ec2_oct.c
index 5150423b99..3b8039af6e 100644
--- a/src/lib/libcrypto/ec/ec2_oct.c
+++ b/src/lib/libcrypto/ec/ec2_oct.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec2_oct.c,v 1.4 2014/07/10 22:45:56 jsing Exp $ */ 1/* $OpenBSD: ec2_oct.c,v 1.5 2014/07/12 16:03:37 miod Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -157,8 +157,7 @@ ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point
157 157
158err: 158err:
159 BN_CTX_end(ctx); 159 BN_CTX_end(ctx);
160 if (new_ctx != NULL) 160 BN_CTX_free(new_ctx);
161 BN_CTX_free(new_ctx);
162 return ret; 161 return ret;
163} 162}
164 163
@@ -267,15 +266,13 @@ ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point,
267 } 266 }
268 if (used_ctx) 267 if (used_ctx)
269 BN_CTX_end(ctx); 268 BN_CTX_end(ctx);
270 if (new_ctx != NULL) 269 BN_CTX_free(new_ctx);
271 BN_CTX_free(new_ctx);
272 return ret; 270 return ret;
273 271
274err: 272err:
275 if (used_ctx) 273 if (used_ctx)
276 BN_CTX_end(ctx); 274 BN_CTX_end(ctx);
277 if (new_ctx != NULL) 275 BN_CTX_free(new_ctx);
278 BN_CTX_free(new_ctx);
279 return 0; 276 return 0;
280} 277}
281 278
@@ -375,8 +372,7 @@ ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
375 372
376err: 373err:
377 BN_CTX_end(ctx); 374 BN_CTX_end(ctx);
378 if (new_ctx != NULL) 375 BN_CTX_free(new_ctx);
379 BN_CTX_free(new_ctx);
380 return ret; 376 return ret;
381} 377}
382#endif 378#endif
diff --git a/src/lib/libcrypto/ec/ec2_smpl.c b/src/lib/libcrypto/ec/ec2_smpl.c
index 001ffcc077..0031a161c7 100644
--- a/src/lib/libcrypto/ec/ec2_smpl.c
+++ b/src/lib/libcrypto/ec/ec2_smpl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec2_smpl.c,v 1.11 2014/07/10 22:45:56 jsing Exp $ */ 1/* $OpenBSD: ec2_smpl.c,v 1.12 2014/07/12 16:03:37 miod Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -310,8 +310,7 @@ ec_GF2m_simple_group_check_discriminant(const EC_GROUP * group, BN_CTX * ctx)
310err: 310err:
311 if (ctx != NULL) 311 if (ctx != NULL)
312 BN_CTX_end(ctx); 312 BN_CTX_end(ctx);
313 if (new_ctx != NULL) 313 BN_CTX_free(new_ctx);
314 BN_CTX_free(new_ctx);
315 return ret; 314 return ret;
316} 315}
317 316
@@ -547,8 +546,7 @@ ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
547 546
548err: 547err:
549 BN_CTX_end(ctx); 548 BN_CTX_end(ctx);
550 if (new_ctx != NULL) 549 BN_CTX_free(new_ctx);
551 BN_CTX_free(new_ctx);
552 return ret; 550 return ret;
553} 551}
554 552
@@ -641,8 +639,7 @@ ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX
641err: 639err:
642 if (ctx) 640 if (ctx)
643 BN_CTX_end(ctx); 641 BN_CTX_end(ctx);
644 if (new_ctx) 642 BN_CTX_free(new_ctx);
645 BN_CTX_free(new_ctx);
646 return ret; 643 return ret;
647} 644}
648 645
@@ -691,8 +688,7 @@ ec_GF2m_simple_cmp(const EC_GROUP * group, const EC_POINT * a, const EC_POINT *
691err: 688err:
692 if (ctx) 689 if (ctx)
693 BN_CTX_end(ctx); 690 BN_CTX_end(ctx);
694 if (new_ctx) 691 BN_CTX_free(new_ctx);
695 BN_CTX_free(new_ctx);
696 return ret; 692 return ret;
697} 693}
698 694
@@ -733,8 +729,7 @@ ec_GF2m_simple_make_affine(const EC_GROUP * group, EC_POINT * point, BN_CTX * ct
733err: 729err:
734 if (ctx) 730 if (ctx)
735 BN_CTX_end(ctx); 731 BN_CTX_end(ctx);
736 if (new_ctx) 732 BN_CTX_free(new_ctx);
737 BN_CTX_free(new_ctx);
738 return ret; 733 return ret;
739} 734}
740 735
diff --git a/src/lib/libcrypto/ec/ec_ameth.c b/src/lib/libcrypto/ec/ec_ameth.c
index 93e305b71a..c201815621 100644
--- a/src/lib/libcrypto/ec/ec_ameth.c
+++ b/src/lib/libcrypto/ec/ec_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_ameth.c,v 1.11 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: ec_ameth.c,v 1.12 2014/07/12 16:03:37 miod Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -492,12 +492,9 @@ do_EC_KEY_print(BIO * bp, const EC_KEY * x, int off, int ktype)
492err: 492err:
493 if (!ret) 493 if (!ret)
494 ECerr(EC_F_DO_EC_KEY_PRINT, reason); 494 ECerr(EC_F_DO_EC_KEY_PRINT, reason);
495 if (pub_key) 495 BN_free(pub_key);
496 BN_free(pub_key); 496 BN_free(order);
497 if (order) 497 BN_CTX_free(ctx);
498 BN_free(order);
499 if (ctx)
500 BN_CTX_free(ctx);
501 free(buffer); 498 free(buffer);
502 return (ret); 499 return (ret);
503} 500}
diff --git a/src/lib/libcrypto/ec/ec_asn1.c b/src/lib/libcrypto/ec/ec_asn1.c
index ef87b599f2..c54f6593d5 100644
--- a/src/lib/libcrypto/ec/ec_asn1.c
+++ b/src/lib/libcrypto/ec/ec_asn1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_asn1.c,v 1.9 2014/07/10 22:45:57 jsing Exp $ */ 1/* $OpenBSD: ec_asn1.c,v 1.10 2014/07/12 16:03:37 miod Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -404,8 +404,8 @@ ec_asn1_group2fieldid(const EC_GROUP * group, X9_62_FIELDID * field)
404 404
405 ok = 1; 405 ok = 1;
406 406
407err: if (tmp) 407err:
408 BN_free(tmp); 408 BN_free(tmp);
409 return (ok); 409 return (ok);
410} 410}
411 411
@@ -509,12 +509,11 @@ ec_asn1_group2curve(const EC_GROUP * group, X9_62_CURVE * curve)
509 509
510 ok = 1; 510 ok = 1;
511 511
512err: free(buffer_1); 512err:
513 free(buffer_1);
513 free(buffer_2); 514 free(buffer_2);
514 if (tmp_1) 515 BN_free(tmp_1);
515 BN_free(tmp_1); 516 BN_free(tmp_2);
516 if (tmp_2)
517 BN_free(tmp_2);
518 return (ok); 517 return (ok);
519} 518}
520 519
@@ -608,8 +607,7 @@ err: if (!ok) {
608 ECPARAMETERS_free(ret); 607 ECPARAMETERS_free(ret);
609 ret = NULL; 608 ret = NULL;
610 } 609 }
611 if (tmp) 610 BN_free(tmp);
612 BN_free(tmp);
613 free(buffer); 611 free(buffer);
614 return (ret); 612 return (ret);
615} 613}
@@ -849,10 +847,8 @@ ec_asn1_parameters2group(const ECPARAMETERS * params)
849 } 847 }
850 /* extract the cofactor (optional) */ 848 /* extract the cofactor (optional) */
851 if (params->cofactor == NULL) { 849 if (params->cofactor == NULL) {
852 if (b) { 850 BN_free(b);
853 BN_free(b); 851 b = NULL;
854 b = NULL;
855 }
856 } else if ((b = ASN1_INTEGER_to_BN(params->cofactor, b)) == NULL) { 852 } else if ((b = ASN1_INTEGER_to_BN(params->cofactor, b)) == NULL) {
857 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB); 853 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB);
858 goto err; 854 goto err;
@@ -865,18 +861,13 @@ ec_asn1_parameters2group(const ECPARAMETERS * params)
865 ok = 1; 861 ok = 1;
866 862
867err: if (!ok) { 863err: if (!ok) {
868 if (ret) 864 EC_GROUP_clear_free(ret);
869 EC_GROUP_clear_free(ret);
870 ret = NULL; 865 ret = NULL;
871 } 866 }
872 if (p) 867 BN_free(p);
873 BN_free(p); 868 BN_free(a);
874 if (a) 869 BN_free(b);
875 BN_free(a); 870 EC_POINT_free(point);
876 if (b)
877 BN_free(b);
878 if (point)
879 EC_POINT_free(point);
880 return (ret); 871 return (ret);
881} 872}
882 873
@@ -992,8 +983,7 @@ d2i_ECPrivateKey(EC_KEY ** a, const unsigned char **in, long len)
992 ret = *a; 983 ret = *a;
993 984
994 if (priv_key->parameters) { 985 if (priv_key->parameters) {
995 if (ret->group) 986 EC_GROUP_clear_free(ret->group);
996 EC_GROUP_clear_free(ret->group);
997 ret->group = ec_asn1_pkparameters2group(priv_key->parameters); 987 ret->group = ec_asn1_pkparameters2group(priv_key->parameters);
998 } 988 }
999 if (ret->group == NULL) { 989 if (ret->group == NULL) {
@@ -1022,8 +1012,7 @@ d2i_ECPrivateKey(EC_KEY ** a, const unsigned char **in, long len)
1022 const unsigned char *pub_oct; 1012 const unsigned char *pub_oct;
1023 size_t pub_oct_len; 1013 size_t pub_oct_len;
1024 1014
1025 if (ret->pub_key) 1015 EC_POINT_clear_free(ret->pub_key);
1026 EC_POINT_clear_free(ret->pub_key);
1027 ret->pub_key = EC_POINT_new(ret->group); 1016 ret->pub_key = EC_POINT_new(ret->group);
1028 if (ret->pub_key == NULL) { 1017 if (ret->pub_key == NULL) {
1029 ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB); 1018 ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);
diff --git a/src/lib/libcrypto/ec/ec_check.c b/src/lib/libcrypto/ec/ec_check.c
index 585590514f..779e03cc2b 100644
--- a/src/lib/libcrypto/ec/ec_check.c
+++ b/src/lib/libcrypto/ec/ec_check.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_check.c,v 1.3 2014/06/12 15:49:29 deraadt Exp $ */ 1/* $OpenBSD: ec_check.c,v 1.4 2014/07/12 16:03:37 miod Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -109,9 +109,7 @@ EC_GROUP_check(const EC_GROUP * group, BN_CTX * ctx)
109err: 109err:
110 if (ctx != NULL) 110 if (ctx != NULL)
111 BN_CTX_end(ctx); 111 BN_CTX_end(ctx);
112 if (new_ctx != NULL) 112 BN_CTX_free(new_ctx);
113 BN_CTX_free(new_ctx); 113 EC_POINT_free(point);
114 if (point)
115 EC_POINT_free(point);
116 return ret; 114 return ret;
117} 115}
diff --git a/src/lib/libcrypto/ec/ec_curve.c b/src/lib/libcrypto/ec/ec_curve.c
index baac8c7156..9d36d0bf22 100644
--- a/src/lib/libcrypto/ec/ec_curve.c
+++ b/src/lib/libcrypto/ec/ec_curve.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_curve.c,v 1.6 2014/07/10 22:45:57 jsing Exp $ */ 1/* $OpenBSD: ec_curve.c,v 1.7 2014/07/12 16:03:37 miod Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -2981,22 +2981,14 @@ err:
2981 EC_GROUP_free(group); 2981 EC_GROUP_free(group);
2982 group = NULL; 2982 group = NULL;
2983 } 2983 }
2984 if (P) 2984 EC_POINT_free(P);
2985 EC_POINT_free(P); 2985 BN_CTX_free(ctx);
2986 if (ctx) 2986 BN_free(p);
2987 BN_CTX_free(ctx); 2987 BN_free(a);
2988 if (p) 2988 BN_free(b);
2989 BN_free(p); 2989 BN_free(order);
2990 if (a) 2990 BN_free(x);
2991 BN_free(a); 2991 BN_free(y);
2992 if (b)
2993 BN_free(b);
2994 if (order)
2995 BN_free(order);
2996 if (x)
2997 BN_free(x);
2998 if (y)
2999 BN_free(y);
3000 return group; 2992 return group;
3001} 2993}
3002 2994
diff --git a/src/lib/libcrypto/ec/ec_key.c b/src/lib/libcrypto/ec/ec_key.c
index 7067a949da..1154c4dbf5 100644
--- a/src/lib/libcrypto/ec/ec_key.c
+++ b/src/lib/libcrypto/ec/ec_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_key.c,v 1.8 2014/07/10 22:45:57 jsing Exp $ */ 1/* $OpenBSD: ec_key.c,v 1.9 2014/07/12 16:03:37 miod Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -116,12 +116,9 @@ EC_KEY_free(EC_KEY * r)
116 if (i > 0) 116 if (i > 0)
117 return; 117 return;
118 118
119 if (r->group != NULL) 119 EC_GROUP_free(r->group);
120 EC_GROUP_free(r->group); 120 EC_POINT_free(r->pub_key);
121 if (r->pub_key != NULL) 121 BN_clear_free(r->priv_key);
122 EC_POINT_free(r->pub_key);
123 if (r->priv_key != NULL)
124 BN_clear_free(r->priv_key);
125 122
126 EC_EX_DATA_free_all_data(&r->method_data); 123 EC_EX_DATA_free_all_data(&r->method_data);
127 124
@@ -143,8 +140,7 @@ EC_KEY_copy(EC_KEY * dest, const EC_KEY * src)
143 if (src->group) { 140 if (src->group) {
144 const EC_METHOD *meth = EC_GROUP_method_of(src->group); 141 const EC_METHOD *meth = EC_GROUP_method_of(src->group);
145 /* clear the old group */ 142 /* clear the old group */
146 if (dest->group) 143 EC_GROUP_free(dest->group);
147 EC_GROUP_free(dest->group);
148 dest->group = EC_GROUP_new(meth); 144 dest->group = EC_GROUP_new(meth);
149 if (dest->group == NULL) 145 if (dest->group == NULL)
150 return NULL; 146 return NULL;
@@ -153,8 +149,7 @@ EC_KEY_copy(EC_KEY * dest, const EC_KEY * src)
153 } 149 }
154 /* copy the public key */ 150 /* copy the public key */
155 if (src->pub_key && src->group) { 151 if (src->pub_key && src->group) {
156 if (dest->pub_key) 152 EC_POINT_free(dest->pub_key);
157 EC_POINT_free(dest->pub_key);
158 dest->pub_key = EC_POINT_new(src->group); 153 dest->pub_key = EC_POINT_new(src->group);
159 if (dest->pub_key == NULL) 154 if (dest->pub_key == NULL)
160 return NULL; 155 return NULL;
@@ -261,14 +256,12 @@ EC_KEY_generate_key(EC_KEY * eckey)
261 ok = 1; 256 ok = 1;
262 257
263err: 258err:
264 if (order) 259 BN_free(order);
265 BN_free(order);
266 if (pub_key != NULL && eckey->pub_key == NULL) 260 if (pub_key != NULL && eckey->pub_key == NULL)
267 EC_POINT_free(pub_key); 261 EC_POINT_free(pub_key);
268 if (priv_key != NULL && eckey->priv_key == NULL) 262 if (priv_key != NULL && eckey->priv_key == NULL)
269 BN_free(priv_key); 263 BN_free(priv_key);
270 if (ctx != NULL) 264 BN_CTX_free(ctx);
271 BN_CTX_free(ctx);
272 return (ok); 265 return (ok);
273} 266}
274 267
@@ -334,10 +327,8 @@ EC_KEY_check_key(const EC_KEY * eckey)
334 } 327 }
335 ok = 1; 328 ok = 1;
336err: 329err:
337 if (ctx != NULL) 330 BN_CTX_free(ctx);
338 BN_CTX_free(ctx); 331 EC_POINT_free(point);
339 if (point != NULL)
340 EC_POINT_free(point);
341 return (ok); 332 return (ok);
342} 333}
343 334
@@ -406,10 +397,8 @@ EC_KEY_set_public_key_affine_coordinates(EC_KEY * key, BIGNUM * x, BIGNUM * y)
406 ok = 1; 397 ok = 1;
407 398
408err: 399err:
409 if (ctx) 400 BN_CTX_free(ctx);
410 BN_CTX_free(ctx); 401 EC_POINT_free(point);
411 if (point)
412 EC_POINT_free(point);
413 return ok; 402 return ok;
414 403
415} 404}
@@ -423,8 +412,7 @@ EC_KEY_get0_group(const EC_KEY * key)
423int 412int
424EC_KEY_set_group(EC_KEY * key, const EC_GROUP * group) 413EC_KEY_set_group(EC_KEY * key, const EC_GROUP * group)
425{ 414{
426 if (key->group != NULL) 415 EC_GROUP_free(key->group);
427 EC_GROUP_free(key->group);
428 key->group = EC_GROUP_dup(group); 416 key->group = EC_GROUP_dup(group);
429 return (key->group == NULL) ? 0 : 1; 417 return (key->group == NULL) ? 0 : 1;
430} 418}
@@ -438,8 +426,7 @@ EC_KEY_get0_private_key(const EC_KEY * key)
438int 426int
439EC_KEY_set_private_key(EC_KEY * key, const BIGNUM * priv_key) 427EC_KEY_set_private_key(EC_KEY * key, const BIGNUM * priv_key)
440{ 428{
441 if (key->priv_key) 429 BN_clear_free(key->priv_key);
442 BN_clear_free(key->priv_key);
443 key->priv_key = BN_dup(priv_key); 430 key->priv_key = BN_dup(priv_key);
444 return (key->priv_key == NULL) ? 0 : 1; 431 return (key->priv_key == NULL) ? 0 : 1;
445} 432}
@@ -453,8 +440,7 @@ EC_KEY_get0_public_key(const EC_KEY * key)
453int 440int
454EC_KEY_set_public_key(EC_KEY * key, const EC_POINT * pub_key) 441EC_KEY_set_public_key(EC_KEY * key, const EC_POINT * pub_key)
455{ 442{
456 if (key->pub_key != NULL) 443 EC_POINT_free(key->pub_key);
457 EC_POINT_free(key->pub_key);
458 key->pub_key = EC_POINT_dup(pub_key, key->group); 444 key->pub_key = EC_POINT_dup(pub_key, key->group);
459 return (key->pub_key == NULL) ? 0 : 1; 445 return (key->pub_key == NULL) ? 0 : 1;
460} 446}
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c
index 3d8b96eb1f..47ccc614d1 100644
--- a/src/lib/libcrypto/ec/ec_lib.c
+++ b/src/lib/libcrypto/ec/ec_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_lib.c,v 1.14 2014/07/10 22:45:57 jsing Exp $ */ 1/* $OpenBSD: ec_lib.c,v 1.15 2014/07/12 16:03:37 miod Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller for the OpenSSL project. 3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */ 4 */
@@ -124,8 +124,7 @@ EC_GROUP_free(EC_GROUP * group)
124 124
125 EC_EX_DATA_free_all_data(&group->extra_data); 125 EC_EX_DATA_free_all_data(&group->extra_data);
126 126
127 if (group->generator != NULL) 127 EC_POINT_free(group->generator);
128 EC_POINT_free(group->generator);
129 BN_free(&group->order); 128 BN_free(&group->order);
130 BN_free(&group->cofactor); 129 BN_free(&group->cofactor);
131 130
@@ -148,8 +147,7 @@ EC_GROUP_clear_free(EC_GROUP * group)
148 147
149 EC_EX_DATA_clear_free_all_data(&group->extra_data); 148 EC_EX_DATA_clear_free_all_data(&group->extra_data);
150 149
151 if (group->generator != NULL) 150 EC_POINT_clear_free(group->generator);
152 EC_POINT_clear_free(group->generator);
153 BN_clear_free(&group->order); 151 BN_clear_free(&group->order);
154 BN_clear_free(&group->cofactor); 152 BN_clear_free(&group->cofactor);
155 153
@@ -200,10 +198,8 @@ EC_GROUP_copy(EC_GROUP * dest, const EC_GROUP * src)
200 return 0; 198 return 0;
201 } else { 199 } else {
202 /* src->generator == NULL */ 200 /* src->generator == NULL */
203 if (dest->generator != NULL) { 201 EC_POINT_clear_free(dest->generator);
204 EC_POINT_clear_free(dest->generator); 202 dest->generator = NULL;
205 dest->generator = NULL;
206 }
207 } 203 }
208 204
209 if (!BN_copy(&dest->order, &src->order)) 205 if (!BN_copy(&dest->order, &src->order))
@@ -252,8 +248,7 @@ EC_GROUP_dup(const EC_GROUP * a)
252 248
253err: 249err:
254 if (!ok) { 250 if (!ok) {
255 if (t) 251 EC_GROUP_free(t);
256 EC_GROUP_free(t);
257 return NULL; 252 return NULL;
258 } else 253 } else
259 return t; 254 return t;
diff --git a/src/lib/libcrypto/ec/ec_mult.c b/src/lib/libcrypto/ec/ec_mult.c
index b6f74a1b09..4e49ce4f7b 100644
--- a/src/lib/libcrypto/ec/ec_mult.c
+++ b/src/lib/libcrypto/ec/ec_mult.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_mult.c,v 1.13 2014/06/12 15:49:29 deraadt Exp $ */ 1/* $OpenBSD: ec_mult.c,v 1.14 2014/07/12 16:03:37 miod Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller and Nils Larsch for the OpenSSL project. 3 * Originally written by Bodo Moeller and Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -679,10 +679,8 @@ ec_wNAF_mul(const EC_GROUP * group, EC_POINT * r, const BIGNUM * scalar,
679 ret = 1; 679 ret = 1;
680 680
681err: 681err:
682 if (new_ctx != NULL) 682 BN_CTX_free(new_ctx);
683 BN_CTX_free(new_ctx); 683 EC_POINT_free(tmp);
684 if (tmp != NULL)
685 EC_POINT_free(tmp);
686 free(wsize); 684 free(wsize);
687 free(wNAF_len); 685 free(wNAF_len);
688 if (wNAF != NULL) { 686 if (wNAF != NULL) {
@@ -862,10 +860,8 @@ ec_wNAF_precompute_mult(EC_GROUP * group, BN_CTX * ctx)
862err: 860err:
863 if (ctx != NULL) 861 if (ctx != NULL)
864 BN_CTX_end(ctx); 862 BN_CTX_end(ctx);
865 if (new_ctx != NULL) 863 BN_CTX_free(new_ctx);
866 BN_CTX_free(new_ctx); 864 ec_pre_comp_free(pre_comp);
867 if (pre_comp)
868 ec_pre_comp_free(pre_comp);
869 if (points) { 865 if (points) {
870 EC_POINT **p; 866 EC_POINT **p;
871 867
@@ -873,10 +869,8 @@ err:
873 EC_POINT_free(*p); 869 EC_POINT_free(*p);
874 free(points); 870 free(points);
875 } 871 }
876 if (tmp_point) 872 EC_POINT_free(tmp_point);
877 EC_POINT_free(tmp_point); 873 EC_POINT_free(base);
878 if (base)
879 EC_POINT_free(base);
880 return ret; 874 return ret;
881} 875}
882 876
diff --git a/src/lib/libcrypto/ec/ec_pmeth.c b/src/lib/libcrypto/ec/ec_pmeth.c
index 7ba1d50d7f..07933dc5fd 100644
--- a/src/lib/libcrypto/ec/ec_pmeth.c
+++ b/src/lib/libcrypto/ec/ec_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_pmeth.c,v 1.7 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: ec_pmeth.c,v 1.8 2014/07/12 16:03:37 miod Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -114,8 +114,7 @@ pkey_ec_cleanup(EVP_PKEY_CTX * ctx)
114{ 114{
115 EC_PKEY_CTX *dctx = ctx->data; 115 EC_PKEY_CTX *dctx = ctx->data;
116 if (dctx) { 116 if (dctx) {
117 if (dctx->gen_group) 117 EC_GROUP_free(dctx->gen_group);
118 EC_GROUP_free(dctx->gen_group);
119 free(dctx); 118 free(dctx);
120 } 119 }
121} 120}
@@ -213,8 +212,7 @@ pkey_ec_ctrl(EVP_PKEY_CTX * ctx, int type, int p1, void *p2)
213 ECerr(EC_F_PKEY_EC_CTRL, EC_R_INVALID_CURVE); 212 ECerr(EC_F_PKEY_EC_CTRL, EC_R_INVALID_CURVE);
214 return 0; 213 return 0;
215 } 214 }
216 if (dctx->gen_group) 215 EC_GROUP_free(dctx->gen_group);
217 EC_GROUP_free(dctx->gen_group);
218 dctx->gen_group = group; 216 dctx->gen_group = group;
219 return 1; 217 return 1;
220 218
diff --git a/src/lib/libcrypto/ec/eck_prn.c b/src/lib/libcrypto/ec/eck_prn.c
index b0c8bcd22a..aa13d8b08c 100644
--- a/src/lib/libcrypto/ec/eck_prn.c
+++ b/src/lib/libcrypto/ec/eck_prn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eck_prn.c,v 1.9 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: eck_prn.c,v 1.10 2014/07/12 16:03:37 miod Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -315,20 +315,13 @@ ECPKParameters_print(BIO * bp, const EC_GROUP * x, int off)
315err: 315err:
316 if (!ret) 316 if (!ret)
317 ECerr(EC_F_ECPKPARAMETERS_PRINT, reason); 317 ECerr(EC_F_ECPKPARAMETERS_PRINT, reason);
318 if (p) 318 BN_free(p);
319 BN_free(p); 319 BN_free(a);
320 if (a) 320 BN_free(b);
321 BN_free(a); 321 BN_free(gen);
322 if (b) 322 BN_free(order);
323 BN_free(b); 323 BN_free(cofactor);
324 if (gen) 324 BN_CTX_free(ctx);
325 BN_free(gen);
326 if (order)
327 BN_free(order);
328 if (cofactor)
329 BN_free(cofactor);
330 if (ctx)
331 BN_CTX_free(ctx);
332 free(buffer); 325 free(buffer);
333 return (ret); 326 return (ret);
334} 327}
diff --git a/src/lib/libcrypto/ec/ecp_mont.c b/src/lib/libcrypto/ec/ecp_mont.c
index ffbce81d4c..af8014ed38 100644
--- a/src/lib/libcrypto/ec/ecp_mont.c
+++ b/src/lib/libcrypto/ec/ecp_mont.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_mont.c,v 1.8 2014/06/12 15:49:29 deraadt Exp $ */ 1/* $OpenBSD: ecp_mont.c,v 1.9 2014/07/12 16:03:37 miod Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller for the OpenSSL project. 3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */ 4 */
@@ -128,14 +128,10 @@ ec_GFp_mont_group_init(EC_GROUP * group)
128void 128void
129ec_GFp_mont_group_finish(EC_GROUP * group) 129ec_GFp_mont_group_finish(EC_GROUP * group)
130{ 130{
131 if (group->field_data1 != NULL) { 131 BN_MONT_CTX_free(group->field_data1);
132 BN_MONT_CTX_free(group->field_data1); 132 group->field_data1 = NULL;
133 group->field_data1 = NULL; 133 BN_free(group->field_data2);
134 } 134 group->field_data2 = NULL;
135 if (group->field_data2 != NULL) {
136 BN_free(group->field_data2);
137 group->field_data2 = NULL;
138 }
139 ec_GFp_simple_group_finish(group); 135 ec_GFp_simple_group_finish(group);
140} 136}
141 137
@@ -143,14 +139,10 @@ ec_GFp_mont_group_finish(EC_GROUP * group)
143void 139void
144ec_GFp_mont_group_clear_finish(EC_GROUP * group) 140ec_GFp_mont_group_clear_finish(EC_GROUP * group)
145{ 141{
146 if (group->field_data1 != NULL) { 142 BN_MONT_CTX_free(group->field_data1);
147 BN_MONT_CTX_free(group->field_data1); 143 group->field_data1 = NULL;
148 group->field_data1 = NULL; 144 BN_clear_free(group->field_data2);
149 } 145 group->field_data2 = NULL;
150 if (group->field_data2 != NULL) {
151 BN_clear_free(group->field_data2);
152 group->field_data2 = NULL;
153 }
154 ec_GFp_simple_group_clear_finish(group); 146 ec_GFp_simple_group_clear_finish(group);
155} 147}
156 148
@@ -158,14 +150,11 @@ ec_GFp_mont_group_clear_finish(EC_GROUP * group)
158int 150int
159ec_GFp_mont_group_copy(EC_GROUP * dest, const EC_GROUP * src) 151ec_GFp_mont_group_copy(EC_GROUP * dest, const EC_GROUP * src)
160{ 152{
161 if (dest->field_data1 != NULL) { 153 BN_MONT_CTX_free(dest->field_data1);
162 BN_MONT_CTX_free(dest->field_data1); 154 dest->field_data1 = NULL;
163 dest->field_data1 = NULL; 155 BN_clear_free(dest->field_data2);
164 } 156 dest->field_data2 = NULL;
165 if (dest->field_data2 != NULL) { 157
166 BN_clear_free(dest->field_data2);
167 dest->field_data2 = NULL;
168 }
169 if (!ec_GFp_simple_group_copy(dest, src)) 158 if (!ec_GFp_simple_group_copy(dest, src))
170 return 0; 159 return 0;
171 160
@@ -201,14 +190,10 @@ ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
201 BIGNUM *one = NULL; 190 BIGNUM *one = NULL;
202 int ret = 0; 191 int ret = 0;
203 192
204 if (group->field_data1 != NULL) { 193 BN_MONT_CTX_free(group->field_data1);
205 BN_MONT_CTX_free(group->field_data1); 194 group->field_data1 = NULL;
206 group->field_data1 = NULL; 195 BN_free(group->field_data2);
207 } 196 group->field_data2 = NULL;
208 if (group->field_data2 != NULL) {
209 BN_free(group->field_data2);
210 group->field_data2 = NULL;
211 }
212 if (ctx == NULL) { 197 if (ctx == NULL) {
213 ctx = new_ctx = BN_CTX_new(); 198 ctx = new_ctx = BN_CTX_new();
214 if (ctx == NULL) 199 if (ctx == NULL)
@@ -241,10 +226,8 @@ ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
241 group->field_data2 = NULL; 226 group->field_data2 = NULL;
242 } 227 }
243err: 228err:
244 if (new_ctx != NULL) 229 BN_CTX_free(new_ctx);
245 BN_CTX_free(new_ctx); 230 BN_MONT_CTX_free(mont);
246 if (mont != NULL)
247 BN_MONT_CTX_free(mont);
248 return ret; 231 return ret;
249} 232}
250 233
diff --git a/src/lib/libcrypto/ec/ecp_nist.c b/src/lib/libcrypto/ec/ecp_nist.c
index d49d1735f3..a33f9d9e39 100644
--- a/src/lib/libcrypto/ec/ecp_nist.c
+++ b/src/lib/libcrypto/ec/ecp_nist.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nist.c,v 1.8 2014/06/12 15:49:29 deraadt Exp $ */ 1/* $OpenBSD: ecp_nist.c,v 1.9 2014/07/12 16:03:37 miod Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -153,8 +153,7 @@ ec_GFp_nist_group_set_curve(EC_GROUP *group, const BIGNUM *p,
153 153
154err: 154err:
155 BN_CTX_end(ctx); 155 BN_CTX_end(ctx);
156 if (new_ctx != NULL) 156 BN_CTX_free(new_ctx);
157 BN_CTX_free(new_ctx);
158 return ret; 157 return ret;
159} 158}
160 159
@@ -181,8 +180,7 @@ ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
181 180
182 ret = 1; 181 ret = 1;
183err: 182err:
184 if (ctx_new) 183 BN_CTX_free(ctx_new);
185 BN_CTX_free(ctx_new);
186 return ret; 184 return ret;
187} 185}
188 186
@@ -209,7 +207,6 @@ ec_GFp_nist_field_sqr(const EC_GROUP * group, BIGNUM * r, const BIGNUM * a,
209 207
210 ret = 1; 208 ret = 1;
211err: 209err:
212 if (ctx_new) 210 BN_CTX_free(ctx_new);
213 BN_CTX_free(ctx_new);
214 return ret; 211 return ret;
215} 212}
diff --git a/src/lib/libcrypto/ec/ecp_nistp224.c b/src/lib/libcrypto/ec/ecp_nistp224.c
index c466d2db83..ed0bad2a72 100644
--- a/src/lib/libcrypto/ec/ecp_nistp224.c
+++ b/src/lib/libcrypto/ec/ecp_nistp224.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistp224.c,v 1.14 2014/07/10 22:45:57 jsing Exp $ */ 1/* $OpenBSD: ecp_nistp224.c,v 1.15 2014/07/12 16:03:37 miod Exp $ */
2/* 2/*
3 * Written by Emilia Kasper (Google) for the OpenSSL project. 3 * Written by Emilia Kasper (Google) for the OpenSSL project.
4 */ 4 */
@@ -1285,8 +1285,7 @@ ec_GFp_nistp224_group_set_curve(EC_GROUP * group, const BIGNUM * p,
1285 ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx); 1285 ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx);
1286err: 1286err:
1287 BN_CTX_end(ctx); 1287 BN_CTX_end(ctx);
1288 if (new_ctx != NULL) 1288 BN_CTX_free(new_ctx);
1289 BN_CTX_free(new_ctx);
1290 return ret; 1289 return ret;
1291} 1290}
1292 1291
@@ -1545,10 +1544,8 @@ ec_GFp_nistp224_points_mul(const EC_GROUP * group, EC_POINT * r,
1545 1544
1546err: 1545err:
1547 BN_CTX_end(ctx); 1546 BN_CTX_end(ctx);
1548 if (generator != NULL) 1547 EC_POINT_free(generator);
1549 EC_POINT_free(generator); 1548 BN_CTX_free(new_ctx);
1550 if (new_ctx != NULL)
1551 BN_CTX_free(new_ctx);
1552 free(secrets); 1549 free(secrets);
1553 free(pre_comp); 1550 free(pre_comp);
1554 free(tmp_felems); 1551 free(tmp_felems);
@@ -1676,12 +1673,9 @@ ec_GFp_nistp224_precompute_mult(EC_GROUP * group, BN_CTX * ctx)
1676 pre = NULL; 1673 pre = NULL;
1677err: 1674err:
1678 BN_CTX_end(ctx); 1675 BN_CTX_end(ctx);
1679 if (generator != NULL) 1676 EC_POINT_free(generator);
1680 EC_POINT_free(generator); 1677 BN_CTX_free(new_ctx);
1681 if (new_ctx != NULL) 1678 nistp224_pre_comp_free(pre);
1682 BN_CTX_free(new_ctx);
1683 if (pre)
1684 nistp224_pre_comp_free(pre);
1685 return ret; 1679 return ret;
1686} 1680}
1687 1681
diff --git a/src/lib/libcrypto/ec/ecp_nistp256.c b/src/lib/libcrypto/ec/ecp_nistp256.c
index 7b122e6307..6905b614bc 100644
--- a/src/lib/libcrypto/ec/ecp_nistp256.c
+++ b/src/lib/libcrypto/ec/ecp_nistp256.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistp256.c,v 1.13 2014/07/10 22:45:57 jsing Exp $ */ 1/* $OpenBSD: ecp_nistp256.c,v 1.14 2014/07/12 16:03:37 miod Exp $ */
2/* 2/*
3 * Written by Adam Langley (Google) for the OpenSSL project 3 * Written by Adam Langley (Google) for the OpenSSL project
4 */ 4 */
@@ -1834,8 +1834,7 @@ ec_GFp_nistp256_group_set_curve(EC_GROUP * group, const BIGNUM * p,
1834 ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx); 1834 ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx);
1835err: 1835err:
1836 BN_CTX_end(ctx); 1836 BN_CTX_end(ctx);
1837 if (new_ctx != NULL) 1837 BN_CTX_free(new_ctx);
1838 BN_CTX_free(new_ctx);
1839 return ret; 1838 return ret;
1840} 1839}
1841 1840
@@ -2098,10 +2097,8 @@ ec_GFp_nistp256_points_mul(const EC_GROUP * group, EC_POINT * r,
2098 2097
2099err: 2098err:
2100 BN_CTX_end(ctx); 2099 BN_CTX_end(ctx);
2101 if (generator != NULL) 2100 EC_POINT_free(generator);
2102 EC_POINT_free(generator); 2101 BN_CTX_free(new_ctx);
2103 if (new_ctx != NULL)
2104 BN_CTX_free(new_ctx);
2105 free(secrets); 2102 free(secrets);
2106 free(pre_comp); 2103 free(pre_comp);
2107 free(tmp_smallfelems); 2104 free(tmp_smallfelems);
@@ -2223,12 +2220,9 @@ ec_GFp_nistp256_precompute_mult(EC_GROUP * group, BN_CTX * ctx)
2223 pre = NULL; 2220 pre = NULL;
2224err: 2221err:
2225 BN_CTX_end(ctx); 2222 BN_CTX_end(ctx);
2226 if (generator != NULL) 2223 EC_POINT_free(generator);
2227 EC_POINT_free(generator); 2224 BN_CTX_free(new_ctx);
2228 if (new_ctx != NULL) 2225 nistp256_pre_comp_free(pre);
2229 BN_CTX_free(new_ctx);
2230 if (pre)
2231 nistp256_pre_comp_free(pre);
2232 return ret; 2226 return ret;
2233} 2227}
2234 2228
diff --git a/src/lib/libcrypto/ec/ecp_nistp521.c b/src/lib/libcrypto/ec/ecp_nistp521.c
index cec0a3b470..c9313ada8e 100644
--- a/src/lib/libcrypto/ec/ecp_nistp521.c
+++ b/src/lib/libcrypto/ec/ecp_nistp521.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistp521.c,v 1.14 2014/07/10 22:45:57 jsing Exp $ */ 1/* $OpenBSD: ecp_nistp521.c,v 1.15 2014/07/12 16:03:37 miod Exp $ */
2/* 2/*
3 * Written by Adam Langley (Google) for the OpenSSL project 3 * Written by Adam Langley (Google) for the OpenSSL project
4 */ 4 */
@@ -1725,8 +1725,7 @@ ec_GFp_nistp521_group_set_curve(EC_GROUP * group, const BIGNUM * p,
1725 ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx); 1725 ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx);
1726err: 1726err:
1727 BN_CTX_end(ctx); 1727 BN_CTX_end(ctx);
1728 if (new_ctx != NULL) 1728 BN_CTX_free(new_ctx);
1729 BN_CTX_free(new_ctx);
1730 return ret; 1729 return ret;
1731} 1730}
1732 1731
@@ -1985,10 +1984,8 @@ ec_GFp_nistp521_points_mul(const EC_GROUP * group, EC_POINT * r,
1985 1984
1986err: 1985err:
1987 BN_CTX_end(ctx); 1986 BN_CTX_end(ctx);
1988 if (generator != NULL) 1987 EC_POINT_free(generator);
1989 EC_POINT_free(generator); 1988 BN_CTX_free(new_ctx);
1990 if (new_ctx != NULL)
1991 BN_CTX_free(new_ctx);
1992 free(secrets); 1989 free(secrets);
1993 free(pre_comp); 1990 free(pre_comp);
1994 free(tmp_felems); 1991 free(tmp_felems);
@@ -2096,12 +2093,9 @@ ec_GFp_nistp521_precompute_mult(EC_GROUP * group, BN_CTX * ctx)
2096 pre = NULL; 2093 pre = NULL;
2097err: 2094err:
2098 BN_CTX_end(ctx); 2095 BN_CTX_end(ctx);
2099 if (generator != NULL) 2096 EC_POINT_free(generator);
2100 EC_POINT_free(generator); 2097 BN_CTX_free(new_ctx);
2101 if (new_ctx != NULL) 2098 nistp521_pre_comp_free(pre);
2102 BN_CTX_free(new_ctx);
2103 if (pre)
2104 nistp521_pre_comp_free(pre);
2105 return ret; 2099 return ret;
2106} 2100}
2107 2101
diff --git a/src/lib/libcrypto/ec/ecp_oct.c b/src/lib/libcrypto/ec/ecp_oct.c
index 2f2920d70d..d2402ee0d8 100644
--- a/src/lib/libcrypto/ec/ecp_oct.c
+++ b/src/lib/libcrypto/ec/ecp_oct.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_oct.c,v 1.4 2014/06/12 15:49:29 deraadt Exp $ */ 1/* $OpenBSD: ecp_oct.c,v 1.5 2014/07/12 16:03:37 miod Exp $ */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> 2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project. 3 * for the OpenSSL project.
4 * Includes code written by Bodo Moeller for the OpenSSL project. 4 * Includes code written by Bodo Moeller for the OpenSSL project.
@@ -190,8 +190,7 @@ ec_GFp_simple_set_compressed_coordinates(const EC_GROUP * group, EC_POINT * poin
190 190
191err: 191err:
192 BN_CTX_end(ctx); 192 BN_CTX_end(ctx);
193 if (new_ctx != NULL) 193 BN_CTX_free(new_ctx);
194 BN_CTX_free(new_ctx);
195 return ret; 194 return ret;
196} 195}
197 196
@@ -290,15 +289,13 @@ ec_GFp_simple_point2oct(const EC_GROUP * group, const EC_POINT * point, point_co
290 } 289 }
291 if (used_ctx) 290 if (used_ctx)
292 BN_CTX_end(ctx); 291 BN_CTX_end(ctx);
293 if (new_ctx != NULL) 292 BN_CTX_free(new_ctx);
294 BN_CTX_free(new_ctx);
295 return ret; 293 return ret;
296 294
297err: 295err:
298 if (used_ctx) 296 if (used_ctx)
299 BN_CTX_end(ctx); 297 BN_CTX_end(ctx);
300 if (new_ctx != NULL) 298 BN_CTX_free(new_ctx);
301 BN_CTX_free(new_ctx);
302 return 0; 299 return 0;
303} 300}
304 301
@@ -391,7 +388,6 @@ ec_GFp_simple_oct2point(const EC_GROUP * group, EC_POINT * point,
391 388
392err: 389err:
393 BN_CTX_end(ctx); 390 BN_CTX_end(ctx);
394 if (new_ctx != NULL) 391 BN_CTX_free(new_ctx);
395 BN_CTX_free(new_ctx);
396 return ret; 392 return ret;
397} 393}
diff --git a/src/lib/libcrypto/ec/ecp_smpl.c b/src/lib/libcrypto/ec/ecp_smpl.c
index 5ba9a925d6..dabc5af899 100644
--- a/src/lib/libcrypto/ec/ecp_smpl.c
+++ b/src/lib/libcrypto/ec/ecp_smpl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_smpl.c,v 1.12 2014/06/12 15:49:29 deraadt Exp $ */ 1/* $OpenBSD: ecp_smpl.c,v 1.13 2014/07/12 16:03:37 miod Exp $ */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> 2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project. 3 * for the OpenSSL project.
4 * Includes code written by Bodo Moeller for the OpenSSL project. 4 * Includes code written by Bodo Moeller for the OpenSSL project.
@@ -222,8 +222,7 @@ ec_GFp_simple_group_set_curve(EC_GROUP * group,
222 222
223err: 223err:
224 BN_CTX_end(ctx); 224 BN_CTX_end(ctx);
225 if (new_ctx != NULL) 225 BN_CTX_free(new_ctx);
226 BN_CTX_free(new_ctx);
227 return ret; 226 return ret;
228} 227}
229 228
@@ -267,8 +266,7 @@ ec_GFp_simple_group_get_curve(const EC_GROUP * group, BIGNUM * p, BIGNUM * a, BI
267 ret = 1; 266 ret = 1;
268 267
269err: 268err:
270 if (new_ctx) 269 BN_CTX_free(new_ctx);
271 BN_CTX_free(new_ctx);
272 return ret; 270 return ret;
273} 271}
274 272
@@ -348,8 +346,7 @@ ec_GFp_simple_group_check_discriminant(const EC_GROUP * group, BN_CTX * ctx)
348err: 346err:
349 if (ctx != NULL) 347 if (ctx != NULL)
350 BN_CTX_end(ctx); 348 BN_CTX_end(ctx);
351 if (new_ctx != NULL) 349 BN_CTX_free(new_ctx);
352 BN_CTX_free(new_ctx);
353 return ret; 350 return ret;
354} 351}
355 352
@@ -457,8 +454,7 @@ ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP * group, EC_POINT *
457 ret = 1; 454 ret = 1;
458 455
459err: 456err:
460 if (new_ctx != NULL) 457 BN_CTX_free(new_ctx);
461 BN_CTX_free(new_ctx);
462 return ret; 458 return ret;
463} 459}
464 460
@@ -506,8 +502,7 @@ ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP * group, const EC_P
506 ret = 1; 502 ret = 1;
507 503
508err: 504err:
509 if (new_ctx != NULL) 505 BN_CTX_free(new_ctx);
510 BN_CTX_free(new_ctx);
511 return ret; 506 return ret;
512} 507}
513 508
@@ -626,8 +621,7 @@ ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP * group, const EC_POIN
626 621
627err: 622err:
628 BN_CTX_end(ctx); 623 BN_CTX_end(ctx);
629 if (new_ctx != NULL) 624 BN_CTX_free(new_ctx);
630 BN_CTX_free(new_ctx);
631 return ret; 625 return ret;
632} 626}
633 627
@@ -810,8 +804,7 @@ ec_GFp_simple_add(const EC_GROUP * group, EC_POINT * r, const EC_POINT * a, cons
810end: 804end:
811 if (ctx) /* otherwise we already called BN_CTX_end */ 805 if (ctx) /* otherwise we already called BN_CTX_end */
812 BN_CTX_end(ctx); 806 BN_CTX_end(ctx);
813 if (new_ctx != NULL) 807 BN_CTX_free(new_ctx);
814 BN_CTX_free(new_ctx);
815 return ret; 808 return ret;
816} 809}
817 810
@@ -951,8 +944,7 @@ ec_GFp_simple_dbl(const EC_GROUP * group, EC_POINT * r, const EC_POINT * a, BN_C
951 944
952err: 945err:
953 BN_CTX_end(ctx); 946 BN_CTX_end(ctx);
954 if (new_ctx != NULL) 947 BN_CTX_free(new_ctx);
955 BN_CTX_free(new_ctx);
956 return ret; 948 return ret;
957} 949}
958 950
@@ -1071,8 +1063,7 @@ ec_GFp_simple_is_on_curve(const EC_GROUP * group, const EC_POINT * point, BN_CTX
1071 1063
1072err: 1064err:
1073 BN_CTX_end(ctx); 1065 BN_CTX_end(ctx);
1074 if (new_ctx != NULL) 1066 BN_CTX_free(new_ctx);
1075 BN_CTX_free(new_ctx);
1076 return ret; 1067 return ret;
1077} 1068}
1078 1069
@@ -1172,8 +1163,7 @@ ec_GFp_simple_cmp(const EC_GROUP * group, const EC_POINT * a, const EC_POINT * b
1172 1163
1173end: 1164end:
1174 BN_CTX_end(ctx); 1165 BN_CTX_end(ctx);
1175 if (new_ctx != NULL) 1166 BN_CTX_free(new_ctx);
1176 BN_CTX_free(new_ctx);
1177 return ret; 1167 return ret;
1178} 1168}
1179 1169
@@ -1211,8 +1201,7 @@ ec_GFp_simple_make_affine(const EC_GROUP * group, EC_POINT * point, BN_CTX * ctx
1211 1201
1212err: 1202err:
1213 BN_CTX_end(ctx); 1203 BN_CTX_end(ctx);
1214 if (new_ctx != NULL) 1204 BN_CTX_free(new_ctx);
1215 BN_CTX_free(new_ctx);
1216 return ret; 1205 return ret;
1217} 1206}
1218 1207
@@ -1377,16 +1366,14 @@ ec_GFp_simple_points_make_affine(const EC_GROUP * group, size_t num, EC_POINT *
1377 1366
1378err: 1367err:
1379 BN_CTX_end(ctx); 1368 BN_CTX_end(ctx);
1380 if (new_ctx != NULL) 1369 BN_CTX_free(new_ctx);
1381 BN_CTX_free(new_ctx);
1382 if (heap != NULL) { 1370 if (heap != NULL) {
1383 /* 1371 /*
1384 * heap[pow2/2] .. heap[pow2-1] have not been allocated 1372 * heap[pow2/2] .. heap[pow2-1] have not been allocated
1385 * locally! 1373 * locally!
1386 */ 1374 */
1387 for (i = pow2 / 2 - 1; i > 0; i--) { 1375 for (i = pow2 / 2 - 1; i > 0; i--) {
1388 if (heap[i] != NULL) 1376 BN_clear_free(heap[i]);
1389 BN_clear_free(heap[i]);
1390 } 1377 }
1391 free(heap); 1378 free(heap);
1392 } 1379 }