示例#1
0
        /**
         * Multiplies a {@link org.bouncycastle.math.ec.F2mPoint F2mPoint}
         * by an element <code>&#955;</code> of <code><b>Z</b>[&#964;]</code>
         * using the window <code>&#964;</code>-adic NAF (TNAF) method, given the
         * WTNAF of <code>&#955;</code>.
         * @param p The F2mPoint to multiply.
         * @param u The the WTNAF of <code>&#955;</code>..
         * @return <code>&#955; * p</code>
         */
        private static F2mPoint MultiplyFromWTnaf(F2mPoint p, sbyte[] u, PreCompInfo preCompInfo)
        {
            F2mCurve curve = (F2mCurve)p.Curve;
            sbyte    a     = (sbyte)curve.A.ToBigInteger().IntValue;

            F2mPoint[] pu;
            if ((preCompInfo == null) || !(preCompInfo is WTauNafPreCompInfo))
            {
                pu = Tnaf.GetPreComp(p, a);

                WTauNafPreCompInfo pre = new WTauNafPreCompInfo();
                pre.PreComp = pu;
                curve.SetPreCompInfo(p, PRECOMP_NAME, pre);
            }
            else
            {
                pu = ((WTauNafPreCompInfo)preCompInfo).PreComp;
            }

            // q = infinity
            F2mPoint q = (F2mPoint)curve.Infinity;

            for (int i = u.Length - 1; i >= 0; i--)
            {
                q = Tnaf.Tau(q);
                sbyte ui = u[i];
                if (ui != 0)
                {
                    if (ui > 0)
                    {
                        q = q.AddSimple(pu[ui]);
                    }
                    else
                    {
                        // u[i] < 0
                        q = q.SubtractSimple(pu[-ui]);
                    }
                }
            }

            return(q);
        }
        /**
         * Multiplies a {@link org.bouncycastle.math.ec.F2mPoint F2mPoint}
         * by an element <code>&#955;</code> of <code><b>Z</b>[&#964;]</code>
         * using the window <code>&#964;</code>-adic NAF (TNAF) method, given the
         * WTNAF of <code>&#955;</code>.
         * @param p The F2mPoint to multiply.
         * @param u The the WTNAF of <code>&#955;</code>..
         * @return <code>&#955; * p</code>
         */
        private static F2MPoint MultiplyFromWTnaf(F2MPoint p, sbyte[] u,
                                                  IPreCompInfo preCompInfo)
        {
            F2MCurve curve = (F2MCurve)p.Curve;
            sbyte    a     = (sbyte)curve.A.ToBigInteger().IntValue;

            F2MPoint[] pu;
            if ((preCompInfo == null) || !(preCompInfo is WTauNafPreCompInfo))
            {
                pu            = Tnaf.GetPreComp(p, a);
                p.PreCompInfo = new WTauNafPreCompInfo(pu);
            }
            else
            {
                pu = ((WTauNafPreCompInfo)preCompInfo).GetPreComp();
            }

            // q = infinity
            F2MPoint q = (F2MPoint)p.Curve.Infinity;

            for (int i = u.Length - 1; i >= 0; i--)
            {
                q = Tnaf.Tau(q);
                if (u[i] != 0)
                {
                    if (u[i] > 0)
                    {
                        q = q.AddSimple(pu[u[i]]);
                    }
                    else
                    {
                        // u[i] < 0
                        q = q.SubtractSimple(pu[-u[i]]);
                    }
                }
            }

            return(q);
        }