package org.bouncycastle.crypto.generators; import org.bouncycastle.crypto.CipherParameters; import org.bouncycastle.crypto.Digest; import org.bouncycastle.crypto.PBEParametersGenerator; import org.bouncycastle.crypto.digests.MD5Digest; import org.bouncycastle.crypto.params.KeyParameter; import org.bouncycastle.crypto.params.ParametersWithIV; /* loaded from: classes6.dex */ public class OpenSSLPBEParametersGenerator extends PBEParametersGenerator { private Digest digest = new MD5Digest(); public void init(byte[] bArr, byte[] bArr2) { super.init(bArr, bArr2, 1); } @Override // org.bouncycastle.crypto.PBEParametersGenerator public CipherParameters generateDerivedParameters(int i, int i2) { int i3 = i / 8; int i4 = i2 / 8; byte[] generateDerivedKey = generateDerivedKey(i3 + i4); return new ParametersWithIV(new KeyParameter(generateDerivedKey, 0, i3), generateDerivedKey, i3, i4); } @Override // org.bouncycastle.crypto.PBEParametersGenerator public CipherParameters generateDerivedParameters(int i) { int i2 = i / 8; return new KeyParameter(generateDerivedKey(i2), 0, i2); } @Override // org.bouncycastle.crypto.PBEParametersGenerator public CipherParameters generateDerivedMacParameters(int i) { return generateDerivedParameters(i); } private byte[] generateDerivedKey(int i) { int digestSize = this.digest.getDigestSize(); byte[] bArr = new byte[digestSize]; byte[] bArr2 = new byte[i]; int i2 = 0; while (true) { this.digest.update(this.password, 0, this.password.length); this.digest.update(this.salt, 0, this.salt.length); this.digest.doFinal(bArr, 0); int i3 = i > digestSize ? digestSize : i; System.arraycopy(bArr, 0, bArr2, i2, i3); i2 += i3; i -= i3; if (i == 0) { return bArr2; } this.digest.reset(); this.digest.update(bArr, 0, digestSize); } } }