Ejemplo n.º 1
0
    def gen_mul_by_0y0_fp6(self, out, x, y, mod):
        # out is f6, x is f6, y is f2
        x0 = x
        x1 = x0 + 96
        x2 = x1 + 96
        y0 = y
        y1 = y0 + 48
        out0 = out
        out1 = out0 + 96
        out2 = out1 + 96
        t = buffer_f6mul

        _Huff = self.Huff
        _F1 = F1(self.Huff)
        p0 = F2(_Huff, _F1, t, x2, y, mod)
        p1 = F2(_Huff, _F1, out2, x1, y, mod)
        p2 = F2(_Huff, _F1, out1, x0, y, mod)

        P = [p0, p1, p2]
        debug_points(P, "F12", "gen_mul_by_0y0_fp6", self.Huff)

        self.F2 * p0
        self.F2 * p1
        self.F2 * p2
        self.F2.gen_mul_by_u_plus_1_fp2(out0, t, mod)
Ejemplo n.º 2
0
    def gen_f12mul(self, out, x, y, mod):
        self.f12mul_count += 1
        self.Huff.pushln("// f12 mul")
        x0 = x
        x1 = x0 + 288
        y0 = y
        y1 = y0 + 288
        out0 = out
        out00 = out0
        out01 = out00 + 96
        out02 = out01 + 96
        out1 = out0 + 288
        # temporary variables
        t0 = buffer_f12mul
        t00 = t0
        t01 = t00 + 96
        t02 = t01 + 96
        t1 = t0 + 288
        t10 = t1
        t11 = t10 + 96
        t12 = t11 + 96
        t2 = t1 + 288

        _Huff = self.Huff
        _F2 = self.F2
        _F1 = F1(self.Huff)
        # debugging
        p0 = F6(_Huff, _F2, out0, x0, y0, mod)
        p1 = F6(_Huff, _F2, out1, x1, y1, mod)
        p2 = F6(_Huff, _F2, t0, x0, y0, mod)
        p3 = F6(_Huff, _F2, t1, x1, y1, mod)
        # out1
        p4 = F6(_Huff, _F2, t2, x0, x1, mod)
        p5 = F6(_Huff, _F2, out1, y0, y1, mod)
        p6 = F6(_Huff, _F2, out1, y0, y1, mod)
        p7 = F6(_Huff, _F2, out1, out1, t0, mod)
        p8 = F6(_Huff, _F2, out1, out1, t1, mod)
        # out0
        p9 = F2(_Huff, _F1, out00, t00, t12, mod)
        p10 = F2(_Huff, _F1, out01, t01, t10, mod)
        p11 = F2(_Huff, _F1, out02, t02, t11, mod)

        # debugging
        self.F6 * p0
        self.F6 * p1
        self.F6 * p2
        self.F6 * p3
        # out1
        self.F6 + p4
        self.F6 + p5
        self.F6 * p6
        self.F6 - p7
        self.F6 - p8
        # out0
        self.F2.gen_mul_by_u_plus_1_fp2(t12, t12, mod)
        self.F2 + p9
        self.F2 + p10
        self.F2 + p11
Ejemplo n.º 3
0
    def gen_mul_by_xy00z0_fp12(self, out: int, x: int, y: int, mod: int):
        # out is f12, x is f12, y is f6
        x0 = x
        x1 = x0 + 288
        y0 = y
        y1 = y0 + 96
        y2 = y1 + 96
        out0 = out
        out00 = out0
        out01 = out00 + 96
        out02 = out01 + 96
        out1 = out + 288
        t0 = buffer_f12mul
        t00 = t0
        t01 = t00 + 96
        t02 = t01 + 96
        t1 = t0 + 288
        t10 = t1
        t11 = t10 + 96
        t12 = t11 + 96
        t2 = t1 + 288
        t20 = t2
        t21 = t2 + 96

        _Huff = self.Huff
        _F2 = self.F2
        _F1 = F1(self.Huff)
        p0 = F2(_Huff, _F1, t21, y1, y2, mod)
        p1 = F6(_Huff, _F2, out1, x0, x1, mod)
        p2 = F6(_Huff, _F2, out1, out1, t0, mod)
        p3 = F6(_Huff, _F2, out1, out1, t1, mod)
        p4 = F2(_Huff, _F1, out00, t00, t12, mod)
        p5 = F2(_Huff, _F1, out01, t01, t10, mod)
        p6 = F2(_Huff, _F1, out02, t02, t11, mod)

        P = [p0, p1, p2, p3, p4, p5, p6]
        debug_points(P, "F12", "gen_mul_by_xy00z0_fp12", self.Huff)

        self.gen_mul_by_xy0_fp6(t0, x0, y, mod)
        self.gen_mul_by_0y0_fp6(t1, x1, y2, mod)
        self.Huff.gen_memcopy(t20, y0, 96)
        self.F2 + p0
        self.F6 + p1
        self.gen_mul_by_xy0_fp6(out1, out1, t2, mod)
        self.F6 - p2
        self.F6 - p3
        self.F2.gen_mul_by_u_plus_1_fp2(t12, t12, mod)
        self.F2 + p4
        self.F2 + p5
        self.F2 + p6
