/** * Multiplies a {@link org.bouncycastle.math.ec.F2mPoint F2mPoint} * by an element <code>λ</code> of <code><b>Z</b>[τ]</code> * using the <code>τ</code>-adic NAF (TNAF) method, given the TNAF * of <code>λ</code>. * @param p The F2mPoint to Multiply. * @param u The the TNAF of <code>λ</code>.. * @return <code>λ * p</code> */ public static F2MPoint MultiplyFromTnaf(F2MPoint p, sbyte[] u) { F2MCurve curve = (F2MCurve)p.Curve; F2MPoint q = (F2MPoint)curve.Infinity; for (int i = u.Length - 1; i >= 0; i--) { q = Tau(q); if (u[i] == 1) { q = (F2MPoint)q.AddSimple(p); } else if (u[i] == -1) { q = (F2MPoint)q.SubtractSimple(p); } } return(q); }
/** * Multiplies a {@link org.bouncycastle.math.ec.F2mPoint F2mPoint} * 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 F2mPoint to multiply. * @param u The the WTNAF of <code>λ</code>.. * @return <code>λ * 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); }