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

141 lines
4.5 KiB
Java
Raw Permalink 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 class GF2mVector extends Vector {
private GF2mField field;
private int[] vector;
@Override // org.bouncycastle.pqc.math.linearalgebra.Vector
public String toString() {
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < this.vector.length; i++) {
for (int i2 = 0; i2 < this.field.getDegree(); i2++) {
stringBuffer.append(((1 << (i2 & 31)) & this.vector[i]) != 0 ? '1' : '0');
}
stringBuffer.append(' ');
}
return stringBuffer.toString();
}
@Override // org.bouncycastle.pqc.math.linearalgebra.Vector
public Vector multiply(Permutation permutation) {
int[] vector = permutation.getVector();
if (this.length != vector.length) {
throw new ArithmeticException("permutation size and vector size mismatch");
}
int[] iArr = new int[this.length];
for (int i = 0; i < vector.length; i++) {
iArr[i] = this.vector[vector[i]];
}
return new GF2mVector(this.field, iArr);
}
@Override // org.bouncycastle.pqc.math.linearalgebra.Vector
public boolean isZero() {
for (int length = this.vector.length - 1; length >= 0; length--) {
if (this.vector[length] != 0) {
return false;
}
}
return true;
}
@Override // org.bouncycastle.pqc.math.linearalgebra.Vector
public int hashCode() {
return (this.field.hashCode() * 31) + this.vector.hashCode();
}
public int[] getIntArrayForm() {
return IntUtils.clone(this.vector);
}
public GF2mField getField() {
return this.field;
}
@Override // org.bouncycastle.pqc.math.linearalgebra.Vector
public byte[] getEncoded() {
int i = 8;
int i2 = 1;
while (this.field.getDegree() > i) {
i2++;
i += 8;
}
byte[] bArr = new byte[this.vector.length * i2];
int i3 = 0;
for (int i4 = 0; i4 < this.vector.length; i4++) {
int i5 = 0;
while (i5 < i) {
bArr[i3] = (byte) (this.vector[i4] >>> i5);
i5 += 8;
i3++;
}
}
return bArr;
}
@Override // org.bouncycastle.pqc.math.linearalgebra.Vector
public boolean equals(Object obj) {
if (!(obj instanceof GF2mVector)) {
return false;
}
GF2mVector gF2mVector = (GF2mVector) obj;
if (this.field.equals(gF2mVector.field)) {
return IntUtils.equals(this.vector, gF2mVector.vector);
}
return false;
}
@Override // org.bouncycastle.pqc.math.linearalgebra.Vector
public Vector add(Vector vector) {
throw new RuntimeException("not implemented");
}
public GF2mVector(GF2mVector gF2mVector) {
this.field = new GF2mField(gF2mVector.field);
this.length = gF2mVector.length;
this.vector = IntUtils.clone(gF2mVector.vector);
}
public GF2mVector(GF2mField gF2mField, int[] iArr) {
this.field = gF2mField;
this.length = iArr.length;
for (int length = iArr.length - 1; length >= 0; length--) {
if (!gF2mField.isElementOfThisField(iArr[length])) {
throw new ArithmeticException("Element array is not specified over the given finite field.");
}
}
this.vector = IntUtils.clone(iArr);
}
public GF2mVector(GF2mField gF2mField, byte[] bArr) {
this.field = new GF2mField(gF2mField);
int i = 8;
int i2 = 1;
while (gF2mField.getDegree() > i) {
i2++;
i += 8;
}
if (bArr.length % i2 != 0) {
throw new IllegalArgumentException("Byte array is not an encoded vector over the given finite field.");
}
this.length = bArr.length / i2;
this.vector = new int[this.length];
int i3 = 0;
for (int i4 = 0; i4 < this.vector.length; i4++) {
int i5 = 0;
while (i5 < i) {
int[] iArr = this.vector;
iArr[i4] = iArr[i4] | ((bArr[i3] & UnsignedBytes.MAX_VALUE) << i5);
i5 += 8;
i3++;
}
if (!gF2mField.isElementOfThisField(this.vector[i4])) {
throw new IllegalArgumentException("Byte array is not an encoded vector over the given finite field.");
}
}
}
}