Ejemplo n.º 4
0
    def gen_line_dbl(self, line, T, Q, mod):
        # line is 3 f2s, T is E2 point, Q E2 point	(note: our pairing algorithm, T=Q)
        line0 = line
        line1 = line0 + 96
        line2 = line1 + 96
        QX = Q
        TZ = T + 192
        # double
        A, B, E, F, ZZ, X1 = self.gen_Edouble__dbl_2009_alnr(
            "f2", T, Q, line0, mod)
        # eval line
        # note: line0=E+QX is already done in alnr function

        p0 = F2(self.Huff, self.F1, line0, line0, 0, mod)
        p1 = F2(self.Huff, self.F1, line0, line0, A, mod)
        p2 = F2(self.Huff, self.F1, line0, line0, F, mod)
        p3 = F2(self.Huff, self.F1, B, B, B, mod)
        p4 = F2(self.Huff, self.F1, line0, line0, B, mod)
        p5 = F2(self.Huff, self.F1, line1, E, ZZ, mod)
        p6 = F2(self.Huff, self.F1, line2, TZ, ZZ, mod)

        p0**2
        self.F2 - p1
        self.F2 - p2
        self.F2 + p3
        self.F2 + p3
        self.F2 - p4
        self.F2 * p5
        self.F2 * p6
Ejemplo n.º 5
0
 def gen_fsub(self, f, out, x, y, mod):
     if f == "f12":  # TODO: untouched / find test
         self.F12.gen_f12sub(out, x, y, mod)
     if f == "f6":  # TODO: untouched / find test
         self.F6.gen_f6sub(out, x, y, mod)
     if f == "f2":
         p0 = F2(self.Huff, self.F1, out, x, y, mod)
         self.F2 - p0
         # self.F2.gen_f2sub(out, x, y, mod)
     if f == "f1":  # TODO: untouched / find test
         self.F1.gen_f1sub(out, x, y, mod)
Ejemplo n.º 6
0
 def gen_fadd(self, f, out, x, y, mod):
     if f == "f12":  # TODO: untouched / find test
         self.F12.gen_f12add(out, x, y, mod)
     if f == "f6":  # TODO: untouched / find test
         self.F6.gen_f6add(out, x, y, mod)
     if f == "f2":
         p0 = F2(self.Huff, self.F1, out, x, y, mod)
         self.F2 + p0
         # self.F2.gen_f2add(out, x, y, mod)
     if f == "f1":  # TODO: untouched / find test
         self.F1.gen_f1add(out, x, y, mod)
Ejemplo n.º 7
0
 def gen_fsqr(self, f, out, x, mod):
     if f == "f12":  # TODO: untouched / find test
         self.F12.gen_f12sqr(out, x, mod)
     if f == "f6":  # TODO: untouched / find test
         self.F6.gen_f6sqr(out, x, mod)
     if f == "f2":
         p0 = F2(self.Huff, self.F1, out, x, 0, mod)
         p0**2
         # self.F2.gen_f2sqr(out, x, mod)
     if f == "f1":  # TODO: untouched / find test
         self.F1.gen_f1sqr(out, x, mod)
Ejemplo n.º 8
0
 def gen_fmul(self, f, out, x, y, mod):
     if f == "f12":  # TODO: untouched / find test
         p0 = F12(self.Huff, self.F2, self.F6, out, x, y, mod)
         # self.F12 * p0
         self.F12.gen_f12mul(out, x, y, mod)
     if f == "f6":  # TODO: untouched / find test
         self.F6.gen_f6mul(out, x, y, mod)
     if f == "f2":
         p0 = F2(self.Huff, self.F1, out, x, y, mod)
         self.F2 * p0
     if f == "f1":  # TODO: untouched / find test
         self.F1.gen_f1mul(out, x, y, mod)
