/* crypto/ec/ec_cvt.c */
+/*
+ * Originally written by Bodo Moeller for the OpenSSL project.
+ */
/* ====================================================================
* Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
*
*
*/
+#include <openssl/err.h>
#include "ec_lcl.h"
{
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)
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;