예제 #1
0
        /// <summary>
        /// https://eprint.iacr.org/2010/354.pdf
        /// Algorithm 17
        /// </summary>
        /// <returns></returns>
        public Fp6 Inverse()
        {
            Fp2 a0 = A;
            Fp2 a1 = B;
            Fp2 a2 = C;

            Fp2 t0 = a0.Squared();
            Fp2 t1 = a1.Squared();
            Fp2 t2 = a2.Squared();
            Fp2 t3 = a0 * a1;
            Fp2 t4 = a0 * a2;
            Fp2 t5 = a1 * a2; // typo (a2 * a3 in paper)?
            Fp2 c0 = t0 - t5.MulByNonResidue();
            Fp2 c1 = t2.MulByNonResidue() - t3;
            Fp2 c2 = t1 - t4; // typo in paper referenced above. should be "-" as per Scott, but is "*"
            Fp2 t6 = a0 * c0;

            t6 = t6 + a2.MulByNonResidue() * c1;
            t6 = t6 + a1.MulByNonResidue() * c2;
            t6 = t6.Inverse();

            c0 = c0 * t6;
            c1 = c1 * t6;
            c2 = c2 * t6;

            return(new Fp6(c0, c1, c2));
        }
예제 #2
0
        /// <summary>
        /// https://eprint.iacr.org/2010/354.pdf
        /// Algorithm 16
        /// </summary>
        /// <returns></returns>
        public Fp6 Squared()
        {
            Fp2 a0 = A;
            Fp2 a1 = B;
            Fp2 a2 = C;

            Fp2 c4 = (a0 * a1).Double();
            Fp2 c5 = a2.Squared();
            Fp2 c1 = c5.MulByNonResidue() + c4;
            Fp2 c2 = c4 - c5;
            Fp2 c3 = a0.Squared();

            c4 = a0 - a1 + a2;
            c5 = (a1 * a2).Double();
            c4 = c4.Squared();
            Fp2 c0 = c5.MulByNonResidue() + c3;

            c2 = c2 + c4 + c5 - c3;

            return(new Fp6(c0, c1, c2));
        }
예제 #3
0
        /// <summary>
        /// https://eprint.iacr.org/2010/354.pdf
        /// Algorithm 13
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public Fp6 Mul(Fp6 o)
        {
            Fp2 a0 = A;
            Fp2 a1 = B;
            Fp2 a2 = C;
            Fp2 b0 = o.A;
            Fp2 b1 = o.B;
            Fp2 b2 = o.C;

            Fp2 v0 = a0 * b0;
            Fp2 v1 = a1 * b1;
            Fp2 v2 = a2 * b2;

            Fp2 c0 = v0 + ((a1 + a2) * (b1 + b2) - v1 - v2).MulByNonResidue();
            Fp2 c1 = (a0 + a1) * (b0 + b1) - v0 - v1 + v2.MulByNonResidue();
            Fp2 c2 = (a0 + a2) * (b0 + b2) - v0 + v1 - v2;

            return(new Fp6(c0, c1, c2));
        }