Exemple #1
0
        private static Precomputed FlippedMillerLoopMixedAddition(BN128G2 base_val, BN128G2 addend)
        {
            Fp2 x1 = addend.x, y1 = addend.y, z1 = addend.z;
            Fp2 x2 = base_val.x, y2 = base_val.y;

            Fp2 d = x1.Sub(x2.Mul(z1));                                 // d = x1 - x2 * z1
            Fp2 e = y1.Sub(y2.Mul(z1));                                 // e = y1 - y2 * z1
            Fp2 f = d.Squared();                                        // f = d^2
            Fp2 g = e.Squared();                                        // g = e^2
            Fp2 h = d.Mul(f);                                           // h = d * f
            Fp2 i = x1.Mul(f);                                          // i = x1 * f
            Fp2 j = h.Add(z1.Mul(g)).Sub(i.Dbl());                      // j = h + z1 * g - 2 * i

            Fp2 x3 = d.Mul(j);                                          // x3 = d * j
            Fp2 y3 = e.Mul(i.Sub(j)).Sub(h.Mul(y1));                    // y3 = e * (i - j) - h * y1)
            Fp2 z3 = z1.Mul(h);                                         // z3 = Z1*H

            Fp2 ell0  = Parameters.TWIST.Mul(e.Mul(x2).Sub(d.Mul(y2))); // ell_0 = TWIST * (e * x2 - d * y2)
            Fp2 ellVV = e.Negate();                                     // ell_VV = -e
            Fp2 ellVW = d;                                              // ell_VW = d

            return(Precomputed.Of(
                       new BN128G2(x3, y3, z3),
                       new EllCoeffs(ell0, ellVW, ellVV)
                       ));
        }
Exemple #2
0
        public Fp6 Squared()
        {
            Fp2 s0 = a.Squared();
            Fp2 ab = a.Mul(b);
            Fp2 s1 = ab.Dbl();
            Fp2 s2 = a.Sub(b).Add(c).Squared();
            Fp2 bc = b.Mul(c);
            Fp2 s3 = bc.Dbl();
            Fp2 s4 = c.Squared();

            Fp2 ra = s0.Add(s3.MulByNonResidue());
            Fp2 rb = s1.Add(s4.MulByNonResidue());
            Fp2 rc = s1.Add(s2).Add(s3).Sub(s0).Sub(s4);

            return(new Fp6(ra, rb, rc));
        }