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

250 lines
9.0 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.Nat;
import org.bouncycastle.math.raw.Nat192;
/* loaded from: classes6.dex */
public class SecT131Field {
private static final long M03 = 7;
private static final long M44 = 17592186044415L;
private static final long[] ROOT_Z = {2791191049453778211L, 2791191049453778402L, 6};
public static int trace(long[] jArr) {
return ((int) ((jArr[0] ^ (jArr[1] >>> 59)) ^ (jArr[2] >>> 1))) & 1;
}
public static void squareN(long[] jArr, int i, long[] jArr2) {
long[] create64 = Nat.create64(5);
implSquare(jArr, create64);
while (true) {
reduce(create64, jArr2);
i--;
if (i <= 0) {
return;
} else {
implSquare(jArr2, create64);
}
}
}
public static void squareAddToExt(long[] jArr, long[] jArr2) {
long[] create64 = Nat.create64(5);
implSquare(jArr, create64);
addExt(jArr2, create64, jArr2);
}
public static void square(long[] jArr, long[] jArr2) {
long[] create64 = Nat.create64(5);
implSquare(jArr, create64);
reduce(create64, jArr2);
}
public static void sqrt(long[] jArr, long[] jArr2) {
long[] create64 = Nat192.create64();
long unshuffle = Interleave.unshuffle(jArr[0]);
long unshuffle2 = Interleave.unshuffle(jArr[1]);
create64[0] = (unshuffle >>> 32) | ((-4294967296L) & unshuffle2);
long unshuffle3 = Interleave.unshuffle(jArr[2]);
create64[1] = unshuffle3 >>> 32;
multiply(create64, ROOT_Z, jArr2);
jArr2[0] = ((unshuffle & KeyboardMap.kValueMask) | (unshuffle2 << 32)) ^ jArr2[0];
jArr2[1] = jArr2[1] ^ (unshuffle3 & KeyboardMap.kValueMask);
}
public static void reduce61(long[] jArr, int i) {
int i2 = i + 2;
long j = jArr[i2];
long j2 = j >>> 3;
jArr[i] = (((j2 << 3) ^ ((j2 << 2) ^ j2)) ^ (j2 << 8)) ^ jArr[i];
int i3 = i + 1;
jArr[i3] = jArr[i3] ^ (j >>> 59);
jArr[i2] = j & M03;
}
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 = j4 ^ (j5 >>> 59);
long j7 = (j3 ^ ((((j5 >>> 3) ^ (j5 >>> 1)) ^ j5) ^ (j5 << 5))) ^ (j6 >>> 59);
long j8 = j7 >>> 3;
jArr2[0] = ((((j ^ ((j6 << 61) ^ (j6 << 63))) ^ j8) ^ (j8 << 2)) ^ (j8 << 3)) ^ (j8 << 8);
jArr2[1] = (j7 >>> 59) ^ ((j2 ^ ((j5 << 63) ^ (j5 << 61))) ^ ((j6 << 5) ^ (((j6 >>> 3) ^ (j6 >>> 1)) ^ j6)));
jArr2[2] = M03 & j7;
}
public static void multiplyAddToExt(long[] jArr, long[] jArr2, long[] jArr3) {
long[] createExt64 = Nat192.createExt64();
implMultiply(jArr, jArr2, createExt64);
addExt(jArr3, createExt64, jArr3);
}
public static void multiply(long[] jArr, long[] jArr2, long[] jArr3) {
long[] createExt64 = Nat192.createExt64();
implMultiply(jArr, jArr2, createExt64);
reduce(createExt64, jArr3);
}
public static void invert(long[] jArr, long[] jArr2) {
if (Nat192.isZero64(jArr)) {
throw new IllegalStateException();
}
long[] create64 = Nat192.create64();
long[] create642 = Nat192.create64();
square(jArr, create64);
multiply(create64, jArr, create64);
squareN(create64, 2, create642);
multiply(create642, create64, create642);
squareN(create642, 4, create64);
multiply(create64, create642, create64);
squareN(create64, 8, create642);
multiply(create642, create64, create642);
squareN(create642, 16, create64);
multiply(create64, create642, create64);
squareN(create64, 32, create642);
multiply(create642, create64, create642);
square(create642, create642);
multiply(create642, jArr, create642);
squareN(create642, 65, create64);
multiply(create64, create642, create64);
square(create64, jArr2);
}
protected static void implSquare(long[] jArr, long[] jArr2) {
Interleave.expand64To128(jArr[0], jArr2, 0);
Interleave.expand64To128(jArr[1], jArr2, 2);
jArr2[4] = Interleave.expand8to16((int) jArr[2]) & KeyboardMap.kValueMask;
}
protected static void implMulw(long j, long j2, long[] jArr, int i) {
long j3 = j2 << 1;
long j4 = j3 ^ j2;
long j5 = j2 << 2;
long j6 = j4 << 1;
long[] jArr2 = {0, j2, j3, j4, j5, j5 ^ j2, j6, j6 ^ j2};
int i2 = (int) j;
long j7 = (jArr2[(i2 >>> 6) & 7] << 6) ^ (jArr2[i2 & 7] ^ (jArr2[(i2 >>> 3) & 7] << 3));
long j8 = 0;
int i3 = 33;
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);
j7 ^= j9 << i3;
j8 ^= j9 >>> (-i3);
i3 -= 12;
} while (i3 > 0);
jArr[i] = M44 & j7;
jArr[i + 1] = (j7 >>> 44) ^ (j8 << 20);
}
protected static void implMultiply(long[] jArr, long[] jArr2, long[] jArr3) {
long j = jArr[0];
long j2 = jArr[1];
long j3 = ((jArr[2] << 40) ^ (j2 >>> 24)) & M44;
long j4 = ((j2 << 20) ^ (j >>> 44)) & M44;
long j5 = j & M44;
long j6 = jArr2[0];
long j7 = jArr2[1];
long j8 = ((j7 >>> 24) ^ (jArr2[2] << 40)) & M44;
long j9 = ((j6 >>> 44) ^ (j7 << 20)) & M44;
long j10 = j6 & M44;
long[] jArr4 = new long[10];
implMulw(j5, j10, jArr4, 0);
implMulw(j3, j8, jArr4, 2);
long j11 = (j5 ^ j4) ^ j3;
long j12 = (j10 ^ j9) ^ j8;
implMulw(j11, j12, jArr4, 4);
long j13 = (j4 << 1) ^ (j3 << 2);
long j14 = (j9 << 1) ^ (j8 << 2);
implMulw(j5 ^ j13, j10 ^ j14, jArr4, 6);
implMulw(j11 ^ j13, j12 ^ j14, jArr4, 8);
long j15 = jArr4[6];
long j16 = jArr4[8] ^ j15;
long j17 = jArr4[7];
long j18 = jArr4[9] ^ j17;
long j19 = jArr4[0];
long j20 = jArr4[1];
long j21 = (j20 ^ j19) ^ jArr4[4];
long j22 = j20 ^ jArr4[5];
long j23 = jArr4[2];
long j24 = ((((j16 << 1) ^ j15) ^ j19) ^ (j23 << 4)) ^ (j23 << 1);
long j25 = jArr4[3];
long j26 = (((j21 ^ ((j16 ^ (j18 << 1)) ^ j17)) ^ (j25 << 4)) ^ (j25 << 1)) ^ (j24 >>> 44);
long j27 = (j22 ^ j18) ^ (j26 >>> 44);
long j28 = ((j24 & M44) >>> 1) ^ ((j26 & 1) << 43);
long j29 = j28 ^ (j28 << 1);
long j30 = j29 ^ (j29 << 2);
long j31 = j30 ^ (j30 << 4);
long j32 = j31 ^ (j31 << 8);
long j33 = j32 ^ (j32 << 16);
long j34 = (j33 ^ (j33 << 32)) & M44;
long j35 = (((j26 & M44) >>> 1) ^ ((1 & j27) << 43)) ^ (j34 >>> 43);
long j36 = j35 ^ (j35 << 1);
long j37 = j36 ^ (j36 << 2);
long j38 = j37 ^ (j37 << 4);
long j39 = j38 ^ (j38 << 8);
long j40 = j39 ^ (j39 << 16);
long j41 = (j40 ^ (j40 << 32)) & M44;
long j42 = (j27 >>> 1) ^ (j41 >>> 43);
long j43 = j42 ^ (j42 << 1);
long j44 = j43 ^ (j43 << 2);
long j45 = j44 ^ (j44 << 4);
long j46 = j45 ^ (j45 << 8);
long j47 = j46 ^ (j46 << 16);
long j48 = j47 ^ (j47 << 32);
jArr3[0] = j19;
jArr3[1] = (j21 ^ j34) ^ j23;
jArr3[2] = ((j22 ^ j41) ^ j34) ^ j25;
jArr3[3] = j48 ^ j41;
jArr3[4] = jArr4[2] ^ j48;
jArr3[5] = jArr4[3];
implCompactExt(jArr3);
}
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];
jArr[0] = j ^ (j2 << 44);
jArr[1] = (j2 >>> 20) ^ (j3 << 24);
jArr[2] = ((j3 >>> 40) ^ (j4 << 4)) ^ (j5 << 48);
jArr[3] = ((j4 >>> 60) ^ (j6 << 28)) ^ (j5 >>> 16);
jArr[4] = j6 >>> 36;
jArr[5] = 0;
}
public static long[] fromBigInteger(BigInteger bigInteger) {
long[] fromBigInteger64 = Nat192.fromBigInteger64(bigInteger);
reduce61(fromBigInteger64, 0);
return fromBigInteger64;
}
public static void addOne(long[] jArr, long[] jArr2) {
jArr2[0] = jArr[0] ^ 1;
jArr2[1] = jArr[1];
jArr2[2] = jArr[2];
}
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] = jArr2[4] ^ jArr[4];
}
public static void add(long[] jArr, long[] jArr2, long[] jArr3) {
jArr3[0] = jArr[0] ^ jArr2[0];
jArr3[1] = jArr[1] ^ jArr2[1];
jArr3[2] = jArr2[2] ^ jArr[2];
}
}