コード例 #1
0
            public Reducer(UInt32MontgomeryReduction reduction, uint modulus)
                : base(reduction, modulus)
            {
                if ((modulus & 1) == 0)
                {
                    throw new InvalidOperationException("not relatively prime");
                }
                var nInv = IntegerMath.ModularInversePowerOfTwoModulus(modulus, 32);

                k0 = IntegerMath.TwosComplement(nInv);
                var rModN = uint.MaxValue % modulus + 1;

                rSquaredModN = IntegerMath.ModularProduct(rModN, rModN, modulus);
            }
コード例 #2
0
            public Reducer(UInt64MontgomeryReduction reduction, ulong modulus)
                : base(reduction, modulus)
            {
                if ((modulus & 1) == 0)
                {
                    throw new InvalidOperationException("not relatively prime");
                }
                int rLength   = modulus == (uint)modulus ? 32 : 64;
                var rMinusOne = rLength == 32 ? uint.MaxValue : ulong.MaxValue;
                var rModN     = rMinusOne % modulus + 1;

                rSquaredModN = IntegerMath.ModularProduct(rModN, rModN, modulus);
                var nInv = IntegerMath.ModularInversePowerOfTwoModulus(modulus, rLength);

                k0     = (uint)IntegerMath.TwosComplement(nInv);
                oneRep = 0;
            }