summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-03-12 18:12:38 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-03-12 18:12:38 +0700
commitb36d98adc758556d73b7baa69846e8c369378f27 (patch)
treec029bb1f359b6af537ecf4b1d316fd20ce7ab223 /crypto/src
parentWeight the performance test more towards random points (diff)
downloadBouncyCastle.NET-ed25519-b36d98adc758556d73b7baa69846e8c369378f27.tar.xz
Allow subclasses to override the ECMultiplier used for base-point multiplication
Diffstat (limited to 'crypto/src')
-rw-r--r--crypto/src/crypto/generators/ECKeyPairGenerator.cs7
-rw-r--r--crypto/src/crypto/signers/ECDsaSigner.cs15
-rw-r--r--crypto/src/crypto/signers/ECGOST3410Signer.cs7
3 files changed, 21 insertions, 8 deletions
diff --git a/crypto/src/crypto/generators/ECKeyPairGenerator.cs b/crypto/src/crypto/generators/ECKeyPairGenerator.cs
index 49afb16dc..301349a9b 100644
--- a/crypto/src/crypto/generators/ECKeyPairGenerator.cs
+++ b/crypto/src/crypto/generators/ECKeyPairGenerator.cs
@@ -105,7 +105,7 @@ namespace Org.BouncyCastle.Crypto.Generators
             }
             while (d.SignValue == 0 || (d.CompareTo(n) >= 0));
 
-            ECPoint q = new FixedPointCombMultiplier().Multiply(parameters.G, d);
+            ECPoint q = CreateBasePointMultiplier().Multiply(parameters.G, d);
 
             if (publicKeyParamSet != null)
             {
@@ -119,6 +119,11 @@ namespace Org.BouncyCastle.Crypto.Generators
                 new ECPrivateKeyParameters(algorithm, d, parameters));
         }
 
+        protected virtual ECMultiplier CreateBasePointMultiplier()
+        {
+            return new FixedPointCombMultiplier();
+        }
+
         internal static X9ECParameters FindECCurveByOid(DerObjectIdentifier oid)
         {
             // TODO ECGost3410NamedCurves support (returns ECDomainParameters though)
diff --git a/crypto/src/crypto/signers/ECDsaSigner.cs b/crypto/src/crypto/signers/ECDsaSigner.cs
index dc9c3dc87..508335149 100644
--- a/crypto/src/crypto/signers/ECDsaSigner.cs
+++ b/crypto/src/crypto/signers/ECDsaSigner.cs
@@ -67,12 +67,12 @@ namespace Org.BouncyCastle.Crypto.Signers
         {
             ECDomainParameters ec = key.Parameters;
             BigInteger n = ec.N;
-            BigInteger e = calculateE(n, message);
+            BigInteger e = CalculateE(n, message);
             BigInteger d = ((ECPrivateKeyParameters)key).D;
 
             BigInteger r, s;
 
-            ECMultiplier basePointMultiplier = new FixedPointCombMultiplier();
+            ECMultiplier basePointMultiplier = CreateBasePointMultiplier();
 
             // 5.3.2
             do // Generate s
@@ -120,7 +120,7 @@ namespace Org.BouncyCastle.Crypto.Signers
                 return false;
             }
 
-            BigInteger e = calculateE(n, message);
+            BigInteger e = CalculateE(n, message);
             BigInteger c = s.ModInverse(n);
 
             BigInteger u1 = e.Multiply(c).Mod(n);
@@ -139,9 +139,7 @@ namespace Org.BouncyCastle.Crypto.Signers
             return v.Equals(r);
         }
 
-        private BigInteger calculateE(
-            BigInteger	n,
-            byte[]		message)
+        protected virtual BigInteger CalculateE(BigInteger n, byte[] message)
         {
             int messageBitLength = message.Length * 8;
             BigInteger trunc = new BigInteger(1, message);
@@ -153,5 +151,10 @@ namespace Org.BouncyCastle.Crypto.Signers
 
             return trunc;
         }
+
+        protected virtual ECMultiplier CreateBasePointMultiplier()
+        {
+            return new FixedPointCombMultiplier();
+        }
     }
 }
diff --git a/crypto/src/crypto/signers/ECGOST3410Signer.cs b/crypto/src/crypto/signers/ECGOST3410Signer.cs
index 872336d87..6027aa9b9 100644
--- a/crypto/src/crypto/signers/ECGOST3410Signer.cs
+++ b/crypto/src/crypto/signers/ECGOST3410Signer.cs
@@ -79,7 +79,7 @@ namespace Org.BouncyCastle.Crypto.Signers
 
             BigInteger r, s = null;
 
-            ECMultiplier basePointMultiplier = new FixedPointCombMultiplier();
+            ECMultiplier basePointMultiplier = CreateBasePointMultiplier();
 
             do // generate s
             {
@@ -153,5 +153,10 @@ namespace Org.BouncyCastle.Crypto.Signers
 
             return R.Equals(r);
         }
+
+        protected virtual ECMultiplier CreateBasePointMultiplier()
+        {
+            return new FixedPointCombMultiplier();
+        }
     }
 }