62 lines
2.0 KiB
Java
62 lines
2.0 KiB
Java
|
package org.bouncycastle.pqc.math.linearalgebra;
|
||
|
|
||
|
import java.math.BigInteger;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public final class BigIntUtils {
|
||
|
public static byte[] toMinimalByteArray(BigInteger bigInteger) {
|
||
|
byte[] byteArray = bigInteger.toByteArray();
|
||
|
if (byteArray.length == 1 || (bigInteger.bitLength() & 7) != 0) {
|
||
|
return byteArray;
|
||
|
}
|
||
|
int bitLength = bigInteger.bitLength() >> 3;
|
||
|
byte[] bArr = new byte[bitLength];
|
||
|
System.arraycopy(byteArray, 1, bArr, 0, bitLength);
|
||
|
return bArr;
|
||
|
}
|
||
|
|
||
|
public static int[] toIntArrayModQ(int i, BigInteger[] bigIntegerArr) {
|
||
|
BigInteger valueOf = BigInteger.valueOf(i);
|
||
|
int[] iArr = new int[bigIntegerArr.length];
|
||
|
for (int i2 = 0; i2 < bigIntegerArr.length; i2++) {
|
||
|
iArr[i2] = bigIntegerArr[i2].mod(valueOf).intValue();
|
||
|
}
|
||
|
return iArr;
|
||
|
}
|
||
|
|
||
|
public static int[] toIntArray(BigInteger[] bigIntegerArr) {
|
||
|
int[] iArr = new int[bigIntegerArr.length];
|
||
|
for (int i = 0; i < bigIntegerArr.length; i++) {
|
||
|
iArr[i] = bigIntegerArr[i].intValue();
|
||
|
}
|
||
|
return iArr;
|
||
|
}
|
||
|
|
||
|
public static BigInteger[] subArray(BigInteger[] bigIntegerArr, int i, int i2) {
|
||
|
int i3 = i2 - i;
|
||
|
BigInteger[] bigIntegerArr2 = new BigInteger[i3];
|
||
|
System.arraycopy(bigIntegerArr, i, bigIntegerArr2, 0, i3);
|
||
|
return bigIntegerArr2;
|
||
|
}
|
||
|
|
||
|
public static void fill(BigInteger[] bigIntegerArr, BigInteger bigInteger) {
|
||
|
for (int length = bigIntegerArr.length - 1; length >= 0; length--) {
|
||
|
bigIntegerArr[length] = bigInteger;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static boolean equals(BigInteger[] bigIntegerArr, BigInteger[] bigIntegerArr2) {
|
||
|
if (bigIntegerArr.length != bigIntegerArr2.length) {
|
||
|
return false;
|
||
|
}
|
||
|
int i = 0;
|
||
|
for (int i2 = 0; i2 < bigIntegerArr.length; i2++) {
|
||
|
i |= bigIntegerArr[i2].compareTo(bigIntegerArr2[i2]);
|
||
|
}
|
||
|
return i == 0;
|
||
|
}
|
||
|
|
||
|
private BigIntUtils() {
|
||
|
}
|
||
|
}
|