private static Fp12 MillerLoop(Bn128Fp g1, Bn128Fp2 g2) { // convert to affine coordinates g1 = g1.ToAffine(); g2 = g2.ToAffine(); // calculate Ell coefficients List <EllCoeffs> coeffs = CalcEllCoeffs(g2); Fp12 f = Fp12.One; int idx = 0; // for each bit except most significant one for (int i = LoopCount.BitLength() - 2; i >= 0; i--) { EllCoeffs cInLoop = coeffs[idx++]; f = f.Squared(); f = f.MulBy024(cInLoop.Ell0, g1.Y.Mul(cInLoop.EllVw), g1.X.Mul(cInLoop.EllVv)); if (LoopCount.TestBit(i)) { cInLoop = coeffs[idx++]; f = f.MulBy024(cInLoop.Ell0, g1.Y.Mul(cInLoop.EllVw), g1.X.Mul(cInLoop.EllVv)); } } EllCoeffs c = coeffs[idx++]; f = f.MulBy024(c.Ell0, g1.Y.Mul(c.EllVw), g1.X.Mul(c.EllVv)); c = coeffs[idx]; f = f.MulBy024(c.Ell0, g1.Y.Mul(c.EllVw), g1.X.Mul(c.EllVv)); return(f); }
public Precomputed(BN128G2 g2, EllCoeffs coeffs) { this.g2 = g2; this.coeffs = coeffs; }
public Precomputed(Bn128Fp2 g2, EllCoeffs coeffs) { G2 = g2; Coeffs = coeffs; }
public static Precomputed Of(BN128G2 g2, EllCoeffs coeffs) { return(new Precomputed(g2, coeffs)); }