*
*/
/* ====================================================================
- * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
+ * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
if (BN_is_zero(z1))
{
- if (!BN_zero(x2)) return 0;
- if (!BN_zero(z2)) return 0;
+ BN_zero(x2);
+ BN_zero(z2);
return 1;
}
if (r == point)
{
- ECerr(EC_F_EC_POINT_MUL, EC_R_INVALID_ARGUMENT);
+ ECerr(EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY, EC_R_INVALID_ARGUMENT);
return 0;
}
}
/* GF(2^m) field elements should always have BIGNUM::neg = 0 */
- BN_set_sign(&r->X, 0);
- BN_set_sign(&r->Y, 0);
+ BN_set_negative(&r->X, 0);
+ BN_set_negative(&r->Y, 0);
ret = 1;
size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
{
BN_CTX *new_ctx = NULL;
- int ret = 0, i;
+ int ret = 0;
+ size_t i;
EC_POINT *p=NULL;
if (ctx == NULL)
}
/* This implementation is more efficient than the wNAF implementation for 2
- * or fewer points. Use the ec_wNAF_mul implementation for 3 or more points.
+ * or fewer points. Use the ec_wNAF_mul implementation for 3 or more points,
+ * or if we can perform a fast multiplication based on precomputation.
*/
- if ((scalar && (num > 1)) || (num > 2))
+ if ((scalar && (num > 1)) || (num > 2) || (num == 0 && EC_GROUP_have_precompute_mult(group)))
{
ret = ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);
goto err;
if (scalar)
{
if (!ec_GF2m_montgomery_point_multiply(group, p, scalar, group->generator, ctx)) goto err;
- if (BN_get_sign(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;
}
for (i = 0; i < num; i++)
{
if (!ec_GF2m_montgomery_point_multiply(group, p, scalars[i], points[i], ctx)) goto err;
- if (BN_get_sign(scalars[i]))
+ 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;
}
}
-/* Precomputation for point multiplication. */
+/* Precomputation for point multiplication: fall back to wNAF methods
+ * because ec_GF2m_simple_mul() uses ec_wNAF_mul() if appropriate */
+
int ec_GF2m_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
{
- /* There is no precomputation to do for Montgomery scalar multiplication but
- * since this implementation falls back to the wNAF multiplication for more than
- * two points, call the wNAF implementation's precompute.
- */
return ec_wNAF_precompute_mult(group, ctx);
- }
+ }
+
+int ec_GF2m_have_precompute_mult(const EC_GROUP *group)
+ {
+ return ec_wNAF_have_precompute_mult(group);
+ }