what-the-bank/sources/org/bouncycastle/crypto/digests/SHAKEDigest.java

84 lines
2.4 KiB
Java

package org.bouncycastle.crypto.digests;
import org.bouncycastle.crypto.Xof;
/* loaded from: classes6.dex */
public class SHAKEDigest extends KeccakDigest implements Xof {
@Override // org.bouncycastle.crypto.digests.KeccakDigest, org.bouncycastle.crypto.Digest
public String getAlgorithmName() {
StringBuilder sb = new StringBuilder("SHAKE");
sb.append(this.fixedOutputLength);
return sb.toString();
}
@Override // org.bouncycastle.crypto.Xof
public int doOutput(byte[] bArr, int i, int i2) {
if (!this.squeezing) {
absorb(new byte[]{15}, 0, 4L);
}
squeeze(bArr, i, i2 << 3);
return i2;
}
protected int doFinal(byte[] bArr, int i, int i2, byte b, int i3) {
if (i3 < 0 || i3 > 7) {
throw new IllegalArgumentException("'partialBits' must be in the range [0,7]");
}
int i4 = (b & ((1 << i3) - 1)) | (15 << i3);
int i5 = i3 + 4;
if (i5 >= 8) {
this.oneByte[0] = (byte) i4;
absorb(this.oneByte, 0, 8L);
i5 = i3 - 4;
i4 >>>= 8;
}
if (i5 > 0) {
this.oneByte[0] = (byte) i4;
absorb(this.oneByte, 0, i5);
}
squeeze(bArr, i, i2 << 3);
reset();
return i2;
}
@Override // org.bouncycastle.crypto.Xof
public int doFinal(byte[] bArr, int i, int i2) {
int doOutput = doOutput(bArr, i, i2);
reset();
return doOutput;
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // org.bouncycastle.crypto.digests.KeccakDigest
public int doFinal(byte[] bArr, int i, byte b, int i2) {
return doFinal(bArr, i, getDigestSize(), b, i2);
}
@Override // org.bouncycastle.crypto.digests.KeccakDigest, org.bouncycastle.crypto.Digest
public int doFinal(byte[] bArr, int i) {
return doFinal(bArr, i, getDigestSize());
}
private static int checkBitLength(int i) {
if (i == 128 || i == 256) {
return i;
}
StringBuilder sb = new StringBuilder("'bitLength' ");
sb.append(i);
sb.append(" not supported for SHAKE");
throw new IllegalArgumentException(sb.toString());
}
public SHAKEDigest(SHAKEDigest sHAKEDigest) {
super(sHAKEDigest);
}
public SHAKEDigest(int i) {
super(checkBitLength(i));
}
public SHAKEDigest() {
this(128);
}
}