54 lines
2.2 KiB
Java
54 lines
2.2 KiB
Java
package org.bouncycastle.crypto.engines;
|
|
|
|
import java.math.BigInteger;
|
|
import org.bouncycastle.crypto.AsymmetricBlockCipher;
|
|
import org.bouncycastle.crypto.CipherParameters;
|
|
import org.bouncycastle.crypto.params.ParametersWithRandom;
|
|
import org.bouncycastle.crypto.params.RSABlindingParameters;
|
|
import org.bouncycastle.crypto.params.RSAKeyParameters;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class RSABlindingEngine implements AsymmetricBlockCipher {
|
|
private BigInteger blindingFactor;
|
|
private RSACoreEngine core = new RSACoreEngine();
|
|
private boolean forEncryption;
|
|
private RSAKeyParameters key;
|
|
|
|
@Override // org.bouncycastle.crypto.AsymmetricBlockCipher
|
|
public byte[] processBlock(byte[] bArr, int i, int i2) {
|
|
BigInteger convertInput = this.core.convertInput(bArr, i, i2);
|
|
return this.core.convertOutput(this.forEncryption ? blindMessage(convertInput) : unblindMessage(convertInput));
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.AsymmetricBlockCipher
|
|
public void init(boolean z, CipherParameters cipherParameters) {
|
|
if (cipherParameters instanceof ParametersWithRandom) {
|
|
cipherParameters = ((ParametersWithRandom) cipherParameters).getParameters();
|
|
}
|
|
RSABlindingParameters rSABlindingParameters = (RSABlindingParameters) cipherParameters;
|
|
this.core.init(z, rSABlindingParameters.getPublicKey());
|
|
this.forEncryption = z;
|
|
this.key = rSABlindingParameters.getPublicKey();
|
|
this.blindingFactor = rSABlindingParameters.getBlindingFactor();
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.AsymmetricBlockCipher
|
|
public int getOutputBlockSize() {
|
|
return this.core.getOutputBlockSize();
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.AsymmetricBlockCipher
|
|
public int getInputBlockSize() {
|
|
return this.core.getInputBlockSize();
|
|
}
|
|
|
|
private BigInteger unblindMessage(BigInteger bigInteger) {
|
|
BigInteger modulus = this.key.getModulus();
|
|
return bigInteger.multiply(this.blindingFactor.modInverse(modulus)).mod(modulus);
|
|
}
|
|
|
|
private BigInteger blindMessage(BigInteger bigInteger) {
|
|
return bigInteger.multiply(this.blindingFactor.modPow(this.key.getExponent(), this.key.getModulus())).mod(this.key.getModulus());
|
|
}
|
|
}
|