summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec/ec2_oct.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_oct.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_oct.c')
-rw-r--r--src/lib/libcrypto/ec/ec2_oct.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/lib/libcrypto/ec/ec2_oct.c b/src/lib/libcrypto/ec/ec2_oct.c
index c45d9c2219..72690b1bc7 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.6 2015/02/08 22:25:03 miod Exp $ */ 1/* $OpenBSD: ec2_oct.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 *
@@ -109,11 +109,13 @@ ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point
109 y_bit = (y_bit != 0) ? 1 : 0; 109 y_bit = (y_bit != 0) ? 1 : 0;
110 110
111 BN_CTX_start(ctx); 111 BN_CTX_start(ctx);
112 tmp = BN_CTX_get(ctx); 112 if ((tmp = BN_CTX_get(ctx)) == NULL)
113 x = BN_CTX_get(ctx); 113 goto err;
114 y = BN_CTX_get(ctx); 114 if ((x = BN_CTX_get(ctx)) == NULL)
115 z = BN_CTX_get(ctx); 115 goto err;
116 if (z == NULL) 116 if ((y = BN_CTX_get(ctx)) == NULL)
117 goto err;
118 if ((z = BN_CTX_get(ctx)) == NULL)
117 goto err; 119 goto err;
118 120
119 if (!BN_GF2m_mod_arr(x, x_, group->poly)) 121 if (!BN_GF2m_mod_arr(x, x_, group->poly))
@@ -212,10 +214,11 @@ ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point,
212 } 214 }
213 BN_CTX_start(ctx); 215 BN_CTX_start(ctx);
214 used_ctx = 1; 216 used_ctx = 1;
215 x = BN_CTX_get(ctx); 217 if ((x = BN_CTX_get(ctx)) == NULL)
216 y = BN_CTX_get(ctx); 218 goto err;
217 yxi = BN_CTX_get(ctx); 219 if ((y = BN_CTX_get(ctx)) == NULL)
218 if (yxi == NULL) 220 goto err;
221 if ((yxi = BN_CTX_get(ctx)) == NULL)
219 goto err; 222 goto err;
220 223
221 if (!EC_POINT_get_affine_coordinates_GF2m(group, point, x, y, ctx)) 224 if (!EC_POINT_get_affine_coordinates_GF2m(group, point, x, y, ctx))
@@ -329,10 +332,11 @@ ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
329 return 0; 332 return 0;
330 } 333 }
331 BN_CTX_start(ctx); 334 BN_CTX_start(ctx);
332 x = BN_CTX_get(ctx); 335 if ((x = BN_CTX_get(ctx)) == NULL)
333 y = BN_CTX_get(ctx); 336 goto err;
334 yxi = BN_CTX_get(ctx); 337 if ((y = BN_CTX_get(ctx)) == NULL)
335 if (yxi == NULL) 338 goto err;
339 if ((yxi = BN_CTX_get(ctx)) == NULL)
336 goto err; 340 goto err;
337 341
338 if (!BN_bin2bn(buf + 1, field_len, x)) 342 if (!BN_bin2bn(buf + 1, field_len, x))