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

175 lines
6.3 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.math.ec.custom.sec;
import java.math.BigInteger;
import org.bouncycastle.math.ec.ECFieldElement;
import org.bouncycastle.math.raw.Mod;
import org.bouncycastle.math.raw.Nat192;
import org.bouncycastle.util.Arrays;
/* loaded from: classes6.dex */
public class SecP192K1FieldElement extends ECFieldElement {
public static final BigInteger Q = SecP192K1Curve.q;
protected int[] x;
@Override // org.bouncycastle.math.ec.ECFieldElement
public BigInteger toBigInteger() {
return Nat192.toBigInteger(this.x);
}
@Override // org.bouncycastle.math.ec.ECFieldElement
public boolean testBitZero() {
return Nat192.getBit(this.x, 0) == 1;
}
@Override // org.bouncycastle.math.ec.ECFieldElement
public ECFieldElement subtract(ECFieldElement eCFieldElement) {
int[] create = Nat192.create();
SecP192K1Field.subtract(this.x, ((SecP192K1FieldElement) eCFieldElement).x, create);
return new SecP192K1FieldElement(create);
}
@Override // org.bouncycastle.math.ec.ECFieldElement
public ECFieldElement square() {
int[] create = Nat192.create();
SecP192K1Field.square(this.x, create);
return new SecP192K1FieldElement(create);
}
@Override // org.bouncycastle.math.ec.ECFieldElement
public ECFieldElement sqrt() {
int[] iArr = this.x;
if (Nat192.isZero(iArr) || Nat192.isOne(iArr)) {
return this;
}
int[] create = Nat192.create();
SecP192K1Field.square(iArr, create);
SecP192K1Field.multiply(create, iArr, create);
int[] create2 = Nat192.create();
SecP192K1Field.square(create, create2);
SecP192K1Field.multiply(create2, iArr, create2);
int[] create3 = Nat192.create();
SecP192K1Field.squareN(create2, 3, create3);
SecP192K1Field.multiply(create3, create2, create3);
SecP192K1Field.squareN(create3, 2, create3);
SecP192K1Field.multiply(create3, create, create3);
SecP192K1Field.squareN(create3, 8, create);
SecP192K1Field.multiply(create, create3, create);
SecP192K1Field.squareN(create, 3, create3);
SecP192K1Field.multiply(create3, create2, create3);
int[] create4 = Nat192.create();
SecP192K1Field.squareN(create3, 16, create4);
SecP192K1Field.multiply(create4, create, create4);
SecP192K1Field.squareN(create4, 35, create);
SecP192K1Field.multiply(create, create4, create);
SecP192K1Field.squareN(create, 70, create4);
SecP192K1Field.multiply(create4, create, create4);
SecP192K1Field.squareN(create4, 19, create);
SecP192K1Field.multiply(create, create3, create);
SecP192K1Field.squareN(create, 20, create);
SecP192K1Field.multiply(create, create3, create);
SecP192K1Field.squareN(create, 4, create);
SecP192K1Field.multiply(create, create2, create);
SecP192K1Field.squareN(create, 6, create);
SecP192K1Field.multiply(create, create2, create);
SecP192K1Field.square(create, create);
SecP192K1Field.square(create, create2);
if (Nat192.eq(iArr, create2)) {
return new SecP192K1FieldElement(create);
}
return null;
}
@Override // org.bouncycastle.math.ec.ECFieldElement
public ECFieldElement negate() {
int[] create = Nat192.create();
SecP192K1Field.negate(this.x, create);
return new SecP192K1FieldElement(create);
}
@Override // org.bouncycastle.math.ec.ECFieldElement
public ECFieldElement multiply(ECFieldElement eCFieldElement) {
int[] create = Nat192.create();
SecP192K1Field.multiply(this.x, ((SecP192K1FieldElement) eCFieldElement).x, create);
return new SecP192K1FieldElement(create);
}
@Override // org.bouncycastle.math.ec.ECFieldElement
public boolean isZero() {
return Nat192.isZero(this.x);
}
@Override // org.bouncycastle.math.ec.ECFieldElement
public boolean isOne() {
return Nat192.isOne(this.x);
}
@Override // org.bouncycastle.math.ec.ECFieldElement
public ECFieldElement invert() {
int[] create = Nat192.create();
Mod.invert(SecP192K1Field.P, this.x, create);
return new SecP192K1FieldElement(create);
}
public int hashCode() {
return Q.hashCode() ^ Arrays.hashCode(this.x, 0, 6);
}
@Override // org.bouncycastle.math.ec.ECFieldElement
public int getFieldSize() {
return Q.bitLength();
}
@Override // org.bouncycastle.math.ec.ECFieldElement
public String getFieldName() {
return "SecP192K1Field";
}
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof SecP192K1FieldElement) {
return Nat192.eq(this.x, ((SecP192K1FieldElement) obj).x);
}
return false;
}
@Override // org.bouncycastle.math.ec.ECFieldElement
public ECFieldElement divide(ECFieldElement eCFieldElement) {
int[] create = Nat192.create();
Mod.invert(SecP192K1Field.P, ((SecP192K1FieldElement) eCFieldElement).x, create);
SecP192K1Field.multiply(create, this.x, create);
return new SecP192K1FieldElement(create);
}
@Override // org.bouncycastle.math.ec.ECFieldElement
public ECFieldElement addOne() {
int[] create = Nat192.create();
SecP192K1Field.addOne(this.x, create);
return new SecP192K1FieldElement(create);
}
@Override // org.bouncycastle.math.ec.ECFieldElement
public ECFieldElement add(ECFieldElement eCFieldElement) {
int[] create = Nat192.create();
SecP192K1Field.add(this.x, ((SecP192K1FieldElement) eCFieldElement).x, create);
return new SecP192K1FieldElement(create);
}
/* JADX INFO: Access modifiers changed from: protected */
public SecP192K1FieldElement(int[] iArr) {
this.x = iArr;
}
public SecP192K1FieldElement(BigInteger bigInteger) {
if (bigInteger == null || bigInteger.signum() < 0 || bigInteger.compareTo(Q) >= 0) {
throw new IllegalArgumentException("x value invalid for SecP192K1FieldElement");
}
this.x = SecP192K1Field.fromBigInteger(bigInteger);
}
public SecP192K1FieldElement() {
this.x = Nat192.create();
}
}