handle negative scalars correctly when doing point multiplication
[openssl.git] / crypto / ec / ec_mult.c
index ddd3db592154f0df8b235f21e453a665ed412afe..01574d8c93bc6286964b6ee806ceb475235aaf6e 100644 (file)
@@ -187,10 +187,18 @@ int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, BIGNUM *scalar,
                if (i < num)
                        {
                        if (!EC_POINT_copy(val_sub[i][0], points[i])) goto err;
+                       if (scalars[i]->neg)
+                               {
+                               if (!EC_POINT_invert(group, val_sub[i][0], ctx)) goto err;
+                               }
                        }
                else
                        {
                        if (!EC_POINT_copy(val_sub[i][0], generator)) goto err;
+                       if (scalar->neg)
+                               {
+                               if (!EC_POINT_invert(group, val_sub[i][0], ctx)) goto err;
+                               }
                        }
 
                if (wsize[i] > 1)