diff options
author | bcook <> | 2016-03-12 21:44:11 +0000 |
---|---|---|
committer | bcook <> | 2016-03-12 21:44:11 +0000 |
commit | 84ad4abc945651758ccaec50eaeafff9ffe582ee (patch) | |
tree | c202c7ef43ff015fb66c468e4c977405d5d0cc88 /src | |
parent | d692c27f466b0683d4f7dd5f72058e64e04f0cd4 (diff) | |
download | openbsd-84ad4abc945651758ccaec50eaeafff9ffe582ee.tar.gz openbsd-84ad4abc945651758ccaec50eaeafff9ffe582ee.tar.bz2 openbsd-84ad4abc945651758ccaec50eaeafff9ffe582ee.zip |
Add error handling to the remaining calls to bn_wexpand().
Noticed by pascal-cuoq from Github:
https://github.com/libressl-portable/openbsd/issues/56
ok beck@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/bn/bn_gf2m.c | 11 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec2_mult.c | 28 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bn/bn_gf2m.c | 11 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/ec/ec2_mult.c | 28 |
4 files changed, 46 insertions, 32 deletions
diff --git a/src/lib/libcrypto/bn/bn_gf2m.c b/src/lib/libcrypto/bn/bn_gf2m.c index 40c1a94220..d83ae291ec 100644 --- a/src/lib/libcrypto/bn/bn_gf2m.c +++ b/src/lib/libcrypto/bn/bn_gf2m.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_gf2m.c,v 1.20 2015/06/11 15:55:28 jsing Exp $ */ | 1 | /* $OpenBSD: bn_gf2m.c,v 1.21 2016/03/12 21:44:11 bcook Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
4 | * | 4 | * |
@@ -702,18 +702,21 @@ BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) | |||
702 | top = p->top; | 702 | top = p->top; |
703 | BN_ULONG *udp, *bdp, *vdp, *cdp; | 703 | BN_ULONG *udp, *bdp, *vdp, *cdp; |
704 | 704 | ||
705 | bn_wexpand(u, top); | 705 | if (!bn_wexpand(u, top)) |
706 | goto err; | ||
706 | udp = u->d; | 707 | udp = u->d; |
707 | for (i = u->top; i < top; i++) | 708 | for (i = u->top; i < top; i++) |
708 | udp[i] = 0; | 709 | udp[i] = 0; |
709 | u->top = top; | 710 | u->top = top; |
710 | bn_wexpand(b, top); | 711 | if (!bn_wexpand(b, top)) |
712 | goto err; | ||
711 | bdp = b->d; | 713 | bdp = b->d; |
712 | bdp[0] = 1; | 714 | bdp[0] = 1; |
713 | for (i = 1; i < top; i++) | 715 | for (i = 1; i < top; i++) |
714 | bdp[i] = 0; | 716 | bdp[i] = 0; |
715 | b->top = top; | 717 | b->top = top; |
716 | bn_wexpand(c, top); | 718 | if (!bn_wexpand(c, top)) |
719 | goto err; | ||
717 | cdp = c->d; | 720 | cdp = c->d; |
718 | for (i = 0; i < top; i++) | 721 | for (i = 0; i < top; i++) |
719 | cdp[i] = 0; | 722 | cdp[i] = 0; |
diff --git a/src/lib/libcrypto/ec/ec2_mult.c b/src/lib/libcrypto/ec/ec2_mult.c index 8f0091efe1..3812611702 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.7 2015/02/09 15:49:22 jsing Exp $ */ | 1 | /* $OpenBSD: ec2_mult.c,v 1.8 2016/03/12 21:44:11 bcook Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
4 | * | 4 | * |
@@ -83,7 +83,7 @@ | |||
83 | * GF(2^m) without precomputation" (CHES '99, LNCS 1717). | 83 | * GF(2^m) without precomputation" (CHES '99, LNCS 1717). |
84 | * modified to not require precomputation of c=b^{2^{m-1}}. | 84 | * modified to not require precomputation of c=b^{2^{m-1}}. |
85 | */ | 85 | */ |
86 | static int | 86 | static int |
87 | gf2m_Mdouble(const EC_GROUP *group, BIGNUM *x, BIGNUM *z, BN_CTX *ctx) | 87 | gf2m_Mdouble(const EC_GROUP *group, BIGNUM *x, BIGNUM *z, BN_CTX *ctx) |
88 | { | 88 | { |
89 | BIGNUM *t1; | 89 | BIGNUM *t1; |
@@ -122,7 +122,7 @@ err: | |||
122 | * Lopez, J. and Dahab, R. "Fast multiplication on elliptic curves over | 122 | * Lopez, J. and Dahab, R. "Fast multiplication on elliptic curves over |
123 | * GF(2^m) without precomputation" (CHES '99, LNCS 1717). | 123 | * GF(2^m) without precomputation" (CHES '99, LNCS 1717). |
124 | */ | 124 | */ |
125 | static int | 125 | static int |
126 | gf2m_Madd(const EC_GROUP *group, const BIGNUM *x, BIGNUM *x1, BIGNUM *z1, | 126 | gf2m_Madd(const EC_GROUP *group, const BIGNUM *x, BIGNUM *x1, BIGNUM *z1, |
127 | const BIGNUM *x2, const BIGNUM *z2, BN_CTX *ctx) | 127 | const BIGNUM *x2, const BIGNUM *z2, BN_CTX *ctx) |
128 | { | 128 | { |
@@ -169,7 +169,7 @@ err: | |||
169 | * 1 if return value should be the point at infinity | 169 | * 1 if return value should be the point at infinity |
170 | * 2 otherwise | 170 | * 2 otherwise |
171 | */ | 171 | */ |
172 | static int | 172 | static int |
173 | gf2m_Mxy(const EC_GROUP *group, const BIGNUM *x, const BIGNUM *y, BIGNUM *x1, | 173 | gf2m_Mxy(const EC_GROUP *group, const BIGNUM *x, const BIGNUM *y, BIGNUM *x1, |
174 | BIGNUM *z1, BIGNUM *x2, BIGNUM *z2, BN_CTX *ctx) | 174 | BIGNUM *z1, BIGNUM *x2, BIGNUM *z2, BN_CTX *ctx) |
175 | { | 175 | { |
@@ -258,7 +258,7 @@ err: | |||
258 | * To protect against side-channel attack the function uses constant time swap, | 258 | * To protect against side-channel attack the function uses constant time swap, |
259 | * avoiding conditional branches. | 259 | * avoiding conditional branches. |
260 | */ | 260 | */ |
261 | static int | 261 | static int |
262 | ec_GF2m_montgomery_point_multiply(const EC_GROUP *group, EC_POINT *r, | 262 | ec_GF2m_montgomery_point_multiply(const EC_GROUP *group, EC_POINT *r, |
263 | const BIGNUM *scalar, const EC_POINT *point, BN_CTX *ctx) | 263 | const BIGNUM *scalar, const EC_POINT *point, BN_CTX *ctx) |
264 | { | 264 | { |
@@ -289,10 +289,14 @@ ec_GF2m_montgomery_point_multiply(const EC_GROUP *group, EC_POINT *r, | |||
289 | x2 = &r->X; | 289 | x2 = &r->X; |
290 | z2 = &r->Y; | 290 | z2 = &r->Y; |
291 | 291 | ||
292 | bn_wexpand(x1, group->field.top); | 292 | if (!bn_wexpand(x1, group->field.top)) |
293 | bn_wexpand(z1, group->field.top); | 293 | goto err; |
294 | bn_wexpand(x2, group->field.top); | 294 | if (!bn_wexpand(z1, group->field.top)) |
295 | bn_wexpand(z2, group->field.top); | 295 | goto err; |
296 | if (!bn_wexpand(x2, group->field.top)) | ||
297 | goto err; | ||
298 | if (!bn_wexpand(z2, group->field.top)) | ||
299 | goto err; | ||
296 | 300 | ||
297 | if (!BN_GF2m_mod_arr(x1, &point->X, group->poly)) | 301 | if (!BN_GF2m_mod_arr(x1, &point->X, group->poly)) |
298 | goto err; /* x1 = x */ | 302 | goto err; /* x1 = x */ |
@@ -362,7 +366,7 @@ err: | |||
362 | * scalar*group->generator + scalars[0]*points[0] + ... + scalars[num-1]*points[num-1] | 366 | * scalar*group->generator + scalars[0]*points[0] + ... + scalars[num-1]*points[num-1] |
363 | * gracefully ignoring NULL scalar values. | 367 | * gracefully ignoring NULL scalar values. |
364 | */ | 368 | */ |
365 | int | 369 | int |
366 | ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, | 370 | ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, |
367 | size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx) | 371 | size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx) |
368 | { | 372 | { |
@@ -431,13 +435,13 @@ err: | |||
431 | /* Precomputation for point multiplication: fall back to wNAF methods | 435 | /* Precomputation for point multiplication: fall back to wNAF methods |
432 | * because ec_GF2m_simple_mul() uses ec_wNAF_mul() if appropriate */ | 436 | * because ec_GF2m_simple_mul() uses ec_wNAF_mul() if appropriate */ |
433 | 437 | ||
434 | int | 438 | int |
435 | ec_GF2m_precompute_mult(EC_GROUP * group, BN_CTX * ctx) | 439 | ec_GF2m_precompute_mult(EC_GROUP * group, BN_CTX * ctx) |
436 | { | 440 | { |
437 | return ec_wNAF_precompute_mult(group, ctx); | 441 | return ec_wNAF_precompute_mult(group, ctx); |
438 | } | 442 | } |
439 | 443 | ||
440 | int | 444 | int |
441 | ec_GF2m_have_precompute_mult(const EC_GROUP * group) | 445 | ec_GF2m_have_precompute_mult(const EC_GROUP * group) |
442 | { | 446 | { |
443 | return ec_wNAF_have_precompute_mult(group); | 447 | return ec_wNAF_have_precompute_mult(group); |
diff --git a/src/lib/libssl/src/crypto/bn/bn_gf2m.c b/src/lib/libssl/src/crypto/bn/bn_gf2m.c index 40c1a94220..d83ae291ec 100644 --- a/src/lib/libssl/src/crypto/bn/bn_gf2m.c +++ b/src/lib/libssl/src/crypto/bn/bn_gf2m.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_gf2m.c,v 1.20 2015/06/11 15:55:28 jsing Exp $ */ | 1 | /* $OpenBSD: bn_gf2m.c,v 1.21 2016/03/12 21:44:11 bcook Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
4 | * | 4 | * |
@@ -702,18 +702,21 @@ BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) | |||
702 | top = p->top; | 702 | top = p->top; |
703 | BN_ULONG *udp, *bdp, *vdp, *cdp; | 703 | BN_ULONG *udp, *bdp, *vdp, *cdp; |
704 | 704 | ||
705 | bn_wexpand(u, top); | 705 | if (!bn_wexpand(u, top)) |
706 | goto err; | ||
706 | udp = u->d; | 707 | udp = u->d; |
707 | for (i = u->top; i < top; i++) | 708 | for (i = u->top; i < top; i++) |
708 | udp[i] = 0; | 709 | udp[i] = 0; |
709 | u->top = top; | 710 | u->top = top; |
710 | bn_wexpand(b, top); | 711 | if (!bn_wexpand(b, top)) |
712 | goto err; | ||
711 | bdp = b->d; | 713 | bdp = b->d; |
712 | bdp[0] = 1; | 714 | bdp[0] = 1; |
713 | for (i = 1; i < top; i++) | 715 | for (i = 1; i < top; i++) |
714 | bdp[i] = 0; | 716 | bdp[i] = 0; |
715 | b->top = top; | 717 | b->top = top; |
716 | bn_wexpand(c, top); | 718 | if (!bn_wexpand(c, top)) |
719 | goto err; | ||
717 | cdp = c->d; | 720 | cdp = c->d; |
718 | for (i = 0; i < top; i++) | 721 | for (i = 0; i < top; i++) |
719 | cdp[i] = 0; | 722 | cdp[i] = 0; |
diff --git a/src/lib/libssl/src/crypto/ec/ec2_mult.c b/src/lib/libssl/src/crypto/ec/ec2_mult.c index 8f0091efe1..3812611702 100644 --- a/src/lib/libssl/src/crypto/ec/ec2_mult.c +++ b/src/lib/libssl/src/crypto/ec/ec2_mult.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec2_mult.c,v 1.7 2015/02/09 15:49:22 jsing Exp $ */ | 1 | /* $OpenBSD: ec2_mult.c,v 1.8 2016/03/12 21:44:11 bcook Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
4 | * | 4 | * |
@@ -83,7 +83,7 @@ | |||
83 | * GF(2^m) without precomputation" (CHES '99, LNCS 1717). | 83 | * GF(2^m) without precomputation" (CHES '99, LNCS 1717). |
84 | * modified to not require precomputation of c=b^{2^{m-1}}. | 84 | * modified to not require precomputation of c=b^{2^{m-1}}. |
85 | */ | 85 | */ |
86 | static int | 86 | static int |
87 | gf2m_Mdouble(const EC_GROUP *group, BIGNUM *x, BIGNUM *z, BN_CTX *ctx) | 87 | gf2m_Mdouble(const EC_GROUP *group, BIGNUM *x, BIGNUM *z, BN_CTX *ctx) |
88 | { | 88 | { |
89 | BIGNUM *t1; | 89 | BIGNUM *t1; |
@@ -122,7 +122,7 @@ err: | |||
122 | * Lopez, J. and Dahab, R. "Fast multiplication on elliptic curves over | 122 | * Lopez, J. and Dahab, R. "Fast multiplication on elliptic curves over |
123 | * GF(2^m) without precomputation" (CHES '99, LNCS 1717). | 123 | * GF(2^m) without precomputation" (CHES '99, LNCS 1717). |
124 | */ | 124 | */ |
125 | static int | 125 | static int |
126 | gf2m_Madd(const EC_GROUP *group, const BIGNUM *x, BIGNUM *x1, BIGNUM *z1, | 126 | gf2m_Madd(const EC_GROUP *group, const BIGNUM *x, BIGNUM *x1, BIGNUM *z1, |
127 | const BIGNUM *x2, const BIGNUM *z2, BN_CTX *ctx) | 127 | const BIGNUM *x2, const BIGNUM *z2, BN_CTX *ctx) |
128 | { | 128 | { |
@@ -169,7 +169,7 @@ err: | |||
169 | * 1 if return value should be the point at infinity | 169 | * 1 if return value should be the point at infinity |
170 | * 2 otherwise | 170 | * 2 otherwise |
171 | */ | 171 | */ |
172 | static int | 172 | static int |
173 | gf2m_Mxy(const EC_GROUP *group, const BIGNUM *x, const BIGNUM *y, BIGNUM *x1, | 173 | gf2m_Mxy(const EC_GROUP *group, const BIGNUM *x, const BIGNUM *y, BIGNUM *x1, |
174 | BIGNUM *z1, BIGNUM *x2, BIGNUM *z2, BN_CTX *ctx) | 174 | BIGNUM *z1, BIGNUM *x2, BIGNUM *z2, BN_CTX *ctx) |
175 | { | 175 | { |
@@ -258,7 +258,7 @@ err: | |||
258 | * To protect against side-channel attack the function uses constant time swap, | 258 | * To protect against side-channel attack the function uses constant time swap, |
259 | * avoiding conditional branches. | 259 | * avoiding conditional branches. |
260 | */ | 260 | */ |
261 | static int | 261 | static int |
262 | ec_GF2m_montgomery_point_multiply(const EC_GROUP *group, EC_POINT *r, | 262 | ec_GF2m_montgomery_point_multiply(const EC_GROUP *group, EC_POINT *r, |
263 | const BIGNUM *scalar, const EC_POINT *point, BN_CTX *ctx) | 263 | const BIGNUM *scalar, const EC_POINT *point, BN_CTX *ctx) |
264 | { | 264 | { |
@@ -289,10 +289,14 @@ ec_GF2m_montgomery_point_multiply(const EC_GROUP *group, EC_POINT *r, | |||
289 | x2 = &r->X; | 289 | x2 = &r->X; |
290 | z2 = &r->Y; | 290 | z2 = &r->Y; |
291 | 291 | ||
292 | bn_wexpand(x1, group->field.top); | 292 | if (!bn_wexpand(x1, group->field.top)) |
293 | bn_wexpand(z1, group->field.top); | 293 | goto err; |
294 | bn_wexpand(x2, group->field.top); | 294 | if (!bn_wexpand(z1, group->field.top)) |
295 | bn_wexpand(z2, group->field.top); | 295 | goto err; |
296 | if (!bn_wexpand(x2, group->field.top)) | ||
297 | goto err; | ||
298 | if (!bn_wexpand(z2, group->field.top)) | ||
299 | goto err; | ||
296 | 300 | ||
297 | if (!BN_GF2m_mod_arr(x1, &point->X, group->poly)) | 301 | if (!BN_GF2m_mod_arr(x1, &point->X, group->poly)) |
298 | goto err; /* x1 = x */ | 302 | goto err; /* x1 = x */ |
@@ -362,7 +366,7 @@ err: | |||
362 | * scalar*group->generator + scalars[0]*points[0] + ... + scalars[num-1]*points[num-1] | 366 | * scalar*group->generator + scalars[0]*points[0] + ... + scalars[num-1]*points[num-1] |
363 | * gracefully ignoring NULL scalar values. | 367 | * gracefully ignoring NULL scalar values. |
364 | */ | 368 | */ |
365 | int | 369 | int |
366 | ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, | 370 | ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, |
367 | size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx) | 371 | size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx) |
368 | { | 372 | { |
@@ -431,13 +435,13 @@ err: | |||
431 | /* Precomputation for point multiplication: fall back to wNAF methods | 435 | /* Precomputation for point multiplication: fall back to wNAF methods |
432 | * because ec_GF2m_simple_mul() uses ec_wNAF_mul() if appropriate */ | 436 | * because ec_GF2m_simple_mul() uses ec_wNAF_mul() if appropriate */ |
433 | 437 | ||
434 | int | 438 | int |
435 | ec_GF2m_precompute_mult(EC_GROUP * group, BN_CTX * ctx) | 439 | ec_GF2m_precompute_mult(EC_GROUP * group, BN_CTX * ctx) |
436 | { | 440 | { |
437 | return ec_wNAF_precompute_mult(group, ctx); | 441 | return ec_wNAF_precompute_mult(group, ctx); |
438 | } | 442 | } |
439 | 443 | ||
440 | int | 444 | int |
441 | ec_GF2m_have_precompute_mult(const EC_GROUP * group) | 445 | ec_GF2m_have_precompute_mult(const EC_GROUP * group) |
442 | { | 446 | { |
443 | return ec_wNAF_have_precompute_mult(group); | 447 | return ec_wNAF_have_precompute_mult(group); |