what-the-bank/sources/org/bouncycastle/crypto/generators/PKCS5S1ParametersGenerator....

62 lines
2.3 KiB
Java

package org.bouncycastle.crypto.generators;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.PBEParametersGenerator;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.params.ParametersWithIV;
/* loaded from: classes6.dex */
public class PKCS5S1ParametersGenerator extends PBEParametersGenerator {
private Digest digest;
@Override // org.bouncycastle.crypto.PBEParametersGenerator
public CipherParameters generateDerivedParameters(int i, int i2) {
int i3 = i / 8;
int i4 = i2 / 8;
int i5 = i3 + i4;
if (i5 <= this.digest.getDigestSize()) {
byte[] generateDerivedKey = generateDerivedKey();
return new ParametersWithIV(new KeyParameter(generateDerivedKey, 0, i3), generateDerivedKey, i3, i4);
}
StringBuilder sb = new StringBuilder("Can't generate a derived key ");
sb.append(i5);
sb.append(" bytes long.");
throw new IllegalArgumentException(sb.toString());
}
@Override // org.bouncycastle.crypto.PBEParametersGenerator
public CipherParameters generateDerivedParameters(int i) {
int i2 = i / 8;
if (i2 <= this.digest.getDigestSize()) {
return new KeyParameter(generateDerivedKey(), 0, i2);
}
StringBuilder sb = new StringBuilder("Can't generate a derived key ");
sb.append(i2);
sb.append(" bytes long.");
throw new IllegalArgumentException(sb.toString());
}
@Override // org.bouncycastle.crypto.PBEParametersGenerator
public CipherParameters generateDerivedMacParameters(int i) {
return generateDerivedParameters(i);
}
private byte[] generateDerivedKey() {
int digestSize = this.digest.getDigestSize();
byte[] bArr = new byte[digestSize];
this.digest.update(this.password, 0, this.password.length);
this.digest.update(this.salt, 0, this.salt.length);
this.digest.doFinal(bArr, 0);
for (int i = 1; i < this.iterationCount; i++) {
this.digest.update(bArr, 0, digestSize);
this.digest.doFinal(bArr, 0);
}
return bArr;
}
public PKCS5S1ParametersGenerator(Digest digest) {
this.digest = digest;
}
}