3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-07 14:54:15 +00:00

ECKey: use sumOfTwoMultiples for better/faster key recovery.

Thanks to Peter Dettman for the tip. Resolves issue 492.
This commit is contained in:
Mike Hearn 2013-12-15 14:55:43 -08:00
parent e9bf717409
commit 8cc1920fa2

View File

@ -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);