コード例 #1
0
            public PreCompInfo Precompute(PreCompInfo existing)
            {
                if (existing is WTauNafPreCompInfo)
                {
                    return(existing);
                }

                WTauNafPreCompInfo result = new WTauNafPreCompInfo();

                result.PreComp = Tnaf.GetPreComp(m_p, m_a);
                return(result);
            }
コード例 #2
0
        /**
         * Multiplies a {@link org.bouncycastle.math.ec.AbstractF2mPoint AbstractF2mPoint}
         * 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 AbstractF2mPoint to multiply.
         * @param u The the WTNAF of <code>&#955;</code>..
         * @return <code>&#955; * p</code>
         */
        private static AbstractF2mPoint MultiplyFromWTnaf(AbstractF2mPoint p, sbyte[] u)
        {
            AbstractF2mCurve curve = (AbstractF2mCurve)p.Curve;
            sbyte            a     = (sbyte)curve.A.ToBigInteger().IntValue;

            WTauNafCallback    callback    = new WTauNafCallback(p, a);
            WTauNafPreCompInfo preCompInfo = (WTauNafPreCompInfo)curve.Precompute(p, PRECOMP_NAME, callback);

            AbstractF2mPoint[] pu = preCompInfo.PreComp;

            // TODO Include negations in precomp (optionally) and use from here
            AbstractF2mPoint[] puNeg = new AbstractF2mPoint[pu.Length];
            for (int i = 0; i < pu.Length; ++i)
            {
                puNeg[i] = (AbstractF2mPoint)pu[i].Negate();
            }


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

            int tauCount = 0;

            for (int i = u.Length - 1; i >= 0; i--)
            {
                ++tauCount;
                int ui = u[i];
                if (ui != 0)
                {
                    q        = q.TauPow(tauCount);
                    tauCount = 0;

                    ECPoint x = ui > 0 ? pu[ui >> 1] : puNeg[(-ui) >> 1];
                    q = (AbstractF2mPoint)q.Add(x);
                }
            }
            if (tauCount > 0)
            {
                q = q.TauPow(tauCount);
            }
            return(q);
        }