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;
     }
 }
 public void Reduce(ref FastReducer reducer)
 {
     // Executes a modulo operation using an optimized reducer.
     // Thus, no need of any switching here, happens in-line.
     _length = reducer.Reduce(_bits, _length);
 }
            public void Reduce(ref FastReducer reducer)
            {
                // Executes a modulo operation using an optimized reducer.
                // Thus, no need of any switching here, happens in-line.

                _length = reducer.Reduce(_bits, _length);
            }
        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 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 uint[] PowCore(uint power, uint[] modulus,
                                      ref BitsBuffer value)
        {
            // Executes the big pow algorithm.

            int size = value.GetSize();

            BitsBuffer temp = new BitsBuffer(size, 0);
            BitsBuffer result = new BitsBuffer(size, 1);

            if (modulus.Length < ReducerThreshold)
            {
                PowCore(power, modulus, ref value, ref result, ref temp);
            }
            else
            {
                FastReducer reducer = new FastReducer(modulus);
                PowCore(power, ref reducer, ref value, ref result, ref temp);
            }

            return result.GetBits();
        }