public static ulong[] PrecompMultiplicand(ulong[] x) { /* * Precompute table of all 4-bit products of x (first section) */ int len = 9 << 4; ulong[] t = new ulong[len << 1]; Array.Copy(x, 0, t, 9, 9); //Reduce5(t, 9); int tOff = 0; for (int i = 7; i > 0; --i) { tOff += 18; Nat.ShiftUpBit64(9, t, tOff >> 1, 0UL, t, tOff); Reduce5(t, tOff); Add(t, 9, t, tOff, t, tOff + 9); } /* * Second section with all 4-bit products of x shifted 4 bits */ Nat.ShiftUpBits64(len, t, 0, 4, 0UL, t, len); return(t); }
protected static void ImplMultiplyPrecomp(ulong[] x, ulong[] precomp, ulong[] zz) { uint MASK = 0xF; /* * Lopez-Dahab algorithm */ for (int k = 56; k >= 0; k -= 8) { for (int j = 1; j < 9; j += 2) { uint aVal = (uint)(x[j] >> k); uint u = aVal & MASK; uint v = (aVal >> 4) & MASK; AddBothTo(precomp, (int)(9 * u), precomp, (int)(9 * (v + 16)), zz, j - 1); } Nat.ShiftUpBits64(16, zz, 0, 8, 0UL); } for (int k = 56; k >= 0; k -= 8) { for (int j = 0; j < 9; j += 2) { uint aVal = (uint)(x[j] >> k); uint u = aVal & MASK; uint v = (aVal >> 4) & MASK; AddBothTo(precomp, (int)(9 * u), precomp, (int)(9 * (v + 16)), zz, j); } if (k > 0) { Nat.ShiftUpBits64(18, zz, 0, 8, 0UL); } } }
protected static void ImplMultiply(ulong[] x, ulong[] y, ulong[] zz) { ulong[] array = new ulong[144]; Array.Copy(y, 0, array, 9, 9); int num = 0; for (int num2 = 7; num2 > 0; num2--) { num += 18; Nat.ShiftUpBit64(9, array, num >> 1, 0uL, array, num); Reduce5(array, num); Add(array, 9, array, num, array, num + 9); } ulong[] array2 = new ulong[array.Length]; Nat.ShiftUpBits64(array.Length, array, 0, 4, 0uL, array2, 0); uint num3 = 15u; for (int num4 = 56; num4 >= 0; num4 -= 8) { for (int i = 1; i < 9; i += 2) { uint num5 = (uint)(x[i] >> num4); uint num6 = num5 & num3; uint num7 = (num5 >> 4) & num3; AddBothTo(array, (int)(9 * num6), array2, (int)(9 * num7), zz, i - 1); } Nat.ShiftUpBits64(16, zz, 0, 8, 0uL); } for (int num8 = 56; num8 >= 0; num8 -= 8) { for (int j = 0; j < 9; j += 2) { uint num9 = (uint)(x[j] >> num8); uint num10 = num9 & num3; uint num11 = (num9 >> 4) & num3; AddBothTo(array, (int)(9 * num10), array2, (int)(9 * num11), zz, j); } if (num8 > 0) { Nat.ShiftUpBits64(18, zz, 0, 8, 0uL); } } }
protected static void ImplMultiply(ulong[] x, ulong[] y, ulong[] zz) { ulong[] array = new ulong[144]; Array.Copy(y, 0, array, 9, 9); int num = 0; for (int i = 7; i > 0; i--) { num += 18; Nat.ShiftUpBit64(9, array, num >> 1, 0uL, array, num); SecT571Field.Reduce5(array, num); SecT571Field.Add(array, 9, array, num, array, num + 9); } ulong[] array2 = new ulong[array.Length]; Nat.ShiftUpBits64(array.Length, array, 0, 4, 0uL, array2, 0); uint num2 = 15u; for (int j = 56; j >= 0; j -= 8) { for (int k = 1; k < 9; k += 2) { uint num3 = (uint)(x[k] >> j); uint num4 = num3 & num2; uint num5 = num3 >> 4 & num2; SecT571Field.AddBothTo(array, (int)(9u * num4), array2, (int)(9u * num5), zz, k - 1); } Nat.ShiftUpBits64(16, zz, 0, 8, 0uL); } for (int l = 56; l >= 0; l -= 8) { for (int m = 0; m < 9; m += 2) { uint num6 = (uint)(x[m] >> l); uint num7 = num6 & num2; uint num8 = num6 >> 4 & num2; SecT571Field.AddBothTo(array, (int)(9u * num7), array2, (int)(9u * num8), zz, m); } if (l > 0) { Nat.ShiftUpBits64(18, zz, 0, 8, 0uL); } } }
protected static void ImplMultiply(ulong[] x, ulong[] y, ulong[] zz) { //for (int i = 0; i < 9; ++i) //{ // ImplMulwAcc(x, y[i], zz, i); //} /* * Precompute table of all 4-bit products of y */ ulong[] T0 = new ulong[9 << 4]; Array.Copy(y, 0, T0, 9, 9); // Reduce5(T0, 9); int tOff = 0; for (int i = 7; i > 0; --i) { tOff += 18; Nat.ShiftUpBit64(9, T0, tOff >> 1, 0UL, T0, tOff); Reduce5(T0, tOff); Add(T0, 9, T0, tOff, T0, tOff + 9); } /* * Second table with all 4-bit products of B shifted 4 bits */ ulong[] T1 = new ulong[T0.Length]; Nat.ShiftUpBits64(T0.Length, T0, 0, 4, 0L, T1, 0); uint MASK = 0xF; /* * Lopez-Dahab algorithm */ for (int k = 56; k >= 0; k -= 8) { for (int j = 1; j < 9; j += 2) { uint aVal = (uint)(x[j] >> k); uint u = aVal & MASK; uint v = (aVal >> 4) & MASK; AddBothTo(T0, (int)(9 * u), T1, (int)(9 * v), zz, j - 1); } Nat.ShiftUpBits64(16, zz, 0, 8, 0L); } for (int k = 56; k >= 0; k -= 8) { for (int j = 0; j < 9; j += 2) { uint aVal = (uint)(x[j] >> k); uint u = aVal & MASK; uint v = (aVal >> 4) & MASK; AddBothTo(T0, (int)(9 * u), T1, (int)(9 * v), zz, j); } if (k > 0) { Nat.ShiftUpBits64(18, zz, 0, 8, 0L); } } }