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

87 lines
2.6 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.crypto.tls;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.Mac;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.util.Arrays;
/* loaded from: classes6.dex */
public class SSL3Mac implements Mac {
private Digest digest;
private int padLength;
private byte[] secret;
private static final byte IPAD_BYTE = 54;
static final byte[] IPAD = genPad(IPAD_BYTE, 48);
private static final byte OPAD_BYTE = 92;
static final byte[] OPAD = genPad(OPAD_BYTE, 48);
@Override // org.bouncycastle.crypto.Mac
public void update(byte[] bArr, int i, int i2) {
this.digest.update(bArr, i, i2);
}
@Override // org.bouncycastle.crypto.Mac
public void update(byte b) {
this.digest.update(b);
}
@Override // org.bouncycastle.crypto.Mac
public void reset() {
this.digest.reset();
Digest digest = this.digest;
byte[] bArr = this.secret;
digest.update(bArr, 0, bArr.length);
this.digest.update(IPAD, 0, this.padLength);
}
@Override // org.bouncycastle.crypto.Mac
public void init(CipherParameters cipherParameters) {
this.secret = Arrays.clone(((KeyParameter) cipherParameters).getKey());
reset();
}
public Digest getUnderlyingDigest() {
return this.digest;
}
@Override // org.bouncycastle.crypto.Mac
public int getMacSize() {
return this.digest.getDigestSize();
}
@Override // org.bouncycastle.crypto.Mac
public String getAlgorithmName() {
StringBuilder sb = new StringBuilder();
sb.append(this.digest.getAlgorithmName());
sb.append("/SSL3MAC");
return sb.toString();
}
@Override // org.bouncycastle.crypto.Mac
public int doFinal(byte[] bArr, int i) {
int digestSize = this.digest.getDigestSize();
byte[] bArr2 = new byte[digestSize];
this.digest.doFinal(bArr2, 0);
Digest digest = this.digest;
byte[] bArr3 = this.secret;
digest.update(bArr3, 0, bArr3.length);
this.digest.update(OPAD, 0, this.padLength);
this.digest.update(bArr2, 0, digestSize);
int doFinal = this.digest.doFinal(bArr, i);
reset();
return doFinal;
}
private static byte[] genPad(byte b, int i) {
byte[] bArr = new byte[i];
Arrays.fill(bArr, b);
return bArr;
}
public SSL3Mac(Digest digest) {
this.digest = digest;
this.padLength = digest.getDigestSize() == 20 ? 40 : 48;
}
}