aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/ec/ec_cvt.c
diff options
context:
space:
mode:
authorBodo Möller <bodo@openssl.org>2002-10-28 13:23:24 +0000
committerBodo Möller <bodo@openssl.org>2002-10-28 13:23:24 +0000
commit5c6bf03117a26942327f43d02e9113e9870f7aba (patch)
tree69fe35ae1e549a9b68c2e6fbb0d209a19dc8856f /crypto/ec/ec_cvt.c
parentf72ed6153b2b54c2129354187a2f50193b68f0a1 (diff)
downloadopenssl-5c6bf03117a26942327f43d02e9113e9870f7aba.tar.gz
fast reduction for NIST curves
Submitted by: Nils Larsch
Diffstat (limited to 'crypto/ec/ec_cvt.c')
-rw-r--r--crypto/ec/ec_cvt.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/crypto/ec/ec_cvt.c b/crypto/ec/ec_cvt.c
index 22789a57e5..20782569a9 100644
--- a/crypto/ec/ec_cvt.c
+++ b/crypto/ec/ec_cvt.c
@@ -82,6 +82,7 @@
*
*/
+#include <openssl/err.h>
#include "ec_lcl.h"
@@ -89,11 +90,8 @@ EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM
{
const EC_METHOD *meth;
EC_GROUP *ret;
-
- /* Finally, this will use EC_GFp_nist_method if 'p' is a special
- * prime with optimized modular arithmetics (for NIST curves)
- */
- meth = EC_GFp_mont_method();
+
+ meth = EC_GFp_nist_method();
ret = EC_GROUP_new(meth);
if (ret == NULL)
@@ -101,8 +99,21 @@ EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM
if (!EC_GROUP_set_curve_GFp(ret, p, a, b, ctx))
{
+ /* remove the last error code form the error queue */
+ ERR_get_error();
+ /* try the normal mont method */
EC_GROUP_clear_free(ret);
- return NULL;
+ meth = EC_GFp_mont_method();
+
+ ret = EC_GROUP_new(meth);
+ if (ret == NULL)
+ return NULL;
+
+ if (!EC_GROUP_set_curve_GFp(ret, p, a, b, ctx))
+ {
+ EC_GROUP_clear_free(ret);
+ return NULL;
+ }
}
return ret;