当前位置: 首页>>代码示例>>C#>>正文


C# IBigInteger.Multiply方法代码示例

本文整理汇总了C#中IBigInteger.Multiply方法的典型用法代码示例。如果您正苦于以下问题:C# IBigInteger.Multiply方法的具体用法?C# IBigInteger.Multiply怎么用?C# IBigInteger.Multiply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IBigInteger的用法示例。


在下文中一共展示了IBigInteger.Multiply方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VerifySignature

        /**
         * return true if the value r and s represent a DSA signature for
         * the passed in message for standard DSA the message should be a
         * SHA-1 hash of the real message to be verified.
         */
        public bool VerifySignature(byte[] message, IBigInteger r, IBigInteger s)
        {
            var parameters = _key.Parameters;
            var q = parameters.Q;
            var m = CalculateE(q, message);

            if (r.SignValue <= 0 || q.CompareTo(r) <= 0)
            {
                return false;
            }

            if (s.SignValue <= 0 || q.CompareTo(s) <= 0)
            {
                return false;
            }

            var w = s.ModInverse(q);

            var u1 = m.Multiply(w).Mod(q);
            var u2 = r.Multiply(w).Mod(q);

            var p = parameters.P;
            u1 = parameters.G.ModPow(u1, p);
            u2 = ((DsaPublicKeyParameters)_key).Y.ModPow(u2, p);

            var v = u1.Multiply(u2).Mod(p).Mod(q);

            return v.Equals(r);
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:34,代码来源:DsaSigner.cs

示例2: VerifySignature

        // 5.4 pg 29
        /**
         * return true if the value r and s represent a DSA signature for
         * the passed in message (for standard DSA the message should be
         * a SHA-1 hash of the real message to be verified).
         */
        public bool VerifySignature(byte[] message, IBigInteger r, IBigInteger s)
        {
            var n = _key.Parameters.N;

            // r and s should both in the range [1,n-1]
            if (r.SignValue < 1 || s.SignValue < 1 || r.CompareTo(n) >= 0 || s.CompareTo(n) >= 0)
            {
                return false;
            }

            var e = CalculateE(n, message);
            var c = s.ModInverse(n);

            var u1 = e.Multiply(c).Mod(n);
            var u2 = r.Multiply(c).Mod(n);

            var g = _key.Parameters.G;
            var q = ((ECPublicKeyParameters)_key).Q;

            var point = ECAlgorithms.SumOfTwoMultiplies(g, u1, q, u2);

            var v = point.X.ToBigInteger().Mod(n);
            return v.Equals(r);
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:30,代码来源:ECDsaSigner.cs

示例3: ApproximateDivisionByN

        /**
        * Approximate division by <code>n</code>. For an integer
        * <code>k</code>, the value <code>&#955; = s k / n</code> is
        * computed to <code>c</code> bits of accuracy.
        * @param k The parameter <code>k</code>.
        * @param s The curve parameter <code>s<sub>0</sub></code> or
        * <code>s<sub>1</sub></code>.
        * @param vm The Lucas Sequence element <code>V<sub>m</sub></code>.
        * @param a The parameter <code>a</code> of the elliptic curve.
        * @param m The bit length of the finite field
        * <code><b>F</b><sub>m</sub></code>.
        * @param c The number of bits of accuracy, i.e. the scale of the returned
        * <code>SimpleBigDecimal</code>.
        * @return The value <code>&#955; = s k / n</code> computed to
        * <code>c</code> bits of accuracy.
        */
        public static SimpleBigDecimal ApproximateDivisionByN(IBigInteger k,
            IBigInteger s, IBigInteger vm, sbyte a, int m, int c)
        {
            int _k = (m + 5)/2 + c;
            IBigInteger ns = k.ShiftRight(m - _k - 2 + a);

            IBigInteger gs = s.Multiply(ns);

            IBigInteger hs = gs.ShiftRight(m);

            IBigInteger js = vm.Multiply(hs);

            IBigInteger gsPlusJs = gs.Add(js);
            IBigInteger ls = gsPlusJs.ShiftRight(_k - c);
            if (gsPlusJs.TestBit(_k-c-1))
            {
                // round up
                ls = ls.Add(BigInteger.One);
            }

            return new SimpleBigDecimal(ls, c);
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:38,代码来源:Tnaf.cs

示例4: BlindMessage

        /*
        * Blind message with the blind factor.
        */
        private IBigInteger BlindMessage(
			IBigInteger msg)
        {
            IBigInteger blindMsg = blindingFactor;
            blindMsg = msg.Multiply(blindMsg.ModPow(key.Exponent, key.Modulus));
            blindMsg = blindMsg.Mod(key.Modulus);

            return blindMsg;
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:12,代码来源:RSABlindingEngine.cs

示例5: VerifySignature

        /**
         * return true if the value r and s represent a Gost3410 signature for
         * the passed in message for standard Gost3410 the message should be a
         * Gost3411 hash of the real message to be verified.
         */
        public bool VerifySignature(
			byte[]		message,
            IBigInteger r,
            IBigInteger s)
        {
            byte[] mRev = new byte[message.Length]; // conversion is little-endian
            for (int i = 0; i != mRev.Length; i++)
            {
                mRev[i] = message[mRev.Length - 1 - i];
            }

            IBigInteger m = new BigInteger(1, mRev);
            Gost3410Parameters parameters = key.Parameters;

            if (r.SignValue < 0 || parameters.Q.CompareTo(r) <= 0)
            {
                return false;
            }

            if (s.SignValue < 0 || parameters.Q.CompareTo(s) <= 0)
            {
                return false;
            }

            IBigInteger v = m.ModPow(parameters.Q.Subtract(BigInteger.Two), parameters.Q);

            IBigInteger z1 = s.Multiply(v).Mod(parameters.Q);
            IBigInteger z2 = (parameters.Q.Subtract(r)).Multiply(v).Mod(parameters.Q);

            z1 = parameters.A.ModPow(z1, parameters.P);
            z2 = ((Gost3410PublicKeyParameters)key).Y.ModPow(z2, parameters.P);

            IBigInteger u = z1.Multiply(z2).Mod(parameters.P).Mod(parameters.Q);

            return u.Equals(r);
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:41,代码来源:GOST3410Signer.cs

示例6: FastLucasSequence

        private static IBigInteger[] FastLucasSequence(IBigInteger p, IBigInteger P, IBigInteger Q, IBigInteger k)
        {
            // TODO Research and apply "common-multiplicand multiplication here"

            var n = k.BitLength;
            var s = k.GetLowestSetBit();

            Debug.Assert(k.TestBit(s));

            var uh = BigInteger.One;
            var vl = BigInteger.Two;
            var vh = P;
            var ql = BigInteger.One;
            var qh = BigInteger.One;

            for (var j = n - 1; j >= s + 1; --j)
            {
                ql = ql.Multiply(qh).Mod(p);

                if (k.TestBit(j))
                {
                    qh = ql.Multiply(Q).Mod(p);
                    uh = uh.Multiply(vh).Mod(p);
                    vl = vh.Multiply(vl).Subtract(P.Multiply(ql)).Mod(p);
                    vh = vh.Multiply(vh).Subtract(qh.ShiftLeft(1)).Mod(p);
                }
                else
                {
                    qh = ql;
                    uh = uh.Multiply(vl).Subtract(ql).Mod(p);
                    vh = vh.Multiply(vl).Subtract(P.Multiply(ql)).Mod(p);
                    vl = vl.Multiply(vl).Subtract(ql.ShiftLeft(1)).Mod(p);
                }
            }

            ql = ql.Multiply(qh).Mod(p);
            qh = ql.Multiply(Q).Mod(p);
            uh = uh.Multiply(vl).Subtract(ql).Mod(p);
            vl = vh.Multiply(vl).Subtract(P.Multiply(ql)).Mod(p);
            ql = ql.Multiply(qh).Mod(p);

            for (var j = 1; j <= s; ++j)
            {
                uh = uh.Multiply(vl).Mod(p);
                vl = vl.Multiply(vl).Subtract(ql.ShiftLeft(1)).Mod(p);
                ql = ql.Multiply(ql).Mod(p);
            }

            return new[] { uh, vl };
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:50,代码来源:FPFieldElement.cs

示例7: VerifySignature

        /**
         * return true if the value r and s represent a GOST3410 signature for
         * the passed in message (for standard GOST3410 the message should be
         * a GOST3411 hash of the real message to be verified).
         */
        public bool VerifySignature(
			byte[]		message,
            IBigInteger r,
            IBigInteger s)
        {
            byte[] mRev = new byte[message.Length]; // conversion is little-endian
            for (int i = 0; i != mRev.Length; i++)
            {
                mRev[i] = message[mRev.Length - 1 - i];
            }

            IBigInteger e = new BigInteger(1, mRev);
            IBigInteger n = key.Parameters.N;

            // r in the range [1,n-1]
            if (r.CompareTo(BigInteger.One) < 0 || r.CompareTo(n) >= 0)
            {
                return false;
            }

            // s in the range [1,n-1]
            if (s.CompareTo(BigInteger.One) < 0 || s.CompareTo(n) >= 0)
            {
                return false;
            }

            IBigInteger v = e.ModInverse(n);

            IBigInteger z1 = s.Multiply(v).Mod(n);
            IBigInteger z2 = (n.Subtract(r)).Multiply(v).Mod(n);

            ECPoint G = key.Parameters.G; // P
            ECPoint Q = ((ECPublicKeyParameters)key).Q;

            ECPoint point = ECAlgorithms.SumOfTwoMultiplies(G, z1, Q, z2);

            IBigInteger R = point.X.ToBigInteger().Mod(n);

            return R.Equals(r);
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:45,代码来源:ECGOST3410Signer.cs


注:本文中的IBigInteger.Multiply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。