161 lines
5.5 KiB
Java
161 lines
5.5 KiB
Java
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.Nat256;
|
|
import org.bouncycastle.util.Arrays;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class SecP256R1FieldElement extends ECFieldElement {
|
|
public static final BigInteger Q = SecP256R1Curve.q;
|
|
protected int[] x;
|
|
|
|
@Override // org.bouncycastle.math.ec.ECFieldElement
|
|
public BigInteger toBigInteger() {
|
|
return Nat256.toBigInteger(this.x);
|
|
}
|
|
|
|
@Override // org.bouncycastle.math.ec.ECFieldElement
|
|
public boolean testBitZero() {
|
|
return Nat256.getBit(this.x, 0) == 1;
|
|
}
|
|
|
|
@Override // org.bouncycastle.math.ec.ECFieldElement
|
|
public ECFieldElement subtract(ECFieldElement eCFieldElement) {
|
|
int[] create = Nat256.create();
|
|
SecP256R1Field.subtract(this.x, ((SecP256R1FieldElement) eCFieldElement).x, create);
|
|
return new SecP256R1FieldElement(create);
|
|
}
|
|
|
|
@Override // org.bouncycastle.math.ec.ECFieldElement
|
|
public ECFieldElement square() {
|
|
int[] create = Nat256.create();
|
|
SecP256R1Field.square(this.x, create);
|
|
return new SecP256R1FieldElement(create);
|
|
}
|
|
|
|
@Override // org.bouncycastle.math.ec.ECFieldElement
|
|
public ECFieldElement sqrt() {
|
|
int[] iArr = this.x;
|
|
if (Nat256.isZero(iArr) || Nat256.isOne(iArr)) {
|
|
return this;
|
|
}
|
|
int[] create = Nat256.create();
|
|
int[] create2 = Nat256.create();
|
|
SecP256R1Field.square(iArr, create);
|
|
SecP256R1Field.multiply(create, iArr, create);
|
|
SecP256R1Field.squareN(create, 2, create2);
|
|
SecP256R1Field.multiply(create2, create, create2);
|
|
SecP256R1Field.squareN(create2, 4, create);
|
|
SecP256R1Field.multiply(create, create2, create);
|
|
SecP256R1Field.squareN(create, 8, create2);
|
|
SecP256R1Field.multiply(create2, create, create2);
|
|
SecP256R1Field.squareN(create2, 16, create);
|
|
SecP256R1Field.multiply(create, create2, create);
|
|
SecP256R1Field.squareN(create, 32, create);
|
|
SecP256R1Field.multiply(create, iArr, create);
|
|
SecP256R1Field.squareN(create, 96, create);
|
|
SecP256R1Field.multiply(create, iArr, create);
|
|
SecP256R1Field.squareN(create, 94, create);
|
|
SecP256R1Field.square(create, create2);
|
|
if (Nat256.eq(iArr, create2)) {
|
|
return new SecP256R1FieldElement(create);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override // org.bouncycastle.math.ec.ECFieldElement
|
|
public ECFieldElement negate() {
|
|
int[] create = Nat256.create();
|
|
SecP256R1Field.negate(this.x, create);
|
|
return new SecP256R1FieldElement(create);
|
|
}
|
|
|
|
@Override // org.bouncycastle.math.ec.ECFieldElement
|
|
public ECFieldElement multiply(ECFieldElement eCFieldElement) {
|
|
int[] create = Nat256.create();
|
|
SecP256R1Field.multiply(this.x, ((SecP256R1FieldElement) eCFieldElement).x, create);
|
|
return new SecP256R1FieldElement(create);
|
|
}
|
|
|
|
@Override // org.bouncycastle.math.ec.ECFieldElement
|
|
public boolean isZero() {
|
|
return Nat256.isZero(this.x);
|
|
}
|
|
|
|
@Override // org.bouncycastle.math.ec.ECFieldElement
|
|
public boolean isOne() {
|
|
return Nat256.isOne(this.x);
|
|
}
|
|
|
|
@Override // org.bouncycastle.math.ec.ECFieldElement
|
|
public ECFieldElement invert() {
|
|
int[] create = Nat256.create();
|
|
Mod.invert(SecP256R1Field.P, this.x, create);
|
|
return new SecP256R1FieldElement(create);
|
|
}
|
|
|
|
public int hashCode() {
|
|
return Q.hashCode() ^ Arrays.hashCode(this.x, 0, 8);
|
|
}
|
|
|
|
@Override // org.bouncycastle.math.ec.ECFieldElement
|
|
public int getFieldSize() {
|
|
return Q.bitLength();
|
|
}
|
|
|
|
@Override // org.bouncycastle.math.ec.ECFieldElement
|
|
public String getFieldName() {
|
|
return "SecP256R1Field";
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (obj == this) {
|
|
return true;
|
|
}
|
|
if (obj instanceof SecP256R1FieldElement) {
|
|
return Nat256.eq(this.x, ((SecP256R1FieldElement) obj).x);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override // org.bouncycastle.math.ec.ECFieldElement
|
|
public ECFieldElement divide(ECFieldElement eCFieldElement) {
|
|
int[] create = Nat256.create();
|
|
Mod.invert(SecP256R1Field.P, ((SecP256R1FieldElement) eCFieldElement).x, create);
|
|
SecP256R1Field.multiply(create, this.x, create);
|
|
return new SecP256R1FieldElement(create);
|
|
}
|
|
|
|
@Override // org.bouncycastle.math.ec.ECFieldElement
|
|
public ECFieldElement addOne() {
|
|
int[] create = Nat256.create();
|
|
SecP256R1Field.addOne(this.x, create);
|
|
return new SecP256R1FieldElement(create);
|
|
}
|
|
|
|
@Override // org.bouncycastle.math.ec.ECFieldElement
|
|
public ECFieldElement add(ECFieldElement eCFieldElement) {
|
|
int[] create = Nat256.create();
|
|
SecP256R1Field.add(this.x, ((SecP256R1FieldElement) eCFieldElement).x, create);
|
|
return new SecP256R1FieldElement(create);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: protected */
|
|
public SecP256R1FieldElement(int[] iArr) {
|
|
this.x = iArr;
|
|
}
|
|
|
|
public SecP256R1FieldElement(BigInteger bigInteger) {
|
|
if (bigInteger == null || bigInteger.signum() < 0 || bigInteger.compareTo(Q) >= 0) {
|
|
throw new IllegalArgumentException("x value invalid for SecP256R1FieldElement");
|
|
}
|
|
this.x = SecP256R1Field.fromBigInteger(bigInteger);
|
|
}
|
|
|
|
public SecP256R1FieldElement() {
|
|
this.x = Nat256.create();
|
|
}
|
|
}
|