Beispiel #1
0
    def gen_f2sqr(self, out, x, mod):
        self.f2mul_count += 1
        self.Huff.pushln("// f2sqr")

        # get offsets
        x0 = x
        x1 = x + 48
        out0 = out
        out1 = out + 48
        tmp0 = buffer_f2mul
        tmp1 = tmp0 + 48

        p0 = F1(Huff(), tmp0, x0, x1, mod)
        p1 = F1(Huff(), tmp1, x0, x1, mod)
        p2 = F1(Huff(), out1, x0, x1, mod)
        p3 = F1(Huff(), out1, out1, out1, mod)
        p4 = F1(Huff(), out0, tmp0, tmp1, mod)

        P = [p0, p1, p2, p3, p4]
        debug_points(P, "F2", "sqr", self.Huff)

        self.F1 + p0
        self.F1 - p1
        self.F1 * p2
        self.F1 + p3
        self.F1 * p4
Beispiel #2
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)
Beispiel #3
0
    def gen_f12_conjugate(self, x, mod):
        x1 = x + 288
        p0 = F6(self.Huff, self.F2, x1, x1, 0, mod)

        P = [p0]
        debug_points(P, "F12", "conj", self.Huff)

        -p0
Beispiel #4
0
    def gen_f2neg(self, out, in_, mod):
        # gen_f2sub(out,zero,in_,mod)
        p0 = F1(Huff(), out, mod, in_, mod)
        p1 = F1(Huff(), out + 48, mod, in_ + 48, mod)

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

        self.F1 - p0
        self.F1 - p1
Beispiel #5
0
    def gen_mul_by_u_plus_1_fp2(self, out, x, mod):
        t = buffer_f2mul  # to prevent clobbering

        p0 = F1(Huff(), t, x, x + 48, mod)
        p1 = F1(Huff(), out + 48, x, x + 48, mod)

        P = [p0, p1]
        debug_points(P, "F2", "gen_mul_by_u_plus_1_fp2", self.Huff)

        self.F1 - p0
        self.F1 + p1
        self.Huff.gen_memcopy(out, t, 48)
Beispiel #6
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
Beispiel #7
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
Beispiel #8
0
    def gen_f2sub(self, out, x, y, mod):
        self.f2sub_count += 1
        self.Huff.pushln("// f2 sub")
        x0 = x
        x1 = x + 48
        y0 = y
        y1 = y + 48
        out0 = out
        out1 = out + 48

        p0 = F1(self.Huff, out0, x0, y0, mod)
        p1 = F1(self.Huff, out1, x1, y1, mod)

        debug_points([p0, p1], "F2", "sub", self.Huff)

        self.F1 - p0
        self.F1 - p1
Beispiel #9
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
Beispiel #10
0
    def gen_f2add(self, out, x, y, mod):
        self.f2add_count += 1
        self.Huff.pushln("// f2 add")
        x0 = x
        x1 = x + 48
        y0 = y
        y1 = y + 48
        out0 = out
        out1 = out + 48

        p0 = F1(self.Huff, out0, x0, y0, mod)

        p1 = F1(self.Huff, out1, x1, y1, mod)

        # debugging -- this investigates the repetition of points
        # _F = "F2"
        # _key = "add"
        # _P = [p0, p1]
        debug_points([p0, p1], "F2", "add", self.Huff)

        self.F1 + p0
        self.F1 + p1
Beispiel #11
0
    def gen_f2mul(self, out, x, y, mod):
        self.f2mul_count += 1
        self.Huff.pushln("// f2 mul")
        # get offsets
        x0 = x
        x1 = x + 48
        y0 = y
        y1 = y + 48
        out0 = out
        out1 = out + 48
        # temporary values
        tmp1 = buffer_f2mul
        tmp2 = tmp1 + 48
        tmp3 = tmp2 + 48

        p0 = F1(Huff(), tmp1, x0, y0, mod)
        p1 = F1(Huff(), tmp2, x1, y1, mod)
        p2 = F1(Huff(), out0, tmp1, tmp2, mod)
        p3 = F1(Huff(), tmp1, tmp1, tmp2, mod)
        p4 = F1(Huff(), tmp2, x0, x1, mod)
        p5 = F1(Huff(), tmp3, y0, y1, mod)
        p6 = F1(Huff(), tmp2, tmp2, tmp3, mod)
        p7 = F1(Huff(), out1, tmp2, tmp1, mod)

        P = [p0, p1, p2, p3, p4, p5, p6, p7]
        debug_points(P, "F2", "mul", self.Huff)

        self.F1 * p0
        self.F1 * p1
        # gen_f1sub(tmp3,zero,tmp2,mod)
        # gen_f1add(out0,tmp1,tmp3,mod)
        self.F1 - p2  # above sub,add give same result as just this sub
        self.F1 + p3
        self.F1 + p4
        self.F1 + p5
        self.F1 * p6
        self.F1 - p7
Beispiel #12
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
Beispiel #13
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
Beispiel #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