aboutsummaryrefslogtreecommitdiff
path: root/crypto/bn
diff options
context:
space:
mode:
authorDavid Benjamin <davidben@google.com>2016-06-24 11:05:48 -0400
committerKurt Roeckx <kurt@roeckx.be>2016-06-25 11:01:30 +0200
commit748e85308ef4f3e672975b3604ea2d76424fa404 (patch)
tree4aae2407243c51b4a4fb490f1d48b4a31e8c5ad9 /crypto/bn
parentf08c8c1a195a29652c956f43eb9e0d97f6094b6f (diff)
downloadopenssl-748e85308ef4f3e672975b3604ea2d76424fa404.zip
openssl-748e85308ef4f3e672975b3604ea2d76424fa404.tar.gz
openssl-748e85308ef4f3e672975b3604ea2d76424fa404.tar.bz2
Fix BN_is_prime* calls.
This function returns a tri-state -1 on error. See BoringSSL's 53409ee3d7595ed37da472bc73b010cd2c8a5ffd. Signed-off-by: Kurt Roeckx <kurt@roeckx.be> Reviewed-by: Rich Salz <rsalz@openssl.org> GH: #1251
Diffstat (limited to 'crypto/bn')
-rw-r--r--crypto/bn/bn_x931p.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/crypto/bn/bn_x931p.c b/crypto/bn/bn_x931p.c
index 83170d4..d863386 100644
--- a/crypto/bn/bn_x931p.c
+++ b/crypto/bn/bn_x931p.c
@@ -21,7 +21,7 @@
static int bn_x931_derive_pi(BIGNUM *pi, const BIGNUM *Xpi, BN_CTX *ctx,
BN_GENCB *cb)
{
- int i = 0;
+ int i = 0, is_prime;
if (!BN_copy(pi, Xpi))
return 0;
if (!BN_is_odd(pi) && !BN_add_word(pi, 1))
@@ -30,7 +30,10 @@ static int bn_x931_derive_pi(BIGNUM *pi, const BIGNUM *Xpi, BN_CTX *ctx,
i++;
BN_GENCB_call(cb, 0, i);
/* NB 27 MR is specified in X9.31 */
- if (BN_is_prime_fasttest_ex(pi, 27, ctx, 1, cb))
+ is_prime = BN_is_prime_fasttest_ex(pi, 27, ctx, 1, cb);
+ if (is_prime < 0)
+ return 0;
+ if (is_prime)
break;
if (!BN_add_word(pi, 2))
return 0;
@@ -119,14 +122,18 @@ int BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,
goto err;
if (!BN_gcd(t, pm1, e, ctx))
goto err;
- if (BN_is_one(t)
+ if (BN_is_one(t)) {
/*
* X9.31 specifies 8 MR and 1 Lucas test or any prime test
* offering similar or better guarantees 50 MR is considerably
* better.
*/
- && BN_is_prime_fasttest_ex(p, 50, ctx, 1, cb))
- break;
+ int r = BN_is_prime_fasttest_ex(p, 50, ctx, 1, cb);
+ if (r < 0)
+ goto err;
+ if (r)
+ break;
+ }
if (!BN_add(p, p, p1p2))
goto err;
}