aboutsummaryrefslogtreecommitdiffstats
path: root/libraries/spongycastle/core/src/main/java/org/spongycastle/math/ec/ReferenceMultiplier.java
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/spongycastle/core/src/main/java/org/spongycastle/math/ec/ReferenceMultiplier.java')
-rw-r--r--libraries/spongycastle/core/src/main/java/org/spongycastle/math/ec/ReferenceMultiplier.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/libraries/spongycastle/core/src/main/java/org/spongycastle/math/ec/ReferenceMultiplier.java b/libraries/spongycastle/core/src/main/java/org/spongycastle/math/ec/ReferenceMultiplier.java
new file mode 100644
index 000000000..6c03173f9
--- /dev/null
+++ b/libraries/spongycastle/core/src/main/java/org/spongycastle/math/ec/ReferenceMultiplier.java
@@ -0,0 +1,37 @@
+package org.spongycastle.math.ec;
+
+import java.math.BigInteger;
+
+public class ReferenceMultiplier extends AbstractECMultiplier
+{
+ /**
+ * Simple shift-and-add multiplication. Serves as reference implementation
+ * to verify (possibly faster) implementations in
+ * {@link org.spongycastle.math.ec.ECPoint ECPoint}.
+ *
+ * @param p The point to multiply.
+ * @param k The factor by which to multiply.
+ * @return The result of the point multiplication <code>k * p</code>.
+ */
+ protected ECPoint multiplyPositive(ECPoint p, BigInteger k)
+ {
+ ECPoint q = p.getCurve().getInfinity();
+ int t = k.bitLength();
+ if (t > 0)
+ {
+ if (k.testBit(0))
+ {
+ q = p;
+ }
+ for (int i = 1; i < t; i++)
+ {
+ p = p.twice();
+ if (k.testBit(i))
+ {
+ q = q.add(p);
+ }
+ }
+ }
+ return q;
+ }
+}