Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 public Precomputed(BN128G2 g2, EllCoeffs coeffs)
 {
     this.g2     = g2;
     this.coeffs = coeffs;
 }
Exemplo n.º 3
0
 public Precomputed(Bn128Fp2 g2, EllCoeffs coeffs)
 {
     G2     = g2;
     Coeffs = coeffs;
 }
Exemplo n.º 4
0
 public static Precomputed Of(BN128G2 g2, EllCoeffs coeffs)
 {
     return(new Precomputed(g2, coeffs));
 }