74 lines
2.5 KiB
Java
74 lines
2.5 KiB
Java
|
package org.bouncycastle.crypto.macs;
|
||
|
|
||
|
import org.bouncycastle.crypto.CipherParameters;
|
||
|
import org.bouncycastle.crypto.DataLengthException;
|
||
|
import org.bouncycastle.crypto.InvalidCipherTextException;
|
||
|
import org.bouncycastle.crypto.Mac;
|
||
|
import org.bouncycastle.crypto.modes.GCMBlockCipher;
|
||
|
import org.bouncycastle.crypto.params.AEADParameters;
|
||
|
import org.bouncycastle.crypto.params.KeyParameter;
|
||
|
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class GMac implements Mac {
|
||
|
private final GCMBlockCipher cipher;
|
||
|
private final int macSizeBits;
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.Mac
|
||
|
public void update(byte[] bArr, int i, int i2) throws DataLengthException, IllegalStateException {
|
||
|
this.cipher.processAADBytes(bArr, i, i2);
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.Mac
|
||
|
public void update(byte b) throws IllegalStateException {
|
||
|
this.cipher.processAADByte(b);
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.Mac
|
||
|
public void reset() {
|
||
|
this.cipher.reset();
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.Mac
|
||
|
public void init(CipherParameters cipherParameters) throws IllegalArgumentException {
|
||
|
if (!(cipherParameters instanceof ParametersWithIV)) {
|
||
|
throw new IllegalArgumentException("GMAC requires ParametersWithIV");
|
||
|
}
|
||
|
ParametersWithIV parametersWithIV = (ParametersWithIV) cipherParameters;
|
||
|
byte[] iv = parametersWithIV.getIV();
|
||
|
this.cipher.init(true, new AEADParameters((KeyParameter) parametersWithIV.getParameters(), this.macSizeBits, iv));
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.Mac
|
||
|
public int getMacSize() {
|
||
|
return this.macSizeBits / 8;
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.Mac
|
||
|
public String getAlgorithmName() {
|
||
|
StringBuilder sb = new StringBuilder();
|
||
|
sb.append(this.cipher.getUnderlyingCipher().getAlgorithmName());
|
||
|
sb.append("-GMAC");
|
||
|
return sb.toString();
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.Mac
|
||
|
public int doFinal(byte[] bArr, int i) throws DataLengthException, IllegalStateException {
|
||
|
try {
|
||
|
return this.cipher.doFinal(bArr, i);
|
||
|
} catch (InvalidCipherTextException e) {
|
||
|
throw new IllegalStateException(e.toString());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public GMac(GCMBlockCipher gCMBlockCipher, int i) {
|
||
|
this.cipher = gCMBlockCipher;
|
||
|
this.macSizeBits = i;
|
||
|
}
|
||
|
|
||
|
public GMac(GCMBlockCipher gCMBlockCipher) {
|
||
|
this.cipher = gCMBlockCipher;
|
||
|
this.macSizeBits = 128;
|
||
|
}
|
||
|
}
|