PR: 2632
[openssl.git] / crypto / ec / ec2_mult.c
index ab631a50a22cbdcc94dc26610f61f9b57dfd5e08..f41665ac10bcbb8bc3065710506f7c97ed7a7854 100644 (file)
  *
  */
 
+#define OPENSSL_FIPSAPI
+
 #include <openssl/err.h>
 
 #include "ec_lcl.h"
 
+#ifndef OPENSSL_NO_EC2M
+
 
 /* Compute the x-coordinate x/z for the point 2*(x/z) in Montgomery projective 
  * coordinates.
@@ -319,6 +323,7 @@ int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
        int ret = 0;
        size_t i;
        EC_POINT *p=NULL;
+       EC_POINT *acc = NULL;
 
        if (ctx == NULL)
                {
@@ -338,15 +343,16 @@ int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
                }
 
        if ((p = EC_POINT_new(group)) == NULL) goto err;
+       if ((acc = EC_POINT_new(group)) == NULL) goto err;
 
-       if (!EC_POINT_set_to_infinity(group, r)) goto err;
+       if (!EC_POINT_set_to_infinity(group, acc)) goto err;
 
        if (scalar)
                {
                if (!ec_GF2m_montgomery_point_multiply(group, p, scalar, group->generator, ctx)) goto err;
-               if (BN_is_negative(scalar)) 
+               if (BN_is_negative(scalar))
                        if (!group->meth->invert(group, p, ctx)) goto err;
-               if (!group->meth->add(group, r, r, p, ctx)) goto err;
+               if (!group->meth->add(group, acc, acc, p, ctx)) goto err;
                }
 
        for (i = 0; i < num; i++)
@@ -354,13 +360,16 @@ int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
                if (!ec_GF2m_montgomery_point_multiply(group, p, scalars[i], points[i], ctx)) goto err;
                if (BN_is_negative(scalars[i]))
                        if (!group->meth->invert(group, p, ctx)) goto err;
-               if (!group->meth->add(group, r, r, p, ctx)) goto err;
+               if (!group->meth->add(group, acc, acc, p, ctx)) goto err;
                }
 
+       if (!EC_POINT_copy(r, acc)) goto err;
+
        ret = 1;
 
   err:
        if (p) EC_POINT_free(p);
+       if (acc) EC_POINT_free(acc);
        if (new_ctx != NULL)
                BN_CTX_free(new_ctx);
        return ret;
@@ -379,3 +388,5 @@ int ec_GF2m_have_precompute_mult(const EC_GROUP *group)
        {
        return ec_wNAF_have_precompute_mult(group);
        }
+
+#endif