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

404 lines
19 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.jcajce.provider.symmetric;
import java.security.AlgorithmParameters;
import java.security.InvalidAlgorithmParameterException;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
import javax.crypto.SecretKey;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.KeyGenerationParameters;
import org.bouncycastle.crypto.engines.DESEngine;
import org.bouncycastle.crypto.engines.RFC3211WrapEngine;
import org.bouncycastle.crypto.generators.DESKeyGenerator;
import org.bouncycastle.crypto.macs.CBCBlockCipherMac;
import org.bouncycastle.crypto.macs.CFBBlockCipherMac;
import org.bouncycastle.crypto.macs.CMac;
import org.bouncycastle.crypto.macs.ISO9797Alg3Mac;
import org.bouncycastle.crypto.modes.CBCBlockCipher;
import org.bouncycastle.crypto.paddings.ISO7816d4Padding;
import org.bouncycastle.crypto.params.DESParameters;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.params.ParametersWithIV;
import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
import org.bouncycastle.jcajce.provider.symmetric.util.BCPBEKey;
import org.bouncycastle.jcajce.provider.symmetric.util.BaseAlgorithmParameterGenerator;
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.BaseSecretKeyFactory;
import org.bouncycastle.jcajce.provider.symmetric.util.BaseWrapCipher;
import org.bouncycastle.jcajce.provider.symmetric.util.PBE;
import org.bouncycastle.jcajce.provider.util.AlgorithmProvider;
/* loaded from: classes6.dex */
public final class DES {
/* loaded from: classes6.dex */
public static class Mappings extends AlgorithmProvider {
private static final String PACKAGE = "org.bouncycastle.jcajce.provider.symmetric";
private static final String PREFIX = DES.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("$ECB");
configurableProvider.addAlgorithm("Cipher.DES", sb.toString());
ASN1ObjectIdentifier aSN1ObjectIdentifier = OIWObjectIdentifiers.desCBC;
StringBuilder sb2 = new StringBuilder();
sb2.append(str);
sb2.append("$CBC");
configurableProvider.addAlgorithm("Cipher", aSN1ObjectIdentifier, sb2.toString());
addAlias(configurableProvider, OIWObjectIdentifiers.desCBC, "DES");
StringBuilder sb3 = new StringBuilder();
sb3.append(str);
sb3.append("$RFC3211");
configurableProvider.addAlgorithm("Cipher.DESRFC3211WRAP", sb3.toString());
StringBuilder sb4 = new StringBuilder();
sb4.append(str);
sb4.append("$KeyGenerator");
configurableProvider.addAlgorithm("KeyGenerator.DES", sb4.toString());
StringBuilder sb5 = new StringBuilder();
sb5.append(str);
sb5.append("$KeyFactory");
configurableProvider.addAlgorithm("SecretKeyFactory.DES", sb5.toString());
StringBuilder sb6 = new StringBuilder();
sb6.append(str);
sb6.append("$CMAC");
configurableProvider.addAlgorithm("Mac.DESCMAC", sb6.toString());
StringBuilder sb7 = new StringBuilder();
sb7.append(str);
sb7.append("$CBCMAC");
configurableProvider.addAlgorithm("Mac.DESMAC", sb7.toString());
configurableProvider.addAlgorithm("Alg.Alias.Mac.DES", "DESMAC");
StringBuilder sb8 = new StringBuilder();
sb8.append(str);
sb8.append("$DESCFB8");
configurableProvider.addAlgorithm("Mac.DESMAC/CFB8", sb8.toString());
configurableProvider.addAlgorithm("Alg.Alias.Mac.DES/CFB8", "DESMAC/CFB8");
StringBuilder sb9 = new StringBuilder();
sb9.append(str);
sb9.append("$DES64");
configurableProvider.addAlgorithm("Mac.DESMAC64", sb9.toString());
configurableProvider.addAlgorithm("Alg.Alias.Mac.DES64", "DESMAC64");
StringBuilder sb10 = new StringBuilder();
sb10.append(str);
sb10.append("$DES64with7816d4");
configurableProvider.addAlgorithm("Mac.DESMAC64WITHISO7816-4PADDING", sb10.toString());
configurableProvider.addAlgorithm("Alg.Alias.Mac.DES64WITHISO7816-4PADDING", "DESMAC64WITHISO7816-4PADDING");
configurableProvider.addAlgorithm("Alg.Alias.Mac.DESISO9797ALG1MACWITHISO7816-4PADDING", "DESMAC64WITHISO7816-4PADDING");
configurableProvider.addAlgorithm("Alg.Alias.Mac.DESISO9797ALG1WITHISO7816-4PADDING", "DESMAC64WITHISO7816-4PADDING");
StringBuilder sb11 = new StringBuilder();
sb11.append(str);
sb11.append("$DES9797Alg3");
configurableProvider.addAlgorithm("Mac.DESWITHISO9797", sb11.toString());
configurableProvider.addAlgorithm("Alg.Alias.Mac.DESISO9797MAC", "DESWITHISO9797");
StringBuilder sb12 = new StringBuilder();
sb12.append(str);
sb12.append("$DES9797Alg3");
configurableProvider.addAlgorithm("Mac.ISO9797ALG3MAC", sb12.toString());
configurableProvider.addAlgorithm("Alg.Alias.Mac.ISO9797ALG3", "ISO9797ALG3MAC");
StringBuilder sb13 = new StringBuilder();
sb13.append(str);
sb13.append("$DES9797Alg3with7816d4");
configurableProvider.addAlgorithm("Mac.ISO9797ALG3WITHISO7816-4PADDING", sb13.toString());
configurableProvider.addAlgorithm("Alg.Alias.Mac.ISO9797ALG3MACWITHISO7816-4PADDING", "ISO9797ALG3WITHISO7816-4PADDING");
configurableProvider.addAlgorithm("AlgorithmParameters.DES", "org.bouncycastle.jcajce.provider.symmetric.util.IvAlgorithmParameters");
configurableProvider.addAlgorithm("Alg.Alias.AlgorithmParameters", OIWObjectIdentifiers.desCBC, "DES");
StringBuilder sb14 = new StringBuilder();
sb14.append(str);
sb14.append("$AlgParamGen");
configurableProvider.addAlgorithm("AlgorithmParameterGenerator.DES", sb14.toString());
StringBuilder sb15 = new StringBuilder("Alg.Alias.AlgorithmParameterGenerator.");
sb15.append(OIWObjectIdentifiers.desCBC);
configurableProvider.addAlgorithm(sb15.toString(), "DES");
StringBuilder sb16 = new StringBuilder();
sb16.append(str);
sb16.append("$PBEWithMD2");
configurableProvider.addAlgorithm("Cipher.PBEWITHMD2ANDDES", sb16.toString());
StringBuilder sb17 = new StringBuilder();
sb17.append(str);
sb17.append("$PBEWithMD5");
configurableProvider.addAlgorithm("Cipher.PBEWITHMD5ANDDES", sb17.toString());
StringBuilder sb18 = new StringBuilder();
sb18.append(str);
sb18.append("$PBEWithSHA1");
configurableProvider.addAlgorithm("Cipher.PBEWITHSHA1ANDDES", sb18.toString());
configurableProvider.addAlgorithm("Alg.Alias.Cipher", PKCSObjectIdentifiers.pbeWithMD2AndDES_CBC, "PBEWITHMD2ANDDES");
configurableProvider.addAlgorithm("Alg.Alias.Cipher", PKCSObjectIdentifiers.pbeWithMD5AndDES_CBC, "PBEWITHMD5ANDDES");
configurableProvider.addAlgorithm("Alg.Alias.Cipher", PKCSObjectIdentifiers.pbeWithSHA1AndDES_CBC, "PBEWITHSHA1ANDDES");
configurableProvider.addAlgorithm("Alg.Alias.Cipher.PBEWITHMD2ANDDES-CBC", "PBEWITHMD2ANDDES");
configurableProvider.addAlgorithm("Alg.Alias.Cipher.PBEWITHMD5ANDDES-CBC", "PBEWITHMD5ANDDES");
configurableProvider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA1ANDDES-CBC", "PBEWITHSHA1ANDDES");
StringBuilder sb19 = new StringBuilder();
sb19.append(str);
sb19.append("$PBEWithMD2KeyFactory");
configurableProvider.addAlgorithm("SecretKeyFactory.PBEWITHMD2ANDDES", sb19.toString());
StringBuilder sb20 = new StringBuilder();
sb20.append(str);
sb20.append("$PBEWithMD5KeyFactory");
configurableProvider.addAlgorithm("SecretKeyFactory.PBEWITHMD5ANDDES", sb20.toString());
StringBuilder sb21 = new StringBuilder();
sb21.append(str);
sb21.append("$PBEWithSHA1KeyFactory");
configurableProvider.addAlgorithm("SecretKeyFactory.PBEWITHSHA1ANDDES", sb21.toString());
configurableProvider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHMD2ANDDES-CBC", "PBEWITHMD2ANDDES");
configurableProvider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHMD5ANDDES-CBC", "PBEWITHMD5ANDDES");
configurableProvider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHSHA1ANDDES-CBC", "PBEWITHSHA1ANDDES");
StringBuilder sb22 = new StringBuilder("Alg.Alias.SecretKeyFactory.");
sb22.append(PKCSObjectIdentifiers.pbeWithMD2AndDES_CBC);
configurableProvider.addAlgorithm(sb22.toString(), "PBEWITHMD2ANDDES");
StringBuilder sb23 = new StringBuilder("Alg.Alias.SecretKeyFactory.");
sb23.append(PKCSObjectIdentifiers.pbeWithMD5AndDES_CBC);
configurableProvider.addAlgorithm(sb23.toString(), "PBEWITHMD5ANDDES");
StringBuilder sb24 = new StringBuilder("Alg.Alias.SecretKeyFactory.");
sb24.append(PKCSObjectIdentifiers.pbeWithSHA1AndDES_CBC);
configurableProvider.addAlgorithm(sb24.toString(), "PBEWITHSHA1ANDDES");
}
private void addAlias(ConfigurableProvider configurableProvider, ASN1ObjectIdentifier aSN1ObjectIdentifier, String str) {
StringBuilder sb = new StringBuilder("Alg.Alias.KeyGenerator.");
sb.append(aSN1ObjectIdentifier.getId());
configurableProvider.addAlgorithm(sb.toString(), str);
StringBuilder sb2 = new StringBuilder("Alg.Alias.KeyFactory.");
sb2.append(aSN1ObjectIdentifier.getId());
configurableProvider.addAlgorithm(sb2.toString(), str);
}
}
/* 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 DES 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("DES");
createParametersInstance.init(new IvParameterSpec(bArr));
return createParametersInstance;
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
}
/* loaded from: classes6.dex */
public static class KeyFactory extends BaseSecretKeyFactory {
@Override // org.bouncycastle.jcajce.provider.symmetric.util.BaseSecretKeyFactory, javax.crypto.SecretKeyFactorySpi
public KeySpec engineGetKeySpec(SecretKey secretKey, Class cls) throws InvalidKeySpecException {
if (cls == null) {
throw new InvalidKeySpecException("keySpec parameter is null");
}
if (secretKey == null) {
throw new InvalidKeySpecException("key parameter is null");
}
if (SecretKeySpec.class.isAssignableFrom(cls)) {
return new SecretKeySpec(secretKey.getEncoded(), this.algName);
}
if (!DESKeySpec.class.isAssignableFrom(cls)) {
throw new InvalidKeySpecException("Invalid KeySpec");
}
try {
return new DESKeySpec(secretKey.getEncoded());
} catch (Exception e) {
throw new InvalidKeySpecException(e.toString());
}
}
@Override // org.bouncycastle.jcajce.provider.symmetric.util.BaseSecretKeyFactory, javax.crypto.SecretKeyFactorySpi
public SecretKey engineGenerateSecret(KeySpec keySpec) throws InvalidKeySpecException {
return keySpec instanceof DESKeySpec ? new SecretKeySpec(((DESKeySpec) keySpec).getKey(), "DES") : super.engineGenerateSecret(keySpec);
}
public KeyFactory() {
super("DES", null);
}
}
/* loaded from: classes6.dex */
public static class KeyGenerator extends BaseKeyGenerator {
@Override // org.bouncycastle.jcajce.provider.symmetric.util.BaseKeyGenerator, javax.crypto.KeyGeneratorSpi
public void engineInit(int i, SecureRandom secureRandom) {
super.engineInit(i, secureRandom);
}
@Override // org.bouncycastle.jcajce.provider.symmetric.util.BaseKeyGenerator, javax.crypto.KeyGeneratorSpi
public SecretKey engineGenerateKey() {
if (this.uninitialised) {
this.engine.init(new KeyGenerationParameters(new SecureRandom(), this.defaultKeySize));
this.uninitialised = false;
}
return new SecretKeySpec(this.engine.generateKey(), this.algName);
}
public KeyGenerator() {
super("DES", 64, new DESKeyGenerator());
}
}
/* loaded from: classes6.dex */
public static class DESPBEKeyFactory extends BaseSecretKeyFactory {
private int digest;
private boolean forCipher;
private int ivSize;
private int keySize;
private int scheme;
@Override // org.bouncycastle.jcajce.provider.symmetric.util.BaseSecretKeyFactory, javax.crypto.SecretKeyFactorySpi
public SecretKey engineGenerateSecret(KeySpec keySpec) throws InvalidKeySpecException {
if (!(keySpec instanceof PBEKeySpec)) {
throw new InvalidKeySpecException("Invalid KeySpec");
}
PBEKeySpec pBEKeySpec = (PBEKeySpec) keySpec;
if (pBEKeySpec.getSalt() == null) {
return new BCPBEKey(this.algName, this.algOid, this.scheme, this.digest, this.keySize, this.ivSize, pBEKeySpec, null);
}
CipherParameters makePBEParameters = this.forCipher ? PBE.Util.makePBEParameters(pBEKeySpec, this.scheme, this.digest, this.keySize, this.ivSize) : PBE.Util.makePBEMacParameters(pBEKeySpec, this.scheme, this.digest, this.keySize);
DESParameters.setOddParity((makePBEParameters instanceof ParametersWithIV ? (KeyParameter) ((ParametersWithIV) makePBEParameters).getParameters() : (KeyParameter) makePBEParameters).getKey());
return new BCPBEKey(this.algName, this.algOid, this.scheme, this.digest, this.keySize, this.ivSize, pBEKeySpec, makePBEParameters);
}
public DESPBEKeyFactory(String str, ASN1ObjectIdentifier aSN1ObjectIdentifier, boolean z, int i, int i2, int i3, int i4) {
super(str, aSN1ObjectIdentifier);
this.forCipher = z;
this.scheme = i;
this.digest = i2;
this.keySize = i3;
this.ivSize = i4;
}
}
/* loaded from: classes6.dex */
public static class CBC extends BaseBlockCipher {
public CBC() {
super(new CBCBlockCipher(new DESEngine()), 64);
}
}
/* loaded from: classes6.dex */
public static class CBCMAC extends BaseMac {
public CBCMAC() {
super(new CBCBlockCipherMac(new DESEngine()));
}
}
/* loaded from: classes6.dex */
public static class CMAC extends BaseMac {
public CMAC() {
super(new CMac(new DESEngine()));
}
}
/* loaded from: classes6.dex */
public static class DES64 extends BaseMac {
public DES64() {
super(new CBCBlockCipherMac(new DESEngine(), 64));
}
}
/* loaded from: classes6.dex */
public static class DES64with7816d4 extends BaseMac {
public DES64with7816d4() {
super(new CBCBlockCipherMac(new DESEngine(), 64, new ISO7816d4Padding()));
}
}
/* loaded from: classes6.dex */
public static class DES9797Alg3 extends BaseMac {
public DES9797Alg3() {
super(new ISO9797Alg3Mac(new DESEngine()));
}
}
/* loaded from: classes6.dex */
public static class DES9797Alg3with7816d4 extends BaseMac {
public DES9797Alg3with7816d4() {
super(new ISO9797Alg3Mac(new DESEngine(), new ISO7816d4Padding()));
}
}
/* loaded from: classes6.dex */
public static class DESCFB8 extends BaseMac {
public DESCFB8() {
super(new CFBBlockCipherMac(new DESEngine()));
}
}
/* loaded from: classes6.dex */
public static class ECB extends BaseBlockCipher {
public ECB() {
super(new DESEngine());
}
}
/* loaded from: classes6.dex */
public static class PBEWithMD2 extends BaseBlockCipher {
public PBEWithMD2() {
super(new CBCBlockCipher(new DESEngine()), 0, 5, 64, 8);
}
}
/* loaded from: classes6.dex */
public static class PBEWithMD2KeyFactory extends DESPBEKeyFactory {
public PBEWithMD2KeyFactory() {
super("PBEwithMD2andDES", PKCSObjectIdentifiers.pbeWithMD2AndDES_CBC, true, 0, 5, 64, 64);
}
}
/* loaded from: classes6.dex */
public static class PBEWithMD5 extends BaseBlockCipher {
public PBEWithMD5() {
super(new CBCBlockCipher(new DESEngine()), 0, 0, 64, 8);
}
}
/* loaded from: classes6.dex */
public static class PBEWithMD5KeyFactory extends DESPBEKeyFactory {
public PBEWithMD5KeyFactory() {
super("PBEwithMD5andDES", PKCSObjectIdentifiers.pbeWithMD5AndDES_CBC, true, 0, 0, 64, 64);
}
}
/* loaded from: classes6.dex */
public static class PBEWithSHA1 extends BaseBlockCipher {
public PBEWithSHA1() {
super(new CBCBlockCipher(new DESEngine()), 0, 1, 64, 8);
}
}
/* loaded from: classes6.dex */
public static class PBEWithSHA1KeyFactory extends DESPBEKeyFactory {
public PBEWithSHA1KeyFactory() {
super("PBEwithSHA1andDES", PKCSObjectIdentifiers.pbeWithSHA1AndDES_CBC, true, 0, 1, 64, 64);
}
}
/* loaded from: classes6.dex */
public static class RFC3211 extends BaseWrapCipher {
public RFC3211() {
super(new RFC3211WrapEngine(new DESEngine()), 8);
}
}
private DES() {
}
}