99 lines
3.5 KiB
Java
99 lines
3.5 KiB
Java
package org.bouncycastle.crypto.engines;
|
|
|
|
import io.flutter.embedding.android.KeyboardMap;
|
|
import org.bouncycastle.util.Pack;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class ChaCha7539Engine extends Salsa20Engine {
|
|
@Override // org.bouncycastle.crypto.engines.Salsa20Engine
|
|
protected int getNonceSize() {
|
|
return 12;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: protected */
|
|
@Override // org.bouncycastle.crypto.engines.Salsa20Engine
|
|
public void setKey(byte[] bArr, byte[] bArr2) {
|
|
if (bArr != null) {
|
|
if (bArr.length != 32) {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append(getAlgorithmName());
|
|
sb.append(" requires 256 bit key");
|
|
throw new IllegalArgumentException(sb.toString());
|
|
}
|
|
packTauOrSigma(bArr.length, this.engineState, 0);
|
|
Pack.littleEndianToInt(bArr, 0, this.engineState, 4, 8);
|
|
}
|
|
Pack.littleEndianToInt(bArr2, 0, this.engineState, 13, 3);
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.engines.Salsa20Engine
|
|
protected void retreatCounter(long j) {
|
|
int i = (int) (j >>> 32);
|
|
int i2 = (int) j;
|
|
if (i != 0) {
|
|
throw new IllegalStateException("attempt to reduce counter past zero.");
|
|
}
|
|
if ((this.engineState[12] & KeyboardMap.kValueMask) < (KeyboardMap.kValueMask & i2)) {
|
|
throw new IllegalStateException("attempt to reduce counter past zero.");
|
|
}
|
|
int[] iArr = this.engineState;
|
|
iArr[12] = iArr[12] - i2;
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.engines.Salsa20Engine
|
|
protected void retreatCounter() {
|
|
if (this.engineState[12] == 0) {
|
|
throw new IllegalStateException("attempt to reduce counter past zero.");
|
|
}
|
|
this.engineState[12] = r0[12] - 1;
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.engines.Salsa20Engine
|
|
protected void resetCounter() {
|
|
this.engineState[12] = 0;
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.engines.Salsa20Engine
|
|
protected long getCounter() {
|
|
return this.engineState[12] & KeyboardMap.kValueMask;
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.engines.Salsa20Engine, org.bouncycastle.crypto.StreamCipher
|
|
public String getAlgorithmName() {
|
|
StringBuilder sb = new StringBuilder("ChaCha");
|
|
sb.append(this.rounds);
|
|
return sb.toString();
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.engines.Salsa20Engine
|
|
protected void generateKeyStream(byte[] bArr) {
|
|
ChaChaEngine.chachaCore(this.rounds, this.engineState, this.x);
|
|
Pack.intToLittleEndian(this.x, bArr, 0);
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.engines.Salsa20Engine
|
|
protected void advanceCounter(long j) {
|
|
int i = (int) (j >>> 32);
|
|
int i2 = (int) j;
|
|
if (i > 0) {
|
|
throw new IllegalStateException("attempt to increase counter past 2^32.");
|
|
}
|
|
int i3 = this.engineState[12];
|
|
int[] iArr = this.engineState;
|
|
iArr[12] = iArr[12] + i2;
|
|
if (i3 != 0 && this.engineState[12] < i3) {
|
|
throw new IllegalStateException("attempt to increase counter past 2^32.");
|
|
}
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.engines.Salsa20Engine
|
|
protected void advanceCounter() {
|
|
int[] iArr = this.engineState;
|
|
int i = iArr[12] + 1;
|
|
iArr[12] = i;
|
|
if (i == 0) {
|
|
throw new IllegalStateException("attempt to increase counter past 2^32.");
|
|
}
|
|
}
|
|
}
|