summaryrefslogtreecommitdiffstats
path: root/lib/libcrypto/ec/ec2_mult.c
diff options
context:
space:
mode:
authorjsing <jsing@openbsd.org>2015-02-09 15:49:22 +0000
committerjsing <jsing@openbsd.org>2015-02-09 15:49:22 +0000
commitaa389b8c4810b45e7b9b876db8debfbd5206e29e (patch)
treeaceaf6b9cc0050d33c77e910c34260780c91f772 /lib/libcrypto/ec/ec2_mult.c
parentExpand the IMPLEMENT_ASN1_FUNCTIONS macro so that the code is visible and (diff)
downloadwireguard-openbsd-aa389b8c4810b45e7b9b876db8debfbd5206e29e.tar.xz
wireguard-openbsd-aa389b8c4810b45e7b9b876db8debfbd5206e29e.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 'lib/libcrypto/ec/ec2_mult.c')
-rw-r--r--lib/libcrypto/ec/ec2_mult.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/lib/libcrypto/ec/ec2_mult.c b/lib/libcrypto/ec/ec2_mult.c
index dd113907be1..8f0091efe1c 100644
--- a/lib/libcrypto/ec/ec2_mult.c
+++ b/lib/libcrypto/ec/ec2_mult.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ec2_mult.c,v 1.6 2015/02/08 22:25:03 miod Exp $ */
+/* $OpenBSD: ec2_mult.c,v 1.7 2015/02/09 15:49:22 jsing Exp $ */
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
@@ -91,8 +91,7 @@ gf2m_Mdouble(const EC_GROUP *group, BIGNUM *x, BIGNUM *z, BN_CTX *ctx)
/* Since Mdouble is static we can guarantee that ctx != NULL. */
BN_CTX_start(ctx);
- t1 = BN_CTX_get(ctx);
- if (t1 == NULL)
+ if ((t1 = BN_CTX_get(ctx)) == NULL)
goto err;
if (!group->meth->field_sqr(group, x, x, ctx))
@@ -132,9 +131,9 @@ gf2m_Madd(const EC_GROUP *group, const BIGNUM *x, BIGNUM *x1, BIGNUM *z1,
/* Since Madd is static we can guarantee that ctx != NULL. */
BN_CTX_start(ctx);
- t1 = BN_CTX_get(ctx);
- t2 = BN_CTX_get(ctx);
- if (t2 == NULL)
+ if ((t1 = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((t2 = BN_CTX_get(ctx)) == NULL)
goto err;
if (!BN_copy(t1, x))
@@ -191,10 +190,11 @@ gf2m_Mxy(const EC_GROUP *group, const BIGNUM *x, const BIGNUM *y, BIGNUM *x1,
}
/* Since Mxy is static we can guarantee that ctx != NULL. */
BN_CTX_start(ctx);
- t3 = BN_CTX_get(ctx);
- t4 = BN_CTX_get(ctx);
- t5 = BN_CTX_get(ctx);
- if (t5 == NULL)
+ if ((t3 = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((t4 = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((t5 = BN_CTX_get(ctx)) == NULL)
goto err;
if (!BN_one(t5))
@@ -281,9 +281,9 @@ ec_GF2m_montgomery_point_multiply(const EC_GROUP *group, EC_POINT *r,
/* Since point_multiply is static we can guarantee that ctx != NULL. */
BN_CTX_start(ctx);
- x1 = BN_CTX_get(ctx);
- z1 = BN_CTX_get(ctx);
- if (z1 == NULL)
+ if ((x1 = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((z1 = BN_CTX_get(ctx)) == NULL)
goto err;
x2 = &r->X;