Ejemplo n.º 9
0
    def gen_line_add(self, line, T, R, Q, mod):
        # line is 3 f2s, T on E2, R on E2, Q on E2 affine
        TZ = T + 192
        QX = Q
        QY = QX + 96
        line0 = line
        line1 = line0 + 96
        line2 = line1 + 96
        # ecadd
        I, J, r = self.gen_Eadd__madd_2007_bl("f2", T, R, Q, line1, mod)

        p0 = F2(self.Huff, self.F1, I, r, QX, mod)
        p1 = F2(self.Huff, self.F1, J, QY, TZ, mod)
        p2 = F2(self.Huff, self.F1, I, I, J, mod)
        p3 = F2(self.Huff, self.F1, line0, I, I, mod)

        self.F2 * p0
        self.F2 * p1
        self.F2 - p2
        self.F2 + p3
        self.Huff.gen_memcopy(line2, TZ, 96)
Ejemplo n.º 10
0
    def gen_f6neg(self, out, x, mod):
        # gen_f6sub(out,f6zero,x,mod)
        # gen_f6sub(out,mod,x,mod)
        x0 = x
        x1 = x0 + 96
        x2 = x1 + 96
        out0 = out
        out1 = out0 + 96
        out2 = out1 + 96

        _huff = self.Huff
        _F1 = F1(self.Huff)
        p0 = F2(_huff, _F1, out0, x0, 0, mod)
        p1 = F2(_huff, _F1, out1, x1, 0, mod)
        p2 = F2(_huff, _F1, out2, x2, 0, mod)

        P = [p0, p1, p2]
        debug_points(P, "F6", "neg", self.Huff)

        -p0
        -p1
        -p2
Ejemplo n.º 11
0
    def gen_f6sub(self, out, x, y, mod):
        self.f6sub_count += 1
        self.Huff.pushln("// f6 sub")
        x0 = x
        x1 = x0 + 96
        x2 = x1 + 96
        y0 = y
        y1 = y0 + 96
        y2 = y1 + 96
        out0 = out
        out1 = out0 + 96
        out2 = out1 + 96

        _F1 = F1(Huff())
        p0 = F2(Huff(), _F1, out0, x0, y0, mod)
        p1 = F2(Huff(), _F1, out1, x1, y1, mod)
        p2 = F2(Huff(), _F1, out2, x2, y2, mod)

        P = [p0, p1, p2]
        debug_points(P, "F6", "sub", self.Huff)

        self.F2 - p0
        self.F2 - p1
        self.F2 - p2
Ejemplo n.º 12
0
    def gen_f6mul(self, out, x, y, mod):
        self.f6mul_count += 1
        self.Huff.pushln("// f6 add")
        x0 = x
        x1 = x0 + 96
        x2 = x1 + 96
        y0 = y
        y1 = y0 + 96
        y2 = y1 + 96
        out0 = out
        out1 = out0 + 96
        out2 = out1 + 96
        # temporary variables
        t0 = buffer_f6mul
        t1 = t0 + 96
        t2 = t1 + 96
        t3 = t2 + 96
        t4 = t3 + 96
        t5 = t4 + 96

        _F1 = F1(Huff())
        p0 = F2(Huff(), _F1, t0, x0, y0, mod)
        p1 = F2(Huff(), _F1, t1, x1, y1, mod)
        p2 = F2(Huff(), _F1, t2, x2, y2, mod)
        p3 = F2(Huff(), _F1, t4, x1, x2, mod)
        p4 = F2(Huff(), _F1, t5, y1, y2, mod)
        p5 = F2(Huff(), _F1, t3, t4, t5, mod)
        p6 = F2(Huff(), _F1, t3, t3, t1, mod)
        p7 = F2(Huff(), _F1, t3, t3, t2, mod)
        p8 = F2(Huff(), _F1, t4, x0, x1, mod)
        p9 = F2(Huff(), _F1, t5, y0, y1, mod)
        p10 = F2(Huff(), _F1, out1, t4, t5, mod)
        p11 = F2(Huff(), _F1, out1, out1, t0, mod)
        p12 = F2(Huff(), _F1, out1, out1, t1, mod)
        p13 = F2(Huff(), _F1, out1, out1, t4, mod)
        p14 = F2(Huff(), _F1, t4, x0, x2, mod)
        p15 = F2(Huff(), _F1, t5, y0, y2, mod)
        p16 = F2(Huff(), _F1, out2, t4, t5, mod)
        p17 = F2(Huff(), _F1, out2, out2, t0, mod)
        p18 = F2(Huff(), _F1, out2, out2, t2, mod)
        p19 = F2(Huff(), _F1, out2, out2, t1, mod)
        p20 = F2(Huff(), _F1, out0, t3, t0, mod)

        P = [
            p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14,
            p15, p16, p17, p18, p19, p20
        ]
        debug_points(P, "F6", "mul", self.Huff)

        # algorithm
        self.F2 * p0
        self.F2 * p1
        self.F2 * p2
        # out0
        self.F2 + p3
        self.F2 + p4
        self.F2 * p5
        self.F2 - p6
        self.F2 - p7
        self.F2.gen_mul_by_u_plus_1_fp2(t3, t3, mod)
        # out1
        self.F2 + p8
        self.F2 + p9
        self.F2 * p10
        self.F2 - p11
        self.F2 - p12
        self.F2.gen_mul_by_u_plus_1_fp2(t4, t2, mod)
        self.F2 + p13
        # out2
        self.F2 + p14
        self.F2 + p15
        self.F2 * p16
        self.F2 - p17
        self.F2 - p18
        self.F2 + p19
        self.F2 + p20
