public LongArray modSquareN(int n, int m, int[] ks) { int len = getUsedLength(); if (len == 0) { return this; } int mLen = (m + 63) >>> 6; long[] r = new long[mLen << 1]; System.arraycopy(m_ints, 0, r, 0, len); while (--n >= 0) { squareInPlace(r, len, m, ks); len = reduceInPlace(r, 0, r.length, m, ks); } return new LongArray(r, 0, len); }
public void addShiftedByWords(LongArray other, int words) { int otherUsedLen = other.getUsedLength(); if (otherUsedLen == 0) { return; } int minLen = otherUsedLen + words; if (minLen > m_ints.length) { m_ints = resizedInts(minLen); } add(m_ints, words, other.m_ints, 0, otherUsedLen); }
public ECFieldElement multiplyPlusProduct(ECFieldElement b, ECFieldElement x, ECFieldElement y) { LongArray ax = this.x, bx = ((F2m)b).x, xx = ((F2m)x).x, yx = ((F2m)y).x; LongArray ab = ax.multiply(bx, m, ks); LongArray xy = xx.multiply(yx, m, ks); if (ab == ax || ab == bx) { ab = (LongArray)ab.clone(); } ab.addShiftedByWords(xy, 0); ab.reduce(m, ks); return new F2m(m, ks, ab); }
private static LongArray reduceResult(long[] buf, int off, int len, int m, int[] ks) { int rLen = reduceInPlace(buf, off, len, m, ks); return new LongArray(buf, off, rLen); }
public static BigInteger inverse(int m, int[] ks, BigInteger x) { return new LongArray(x).modInverse(m, ks).toBigInteger(); }
private static void flipVector(long[] x, int xOff, long[] y, int yOff, int yLen, int bits) { xOff += bits >>> 6; bits &= 0x3F; if (bits == 0) { add(x, xOff, y, yOff, yLen); } else { long carry = addShiftedDown(x, xOff + 1, y, yOff, yLen, 64 - bits); x[xOff] ^= carry; } }
int aDeg = degree(); if (aDeg == 0) int bDeg = other.degree(); if (bDeg == 0) multiplyWord(a0, B.m_ints, bLen, c0, 0); return reduceResult(c0, 0, cLen, m, ks); if ((i & 1) == 0) shiftUp(T0, tOff >>> 1, T0, tOff, bMax, 1); add(T0, bMax, T0, tOff - bMax, T0, tOff, bMax); shiftUp(T0, 0, T1, 0, T0.length, 4); aVal >>>= 4; int v = (int)aVal & MASK; addBoth(c, cOff, T0, ti[u], T1, ti[v], bMax); aVal >>>= 4; if (aVal == 0L) addShiftedUp(c, cOff - cLen, c, cOff, cLen, 8); return reduceResult(c, 0, cLen, m, ks);
int aDeg = degree(); if (aDeg == 0) int bDeg = other.degree(); if (bDeg == 0) multiplyWord(a0, B.m_ints, bLen, c0, 0); return reduceResult(c0, 0, cLen, m, ks); interleave(A.m_ints, 0, c, 0, aLen, width); for (int bank = 1; bank < banks; ++bank) shiftUp(c, aLen, c, bOff += bMax, bMax, bank); add(c, aPos + ci[index], c, bOff, bMax); shiftUp(c, aLen, bTotal, banks); addShiftedUp(c, ci[ciPos >>> 1], c, ci[ciPos], cLen, positions); distribute(c, ci[ciPos], ci[ciPos - 1], ci[1], cLen); return reduceResult(c, ci[1], cLen, m, ks);
int aDeg = degree(); if (aDeg == 0) int bDeg = other.degree(); if (bDeg == 0) multiplyWord(a0, B.m_ints, bLen, c0, 0); return new LongArray(c0, 0, cLen); if ((i & 1) == 0) shiftUp(T0, tOff >>> 1, T0, tOff, bMax, 1); add(T0, bMax, T0, tOff - bMax, T0, tOff, bMax); shiftUp(T0, 0, T1, 0, T0.length, 4); aVal >>>= 4; int v = (int)aVal & MASK; addBoth(c, cOff, T0, ti[u], T1, ti[v], bMax); aVal >>>= 4; if (aVal == 0L) addShiftedUp(c, cOff - cLen, c, cOff, cLen, 8); return new LongArray(c, 0, cLen);
int uzDegree = degree(); if (uzDegree == 0) LongArray uz = (LongArray)clone(); LongArray vz = new LongArray(t); reduceBit(vz.m_ints, 0, m, m, ks); LongArray g1z = new LongArray(t); g1z.m_ints[0] = 1L; LongArray g2z = new LongArray(t); uv[b].addShiftedByBitsSafe(uv[1 - b], uvDeg[1 - b], j); int duv2 = uv[b].degreeFrom(duv1); if (duv2 == 0) gg[b].addShiftedByBitsSafe(gg[1 - b], dgg2, j); dgg2 += j; dgg1 = gg[b].degreeFrom(dgg1);
public LongArray modSquare(int m, int[] ks) { int len = getUsedLength(); if (len == 0) { return this; } int _2len = len << 1; long[] r = new long[_2len]; int pos = 0; while (pos < _2len) { long mi = m_ints[pos >>> 1]; r[pos++] = interleave2_32to64((int)mi); r[pos++] = interleave2_32to64((int)(mi >>> 32)); } return new LongArray(r, 0, reduceInPlace(r, 0, r.length, m, ks)); }
public LongArray addOne() { if (m_ints.length == 0) { return new LongArray(new long[]{ 1L }); } int resultLen = Math.max(1, getUsedLength()); long[] ints = resizedInts(resultLen); ints[0] ^= 1L; return new LongArray(ints); }
public LongArray square(int m, int[] ks) { int len = getUsedLength(); if (len == 0) { return this; } int _2len = len << 1; long[] r = new long[_2len]; int pos = 0; while (pos < _2len) { long mi = m_ints[pos >>> 1]; r[pos++] = interleave2_32to64((int)mi); r[pos++] = interleave2_32to64((int)(mi >>> 32)); } return new LongArray(r, 0, r.length); }
private void addShiftedByBitsSafe(LongArray other, int otherDegree, int bits) { int otherLen = (otherDegree + 63) >>> 6; int words = bits >>> 6; int shift = bits & 0x3F; if (shift == 0) { add(m_ints, words, other.m_ints, 0, otherLen); return; } long carry = addShiftedUp(m_ints, words, other.m_ints, 0, otherLen, shift); if (carry != 0L) { m_ints[otherLen + words] ^= carry; } }
public Object clone() { return new LongArray(Arrays.clone(m_ints)); }
public int degree() { int i = m_ints.length; long w; do { if (i == 0) { return 0; } w = m_ints[--i]; } while (w == 0); return (i << 6) + bitLength(w); }
public ECFieldElement add(final ECFieldElement b) { // No check performed here for performance reasons. Instead the // elements involved are checked in ECPoint.F2m // checkFieldElements(this, b); LongArray iarrClone = (LongArray)this.x.clone(); F2m bF2m = (F2m)b; iarrClone.addShiftedByWords(bF2m.x, 0); return new F2m(m, ks, iarrClone); }
public ECFieldElement addOne() { return new F2m(m, ks, x.addOne()); }
int aDeg = degree(); if (aDeg == 0) int bDeg = other.degree(); if (bDeg == 0) multiplyWord(a0, B.m_ints, bLen, c0, 0); return reduceResult(c0, 0, cLen, m, ks); shiftUp(T0, tOff >>> 1, T0, tOff, bMax, 1); add(T0, bMax, T0, tOff - bMax, T0, tOff, bMax); shiftUp(T0, 0, T1, 0, T0.length, 4); int u = aVal & MASK; int v = (aVal >>> 4) & MASK; addBoth(c, j - 1, T0, ti[u], T1, ti[v], bMax); shiftUp(c, 0, cLen, 8); int u = aVal & MASK; int v = (aVal >>> 4) & MASK; addBoth(c, j, T0, ti[u], T1, ti[v], bMax); shiftUp(c, 0, cLen, 8); return reduceResult(c, 0, cLen, m, ks);
int aDeg = degree(); if (aDeg == 0) int bDeg = other.degree(); if (bDeg == 0) multiplyWord(a0, B.m_ints, bLen, c0, 0); return reduceResult(c0, 0, cLen, m, ks); interleave(A.m_ints, 0, c, 0, aLen, width); for (int bank = 1; bank < banks; ++bank) shiftUp(c, aLen, c, bOff += bMax, bMax, bank); add(c, aPos + ci[index], c, bOff, bMax); shiftUp(c, aLen, bTotal, banks); addShiftedUp(c, ci[ciPos >>> 1], c, ci[ciPos], cLen, positions); distribute(c, ci[ciPos], ci[ciPos - 1], ci[1], cLen); return reduceResult(c, ci[1], cLen, m, ks);