what-the-bank/sources/org/bouncycastle/math/ec/custom/sec/SecT193Field.java

244 lines
8.5 KiB
Java

package org.bouncycastle.math.ec.custom.sec;
import io.flutter.embedding.android.KeyboardMap;
import java.math.BigInteger;
import org.bouncycastle.math.raw.Interleave;
import org.bouncycastle.math.raw.Nat256;
/* loaded from: classes6.dex */
public class SecT193Field {
private static final long M01 = 1;
private static final long M49 = 562949953421311L;
public static int trace(long[] jArr) {
return ((int) jArr[0]) & 1;
}
public static void squareN(long[] jArr, int i, long[] jArr2) {
long[] createExt64 = Nat256.createExt64();
implSquare(jArr, createExt64);
while (true) {
reduce(createExt64, jArr2);
i--;
if (i <= 0) {
return;
} else {
implSquare(jArr2, createExt64);
}
}
}
public static void squareAddToExt(long[] jArr, long[] jArr2) {
long[] createExt64 = Nat256.createExt64();
implSquare(jArr, createExt64);
addExt(jArr2, createExt64, jArr2);
}
public static void square(long[] jArr, long[] jArr2) {
long[] createExt64 = Nat256.createExt64();
implSquare(jArr, createExt64);
reduce(createExt64, jArr2);
}
public static void sqrt(long[] jArr, long[] jArr2) {
long unshuffle = Interleave.unshuffle(jArr[0]);
long unshuffle2 = Interleave.unshuffle(jArr[1]);
long j = (unshuffle >>> 32) | ((-4294967296L) & unshuffle2);
long unshuffle3 = Interleave.unshuffle(jArr[2]);
long j2 = jArr[3];
long j3 = unshuffle3 >>> 32;
jArr2[0] = ((unshuffle & KeyboardMap.kValueMask) | (unshuffle2 << 32)) ^ (j << 8);
jArr2[1] = ((((unshuffle3 & KeyboardMap.kValueMask) ^ (j2 << 32)) ^ (j3 << 8)) ^ (j >>> 56)) ^ (j << 33);
jArr2[2] = (j >>> 31) ^ ((unshuffle3 >>> 88) ^ (j3 << 33));
jArr2[3] = unshuffle3 >>> 63;
}
public static void reduce63(long[] jArr, int i) {
int i2 = i + 3;
long j = jArr[i2];
long j2 = j >>> M01;
jArr[i] = (j2 ^ (j2 << 15)) ^ jArr[i];
int i3 = i + 1;
jArr[i3] = jArr[i3] ^ (j >>> 50);
jArr[i2] = j & M01;
}
public static void reduce(long[] jArr, long[] jArr2) {
long j = jArr[0];
long j2 = jArr[1];
long j3 = jArr[2];
long j4 = jArr[3];
long j5 = jArr[4];
long j6 = jArr[5];
long j7 = jArr[6];
long j8 = j5 ^ (j7 >>> 50);
long j9 = (j4 ^ ((j7 >>> M01) ^ (j7 << 14))) ^ (j6 >>> 50);
long j10 = j9 >>> M01;
jArr2[0] = ((j ^ (j8 << 63)) ^ j10) ^ (j10 << 15);
jArr2[1] = (j9 >>> 50) ^ ((j2 ^ (j6 << 63)) ^ ((j8 >>> M01) ^ (j8 << 14)));
jArr2[2] = (((j7 << 63) ^ j3) ^ ((j6 >>> M01) ^ (j6 << 14))) ^ (j8 >>> 50);
jArr2[3] = M01 & j9;
}
public static void multiplyAddToExt(long[] jArr, long[] jArr2, long[] jArr3) {
long[] createExt64 = Nat256.createExt64();
implMultiply(jArr, jArr2, createExt64);
addExt(jArr3, createExt64, jArr3);
}
public static void multiply(long[] jArr, long[] jArr2, long[] jArr3) {
long[] createExt64 = Nat256.createExt64();
implMultiply(jArr, jArr2, createExt64);
reduce(createExt64, jArr3);
}
public static void invert(long[] jArr, long[] jArr2) {
if (Nat256.isZero64(jArr)) {
throw new IllegalStateException();
}
long[] create64 = Nat256.create64();
long[] create642 = Nat256.create64();
square(jArr, create64);
squareN(create64, 1, create642);
multiply(create64, create642, create64);
squareN(create642, 1, create642);
multiply(create64, create642, create64);
squareN(create64, 3, create642);
multiply(create64, create642, create64);
squareN(create64, 6, create642);
multiply(create64, create642, create64);
squareN(create64, 12, create642);
multiply(create64, create642, create64);
squareN(create64, 24, create642);
multiply(create64, create642, create64);
squareN(create64, 48, create642);
multiply(create64, create642, create64);
squareN(create64, 96, create642);
multiply(create64, create642, jArr2);
}
protected static void implSquare(long[] jArr, long[] jArr2) {
Interleave.expand64To128(jArr[0], jArr2, 0);
Interleave.expand64To128(jArr[1], jArr2, 2);
Interleave.expand64To128(jArr[2], jArr2, 4);
jArr2[6] = jArr[3] & M01;
}
protected static void implMulwAcc(long j, long j2, long[] jArr, int i) {
long j3 = j2 << M01;
long j4 = j3 ^ j2;
long j5 = j2 << 2;
long j6 = j4 << M01;
long[] jArr2 = {0, j2, j3, j4, j5, j5 ^ j2, j6, j6 ^ j2};
int i2 = (int) j;
long j7 = (jArr2[(i2 >>> 3) & 7] << 3) ^ jArr2[i2 & 7];
long j8 = 0;
int i3 = 36;
do {
int i4 = (int) (j >>> i3);
long j9 = (((jArr2[i4 & 7] ^ (jArr2[(i4 >>> 3) & 7] << 3)) ^ (jArr2[(i4 >>> 6) & 7] << 6)) ^ (jArr2[(i4 >>> 9) & 7] << 9)) ^ (jArr2[(i4 >>> 12) & 7] << 12);
j7 ^= j9 << i3;
j8 ^= j9 >>> (-i3);
i3 -= 15;
} while (i3 > 0);
jArr[i] = jArr[i] ^ (M49 & j7);
int i5 = i + 1;
jArr[i5] = jArr[i5] ^ ((j7 >>> 49) ^ (j8 << 15));
}
protected static void implMultiply(long[] jArr, long[] jArr2, long[] jArr3) {
long[] jArr4 = new long[4];
long[] jArr5 = new long[4];
implExpand(jArr, jArr4);
implExpand(jArr2, jArr5);
implMulwAcc(jArr4[0], jArr5[0], jArr3, 0);
implMulwAcc(jArr4[1], jArr5[1], jArr3, 1);
implMulwAcc(jArr4[2], jArr5[2], jArr3, 2);
implMulwAcc(jArr4[3], jArr5[3], jArr3, 3);
for (int i = 5; i > 0; i--) {
jArr3[i] = jArr3[i] ^ jArr3[i - 1];
}
implMulwAcc(jArr4[0] ^ jArr4[1], jArr5[0] ^ jArr5[1], jArr3, 1);
implMulwAcc(jArr4[2] ^ jArr4[3], jArr5[2] ^ jArr5[3], jArr3, 3);
for (int i2 = 7; i2 > 1; i2--) {
jArr3[i2] = jArr3[i2] ^ jArr3[i2 - 2];
}
long j = jArr4[0] ^ jArr4[2];
long j2 = jArr4[1] ^ jArr4[3];
long j3 = jArr5[0] ^ jArr5[2];
long j4 = jArr5[1] ^ jArr5[3];
implMulwAcc(j ^ j2, j3 ^ j4, jArr3, 3);
long[] jArr6 = new long[3];
implMulwAcc(j, j3, jArr6, 0);
implMulwAcc(j2, j4, jArr6, 1);
long j5 = jArr6[0];
long j6 = jArr6[1];
long j7 = jArr6[2];
jArr3[2] = jArr3[2] ^ j5;
jArr3[3] = (j5 ^ j6) ^ jArr3[3];
jArr3[4] = jArr3[4] ^ (j7 ^ j6);
jArr3[5] = jArr3[5] ^ j7;
implCompactExt(jArr3);
}
protected static void implExpand(long[] jArr, long[] jArr2) {
long j = jArr[0];
long j2 = jArr[1];
long j3 = jArr[2];
long j4 = jArr[3];
jArr2[0] = j & M49;
jArr2[1] = ((j >>> 49) ^ (j2 << 15)) & M49;
jArr2[2] = ((j2 >>> 34) ^ (j3 << 30)) & M49;
jArr2[3] = (j3 >>> 19) ^ (j4 << 45);
}
protected static void implCompactExt(long[] jArr) {
long j = jArr[0];
long j2 = jArr[1];
long j3 = jArr[2];
long j4 = jArr[3];
long j5 = jArr[4];
long j6 = jArr[5];
long j7 = jArr[6];
long j8 = jArr[7];
jArr[0] = j ^ (j2 << 49);
jArr[1] = (j2 >>> 15) ^ (j3 << 34);
jArr[2] = (j3 >>> 30) ^ (j4 << 19);
jArr[3] = ((j4 >>> 45) ^ (j5 << 4)) ^ (j6 << 53);
jArr[4] = ((j5 >>> 60) ^ (j7 << 38)) ^ (j6 >>> 11);
jArr[5] = (j7 >>> 26) ^ (j8 << 23);
jArr[6] = j8 >>> 41;
jArr[7] = 0;
}
public static long[] fromBigInteger(BigInteger bigInteger) {
long[] fromBigInteger64 = Nat256.fromBigInteger64(bigInteger);
reduce63(fromBigInteger64, 0);
return fromBigInteger64;
}
public static void addOne(long[] jArr, long[] jArr2) {
jArr2[0] = jArr[0] ^ M01;
jArr2[1] = jArr[1];
jArr2[2] = jArr[2];
jArr2[3] = jArr[3];
}
public static void addExt(long[] jArr, long[] jArr2, long[] jArr3) {
jArr3[0] = jArr[0] ^ jArr2[0];
jArr3[1] = jArr[1] ^ jArr2[1];
jArr3[2] = jArr[2] ^ jArr2[2];
jArr3[3] = jArr[3] ^ jArr2[3];
jArr3[4] = jArr[4] ^ jArr2[4];
jArr3[5] = jArr[5] ^ jArr2[5];
jArr3[6] = jArr2[6] ^ jArr[6];
}
public static void add(long[] jArr, long[] jArr2, long[] jArr3) {
jArr3[0] = jArr[0] ^ jArr2[0];
jArr3[1] = jArr[1] ^ jArr2[1];
jArr3[2] = jArr[2] ^ jArr2[2];
jArr3[3] = jArr2[3] ^ jArr[3];
}
}