Ejemplo n.º 13
0
    def gen_mul_by_xy0_fp6(self, out, x, y, mod):
        # out if f6, x is f6, y is f6
        x0 = x
        x1 = x0 + 96
        x2 = x1 + 96
        y0 = y
        y1 = y0 + 96
        y2 = y1 + 96
        out0 = out
        out1 = out0 + 96
        out2 = out1 + 96
        t0 = buffer_f6mul
        t1 = t0 + 96
        t2 = t1 + 96  # unused
        t3 = t2 + 96
        t4 = t3 + 96
        t5 = t4 + 96

        _Huff = self.Huff
        _F1 = F1(self.Huff)
        p0 = F2(_Huff, _F1, t0, x0, y0, mod)
        p1 = F2(_Huff, _F1, t1, x1, y1, mod)
        p2 = F2(_Huff, _F1, t3, x2, y1, mod)
        p3 = F2(_Huff, _F1, t4, x0, x1, mod)
        p4 = F2(_Huff, _F1, t5, y0, y1, mod)
        p5 = F2(_Huff, _F1, out1, t4, t5, mod)
        p6 = F2(_Huff, _F1, out1, out1, t0, mod)
        p7 = F2(_Huff, _F1, out1, out1, t1, mod)
        p8 = F2(_Huff, _F1, out2, x2, y0, mod)
        p9 = F2(_Huff, _F1, out2, out2, t1, mod)
        p10 = F2(_Huff, _F1, out0, t3, t0, mod)

        P = [p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10]
        debug_points(P, "F12", "gen_mul_by_xy0_fp6", self.Huff)

        self.F2 * p0
        self.F2 * p1
        self.F2 * p2
        self.F2.gen_mul_by_u_plus_1_fp2(t3, t3, mod)

        self.F2 + p3
        self.F2 + p4
        self.F2 * p5
        self.F2 - p6
        self.F2 - p7

        self.F2 * p8
        self.F2 + p9

        self.F2 + p10
Ejemplo n.º 14
0
    def gen_f12sqr(self, out, x, mod):
        # gen_f12mul(out,x,x,mod)		# TODO: optimize
        self.Huff.pushln("// f12 sqr")
        x0 = x
        x00 = x0
        x01 = x00 + 96
        x02 = x01 + 96
        x1 = x0 + 288
        x10 = x1
        x11 = x10 + 96
        x12 = x11 + 96
        out0 = out
        out00 = out0
        out01 = out00 + 96
        out02 = out01 + 96
        out1 = out0 + 288
        # temporary variables
        t0 = buffer_f12mul
        t00 = t0
        t01 = t00 + 96
        t02 = t01 + 96
        t1 = t0 + 288
        t10 = t1
        t11 = t10 + 96
        t12 = t11 + 96

        _Huff = self.Huff
        _F2 = self.F2
        _F1 = F1(self.Huff)
        p0 = F6(_Huff, _F2, t0, x0, x1, mod)
        p1 = F2(_Huff, _F1, t10, x00, t12, mod)
        p2 = F2(_Huff, _F1, t11, x01, x10, mod)
        p3 = F2(_Huff, _F1, t12, x02, x11, mod)
        p4 = F6(_Huff, _F2, t0, t0, t1, mod)
        p5 = F6(_Huff, _F2, t1, x0, x1, mod)
        p6 = F6(_Huff, _F2, out1, t1, t1, mod)
        p7 = F6(_Huff, _F2, out0, t0, t1, mod)
        p8 = F2(_Huff, _F1, out00, out00, t12, mod)
        p9 = F2(_Huff, _F1, out01, out01, t10, mod)
        p10 = F2(_Huff, _F1, out02, out02, t11, mod)

        P = [p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10]
        debug_points(P, "F12", "sqr", self.Huff)

        self.F6 + p0

        self.F2.gen_mul_by_u_plus_1_fp2(t12, x12, mod)
        self.F2 + p1
        self.F2 + p2
        self.F2 + p3

        self.F6 * p4
        self.F6 * p5

        self.F6 + p6

        self.F6 - p7

        self.F2.gen_mul_by_u_plus_1_fp2(t12, t12, mod)
        self.F2 - p8
        self.F2 - p9
        self.F2 - p10