From 8cc1920fa27360f05f6cbda6f134a4501ca580dd Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Sun, 15 Dec 2013 14:55:43 -0800 Subject: [PATCH] ECKey: use sumOfTwoMultiples for better/faster key recovery. Thanks to Peter Dettman for the tip. Resolves issue 492. --- core/src/main/java/com/google/bitcoin/core/ECKey.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/core/ECKey.java b/core/src/main/java/com/google/bitcoin/core/ECKey.java index 84a326e8..03ace6b3 100644 --- a/core/src/main/java/com/google/bitcoin/core/ECKey.java +++ b/core/src/main/java/com/google/bitcoin/core/ECKey.java @@ -33,8 +33,8 @@ import org.spongycastle.crypto.AsymmetricCipherKeyPair; import org.spongycastle.crypto.generators.ECKeyPairGenerator; import org.spongycastle.crypto.params.*; import org.spongycastle.crypto.signers.ECDSASigner; +import org.spongycastle.math.ec.ECAlgorithms; import org.spongycastle.math.ec.ECCurve; -import org.spongycastle.math.ec.ECFieldElement; import org.spongycastle.math.ec.ECPoint; import org.spongycastle.util.encoders.Base64; @@ -748,9 +748,7 @@ public class ECKey implements Serializable { BigInteger rInv = sig.r.modInverse(n); BigInteger srInv = rInv.multiply(sig.s).mod(n); BigInteger eInvrInv = rInv.multiply(eInv).mod(n); - ECPoint p1 = CURVE.getG().multiply(eInvrInv); - ECPoint p2 = R.multiply(srInv); - ECPoint.Fp q = (ECPoint.Fp) p2.add(p1); + ECPoint.Fp q = (ECPoint.Fp) ECAlgorithms.sumOfTwoMultiplies(CURVE.getG(), eInvrInv, R, srInv); if (compressed) { // We have to manually recompress the point as the compressed-ness gets lost when multiply() is used. q = new ECPoint.Fp(curve, q.getX(), q.getY(), true);