diff options
| author | bcook <> | 2016-03-12 21:44:11 +0000 |
|---|---|---|
| committer | bcook <> | 2016-03-12 21:44:11 +0000 |
| commit | 0ff254bfb6289f6163d5eb805b19dd60ad3499cc (patch) | |
| tree | c202c7ef43ff015fb66c468e4c977405d5d0cc88 /src/lib/libcrypto/ec/ec2_mult.c | |
| parent | d7e23979f786be3c146be16ec4363c6da83c906e (diff) | |
| download | openbsd-0ff254bfb6289f6163d5eb805b19dd60ad3499cc.tar.gz openbsd-0ff254bfb6289f6163d5eb805b19dd60ad3499cc.tar.bz2 openbsd-0ff254bfb6289f6163d5eb805b19dd60ad3499cc.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/lib/libcrypto/ec/ec2_mult.c')
| -rw-r--r-- | src/lib/libcrypto/ec/ec2_mult.c | 28 |
1 files changed, 16 insertions, 12 deletions
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); |
