summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2019-08-02 23:18:00 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2019-08-02 23:18:00 +0700
commit0bf12a6eecc228470839190c8519f8fee4c10656 (patch)
tree4e836bbbaec9828189484b7ec46f09bdfeed0ca5
parentHandle x400Address as sequence in GeneralName (diff)
downloadBouncyCastle.NET-ed25519-0bf12a6eecc228470839190c8519f8fee4c10656.tar.xz
Use fixed-point comb when multiplying basepoint
-rw-r--r--crypto/src/crypto/parameters/MqvPrivateParameters.cs9
-rw-r--r--crypto/src/crypto/parameters/SM2KeyExchangePrivateParameters.cs7
2 files changed, 11 insertions, 5 deletions
diff --git a/crypto/src/crypto/parameters/MqvPrivateParameters.cs b/crypto/src/crypto/parameters/MqvPrivateParameters.cs
index 9159cac12..37145715f 100644
--- a/crypto/src/crypto/parameters/MqvPrivateParameters.cs
+++ b/crypto/src/crypto/parameters/MqvPrivateParameters.cs
@@ -1,5 +1,8 @@
 using System;
 
+using Org.BouncyCastle.Math.EC;
+using Org.BouncyCastle.Math.EC.Multiplier;
+
 namespace Org.BouncyCastle.Crypto.Parameters
 {
 	public class MqvPrivateParameters
@@ -32,9 +35,9 @@ namespace Org.BouncyCastle.Crypto.Parameters
 
             if (ephemeralPublicKey == null)
             {
-                ephemeralPublicKey = new ECPublicKeyParameters(
-                    parameters.G.Multiply(ephemeralPrivateKey.D),
-                    parameters);
+                ECPoint q = new FixedPointCombMultiplier().Multiply(parameters.G, ephemeralPrivateKey.D);
+
+                ephemeralPublicKey = new ECPublicKeyParameters(q, parameters);
             }
             else if (!parameters.Equals(ephemeralPublicKey.Parameters))
             {
diff --git a/crypto/src/crypto/parameters/SM2KeyExchangePrivateParameters.cs b/crypto/src/crypto/parameters/SM2KeyExchangePrivateParameters.cs
index 8afb61544..666566426 100644
--- a/crypto/src/crypto/parameters/SM2KeyExchangePrivateParameters.cs
+++ b/crypto/src/crypto/parameters/SM2KeyExchangePrivateParameters.cs
@@ -1,6 +1,7 @@
 using System;
 
 using Org.BouncyCastle.Math.EC;
+using Org.BouncyCastle.Math.EC.Multiplier;
 
 namespace Org.BouncyCastle.Crypto.Parameters
 {
@@ -29,11 +30,13 @@ namespace Org.BouncyCastle.Crypto.Parameters
             if (!parameters.Equals(ephemeralPrivateKey.Parameters))
                 throw new ArgumentException("Static and ephemeral private keys have different domain parameters");
 
+            ECMultiplier m = new FixedPointCombMultiplier();
+
             this.mInitiator = initiator;
             this.mStaticPrivateKey = staticPrivateKey;
-            this.mStaticPublicPoint = parameters.G.Multiply(staticPrivateKey.D).Normalize();
+            this.mStaticPublicPoint = m.Multiply(parameters.G, staticPrivateKey.D).Normalize(); 
             this.mEphemeralPrivateKey = ephemeralPrivateKey;
-            this.mEphemeralPublicPoint = parameters.G.Multiply(ephemeralPrivateKey.D).Normalize();
+            this.mEphemeralPublicPoint = m.Multiply(parameters.G, ephemeralPrivateKey.D).Normalize();
         }
 
         public virtual bool IsInitiator