summary refs log tree commit diff
path: root/crypto/src/math/ec/multiplier/ReferenceMultiplier.cs
blob: cdccffc2d55aa197cc5db53b6a0b7ee65f83baf0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
namespace Org.BouncyCastle.Math.EC.Multiplier
{
	internal class ReferenceMultiplier
		: ECMultiplier
	{
		/**
		* Simple shift-and-add multiplication. Serves as reference implementation
		* to verify (possibly faster) implementations in
		* {@link org.bouncycastle.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>.
		*/
		public ECPoint Multiply(ECPoint p, BigInteger k, PreCompInfo preCompInfo)
		{
			ECPoint q = p.Curve.Infinity;
			int t = k.BitLength;
			for (int i = 0; i < t; i++)
			{
				if (k.TestBit(i))
				{
					q = q.Add(p);
				}
				p = p.Twice();
			}
			return q;
		}
	}
}