summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-02-06 12:26:23 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-02-06 12:26:23 +0700
commitecb284b4b7decbc0313f1e9053360aa36cf2efc7 (patch)
treeb1812f1a16f9748bc08ca6c7854fb73bbdc42cfd /crypto/src
parentA few improvements to the fixed-point comb (diff)
downloadBouncyCastle.NET-ed25519-ecb284b4b7decbc0313f1e9053360aa36cf2efc7.tar.xz
Use fixed-point comb for multiplying by the base-point
Diffstat (limited to 'crypto/src')
-rw-r--r--crypto/src/crypto/signers/ECDsaSigner.cs24
1 files changed, 11 insertions, 13 deletions
diff --git a/crypto/src/crypto/signers/ECDsaSigner.cs b/crypto/src/crypto/signers/ECDsaSigner.cs
index 3b0b8ddf1..dc9c3dc87 100644
--- a/crypto/src/crypto/signers/ECDsaSigner.cs
+++ b/crypto/src/crypto/signers/ECDsaSigner.cs
@@ -1,6 +1,7 @@
 using System;
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Math.EC;
+using Org.BouncyCastle.Math.EC.Multiplier;
 using Org.BouncyCastle.Security;
 using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Crypto.Digests;
@@ -62,20 +63,21 @@ namespace Org.BouncyCastle.Crypto.Signers
          *
          * @param message the message that will be verified later.
          */
-        public BigInteger[] GenerateSignature(
-            byte[] message)
+        public BigInteger[] GenerateSignature(byte[] message)
         {
-            BigInteger n = key.Parameters.N;
+            ECDomainParameters ec = key.Parameters;
+            BigInteger n = ec.N;
             BigInteger e = calculateE(n, message);
+            BigInteger d = ((ECPrivateKeyParameters)key).D;
+
+            BigInteger r, s;
 
-            BigInteger r = null;
-            BigInteger s = null;
+            ECMultiplier basePointMultiplier = new FixedPointCombMultiplier();
 
             // 5.3.2
             do // Generate s
             {
-                BigInteger k = null;
-
+                BigInteger k;
                 do // Generate r
                 {
                     do
@@ -84,17 +86,13 @@ namespace Org.BouncyCastle.Crypto.Signers
                     }
                     while (k.SignValue == 0 || k.CompareTo(n) >= 0);
 
-                    ECPoint p = key.Parameters.G.Multiply(k).Normalize();
+                    ECPoint p = basePointMultiplier.Multiply(ec.G, k).Normalize();
 
                     // 5.3.3
-                    BigInteger x = p.AffineXCoord.ToBigInteger();
-
-                    r = x.Mod(n);
+                    r = p.AffineXCoord.ToBigInteger().Mod(n);
                 }
                 while (r.SignValue == 0);
 
-                BigInteger d = ((ECPrivateKeyParameters)key).D;
-
                 s = k.ModInverse(n).Multiply(e.Add(d.Multiply(r))).Mod(n);
             }
             while (s.SignValue == 0);