aboutsummaryrefslogtreecommitdiff
path: root/crypto/ec/ec2_mult.c
diff options
context:
space:
mode:
authorBodo Möller <bodo@openssl.org>2003-02-06 19:25:12 +0000
committerBodo Möller <bodo@openssl.org>2003-02-06 19:25:12 +0000
commit37c660ff9b22d6f0eb19a9881d3b663ca4f63449 (patch)
treeb4e2e8e2eb24d85d0a9859194f34b1e62ee9f396 /crypto/ec/ec2_mult.c
parent772ec4135c4c6f65c8cb6b3c7deb18f6e50dd6f9 (diff)
downloadopenssl-37c660ff9b22d6f0eb19a9881d3b663ca4f63449.zip
openssl-37c660ff9b22d6f0eb19a9881d3b663ca4f63449.tar.gz
openssl-37c660ff9b22d6f0eb19a9881d3b663ca4f63449.tar.bz2
implement fast point multiplication with precomputation
Submitted by: Nils Larsch Reviewed by: Bodo Moeller
Diffstat (limited to 'crypto/ec/ec2_mult.c')
-rw-r--r--crypto/ec/ec2_mult.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/crypto/ec/ec2_mult.c b/crypto/ec/ec2_mult.c
index eefb41a..a0effa9 100644
--- a/crypto/ec/ec2_mult.c
+++ b/crypto/ec/ec2_mult.c
@@ -14,7 +14,7 @@
*
*/
/* ====================================================================
- * 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
@@ -326,9 +326,10 @@ int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
}
/* 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;
@@ -364,12 +365,15 @@ int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
}
-/* 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);
+ }