summary refs log tree commit diff
path: root/crypto/src/math/ec/multiplier/FpNafMultiplier.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/math/ec/multiplier/FpNafMultiplier.cs')
-rw-r--r--crypto/src/math/ec/multiplier/FpNafMultiplier.cs66
1 files changed, 34 insertions, 32 deletions
diff --git a/crypto/src/math/ec/multiplier/FpNafMultiplier.cs b/crypto/src/math/ec/multiplier/FpNafMultiplier.cs
index f5a98501a..3453e5600 100644
--- a/crypto/src/math/ec/multiplier/FpNafMultiplier.cs
+++ b/crypto/src/math/ec/multiplier/FpNafMultiplier.cs
@@ -1,39 +1,41 @@
 namespace Org.BouncyCastle.Math.EC.Multiplier
 {
-	/**
-	* Class implementing the NAF (Non-Adjacent Form) multiplication algorithm.
-	*/
-	internal class FpNafMultiplier
-		: ECMultiplier
-	{
-		/**
-		* D.3.2 pg 101
-		* @see org.bouncycastle.math.ec.multiplier.ECMultiplier#multiply(org.bouncycastle.math.ec.ECPoint, java.math.BigInteger)
-		*/
-		public ECPoint Multiply(ECPoint p, BigInteger k, PreCompInfo preCompInfo)
-		{
-			// TODO Probably should try to add this
-			// BigInteger e = k.Mod(n); // n == order of p
-			BigInteger e = k;
-			BigInteger h = e.Multiply(BigInteger.Three);
+    /**
+    * Class implementing the NAF (Non-Adjacent Form) multiplication algorithm.
+    */
+    internal class FpNafMultiplier
+        : ECMultiplier
+    {
+        /**
+        * D.3.2 pg 101
+        * @see org.bouncycastle.math.ec.multiplier.ECMultiplier#multiply(org.bouncycastle.math.ec.ECPoint, java.math.BigInteger)
+        */
+        public ECPoint Multiply(ECPoint p, BigInteger k, PreCompInfo preCompInfo)
+        {
+            // TODO Probably should try to add this
+            // BigInteger e = k.Mod(n); // n == order of p
+            BigInteger e = k;
+            BigInteger h = e.Multiply(BigInteger.Three);
 
-			ECPoint neg = p.Negate();
-			ECPoint R = p;
+            ECPoint neg = p.Negate();
+            ECPoint R = p;
 
-			for (int i = h.BitLength - 2; i > 0; --i)
-			{             
-				R = R.Twice();
+            for (int i = h.BitLength - 2; i > 0; --i)
+            {             
+                bool hBit = h.TestBit(i);
+                bool eBit = e.TestBit(i);
 
-				bool hBit = h.TestBit(i);
-				bool eBit = e.TestBit(i);
+                if (hBit == eBit)
+                {
+                    R = R.Twice();
+                }
+                else
+                {
+                    R = R.TwicePlus(hBit ? p : neg);
+                }
+            }
 
-				if (hBit != eBit)
-				{
-					R = R.Add(hBit ? p : neg);
-				}
-			}
-
-			return R;
-		}
-	}
+            return R;
+        }
+    }
 }