what-the-bank/sources/org/bouncycastle/crypto/ec/ECNewRandomnessTransform.java

64 lines
2.8 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.crypto.ec;
import java.math.BigInteger;
import java.security.SecureRandom;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
import org.bouncycastle.crypto.params.ParametersWithRandom;
import org.bouncycastle.math.ec.ECMultiplier;
import org.bouncycastle.math.ec.ECPoint;
import org.bouncycastle.math.ec.FixedPointCombMultiplier;
/* loaded from: classes6.dex */
public class ECNewRandomnessTransform implements ECPairFactorTransform {
private ECPublicKeyParameters key;
private BigInteger lastK;
private SecureRandom random;
@Override // org.bouncycastle.crypto.ec.ECPairTransform
public ECPair transform(ECPair eCPair) {
ECPublicKeyParameters eCPublicKeyParameters = this.key;
if (eCPublicKeyParameters == null) {
throw new IllegalStateException("ECNewRandomnessTransform not initialised");
}
ECDomainParameters parameters = eCPublicKeyParameters.getParameters();
BigInteger n = parameters.getN();
ECMultiplier createBasePointMultiplier = createBasePointMultiplier();
BigInteger generateK = ECUtil.generateK(n, this.random);
ECPoint[] eCPointArr = {createBasePointMultiplier.multiply(parameters.getG(), generateK).add(eCPair.getX()), this.key.getQ().multiply(generateK).add(eCPair.getY())};
parameters.getCurve().normalizeAll(eCPointArr);
this.lastK = generateK;
return new ECPair(eCPointArr[0], eCPointArr[1]);
}
@Override // org.bouncycastle.crypto.ec.ECPairTransform
public void init(CipherParameters cipherParameters) {
SecureRandom secureRandom;
if (cipherParameters instanceof ParametersWithRandom) {
ParametersWithRandom parametersWithRandom = (ParametersWithRandom) cipherParameters;
if (!(parametersWithRandom.getParameters() instanceof ECPublicKeyParameters)) {
throw new IllegalArgumentException("ECPublicKeyParameters are required for new randomness transform.");
}
this.key = (ECPublicKeyParameters) parametersWithRandom.getParameters();
secureRandom = parametersWithRandom.getRandom();
} else {
if (!(cipherParameters instanceof ECPublicKeyParameters)) {
throw new IllegalArgumentException("ECPublicKeyParameters are required for new randomness transform.");
}
this.key = (ECPublicKeyParameters) cipherParameters;
secureRandom = new SecureRandom();
}
this.random = secureRandom;
}
@Override // org.bouncycastle.crypto.ec.ECPairFactorTransform
public BigInteger getTransformValue() {
return this.lastK;
}
protected ECMultiplier createBasePointMultiplier() {
return new FixedPointCombMultiplier();
}
}