private static void PowCore(uint power, uint[] modulus, ref BitsBuffer value, ref BitsBuffer result, ref BitsBuffer temp) { // The big modulus pow algorithm for the last or // the only power limb using square-and-multiply. // NOTE: we're using an ordinary remainder here, // since the reducer overhead doesn't pay off. while (power != 0) { if ((power & 1) == 1) { result.MultiplySelf(ref value, ref temp); result.Reduce(modulus); } if (power != 1) { value.SquareSelf(ref temp); value.Reduce(modulus); } power = power >> 1; } }
private static void PowCore(uint[] power, ref FastReducer reducer, ref BitsBuffer value, ref BitsBuffer result, ref BitsBuffer temp) { // The big modulus pow algorithm for all but // the last power limb using square-and-multiply. // NOTE: we're using a special reducer here, // since it's additional overhead does pay off. for (int i = 0; i < power.Length - 1; i++) { uint p = power[i]; for (int j = 0; j < 32; j++) { if ((p & 1) == 1) { result.MultiplySelf(ref value, ref temp); result.Reduce(ref reducer); } value.SquareSelf(ref temp); value.Reduce(ref reducer); p = p >> 1; } } PowCore(power[power.Length - 1], ref reducer, ref value, ref result, ref temp); }
private static void PowCore(uint power, ref FastReducer reducer, ref BitsBuffer value, ref BitsBuffer result, ref BitsBuffer temp) { // The big modulus pow algorithm for the last or // the only power limb using square-and-multiply. // NOTE: we're using a special reducer here, // since it's additional overhead does pay off. while (power != 0) { if ((power & 1) == 1) { result.MultiplySelf(ref value, ref temp); result.Reduce(ref reducer); } if (power != 1) { value.SquareSelf(ref temp); value.Reduce(ref reducer); } power = power >> 1; } }
private static void PowCore(uint power, ref BitsBuffer value, ref BitsBuffer result, ref BitsBuffer temp) { // The basic pow algorithm using square-and-multiply. while (power != 0) { if ((power & 1) == 1) result.MultiplySelf(ref value, ref temp); if (power != 1) value.SquareSelf(ref temp); power = power >> 1; } }
private static void PowCore(uint power, ref BitsBuffer value, ref BitsBuffer result, ref BitsBuffer temp) { // The basic pow algorithm using square-and-multiply. while (power != 0) { if ((power & 1) == 1) { result.MultiplySelf(ref value, ref temp); } if (power != 1) { value.SquareSelf(ref temp); } power = power >> 1; } }