summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec/ec2_smpl.c
diff options
context:
space:
mode:
authorjsing <>2015-02-09 15:49:22 +0000
committerjsing <>2015-02-09 15:49:22 +0000
commit16f790d01f7a6fc6c94e2a033a67b80c8ec5291c (patch)
treed924c624d5eb949a9e7e395dc99d92616e911ce9 /src/lib/libcrypto/ec/ec2_smpl.c
parent42f7780549de5b7b5e3e7943cfef87e0e41970fc (diff)
downloadopenbsd-16f790d01f7a6fc6c94e2a033a67b80c8ec5291c.tar.gz
openbsd-16f790d01f7a6fc6c94e2a033a67b80c8ec5291c.tar.bz2
openbsd-16f790d01f7a6fc6c94e2a033a67b80c8ec5291c.zip
BN_CTX_get() can fail - consistently check its return value.
There are currently cases where the return from each call is checked, the return from only the last call is checked and cases where it is not checked at all (including code in bn, ec and engine). Checking the last return value is valid as once the function fails it will continue to return NULL. However, in order to be consistent check each call with the same idiom. This makes it easy to verify. Note there are still a handful of cases that do not follow the idiom - these will be handled separately. ok beck@ doug@
Diffstat (limited to 'src/lib/libcrypto/ec/ec2_smpl.c')
-rw-r--r--src/lib/libcrypto/ec/ec2_smpl.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/src/lib/libcrypto/ec/ec2_smpl.c b/src/lib/libcrypto/ec/ec2_smpl.c
index b9c066c5c1..43f0afd5ae 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.13 2015/02/08 22:25:03 miod Exp $ */ 1/* $OpenBSD: ec2_smpl.c,v 1.14 2015/02/09 15:49:22 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -291,8 +291,7 @@ ec_GF2m_simple_group_check_discriminant(const EC_GROUP * group, BN_CTX * ctx)
291 } 291 }
292 } 292 }
293 BN_CTX_start(ctx); 293 BN_CTX_start(ctx);
294 b = BN_CTX_get(ctx); 294 if ((b = BN_CTX_get(ctx)) == NULL)
295 if (b == NULL)
296 goto err; 295 goto err;
297 296
298 if (!BN_GF2m_mod_arr(b, &group->b, group->poly)) 297 if (!BN_GF2m_mod_arr(b, &group->b, group->poly))
@@ -464,15 +463,21 @@ ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
464 return 0; 463 return 0;
465 } 464 }
466 BN_CTX_start(ctx); 465 BN_CTX_start(ctx);
467 x0 = BN_CTX_get(ctx); 466 if ((x0 = BN_CTX_get(ctx)) == NULL)
468 y0 = BN_CTX_get(ctx); 467 goto err;
469 x1 = BN_CTX_get(ctx); 468 if ((y0 = BN_CTX_get(ctx)) == NULL)
470 y1 = BN_CTX_get(ctx); 469 goto err;
471 x2 = BN_CTX_get(ctx); 470 if ((x1 = BN_CTX_get(ctx)) == NULL)
472 y2 = BN_CTX_get(ctx); 471 goto err;
473 s = BN_CTX_get(ctx); 472 if ((y1 = BN_CTX_get(ctx)) == NULL)
474 t = BN_CTX_get(ctx); 473 goto err;
475 if (t == NULL) 474 if ((x2 = BN_CTX_get(ctx)) == NULL)
475 goto err;
476 if ((y2 = BN_CTX_get(ctx)) == NULL)
477 goto err;
478 if ((s = BN_CTX_get(ctx)) == NULL)
479 goto err;
480 if ((t = BN_CTX_get(ctx)) == NULL)
476 goto err; 481 goto err;
477 482
478 if (a->Z_is_one) { 483 if (a->Z_is_one) {
@@ -611,9 +616,9 @@ ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX
611 return -1; 616 return -1;
612 } 617 }
613 BN_CTX_start(ctx); 618 BN_CTX_start(ctx);
614 y2 = BN_CTX_get(ctx); 619 if ((y2 = BN_CTX_get(ctx)) == NULL)
615 lh = BN_CTX_get(ctx); 620 goto err;
616 if (lh == NULL) 621 if ((lh = BN_CTX_get(ctx)) == NULL)
617 goto err; 622 goto err;
618 623
619 /* 624 /*
@@ -651,7 +656,8 @@ err:
651 * 1 not equal 656 * 1 not equal
652 */ 657 */
653int 658int
654ec_GF2m_simple_cmp(const EC_GROUP * group, const EC_POINT * a, const EC_POINT * b, BN_CTX * ctx) 659ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a,
660 const EC_POINT *b, BN_CTX *ctx)
655{ 661{
656 BIGNUM *aX, *aY, *bX, *bY; 662 BIGNUM *aX, *aY, *bX, *bY;
657 BN_CTX *new_ctx = NULL; 663 BN_CTX *new_ctx = NULL;
@@ -672,11 +678,13 @@ ec_GF2m_simple_cmp(const EC_GROUP * group, const EC_POINT * a, const EC_POINT *
672 return -1; 678 return -1;
673 } 679 }
674 BN_CTX_start(ctx); 680 BN_CTX_start(ctx);
675 aX = BN_CTX_get(ctx); 681 if ((aX = BN_CTX_get(ctx)) == NULL)
676 aY = BN_CTX_get(ctx); 682 goto err;
677 bX = BN_CTX_get(ctx); 683 if ((aY = BN_CTX_get(ctx)) == NULL)
678 bY = BN_CTX_get(ctx); 684 goto err;
679 if (bY == NULL) 685 if ((bX = BN_CTX_get(ctx)) == NULL)
686 goto err;
687 if ((bY = BN_CTX_get(ctx)) == NULL)
680 goto err; 688 goto err;
681 689
682 if (!EC_POINT_get_affine_coordinates_GF2m(group, a, aX, aY, ctx)) 690 if (!EC_POINT_get_affine_coordinates_GF2m(group, a, aX, aY, ctx))
@@ -710,9 +718,9 @@ ec_GF2m_simple_make_affine(const EC_GROUP * group, EC_POINT * point, BN_CTX * ct
710 return 0; 718 return 0;
711 } 719 }
712 BN_CTX_start(ctx); 720 BN_CTX_start(ctx);
713 x = BN_CTX_get(ctx); 721 if ((x = BN_CTX_get(ctx)) == NULL)
714 y = BN_CTX_get(ctx); 722 goto err;
715 if (y == NULL) 723 if ((y = BN_CTX_get(ctx)) == NULL)
716 goto err; 724 goto err;
717 725
718 if (!EC_POINT_get_affine_coordinates_GF2m(group, point, x, y, ctx)) 726 if (!EC_POINT_get_affine_coordinates_GF2m(group, point, x, y, ctx))