From 3a6a4a93518fbb3d96632bfdcb538d340f29c56b Mon Sep 17 00:00:00 2001 From: Billy Brumley Date: Wed, 20 Jan 2016 13:18:21 +0200 Subject: [PATCH] Fix BN_gcd errors for some curves MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Those even order that do not play nicely with Montgomery arithmetic Signed-off-by: Rich Salz Reviewed-by: Emilia Käsper --- crypto/ec/ec_lib.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crypto/ec/ec_lib.c b/crypto/ec/ec_lib.c index abb15a5076..a34113c953 100644 --- a/crypto/ec/ec_lib.c +++ b/crypto/ec/ec_lib.c @@ -327,13 +327,18 @@ int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, } else BN_zero(group->cofactor); + /* - * We ignore the return value because some groups have an order with + * Some groups have an order with * factors of two, which makes the Montgomery setup fail. * |group->mont_data| will be NULL in this case. */ - ec_precompute_mont_data(group); + if (BN_is_odd(group->order)) { + return ec_precompute_mont_data(group); + } + BN_MONT_CTX_free(group->mont_data); + group->mont_data = NULL; return 1; } -- 2.25.1