what-the-bank/sources/org/bouncycastle/jcajce/provider/symmetric/CAST5.java

177 lines
7.6 KiB
Java

package org.bouncycastle.jcajce.provider.symmetric;
import java.io.IOException;
import java.security.AlgorithmParameters;
import java.security.InvalidAlgorithmParameterException;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidParameterSpecException;
import javax.crypto.spec.IvParameterSpec;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.misc.CAST5CBCParameters;
import org.bouncycastle.asn1.misc.MiscObjectIdentifiers;
import org.bouncycastle.crypto.CipherKeyGenerator;
import org.bouncycastle.crypto.engines.CAST5Engine;
import org.bouncycastle.crypto.modes.CBCBlockCipher;
import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
import org.bouncycastle.jcajce.provider.symmetric.util.BaseAlgorithmParameterGenerator;
import org.bouncycastle.jcajce.provider.symmetric.util.BaseAlgorithmParameters;
import org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher;
import org.bouncycastle.jcajce.provider.symmetric.util.BaseKeyGenerator;
import org.bouncycastle.jcajce.provider.util.AlgorithmProvider;
/* loaded from: classes6.dex */
public final class CAST5 {
/* loaded from: classes6.dex */
public static class AlgParams extends BaseAlgorithmParameters {
private byte[] iv;
private int keyLength = 128;
@Override // org.bouncycastle.jcajce.provider.symmetric.util.BaseAlgorithmParameters
public AlgorithmParameterSpec localEngineGetParameterSpec(Class cls) throws InvalidParameterSpecException {
if (cls == IvParameterSpec.class) {
return new IvParameterSpec(this.iv);
}
throw new InvalidParameterSpecException("unknown parameter spec passed to CAST5 parameters object.");
}
@Override // java.security.AlgorithmParametersSpi
protected String engineToString() {
return "CAST5 Parameters";
}
@Override // java.security.AlgorithmParametersSpi
protected void engineInit(byte[] bArr, String str) throws IOException {
if (isASN1FormatString(str)) {
CAST5CBCParameters cAST5CBCParameters = CAST5CBCParameters.getInstance(new ASN1InputStream(bArr).readObject());
this.keyLength = cAST5CBCParameters.getKeyLength();
this.iv = cAST5CBCParameters.getIV();
} else {
if (!str.equals("RAW")) {
throw new IOException("Unknown parameters format in IV parameters object");
}
engineInit(bArr);
}
}
@Override // java.security.AlgorithmParametersSpi
protected void engineInit(byte[] bArr) throws IOException {
int length = bArr.length;
byte[] bArr2 = new byte[length];
this.iv = bArr2;
System.arraycopy(bArr, 0, bArr2, 0, length);
}
@Override // java.security.AlgorithmParametersSpi
protected void engineInit(AlgorithmParameterSpec algorithmParameterSpec) throws InvalidParameterSpecException {
if (!(algorithmParameterSpec instanceof IvParameterSpec)) {
throw new InvalidParameterSpecException("IvParameterSpec required to initialise a CAST5 parameters algorithm parameters object");
}
this.iv = ((IvParameterSpec) algorithmParameterSpec).getIV();
}
@Override // java.security.AlgorithmParametersSpi
protected byte[] engineGetEncoded(String str) throws IOException {
if (isASN1FormatString(str)) {
return new CAST5CBCParameters(engineGetEncoded(), this.keyLength).getEncoded();
}
if (str.equals("RAW")) {
return engineGetEncoded();
}
return null;
}
@Override // java.security.AlgorithmParametersSpi
protected byte[] engineGetEncoded() {
byte[] bArr = this.iv;
byte[] bArr2 = new byte[bArr.length];
System.arraycopy(bArr, 0, bArr2, 0, bArr.length);
return bArr2;
}
}
/* loaded from: classes6.dex */
public static class AlgParamGen extends BaseAlgorithmParameterGenerator {
@Override // java.security.AlgorithmParameterGeneratorSpi
protected void engineInit(AlgorithmParameterSpec algorithmParameterSpec, SecureRandom secureRandom) throws InvalidAlgorithmParameterException {
throw new InvalidAlgorithmParameterException("No supported AlgorithmParameterSpec for CAST5 parameter generation.");
}
@Override // java.security.AlgorithmParameterGeneratorSpi
protected AlgorithmParameters engineGenerateParameters() {
byte[] bArr = new byte[8];
if (this.random == null) {
this.random = new SecureRandom();
}
this.random.nextBytes(bArr);
try {
AlgorithmParameters createParametersInstance = createParametersInstance("CAST5");
createParametersInstance.init(new IvParameterSpec(bArr));
return createParametersInstance;
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
}
/* loaded from: classes6.dex */
public static class Mappings extends AlgorithmProvider {
private static final String PREFIX = CAST5.class.getName();
@Override // org.bouncycastle.jcajce.provider.util.AlgorithmProvider
public void configure(ConfigurableProvider configurableProvider) {
StringBuilder sb = new StringBuilder();
String str = PREFIX;
sb.append(str);
sb.append("$AlgParams");
configurableProvider.addAlgorithm("AlgorithmParameters.CAST5", sb.toString());
configurableProvider.addAlgorithm("Alg.Alias.AlgorithmParameters.1.2.840.113533.7.66.10", "CAST5");
StringBuilder sb2 = new StringBuilder();
sb2.append(str);
sb2.append("$AlgParamGen");
configurableProvider.addAlgorithm("AlgorithmParameterGenerator.CAST5", sb2.toString());
configurableProvider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator.1.2.840.113533.7.66.10", "CAST5");
StringBuilder sb3 = new StringBuilder();
sb3.append(str);
sb3.append("$ECB");
configurableProvider.addAlgorithm("Cipher.CAST5", sb3.toString());
ASN1ObjectIdentifier aSN1ObjectIdentifier = MiscObjectIdentifiers.cast5CBC;
StringBuilder sb4 = new StringBuilder();
sb4.append(str);
sb4.append("$CBC");
configurableProvider.addAlgorithm("Cipher", aSN1ObjectIdentifier, sb4.toString());
StringBuilder sb5 = new StringBuilder();
sb5.append(str);
sb5.append("$KeyGen");
configurableProvider.addAlgorithm("KeyGenerator.CAST5", sb5.toString());
configurableProvider.addAlgorithm("Alg.Alias.KeyGenerator", MiscObjectIdentifiers.cast5CBC, "CAST5");
}
}
/* loaded from: classes6.dex */
public static class CBC extends BaseBlockCipher {
public CBC() {
super(new CBCBlockCipher(new CAST5Engine()), 64);
}
}
/* loaded from: classes6.dex */
public static class ECB extends BaseBlockCipher {
public ECB() {
super(new CAST5Engine());
}
}
/* loaded from: classes6.dex */
public static class KeyGen extends BaseKeyGenerator {
public KeyGen() {
super("CAST5", 128, new CipherKeyGenerator());
}
}
private CAST5() {
}
}