251 lines
9.2 KiB
Java
251 lines
9.2 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.Nat192;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class SecT163Field {
|
||
|
private static final long M35 = 34359738367L;
|
||
|
private static final long M55 = 36028797018963967L;
|
||
|
private static final long[] ROOT_Z = {-5270498306774157648L, 5270498306774195053L, 19634136210L};
|
||
|
|
||
|
public static int trace(long[] jArr) {
|
||
|
return ((int) (jArr[0] ^ (jArr[2] >>> 29))) & 1;
|
||
|
}
|
||
|
|
||
|
public static void squareN(long[] jArr, int i, long[] jArr2) {
|
||
|
long[] createExt64 = Nat192.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 = Nat192.createExt64();
|
||
|
implSquare(jArr, createExt64);
|
||
|
addExt(jArr2, createExt64, jArr2);
|
||
|
}
|
||
|
|
||
|
public static void square(long[] jArr, long[] jArr2) {
|
||
|
long[] createExt64 = Nat192.createExt64();
|
||
|
implSquare(jArr, createExt64);
|
||
|
reduce(createExt64, 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 reduce29(long[] jArr, int i) {
|
||
|
int i2 = i + 2;
|
||
|
long j = jArr[i2];
|
||
|
long j2 = j >>> 35;
|
||
|
jArr[i] = (((j2 << 6) ^ ((j2 << 3) ^ j2)) ^ (j2 << 7)) ^ jArr[i];
|
||
|
jArr[i2] = j & M35;
|
||
|
}
|
||
|
|
||
|
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 = j4 ^ ((((j6 >>> 35) ^ (j6 >>> 32)) ^ (j6 >>> 29)) ^ (j6 >>> 28));
|
||
|
long j8 = (j3 ^ ((((j6 << 29) ^ (j6 << 32)) ^ (j6 << 35)) ^ (j6 << 36))) ^ ((j5 >>> 28) ^ (((j5 >>> 35) ^ (j5 >>> 32)) ^ (j5 >>> 29)));
|
||
|
long j9 = j8 >>> 35;
|
||
|
jArr2[0] = ((((j ^ ((((j7 << 29) ^ (j7 << 32)) ^ (j7 << 35)) ^ (j7 << 36))) ^ j9) ^ (j9 << 3)) ^ (j9 << 6)) ^ (j9 << 7);
|
||
|
jArr2[1] = (((((j5 << 29) ^ (j5 << 32)) ^ (j5 << 35)) ^ (j5 << 36)) ^ j2) ^ ((j7 >>> 28) ^ ((j7 >>> 29) ^ ((j7 >>> 35) ^ (j7 >>> 32))));
|
||
|
jArr2[2] = M35 & j8;
|
||
|
}
|
||
|
|
||
|
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);
|
||
|
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(create642, 3, create642);
|
||
|
multiply(create64, create642, create64);
|
||
|
squareN(create64, 9, create642);
|
||
|
multiply(create64, create642, create64);
|
||
|
squareN(create642, 9, create642);
|
||
|
multiply(create64, create642, create64);
|
||
|
squareN(create64, 27, create642);
|
||
|
multiply(create64, create642, create64);
|
||
|
squareN(create642, 27, create642);
|
||
|
multiply(create64, create642, create64);
|
||
|
squareN(create64, 81, 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);
|
||
|
jArr2[4] = Interleave.expand32to64((int) jArr[2]);
|
||
|
jArr2[5] = Interleave.expand8to16((int) (r0 >>> 32)) & 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};
|
||
|
long j7 = jArr2[((int) j) & 3];
|
||
|
long j8 = 0;
|
||
|
int i2 = 47;
|
||
|
do {
|
||
|
int i3 = (int) (j >>> i2);
|
||
|
long j9 = (jArr2[i3 & 7] ^ (jArr2[(i3 >>> 3) & 7] << 3)) ^ (jArr2[(i3 >>> 6) & 7] << 6);
|
||
|
j7 ^= j9 << i2;
|
||
|
j8 ^= j9 >>> (-i2);
|
||
|
i2 -= 9;
|
||
|
} while (i2 > 0);
|
||
|
jArr[i] = M55 & j7;
|
||
|
jArr[i + 1] = (j7 >>> 55) ^ (j8 << 9);
|
||
|
}
|
||
|
|
||
|
protected static void implMultiply(long[] jArr, long[] jArr2, long[] jArr3) {
|
||
|
long j = jArr[0];
|
||
|
long j2 = jArr[1];
|
||
|
long j3 = (jArr[2] << 18) ^ (j2 >>> 46);
|
||
|
long j4 = ((j2 << 9) ^ (j >>> 55)) & M55;
|
||
|
long j5 = j & M55;
|
||
|
long j6 = jArr2[0];
|
||
|
long j7 = jArr2[1];
|
||
|
long j8 = (j7 >>> 46) ^ (jArr2[2] << 18);
|
||
|
long j9 = ((j6 >>> 55) ^ (j7 << 9)) & M55;
|
||
|
long j10 = j6 & M55;
|
||
|
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 >>> 55);
|
||
|
long j27 = (j22 ^ j18) ^ (j26 >>> 55);
|
||
|
long j28 = ((j24 & M55) >>> 1) ^ ((j26 & 1) << 54);
|
||
|
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)) & M55;
|
||
|
long j35 = (((j26 & M55) >>> 1) ^ ((1 & j27) << 54)) ^ (j34 >>> 54);
|
||
|
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)) & M55;
|
||
|
long j42 = (j27 >>> 1) ^ (j41 >>> 54);
|
||
|
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 << 55);
|
||
|
jArr[1] = (j2 >>> 9) ^ (j3 << 46);
|
||
|
jArr[2] = (j3 >>> 18) ^ (j4 << 37);
|
||
|
jArr[3] = (j4 >>> 27) ^ (j5 << 28);
|
||
|
jArr[4] = (j5 >>> 36) ^ (j6 << 19);
|
||
|
jArr[5] = j6 >>> 45;
|
||
|
}
|
||
|
|
||
|
public static long[] fromBigInteger(BigInteger bigInteger) {
|
||
|
long[] fromBigInteger64 = Nat192.fromBigInteger64(bigInteger);
|
||
|
reduce29(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] = jArr[4] ^ jArr2[4];
|
||
|
jArr3[5] = jArr2[5] ^ jArr[5];
|
||
|
}
|
||
|
|
||
|
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];
|
||
|
}
|
||
|
}
|