public ECFieldElement fromBigInteger(BigInteger x) { return new SecP224R1FieldElement(x); }
/** * return a sqrt root - the routine verifies that the calculation returns the right value - if * none exists it returns null. */ public ECFieldElement sqrt() { int[] c = this.x; if (Nat224.isZero(c) || Nat224.isOne(c)) { return this; } int[] nc = Nat224.create(); SecP224R1Field.negate(c, nc); int[] r = Mod.random(SecP224R1Field.P); int[] t = Nat224.create(); if (!isSquare(c)) { return null; } while (!trySqrt(nc, r, t)) { SecP224R1Field.addOne(r, r); } SecP224R1Field.square(t, r); return Nat224.eq(c, r) ? new SecP224R1FieldElement(t) : null; }
if (Y1.isZero()) SecP224R1Field.square(Y1Squared, T); boolean Z1IsOne = Z1.isOne(); SecP224R1Field.reduce32(c, t1); SecP224R1FieldElement X3 = new SecP224R1FieldElement(T); SecP224R1Field.square(M, X3.x); SecP224R1Field.subtract(X3.x, S, X3.x); SecP224R1Field.subtract(X3.x, S, X3.x); SecP224R1FieldElement Y3 = new SecP224R1FieldElement(S); SecP224R1Field.subtract(S, X3.x, Y3.x); SecP224R1Field.multiply(Y3.x, M, Y3.x); SecP224R1Field.subtract(Y3.x, t1, Y3.x); SecP224R1FieldElement Z3 = new SecP224R1FieldElement(M); SecP224R1Field.twice(Y1.x, Z3.x); if (!Z1IsOne)
private static void RP(int[] nc, int[] d1, int[] e1, int[] f1, int[] t) { Nat224.copy(nc, f1); int[] d0 = Nat224.create(); int[] e0 = Nat224.create(); for (int i = 0; i < 7; ++i) { Nat224.copy(d1, d0); Nat224.copy(e1, e0); int j = 1 << i; while (--j >= 0) { RS(d1, e1, f1, t); } RM(nc, d0, e0, d1, e1, f1, t); } }
private static boolean trySqrt(int[] nc, int[] r, int[] t) { int[] d1 = Nat224.create(); Nat224.copy(r, d1); int[] e1 = Nat224.create(); e1[0] = 1; int[] f1 = Nat224.create(); RP(nc, d1, e1, f1, t); int[] d0 = Nat224.create(); int[] e0 = Nat224.create(); for (int k = 1; k < 96; ++k) { Nat224.copy(d1, d0); Nat224.copy(e1, e0); RS(d1, e1, f1, t); if (Nat224.isZero(d1)) { Mod.invert(SecP224R1Field.P, e0, t); SecP224R1Field.multiply(t, d0, t); return true; } } return false; } }
int[] t4 = Nat224.create(); boolean Z1IsOne = Z1.isOne(); int[] U2, S2; if (Z1IsOne) boolean Z2IsOne = Z2.isOne(); int[] U1, S1; if (Z2IsOne) SecP224R1Field.reduce32(c, G); SecP224R1FieldElement X3 = new SecP224R1FieldElement(t4); SecP224R1Field.square(R, X3.x); SecP224R1Field.subtract(X3.x, G, X3.x); SecP224R1FieldElement Y3 = new SecP224R1FieldElement(G); SecP224R1Field.subtract(V, X3.x, Y3.x); SecP224R1Field.multiplyAddToExt(Y3.x, R, tt1); SecP224R1Field.reduce(tt1, Y3.x); SecP224R1FieldElement Z3 = new SecP224R1FieldElement(H); if (!Z1IsOne)
/** * return a sqrt root - the routine verifies that the calculation returns the right value - if * none exists it returns null. */ public ECFieldElement sqrt() { int[] c = this.x; if (Nat224.isZero(c) || Nat224.isOne(c)) { return this; } int[] nc = Nat224.create(); SecP224R1Field.negate(c, nc); int[] r = Mod.random(SecP224R1Field.P); int[] t = Nat224.create(); if (!isSquare(c)) { return null; } while (!trySqrt(nc, r, t)) { SecP224R1Field.addOne(r, r); } SecP224R1Field.square(t, r); return Nat224.eq(c, r) ? new SecP224R1FieldElement(t) : null; }
if (Y1.isZero()) SecP224R1Field.square(Y1Squared, T); boolean Z1IsOne = Z1.isOne(); SecP224R1Field.reduce32(c, t1); SecP224R1FieldElement X3 = new SecP224R1FieldElement(T); SecP224R1Field.square(M, X3.x); SecP224R1Field.subtract(X3.x, S, X3.x); SecP224R1Field.subtract(X3.x, S, X3.x); SecP224R1FieldElement Y3 = new SecP224R1FieldElement(S); SecP224R1Field.subtract(S, X3.x, Y3.x); SecP224R1Field.multiply(Y3.x, M, Y3.x); SecP224R1Field.subtract(Y3.x, t1, Y3.x); SecP224R1FieldElement Z3 = new SecP224R1FieldElement(M); SecP224R1Field.twice(Y1.x, Z3.x); if (!Z1IsOne)
private static void RP(int[] nc, int[] d1, int[] e1, int[] f1, int[] t) { Nat224.copy(nc, f1); int[] d0 = Nat224.create(); int[] e0 = Nat224.create(); for (int i = 0; i < 7; ++i) { Nat224.copy(d1, d0); Nat224.copy(e1, e0); int j = 1 << i; while (--j >= 0) { RS(d1, e1, f1, t); } RM(nc, d0, e0, d1, e1, f1, t); } }
private static boolean trySqrt(int[] nc, int[] r, int[] t) { int[] d1 = Nat224.create(); Nat224.copy(r, d1); int[] e1 = Nat224.create(); e1[0] = 1; int[] f1 = Nat224.create(); RP(nc, d1, e1, f1, t); int[] d0 = Nat224.create(); int[] e0 = Nat224.create(); for (int k = 1; k < 96; ++k) { Nat224.copy(d1, d0); Nat224.copy(e1, e0); RS(d1, e1, f1, t); if (Nat224.isZero(d1)) { Mod.invert(SecP224R1Field.P, e0, t); SecP224R1Field.multiply(t, d0, t); return true; } } return false; } }
int[] t4 = Nat224.create(); boolean Z1IsOne = Z1.isOne(); int[] U2, S2; if (Z1IsOne) boolean Z2IsOne = Z2.isOne(); int[] U1, S1; if (Z2IsOne) SecP224R1Field.reduce32(c, G); SecP224R1FieldElement X3 = new SecP224R1FieldElement(t4); SecP224R1Field.square(R, X3.x); SecP224R1Field.subtract(X3.x, G, X3.x); SecP224R1FieldElement Y3 = new SecP224R1FieldElement(G); SecP224R1Field.subtract(V, X3.x, Y3.x); SecP224R1Field.multiplyAddToExt(Y3.x, R, tt1); SecP224R1Field.reduce(tt1, Y3.x); SecP224R1FieldElement Z3 = new SecP224R1FieldElement(H); if (!Z1IsOne)
public ECFieldElement fromBigInteger(BigInteger x) { return new SecP224R1FieldElement(x); }
public ECPoint lookup(int index) { int[] x = Nat224.create(), y = Nat224.create(); int pos = 0; for (int i = 0; i < len; ++i) { int MASK = ((i ^ index) - 1) >> 31; for (int j = 0; j < FE_INTS; ++j) { x[j] ^= table[pos + j] & MASK; y[j] ^= table[pos + FE_INTS + j] & MASK; } pos += (FE_INTS * 2); } return createRawPoint(new SecP224R1FieldElement(x), new SecP224R1FieldElement(y), false); } };
public ECFieldElement addOne() { int[] z = Nat224.create(); SecP224R1Field.addOne(x, z); return new SecP224R1FieldElement(z); }
public ECFieldElement subtract(ECFieldElement b) { int[] z = Nat224.create(); SecP224R1Field.subtract(x, ((SecP224R1FieldElement)b).x, z); return new SecP224R1FieldElement(z); }
public ECFieldElement square() { int[] z = Nat224.create(); SecP224R1Field.square(x, z); return new SecP224R1FieldElement(z); }
public ECFieldElement subtract(ECFieldElement b) { int[] z = Nat224.create(); SecP224R1Field.subtract(x, ((SecP224R1FieldElement)b).x, z); return new SecP224R1FieldElement(z); }
public ECFieldElement square() { int[] z = Nat224.create(); SecP224R1Field.square(x, z); return new SecP224R1FieldElement(z); }
public ECFieldElement invert() { // return new SecP224R1FieldElement(toBigInteger().modInverse(Q)); int[] z = Nat224.create(); Mod.invert(SecP224R1Field.P, x, z); return new SecP224R1FieldElement(z); }
public ECFieldElement add(ECFieldElement b) { int[] z = Nat224.create(); SecP224R1Field.add(x, ((SecP224R1FieldElement)b).x, z); return new SecP224R1FieldElement(z); }