01: package org.bouncycastle.math.ec;
02:
03: import java.math.BigInteger;
04:
05: class ReferenceMultiplier implements ECMultiplier {
06: /**
07: * Simple shift-and-add multiplication. Serves as reference implementation
08: * to verify (possibly faster) implementations in
09: * {@link org.bouncycastle.math.ec.ECPoint ECPoint}.
10: *
11: * @param p The point to multiply.
12: * @param k The factor by which to multiply.
13: * @return The result of the point multiplication <code>k * p</code>.
14: */
15: public ECPoint multiply(ECPoint p, BigInteger k,
16: PreCompInfo preCompInfo) {
17: ECPoint q = p.getCurve().getInfinity();
18: int t = k.bitLength();
19: for (int i = 0; i < t; i++) {
20: if (k.testBit(i)) {
21: q = q.add(p);
22: }
23: p = p.twice();
24: }
25: return q;
26: }
27: }
|