114 lines
3.8 KiB
Java
114 lines
3.8 KiB
Java
package org.bouncycastle.crypto.tls;
|
|
|
|
import org.bouncycastle.crypto.Digest;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes6.dex */
|
|
public class CombinedHash implements TlsHandshakeHash {
|
|
protected TlsContext context;
|
|
protected Digest md5;
|
|
protected Digest sha1;
|
|
|
|
@Override // org.bouncycastle.crypto.tls.TlsHandshakeHash
|
|
public TlsHandshakeHash notifyPRFDetermined() {
|
|
return this;
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.tls.TlsHandshakeHash
|
|
public void sealHashAlgorithms() {
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.Digest
|
|
public void update(byte[] bArr, int i, int i2) {
|
|
this.md5.update(bArr, i, i2);
|
|
this.sha1.update(bArr, i, i2);
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.Digest
|
|
public void update(byte b) {
|
|
this.md5.update(b);
|
|
this.sha1.update(b);
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.tls.TlsHandshakeHash
|
|
public void trackHashAlgorithm(short s) {
|
|
throw new IllegalStateException("CombinedHash only supports calculating the legacy PRF for handshake hash");
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.tls.TlsHandshakeHash
|
|
public TlsHandshakeHash stopTracking() {
|
|
return new CombinedHash(this);
|
|
}
|
|
|
|
protected void ssl3Complete(Digest digest, byte[] bArr, byte[] bArr2, int i) {
|
|
byte[] bArr3 = this.context.getSecurityParameters().masterSecret;
|
|
digest.update(bArr3, 0, bArr3.length);
|
|
digest.update(bArr, 0, i);
|
|
int digestSize = digest.getDigestSize();
|
|
byte[] bArr4 = new byte[digestSize];
|
|
digest.doFinal(bArr4, 0);
|
|
digest.update(bArr3, 0, bArr3.length);
|
|
digest.update(bArr2, 0, i);
|
|
digest.update(bArr4, 0, digestSize);
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.Digest
|
|
public void reset() {
|
|
this.md5.reset();
|
|
this.sha1.reset();
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.tls.TlsHandshakeHash
|
|
public void init(TlsContext tlsContext) {
|
|
this.context = tlsContext;
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.tls.TlsHandshakeHash
|
|
public byte[] getFinalHash(short s) {
|
|
throw new IllegalStateException("CombinedHash doesn't support multiple hashes");
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.Digest
|
|
public int getDigestSize() {
|
|
return this.md5.getDigestSize() + this.sha1.getDigestSize();
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.Digest
|
|
public String getAlgorithmName() {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append(this.md5.getAlgorithmName());
|
|
sb.append(" and ");
|
|
sb.append(this.sha1.getAlgorithmName());
|
|
return sb.toString();
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.tls.TlsHandshakeHash
|
|
public Digest forkPRFHash() {
|
|
return new CombinedHash(this);
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.Digest
|
|
public int doFinal(byte[] bArr, int i) {
|
|
TlsContext tlsContext = this.context;
|
|
if (tlsContext != null && TlsUtils.isSSL(tlsContext)) {
|
|
ssl3Complete(this.md5, SSL3Mac.IPAD, SSL3Mac.OPAD, 48);
|
|
ssl3Complete(this.sha1, SSL3Mac.IPAD, SSL3Mac.OPAD, 40);
|
|
}
|
|
int doFinal = this.md5.doFinal(bArr, i);
|
|
return doFinal + this.sha1.doFinal(bArr, i + doFinal);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public CombinedHash(CombinedHash combinedHash) {
|
|
this.context = combinedHash.context;
|
|
this.md5 = TlsUtils.cloneHash((short) 1, combinedHash.md5);
|
|
this.sha1 = TlsUtils.cloneHash((short) 2, combinedHash.sha1);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public CombinedHash() {
|
|
this.md5 = TlsUtils.createHash((short) 1);
|
|
this.sha1 = TlsUtils.createHash((short) 2);
|
|
}
|
|
}
|