github.com/emmansun/gmsm@v0.29.1/sm9/bn256/gfp12b6_exp_u.go (about)

     1  package bn256
     2  
     3  // Use special square
     4  func (e *gfP12b6) Cyclo6PowToU(x *gfP12b6) *gfP12b6 {
     5  	// The sequence of 10 multiplications and 61 squarings is derived from the
     6  	// following addition chain generated with github.com/mmcloughlin/addchain v0.4.0.
     7  	//
     8  	//	_10    = 2*1
     9  	//	_100   = 2*_10
    10  	//	_101   = 1 + _100
    11  	//	_1001  = _100 + _101
    12  	//	_1011  = _10 + _1001
    13  	//	_1100  = 1 + _1011
    14  	//	i56    = (_1100 << 40 + _1011) << 7 + _1011 + _100
    15  	//	i69    = (2*(i56 << 4 + _1001) + 1) << 6
    16  	//	return   2*(_101 + i69)
    17  	//
    18  	var z = e
    19  	var t0 = new(gfP12b6)
    20  	var t1 = new(gfP12b6)
    21  	var t2 = new(gfP12b6)
    22  	var t3 = new(gfP12b6)
    23  
    24  	t2.Cyclo6SquareNC(x)
    25  	t1.Cyclo6SquareNC(t2)
    26  	z.MulNC(x, t1)
    27  	t0.MulNC(t1, z)
    28  	t2.Mul(t2, t0)
    29  	t3.MulNC(x, t2)
    30  	t3.Cyclo6Squares(t3, 40)
    31  	t3.Mul(t2, t3)
    32  	t3.Cyclo6Squares(t3, 7)
    33  	t2.Mul(t2, t3)
    34  	t1.Mul(t1, t2)
    35  	t1.Cyclo6Squares(t1, 4)
    36  	t0.Mul(t0, t1)
    37  	t0.Cyclo6Square(t0)
    38  	t0.Mul(x, t0)
    39  	t0.Cyclo6Squares(t0, 6)
    40  	z.Mul(z, t0)
    41  	z.Cyclo6Square(z)
    42  	return e
    43  }