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); }
/** * Multiplies a {@link org.bouncycastle.math.ec.AbstractF2mPoint AbstractF2mPoint} * by an element <code>λ</code> of <code><b>Z</b>[τ]</code> * using the window <code>τ</code>-adic NAF (TNAF) method, given the * WTNAF of <code>λ</code>. * @param p The AbstractF2mPoint to multiply. * @param u The the WTNAF of <code>λ</code>.. * @return <code>λ * 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); }