summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec/ec2_mult.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_mult.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_mult.c')
-rw-r--r--src/lib/libcrypto/ec/ec2_mult.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/lib/libcrypto/ec/ec2_mult.c b/src/lib/libcrypto/ec/ec2_mult.c
index dd113907be..8f0091efe1 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.6 2015/02/08 22:25:03 miod Exp $ */ 1/* $OpenBSD: ec2_mult.c,v 1.7 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 *
@@ -91,8 +91,7 @@ gf2m_Mdouble(const EC_GROUP *group, BIGNUM *x, BIGNUM *z, BN_CTX *ctx)
91 91
92 /* Since Mdouble is static we can guarantee that ctx != NULL. */ 92 /* Since Mdouble is static we can guarantee that ctx != NULL. */
93 BN_CTX_start(ctx); 93 BN_CTX_start(ctx);
94 t1 = BN_CTX_get(ctx); 94 if ((t1 = BN_CTX_get(ctx)) == NULL)
95 if (t1 == NULL)
96 goto err; 95 goto err;
97 96
98 if (!group->meth->field_sqr(group, x, x, ctx)) 97 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,
132 131
133 /* Since Madd is static we can guarantee that ctx != NULL. */ 132 /* Since Madd is static we can guarantee that ctx != NULL. */
134 BN_CTX_start(ctx); 133 BN_CTX_start(ctx);
135 t1 = BN_CTX_get(ctx); 134 if ((t1 = BN_CTX_get(ctx)) == NULL)
136 t2 = BN_CTX_get(ctx); 135 goto err;
137 if (t2 == NULL) 136 if ((t2 = BN_CTX_get(ctx)) == NULL)
138 goto err; 137 goto err;
139 138
140 if (!BN_copy(t1, x)) 139 if (!BN_copy(t1, x))
@@ -191,10 +190,11 @@ gf2m_Mxy(const EC_GROUP *group, const BIGNUM *x, const BIGNUM *y, BIGNUM *x1,
191 } 190 }
192 /* Since Mxy is static we can guarantee that ctx != NULL. */ 191 /* Since Mxy is static we can guarantee that ctx != NULL. */
193 BN_CTX_start(ctx); 192 BN_CTX_start(ctx);
194 t3 = BN_CTX_get(ctx); 193 if ((t3 = BN_CTX_get(ctx)) == NULL)
195 t4 = BN_CTX_get(ctx); 194 goto err;
196 t5 = BN_CTX_get(ctx); 195 if ((t4 = BN_CTX_get(ctx)) == NULL)
197 if (t5 == NULL) 196 goto err;
197 if ((t5 = BN_CTX_get(ctx)) == NULL)
198 goto err; 198 goto err;
199 199
200 if (!BN_one(t5)) 200 if (!BN_one(t5))
@@ -281,9 +281,9 @@ ec_GF2m_montgomery_point_multiply(const EC_GROUP *group, EC_POINT *r,
281 281
282 /* Since point_multiply is static we can guarantee that ctx != NULL. */ 282 /* Since point_multiply is static we can guarantee that ctx != NULL. */
283 BN_CTX_start(ctx); 283 BN_CTX_start(ctx);
284 x1 = BN_CTX_get(ctx); 284 if ((x1 = BN_CTX_get(ctx)) == NULL)
285 z1 = BN_CTX_get(ctx); 285 goto err;
286 if (z1 == NULL) 286 if ((z1 = BN_CTX_get(ctx)) == NULL)
287 goto err; 287 goto err;
288 288
289 x2 = &r->X; 289 x2 = &r->X;