52 lines
2.0 KiB
Java
52 lines
2.0 KiB
Java
|
package org.bouncycastle.crypto.ec;
|
||
|
|
||
|
import java.math.BigInteger;
|
||
|
import org.bouncycastle.crypto.CipherParameters;
|
||
|
import org.bouncycastle.crypto.params.ECDomainParameters;
|
||
|
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
|
||
|
import org.bouncycastle.math.ec.ECMultiplier;
|
||
|
import org.bouncycastle.math.ec.ECPoint;
|
||
|
import org.bouncycastle.math.ec.FixedPointCombMultiplier;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class ECFixedTransform implements ECPairFactorTransform {
|
||
|
private BigInteger k;
|
||
|
private ECPublicKeyParameters key;
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.ec.ECPairTransform
|
||
|
public ECPair transform(ECPair eCPair) {
|
||
|
ECPublicKeyParameters eCPublicKeyParameters = this.key;
|
||
|
if (eCPublicKeyParameters == null) {
|
||
|
throw new IllegalStateException("ECFixedTransform not initialised");
|
||
|
}
|
||
|
ECDomainParameters parameters = eCPublicKeyParameters.getParameters();
|
||
|
BigInteger n = parameters.getN();
|
||
|
ECMultiplier createBasePointMultiplier = createBasePointMultiplier();
|
||
|
BigInteger mod = this.k.mod(n);
|
||
|
ECPoint[] eCPointArr = {createBasePointMultiplier.multiply(parameters.getG(), mod).add(eCPair.getX()), this.key.getQ().multiply(mod).add(eCPair.getY())};
|
||
|
parameters.getCurve().normalizeAll(eCPointArr);
|
||
|
return new ECPair(eCPointArr[0], eCPointArr[1]);
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.ec.ECPairTransform
|
||
|
public void init(CipherParameters cipherParameters) {
|
||
|
if (!(cipherParameters instanceof ECPublicKeyParameters)) {
|
||
|
throw new IllegalArgumentException("ECPublicKeyParameters are required for fixed transform.");
|
||
|
}
|
||
|
this.key = (ECPublicKeyParameters) cipherParameters;
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.ec.ECPairFactorTransform
|
||
|
public BigInteger getTransformValue() {
|
||
|
return this.k;
|
||
|
}
|
||
|
|
||
|
protected ECMultiplier createBasePointMultiplier() {
|
||
|
return new FixedPointCombMultiplier();
|
||
|
}
|
||
|
|
||
|
public ECFixedTransform(BigInteger bigInteger) {
|
||
|
this.k = bigInteger;
|
||
|
}
|
||
|
}
|