what-the-bank/sources/org/bouncycastle/pqc/math/linearalgebra/LittleEndianConversions.java

102 lines
3.4 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.pqc.math.linearalgebra;
import com.google.common.primitives.UnsignedBytes;
/* loaded from: classes6.dex */
public final class LittleEndianConversions {
public static int[] toIntArray(byte[] bArr) {
int length = (bArr.length + 3) / 4;
int length2 = bArr.length & 3;
int[] iArr = new int[length];
int i = 0;
int i2 = 0;
while (i <= length - 2) {
iArr[i] = OS2IP(bArr, i2);
i++;
i2 += 4;
}
int i3 = length - 1;
if (length2 != 0) {
iArr[i3] = OS2IP(bArr, i2, length2);
} else {
iArr[i3] = OS2IP(bArr, i2);
}
return iArr;
}
public static byte[] toByteArray(int[] iArr, int i) {
int length = iArr.length;
byte[] bArr = new byte[i];
int i2 = 0;
int i3 = 0;
while (i2 <= length - 2) {
I2OSP(iArr[i2], bArr, i3);
i2++;
i3 += 4;
}
I2OSP(iArr[length - 1], bArr, i3, i - i3);
return bArr;
}
public static long OS2LIP(byte[] bArr, int i) {
return (bArr[i] & UnsignedBytes.MAX_VALUE) | ((bArr[i + 1] & UnsignedBytes.MAX_VALUE) << 8) | ((bArr[i + 2] & UnsignedBytes.MAX_VALUE) << 16) | ((bArr[i + 3] & 255) << 24) | ((bArr[i + 4] & 255) << 32) | ((bArr[i + 5] & 255) << 40) | ((bArr[i + 6] & 255) << 48) | ((bArr[i + 7] & 255) << 56);
}
public static int OS2IP(byte[] bArr, int i, int i2) {
int i3 = 0;
for (int i4 = i2 - 1; i4 >= 0; i4--) {
i3 |= (bArr[i + i4] & 255) << (i4 << 3);
}
return i3;
}
public static int OS2IP(byte[] bArr, int i) {
byte b = bArr[i];
return ((bArr[i + 3] & UnsignedBytes.MAX_VALUE) << 24) | ((bArr[i + 1] & UnsignedBytes.MAX_VALUE) << 8) | (b & UnsignedBytes.MAX_VALUE) | ((bArr[i + 2] & UnsignedBytes.MAX_VALUE) << 16);
}
public static int OS2IP(byte[] bArr) {
return ((bArr[3] & UnsignedBytes.MAX_VALUE) << 24) | (bArr[0] & UnsignedBytes.MAX_VALUE) | ((bArr[1] & UnsignedBytes.MAX_VALUE) << 8) | ((bArr[2] & UnsignedBytes.MAX_VALUE) << 16);
}
public static byte[] I2OSP(long j) {
return new byte[]{(byte) j, (byte) (j >>> 8), (byte) (j >>> 16), (byte) (j >>> 24), (byte) (j >>> 32), (byte) (j >>> 40), (byte) (j >>> 48), (byte) (j >>> 56)};
}
public static byte[] I2OSP(int i) {
return new byte[]{(byte) i, (byte) (i >>> 8), (byte) (i >>> 16), (byte) (i >>> 24)};
}
public static void I2OSP(long j, byte[] bArr, int i) {
bArr[i] = (byte) j;
bArr[i + 1] = (byte) (j >>> 8);
bArr[i + 2] = (byte) (j >>> 16);
bArr[i + 3] = (byte) (j >>> 24);
bArr[i + 4] = (byte) (j >>> 32);
bArr[i + 5] = (byte) (j >>> 40);
bArr[i + 6] = (byte) (j >>> 48);
bArr[i + 7] = (byte) (j >>> 56);
}
public static void I2OSP(int i, byte[] bArr, int i2, int i3) {
while (true) {
i3--;
if (i3 < 0) {
return;
} else {
bArr[i2 + i3] = (byte) (i >>> (i3 << 3));
}
}
}
public static void I2OSP(int i, byte[] bArr, int i2) {
bArr[i2] = (byte) i;
bArr[i2 + 1] = (byte) (i >>> 8);
bArr[i2 + 2] = (byte) (i >>> 16);
bArr[i2 + 3] = (byte) (i >>> 24);
}
private LittleEndianConversions() {
}
}