what-the-bank/sources/org/bouncycastle/crypto/tls/DefaultTlsCipherFactory.java

181 lines
7.1 KiB
Java

package org.bouncycastle.crypto.tls;
import java.io.IOException;
import org.bouncycastle.crypto.BlockCipher;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.StreamCipher;
import org.bouncycastle.crypto.engines.AESEngine;
import org.bouncycastle.crypto.engines.CamelliaEngine;
import org.bouncycastle.crypto.engines.DESedeEngine;
import org.bouncycastle.crypto.engines.RC4Engine;
import org.bouncycastle.crypto.engines.SEEDEngine;
import org.bouncycastle.crypto.modes.AEADBlockCipher;
import org.bouncycastle.crypto.modes.CBCBlockCipher;
import org.bouncycastle.crypto.modes.CCMBlockCipher;
import org.bouncycastle.crypto.modes.GCMBlockCipher;
import org.bouncycastle.crypto.modes.OCBBlockCipher;
/* loaded from: classes6.dex */
public class DefaultTlsCipherFactory extends AbstractTlsCipherFactory {
protected TlsBlockCipher createSEEDCipher(TlsContext tlsContext, int i) throws IOException {
return new TlsBlockCipher(tlsContext, createSEEDBlockCipher(), createSEEDBlockCipher(), createHMACDigest(i), createHMACDigest(i), 16);
}
protected BlockCipher createSEEDBlockCipher() {
return new CBCBlockCipher(new SEEDEngine());
}
protected StreamCipher createRC4StreamCipher() {
return new RC4Engine();
}
protected TlsStreamCipher createRC4Cipher(TlsContext tlsContext, int i, int i2) throws IOException {
return new TlsStreamCipher(tlsContext, createRC4StreamCipher(), createRC4StreamCipher(), createHMACDigest(i2), createHMACDigest(i2), i, false);
}
protected TlsNullCipher createNullCipher(TlsContext tlsContext, int i) throws IOException {
return new TlsNullCipher(tlsContext, createHMACDigest(i), createHMACDigest(i));
}
protected Digest createHMACDigest(int i) throws IOException {
if (i == 0) {
return null;
}
if (i == 1) {
return TlsUtils.createHash((short) 1);
}
if (i == 2) {
return TlsUtils.createHash((short) 2);
}
if (i == 3) {
return TlsUtils.createHash((short) 4);
}
if (i == 4) {
return TlsUtils.createHash((short) 5);
}
if (i == 5) {
return TlsUtils.createHash((short) 6);
}
throw new TlsFatalAlert((short) 80);
}
protected TlsBlockCipher createDESedeCipher(TlsContext tlsContext, int i) throws IOException {
return new TlsBlockCipher(tlsContext, createDESedeBlockCipher(), createDESedeBlockCipher(), createHMACDigest(i), createHMACDigest(i), 24);
}
protected BlockCipher createDESedeBlockCipher() {
return new CBCBlockCipher(new DESedeEngine());
}
protected TlsAEADCipher createCipher_Camellia_GCM(TlsContext tlsContext, int i, int i2) throws IOException {
return new TlsAEADCipher(tlsContext, createAEADBlockCipher_Camellia_GCM(), createAEADBlockCipher_Camellia_GCM(), i, i2);
}
protected TlsAEADCipher createCipher_AES_OCB(TlsContext tlsContext, int i, int i2) throws IOException {
return new TlsAEADCipher(tlsContext, createAEADBlockCipher_AES_OCB(), createAEADBlockCipher_AES_OCB(), i, i2, 2);
}
protected TlsAEADCipher createCipher_AES_GCM(TlsContext tlsContext, int i, int i2) throws IOException {
return new TlsAEADCipher(tlsContext, createAEADBlockCipher_AES_GCM(), createAEADBlockCipher_AES_GCM(), i, i2);
}
protected TlsAEADCipher createCipher_AES_CCM(TlsContext tlsContext, int i, int i2) throws IOException {
return new TlsAEADCipher(tlsContext, createAEADBlockCipher_AES_CCM(), createAEADBlockCipher_AES_CCM(), i, i2);
}
@Override // org.bouncycastle.crypto.tls.AbstractTlsCipherFactory, org.bouncycastle.crypto.tls.TlsCipherFactory
public TlsCipher createCipher(TlsContext tlsContext, int i, int i2) throws IOException {
if (i == 0) {
return createNullCipher(tlsContext, i2);
}
if (i == 2) {
return createRC4Cipher(tlsContext, 16, i2);
}
switch (i) {
case 7:
return createDESedeCipher(tlsContext, i2);
case 8:
return createAESCipher(tlsContext, 16, i2);
case 9:
return createAESCipher(tlsContext, 32, i2);
case 10:
return createCipher_AES_GCM(tlsContext, 16, 16);
case 11:
return createCipher_AES_GCM(tlsContext, 32, 16);
case 12:
return createCamelliaCipher(tlsContext, 16, i2);
case 13:
return createCamelliaCipher(tlsContext, 32, i2);
case 14:
return createSEEDCipher(tlsContext, i2);
case 15:
return createCipher_AES_CCM(tlsContext, 16, 16);
case 16:
return createCipher_AES_CCM(tlsContext, 16, 8);
case 17:
return createCipher_AES_CCM(tlsContext, 32, 16);
case 18:
return createCipher_AES_CCM(tlsContext, 32, 8);
case 19:
return createCipher_Camellia_GCM(tlsContext, 16, 16);
case 20:
return createCipher_Camellia_GCM(tlsContext, 32, 16);
default:
switch (i) {
case 102:
return createChaCha20Poly1305(tlsContext);
case 103:
return createCipher_AES_OCB(tlsContext, 16, 12);
case 104:
return createCipher_AES_OCB(tlsContext, 32, 12);
default:
throw new TlsFatalAlert((short) 80);
}
}
}
protected TlsCipher createChaCha20Poly1305(TlsContext tlsContext) throws IOException {
return new Chacha20Poly1305(tlsContext);
}
protected BlockCipher createCamelliaEngine() {
return new CamelliaEngine();
}
protected TlsBlockCipher createCamelliaCipher(TlsContext tlsContext, int i, int i2) throws IOException {
return new TlsBlockCipher(tlsContext, createCamelliaBlockCipher(), createCamelliaBlockCipher(), createHMACDigest(i2), createHMACDigest(i2), i);
}
protected BlockCipher createCamelliaBlockCipher() {
return new CBCBlockCipher(createCamelliaEngine());
}
protected BlockCipher createAESEngine() {
return new AESEngine();
}
protected TlsBlockCipher createAESCipher(TlsContext tlsContext, int i, int i2) throws IOException {
return new TlsBlockCipher(tlsContext, createAESBlockCipher(), createAESBlockCipher(), createHMACDigest(i2), createHMACDigest(i2), i);
}
protected BlockCipher createAESBlockCipher() {
return new CBCBlockCipher(createAESEngine());
}
protected AEADBlockCipher createAEADBlockCipher_Camellia_GCM() {
return new GCMBlockCipher(createCamelliaEngine());
}
protected AEADBlockCipher createAEADBlockCipher_AES_OCB() {
return new OCBBlockCipher(createAESEngine(), createAESEngine());
}
protected AEADBlockCipher createAEADBlockCipher_AES_GCM() {
return new GCMBlockCipher(createAESEngine());
}
protected AEADBlockCipher createAEADBlockCipher_AES_CCM() {
return new CCMBlockCipher(createAESEngine());
}
}