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 ECNewPublicKeyTransform implements ECPairTransform { private ECPublicKeyParameters key; private SecureRandom random; @Override // org.bouncycastle.crypto.ec.ECPairTransform public ECPair transform(ECPair eCPair) { ECPublicKeyParameters eCPublicKeyParameters = this.key; if (eCPublicKeyParameters == null) { throw new IllegalStateException("ECNewPublicKeyTransform 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), this.key.getQ().multiply(generateK).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) { SecureRandom secureRandom; if (cipherParameters instanceof ParametersWithRandom) { ParametersWithRandom parametersWithRandom = (ParametersWithRandom) cipherParameters; if (!(parametersWithRandom.getParameters() instanceof ECPublicKeyParameters)) { throw new IllegalArgumentException("ECPublicKeyParameters are required for new public key transform."); } this.key = (ECPublicKeyParameters) parametersWithRandom.getParameters(); secureRandom = parametersWithRandom.getRandom(); } else { if (!(cipherParameters instanceof ECPublicKeyParameters)) { throw new IllegalArgumentException("ECPublicKeyParameters are required for new public key transform."); } this.key = (ECPublicKeyParameters) cipherParameters; secureRandom = new SecureRandom(); } this.random = secureRandom; } protected ECMultiplier createBasePointMultiplier() { return new FixedPointCombMultiplier(); } }