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

386 lines
22 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 javax.crypto.spec.RC2ParameterSpec;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.RC2CBCParameter;
import org.bouncycastle.crypto.CipherKeyGenerator;
import org.bouncycastle.crypto.engines.RC2Engine;
import org.bouncycastle.crypto.engines.RC2WrapEngine;
import org.bouncycastle.crypto.macs.CBCBlockCipherMac;
import org.bouncycastle.crypto.macs.CFBBlockCipherMac;
import org.bouncycastle.crypto.modes.CBCBlockCipher;
import org.bouncycastle.crypto.tls.AlertDescription;
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.symmetric.util.BaseMac;
import org.bouncycastle.jcajce.provider.symmetric.util.BaseWrapCipher;
import org.bouncycastle.jcajce.provider.symmetric.util.PBESecretKeyFactory;
import org.bouncycastle.jcajce.provider.util.AlgorithmProvider;
import org.bouncycastle.util.Arrays;
/* loaded from: classes6.dex */
public final class RC2 {
/* loaded from: classes6.dex */
public static class AlgParams extends BaseAlgorithmParameters {
private byte[] iv;
private int parameterVersion = 58;
private static final short[] table = {189, 86, 234, 242, 162, 241, 172, 42, 176, 147, 209, 156, 27, 51, 253, 208, 48, 4, 182, 220, 125, 223, 50, 75, 247, 203, 69, 155, 49, 187, 33, 90, 65, 159, 225, 217, 74, 77, 158, 218, 160, 104, 44, 195, 39, 95, 128, 54, 62, 238, 251, 149, 26, 254, 206, 168, 52, 169, 19, 240, 166, 63, 216, 12, 120, 36, 175, 35, 82, 193, 103, 23, 245, 102, 144, 231, 232, 7, 184, 96, 72, 230, 30, 83, 243, 146, 164, AlertDescription.bad_certificate_hash_value, 140, 8, 21, AlertDescription.unsupported_extension, 134, 0, 132, 250, 244, 127, 138, 66, 25, 246, 219, 205, 20, 141, 80, 18, 186, 60, 6, 78, 236, 179, 53, 17, 161, 136, 142, 43, 148, 153, 183, AlertDescription.bad_certificate_status_response, 116, 211, 228, 191, 58, 222, 150, 14, 188, 10, 237, 119, 252, 55, 107, 3, 121, 137, 98, 198, 215, 192, 210, 124, 106, 139, 34, 163, 91, 5, 93, 2, 117, 213, 97, 227, 24, 143, 85, 81, 173, 31, 11, 94, 133, 229, 194, 87, 99, 202, 61, 108, 180, 197, 204, AlertDescription.unrecognized_name, 178, 145, 89, 13, 71, 32, 200, 79, 88, 224, 1, 226, 22, 56, 196, AlertDescription.certificate_unobtainable, 59, 15, 101, 70, 190, 126, 45, 123, 130, 249, 64, 181, 29, AlertDescription.unknown_psk_identity, 248, 235, 38, 199, 135, 151, 37, 84, 177, 40, 170, 152, 157, 165, 100, 109, 122, 212, 16, 129, 68, 239, 73, 214, 174, 46, 221, 118, 92, 47, 167, 28, 201, 9, 105, 154, 131, 207, 41, 57, 185, 233, 76, 255, 67, 171};
private static final short[] ekb = {93, 190, 155, 139, 17, 153, AlertDescription.unsupported_extension, 77, 89, 243, 133, 166, 63, 183, 131, 197, 228, AlertDescription.unknown_psk_identity, 107, 58, 104, 90, 192, 71, 160, 100, 52, 12, 241, 208, 82, 165, 185, 30, 150, 67, 65, 216, 212, 44, 219, 248, 7, 119, 42, 202, 235, 239, 16, 28, 22, 13, 56, AlertDescription.bad_certificate_hash_value, 47, 137, 193, 249, 128, 196, 109, 174, 48, 61, 206, 32, 99, 254, 230, 26, 199, 184, 80, 232, 36, 23, 252, 37, AlertDescription.certificate_unobtainable, 187, 106, 163, 68, 83, 217, 162, 1, 171, 188, 182, 31, 152, 238, 154, 167, 45, 79, 158, 142, 172, 224, 198, 73, 70, 41, 244, 148, 138, 175, 225, 91, 195, 179, 123, 87, 209, 124, 156, 237, 135, 64, 140, 226, 203, 147, 20, 201, 97, 46, 229, 204, 246, 94, 168, 92, 214, 117, 141, 98, 149, 88, 105, 118, 161, 74, 181, 85, 9, 120, 51, 130, 215, 221, 121, 245, 27, 11, 222, 38, 33, 40, 116, 4, 151, 86, 223, 60, 240, 55, 57, 220, 255, 6, 164, 234, 66, 8, 218, 180, AlertDescription.bad_certificate_status_response, 176, 207, 18, 122, 78, 250, 108, 29, 132, 0, 200, 127, 145, 69, 170, 43, 194, 177, 143, 213, 186, 242, 173, 25, 178, 103, 54, 247, 15, 10, 146, 125, 227, 157, 233, 144, 62, 35, 39, 102, 19, 236, 129, 21, 189, 34, 191, 159, 126, 169, 81, 75, 76, 251, 2, 211, AlertDescription.unrecognized_name, 134, 49, 231, 59, 5, 3, 84, 96, 72, 101, 24, 210, 205, 95, 50, 136, 14, 53, 253};
@Override // org.bouncycastle.jcajce.provider.symmetric.util.BaseAlgorithmParameters
public AlgorithmParameterSpec localEngineGetParameterSpec(Class cls) throws InvalidParameterSpecException {
int i;
if (cls == RC2ParameterSpec.class && (i = this.parameterVersion) != -1) {
return i < 256 ? new RC2ParameterSpec(ekb[this.parameterVersion], this.iv) : new RC2ParameterSpec(this.parameterVersion, this.iv);
}
if (cls == IvParameterSpec.class) {
return new IvParameterSpec(this.iv);
}
throw new InvalidParameterSpecException("unknown parameter spec passed to RC2 parameters object.");
}
@Override // java.security.AlgorithmParametersSpi
protected String engineToString() {
return "RC2 Parameters";
}
@Override // java.security.AlgorithmParametersSpi
protected void engineInit(byte[] bArr, String str) throws IOException {
if (!isASN1FormatString(str)) {
if (!str.equals("RAW")) {
throw new IOException("Unknown parameters format in IV parameters object");
}
engineInit(bArr);
} else {
RC2CBCParameter rC2CBCParameter = RC2CBCParameter.getInstance(ASN1Primitive.fromByteArray(bArr));
if (rC2CBCParameter.getRC2ParameterVersion() != null) {
this.parameterVersion = rC2CBCParameter.getRC2ParameterVersion().intValue();
}
this.iv = rC2CBCParameter.getIV();
}
}
@Override // java.security.AlgorithmParametersSpi
protected void engineInit(byte[] bArr) throws IOException {
this.iv = Arrays.clone(bArr);
}
@Override // java.security.AlgorithmParametersSpi
protected void engineInit(AlgorithmParameterSpec algorithmParameterSpec) throws InvalidParameterSpecException {
if (algorithmParameterSpec instanceof IvParameterSpec) {
this.iv = ((IvParameterSpec) algorithmParameterSpec).getIV();
return;
}
if (!(algorithmParameterSpec instanceof RC2ParameterSpec)) {
throw new InvalidParameterSpecException("IvParameterSpec or RC2ParameterSpec required to initialise a RC2 parameters algorithm parameters object");
}
RC2ParameterSpec rC2ParameterSpec = (RC2ParameterSpec) algorithmParameterSpec;
int effectiveKeyBits = rC2ParameterSpec.getEffectiveKeyBits();
if (effectiveKeyBits != -1) {
int i = effectiveKeyBits;
if (effectiveKeyBits < 256) {
i = table[effectiveKeyBits];
}
this.parameterVersion = i;
}
this.iv = rC2ParameterSpec.getIV();
}
@Override // java.security.AlgorithmParametersSpi
protected byte[] engineGetEncoded(String str) throws IOException {
if (isASN1FormatString(str)) {
int i = this.parameterVersion;
return (i == -1 ? new RC2CBCParameter(engineGetEncoded()) : new RC2CBCParameter(i, engineGetEncoded())).getEncoded();
}
if (str.equals("RAW")) {
return engineGetEncoded();
}
return null;
}
@Override // java.security.AlgorithmParametersSpi
protected byte[] engineGetEncoded() {
return Arrays.clone(this.iv);
}
}
/* loaded from: classes6.dex */
public static class AlgParamGen extends BaseAlgorithmParameterGenerator {
RC2ParameterSpec spec = null;
@Override // java.security.AlgorithmParameterGeneratorSpi
protected void engineInit(AlgorithmParameterSpec algorithmParameterSpec, SecureRandom secureRandom) throws InvalidAlgorithmParameterException {
if (!(algorithmParameterSpec instanceof RC2ParameterSpec)) {
throw new InvalidAlgorithmParameterException("No supported AlgorithmParameterSpec for RC2 parameter generation.");
}
this.spec = (RC2ParameterSpec) algorithmParameterSpec;
}
@Override // java.security.AlgorithmParameterGeneratorSpi
protected AlgorithmParameters engineGenerateParameters() {
if (this.spec != null) {
try {
AlgorithmParameters createParametersInstance = createParametersInstance("RC2");
createParametersInstance.init(this.spec);
return createParametersInstance;
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
byte[] bArr = new byte[8];
if (this.random == null) {
this.random = new SecureRandom();
}
this.random.nextBytes(bArr);
try {
AlgorithmParameters createParametersInstance2 = createParametersInstance("RC2");
createParametersInstance2.init(new IvParameterSpec(bArr));
return createParametersInstance2;
} catch (Exception e2) {
throw new RuntimeException(e2.getMessage());
}
}
}
/* loaded from: classes6.dex */
public static class Mappings extends AlgorithmProvider {
private static final String PREFIX = RC2.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("$AlgParamGen");
configurableProvider.addAlgorithm("AlgorithmParameterGenerator.RC2", sb.toString());
StringBuilder sb2 = new StringBuilder();
sb2.append(str);
sb2.append("$AlgParamGen");
configurableProvider.addAlgorithm("AlgorithmParameterGenerator.1.2.840.113549.3.2", sb2.toString());
StringBuilder sb3 = new StringBuilder();
sb3.append(str);
sb3.append("$KeyGenerator");
configurableProvider.addAlgorithm("KeyGenerator.RC2", sb3.toString());
StringBuilder sb4 = new StringBuilder();
sb4.append(str);
sb4.append("$KeyGenerator");
configurableProvider.addAlgorithm("KeyGenerator.1.2.840.113549.3.2", sb4.toString());
StringBuilder sb5 = new StringBuilder();
sb5.append(str);
sb5.append("$AlgParams");
configurableProvider.addAlgorithm("AlgorithmParameters.RC2", sb5.toString());
StringBuilder sb6 = new StringBuilder();
sb6.append(str);
sb6.append("$AlgParams");
configurableProvider.addAlgorithm("AlgorithmParameters.1.2.840.113549.3.2", sb6.toString());
StringBuilder sb7 = new StringBuilder();
sb7.append(str);
sb7.append("$ECB");
configurableProvider.addAlgorithm("Cipher.RC2", sb7.toString());
StringBuilder sb8 = new StringBuilder();
sb8.append(str);
sb8.append("$Wrap");
configurableProvider.addAlgorithm("Cipher.RC2WRAP", sb8.toString());
configurableProvider.addAlgorithm("Alg.Alias.Cipher", PKCSObjectIdentifiers.id_alg_CMSRC2wrap, "RC2WRAP");
ASN1ObjectIdentifier aSN1ObjectIdentifier = PKCSObjectIdentifiers.RC2_CBC;
StringBuilder sb9 = new StringBuilder();
sb9.append(str);
sb9.append("$CBC");
configurableProvider.addAlgorithm("Cipher", aSN1ObjectIdentifier, sb9.toString());
StringBuilder sb10 = new StringBuilder();
sb10.append(str);
sb10.append("$CBCMAC");
configurableProvider.addAlgorithm("Mac.RC2MAC", sb10.toString());
configurableProvider.addAlgorithm("Alg.Alias.Mac.RC2", "RC2MAC");
StringBuilder sb11 = new StringBuilder();
sb11.append(str);
sb11.append("$CFB8MAC");
configurableProvider.addAlgorithm("Mac.RC2MAC/CFB8", sb11.toString());
configurableProvider.addAlgorithm("Alg.Alias.Mac.RC2/CFB8", "RC2MAC/CFB8");
configurableProvider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHMD2ANDRC2-CBC", "PBEWITHMD2ANDRC2");
configurableProvider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHMD5ANDRC2-CBC", "PBEWITHMD5ANDRC2");
configurableProvider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHSHA1ANDRC2-CBC", "PBEWITHSHA1ANDRC2");
configurableProvider.addAlgorithm("Alg.Alias.SecretKeyFactory", PKCSObjectIdentifiers.pbeWithMD2AndRC2_CBC, "PBEWITHMD2ANDRC2");
configurableProvider.addAlgorithm("Alg.Alias.SecretKeyFactory", PKCSObjectIdentifiers.pbeWithMD5AndRC2_CBC, "PBEWITHMD5ANDRC2");
configurableProvider.addAlgorithm("Alg.Alias.SecretKeyFactory", PKCSObjectIdentifiers.pbeWithSHA1AndRC2_CBC, "PBEWITHSHA1ANDRC2");
configurableProvider.addAlgorithm("Alg.Alias.SecretKeyFactory.1.2.840.113549.1.12.1.5", "PBEWITHSHAAND128BITRC2-CBC");
configurableProvider.addAlgorithm("Alg.Alias.SecretKeyFactory.1.2.840.113549.1.12.1.6", "PBEWITHSHAAND40BITRC2-CBC");
StringBuilder sb12 = new StringBuilder();
sb12.append(str);
sb12.append("$PBEWithMD2KeyFactory");
configurableProvider.addAlgorithm("SecretKeyFactory.PBEWITHMD2ANDRC2", sb12.toString());
StringBuilder sb13 = new StringBuilder();
sb13.append(str);
sb13.append("$PBEWithMD5KeyFactory");
configurableProvider.addAlgorithm("SecretKeyFactory.PBEWITHMD5ANDRC2", sb13.toString());
StringBuilder sb14 = new StringBuilder();
sb14.append(str);
sb14.append("$PBEWithSHA1KeyFactory");
configurableProvider.addAlgorithm("SecretKeyFactory.PBEWITHSHA1ANDRC2", sb14.toString());
StringBuilder sb15 = new StringBuilder();
sb15.append(str);
sb15.append("$PBEWithSHAAnd128BitKeyFactory");
configurableProvider.addAlgorithm("SecretKeyFactory.PBEWITHSHAAND128BITRC2-CBC", sb15.toString());
StringBuilder sb16 = new StringBuilder();
sb16.append(str);
sb16.append("$PBEWithSHAAnd40BitKeyFactory");
configurableProvider.addAlgorithm("SecretKeyFactory.PBEWITHSHAAND40BITRC2-CBC", sb16.toString());
configurableProvider.addAlgorithm("Alg.Alias.Cipher", PKCSObjectIdentifiers.pbeWithMD2AndRC2_CBC, "PBEWITHMD2ANDRC2");
configurableProvider.addAlgorithm("Alg.Alias.Cipher", PKCSObjectIdentifiers.pbeWithMD5AndRC2_CBC, "PBEWITHMD5ANDRC2");
configurableProvider.addAlgorithm("Alg.Alias.Cipher", PKCSObjectIdentifiers.pbeWithSHA1AndRC2_CBC, "PBEWITHSHA1ANDRC2");
configurableProvider.addAlgorithm("Alg.Alias.AlgorithmParameters.1.2.840.113549.1.12.1.5", "PKCS12PBE");
configurableProvider.addAlgorithm("Alg.Alias.AlgorithmParameters.1.2.840.113549.1.12.1.6", "PKCS12PBE");
configurableProvider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWithSHAAnd3KeyTripleDES", "PKCS12PBE");
configurableProvider.addAlgorithm("Alg.Alias.Cipher", PKCSObjectIdentifiers.pbeWithSHAAnd128BitRC2_CBC, "PBEWITHSHAAND128BITRC2-CBC");
configurableProvider.addAlgorithm("Alg.Alias.Cipher", PKCSObjectIdentifiers.pbeWithSHAAnd40BitRC2_CBC, "PBEWITHSHAAND40BITRC2-CBC");
configurableProvider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA1AND128BITRC2-CBC", "PBEWITHSHAAND128BITRC2-CBC");
configurableProvider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA1AND40BITRC2-CBC", "PBEWITHSHAAND40BITRC2-CBC");
StringBuilder sb17 = new StringBuilder();
sb17.append(str);
sb17.append("$PBEWithSHA1AndRC2");
configurableProvider.addAlgorithm("Cipher.PBEWITHSHA1ANDRC2", sb17.toString());
configurableProvider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHAANDRC2-CBC", "PBEWITHSHA1ANDRC2");
configurableProvider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA1ANDRC2-CBC", "PBEWITHSHA1ANDRC2");
StringBuilder sb18 = new StringBuilder();
sb18.append(str);
sb18.append("$PBEWithSHAAnd128BitRC2");
configurableProvider.addAlgorithm("Cipher.PBEWITHSHAAND128BITRC2-CBC", sb18.toString());
StringBuilder sb19 = new StringBuilder();
sb19.append(str);
sb19.append("$PBEWithSHAAnd40BitRC2");
configurableProvider.addAlgorithm("Cipher.PBEWITHSHAAND40BITRC2-CBC", sb19.toString());
StringBuilder sb20 = new StringBuilder();
sb20.append(str);
sb20.append("$PBEWithMD5AndRC2");
configurableProvider.addAlgorithm("Cipher.PBEWITHMD5ANDRC2", sb20.toString());
configurableProvider.addAlgorithm("Alg.Alias.Cipher.PBEWITHMD5ANDRC2-CBC", "PBEWITHMD5ANDRC2");
configurableProvider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHA1ANDRC2", "PKCS12PBE");
configurableProvider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHAANDRC2", "PKCS12PBE");
configurableProvider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHA1ANDRC2-CBC", "PKCS12PBE");
configurableProvider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND40BITRC2-CBC", "PKCS12PBE");
configurableProvider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND128BITRC2-CBC", "PKCS12PBE");
}
}
/* loaded from: classes6.dex */
public static class CBC extends BaseBlockCipher {
public CBC() {
super(new CBCBlockCipher(new RC2Engine()), 64);
}
}
/* loaded from: classes6.dex */
public static class CBCMAC extends BaseMac {
public CBCMAC() {
super(new CBCBlockCipherMac(new RC2Engine()));
}
}
/* loaded from: classes6.dex */
public static class CFB8MAC extends BaseMac {
public CFB8MAC() {
super(new CFBBlockCipherMac(new RC2Engine()));
}
}
/* loaded from: classes6.dex */
public static class ECB extends BaseBlockCipher {
public ECB() {
super(new RC2Engine());
}
}
/* loaded from: classes6.dex */
public static class KeyGenerator extends BaseKeyGenerator {
public KeyGenerator() {
super("RC2", 128, new CipherKeyGenerator());
}
}
/* loaded from: classes6.dex */
public static class PBEWithMD2KeyFactory extends PBESecretKeyFactory {
public PBEWithMD2KeyFactory() {
super("PBEwithMD2andRC2", PKCSObjectIdentifiers.pbeWithMD2AndRC2_CBC, true, 0, 5, 64, 64);
}
}
/* loaded from: classes6.dex */
public static class PBEWithMD5AndRC2 extends BaseBlockCipher {
public PBEWithMD5AndRC2() {
super(new CBCBlockCipher(new RC2Engine()), 0, 0, 64, 8);
}
}
/* loaded from: classes6.dex */
public static class PBEWithMD5KeyFactory extends PBESecretKeyFactory {
public PBEWithMD5KeyFactory() {
super("PBEwithMD5andRC2", PKCSObjectIdentifiers.pbeWithMD5AndRC2_CBC, true, 0, 0, 64, 64);
}
}
/* loaded from: classes6.dex */
public static class PBEWithSHA1AndRC2 extends BaseBlockCipher {
public PBEWithSHA1AndRC2() {
super(new CBCBlockCipher(new RC2Engine()), 0, 1, 64, 8);
}
}
/* loaded from: classes6.dex */
public static class PBEWithSHA1KeyFactory extends PBESecretKeyFactory {
public PBEWithSHA1KeyFactory() {
super("PBEwithSHA1andRC2", PKCSObjectIdentifiers.pbeWithSHA1AndRC2_CBC, true, 0, 1, 64, 64);
}
}
/* loaded from: classes6.dex */
public static class PBEWithSHAAnd128BitKeyFactory extends PBESecretKeyFactory {
public PBEWithSHAAnd128BitKeyFactory() {
super("PBEwithSHAand128BitRC2-CBC", PKCSObjectIdentifiers.pbeWithSHAAnd128BitRC2_CBC, true, 2, 1, 128, 64);
}
}
/* loaded from: classes6.dex */
public static class PBEWithSHAAnd128BitRC2 extends BaseBlockCipher {
public PBEWithSHAAnd128BitRC2() {
super(new CBCBlockCipher(new RC2Engine()), 2, 1, 128, 8);
}
}
/* loaded from: classes6.dex */
public static class PBEWithSHAAnd40BitKeyFactory extends PBESecretKeyFactory {
public PBEWithSHAAnd40BitKeyFactory() {
super("PBEwithSHAand40BitRC2-CBC", PKCSObjectIdentifiers.pbeWithSHAAnd40BitRC2_CBC, true, 2, 1, 40, 64);
}
}
/* loaded from: classes6.dex */
public static class PBEWithSHAAnd40BitRC2 extends BaseBlockCipher {
public PBEWithSHAAnd40BitRC2() {
super(new CBCBlockCipher(new RC2Engine()), 2, 1, 40, 8);
}
}
/* loaded from: classes6.dex */
public static class Wrap extends BaseWrapCipher {
public Wrap() {
super(new RC2WrapEngine());
}
}
private RC2() {
}
}