diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-02-06 13:30:44 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-02-06 13:30:44 +0700 |
commit | f7c5174803bfb4de7fb12e795ede8ef07f563461 (patch) | |
tree | c7abf61a09b4ee195aa20c2b9bb99822184313a5 /crypto | |
parent | Fix incomplete port (diff) | |
download | BouncyCastle.NET-ed25519-f7c5174803bfb4de7fb12e795ede8ef07f563461.tar.xz |
Use FixedPointCombMultiplier for most base-point multiplications
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/src/crypto/generators/ECKeyPairGenerator.cs | 9 | ||||
-rw-r--r-- | crypto/src/crypto/signers/ECGOST3410Signer.cs | 22 |
2 files changed, 16 insertions, 15 deletions
diff --git a/crypto/src/crypto/generators/ECKeyPairGenerator.cs b/crypto/src/crypto/generators/ECKeyPairGenerator.cs index d1387a55c..49afb16dc 100644 --- a/crypto/src/crypto/generators/ECKeyPairGenerator.cs +++ b/crypto/src/crypto/generators/ECKeyPairGenerator.cs @@ -10,6 +10,7 @@ using Org.BouncyCastle.Crypto.EC; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Math; using Org.BouncyCastle.Math.EC; +using Org.BouncyCastle.Math.EC.Multiplier; using Org.BouncyCastle.Security; using Org.BouncyCastle.Utilities; @@ -104,7 +105,7 @@ namespace Org.BouncyCastle.Crypto.Generators } while (d.SignValue == 0 || (d.CompareTo(n) >= 0)); - ECPoint q = parameters.G.Multiply(d); + ECPoint q = new FixedPointCombMultiplier().Multiply(parameters.G, d); if (publicKeyParamSet != null) { @@ -133,15 +134,15 @@ namespace Org.BouncyCastle.Crypto.Generators internal static ECPublicKeyParameters GetCorrespondingPublicKey( ECPrivateKeyParameters privKey) { - ECDomainParameters parameters = privKey.Parameters; - ECPoint q = parameters.G.Multiply(privKey.D); + ECDomainParameters ec = privKey.Parameters; + ECPoint q = new FixedPointCombMultiplier().Multiply(ec.G, privKey.D); if (privKey.PublicKeyParamSet != null) { return new ECPublicKeyParameters(privKey.AlgorithmName, q, privKey.PublicKeyParamSet); } - return new ECPublicKeyParameters(privKey.AlgorithmName, q, parameters); + return new ECPublicKeyParameters(privKey.AlgorithmName, q, ec); } } } diff --git a/crypto/src/crypto/signers/ECGOST3410Signer.cs b/crypto/src/crypto/signers/ECGOST3410Signer.cs index 3d71ace04..872336d87 100644 --- a/crypto/src/crypto/signers/ECGOST3410Signer.cs +++ b/crypto/src/crypto/signers/ECGOST3410Signer.cs @@ -4,6 +4,7 @@ using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Math; using Org.BouncyCastle.Math.EC; +using Org.BouncyCastle.Math.EC.Multiplier; using Org.BouncyCastle.Security; namespace Org.BouncyCastle.Crypto.Signers @@ -71,15 +72,18 @@ namespace Org.BouncyCastle.Crypto.Signers } BigInteger e = new BigInteger(1, mRev); - BigInteger n = key.Parameters.N; - BigInteger r = null; - BigInteger s = null; + ECDomainParameters ec = key.Parameters; + BigInteger n = ec.N; + BigInteger d = ((ECPrivateKeyParameters)key).D; + + BigInteger r, s = null; + + ECMultiplier basePointMultiplier = new FixedPointCombMultiplier(); do // generate s { - BigInteger k = null; - + BigInteger k; do // generate r { do @@ -88,16 +92,12 @@ namespace Org.BouncyCastle.Crypto.Signers } while (k.SignValue == 0); - ECPoint p = key.Parameters.G.Multiply(k).Normalize(); - - BigInteger x = p.AffineXCoord.ToBigInteger(); + ECPoint p = basePointMultiplier.Multiply(ec.G, k).Normalize(); - r = x.Mod(n); + r = p.AffineXCoord.ToBigInteger().Mod(n); } while (r.SignValue == 0); - BigInteger d = ((ECPrivateKeyParameters)key).D; - s = (k.Multiply(e)).Add(d.Multiply(r)).Mod(n); } while (s.SignValue == 0); |