github.com/consensys/gnark-crypto@v0.14.0/ecc/stark-curve/fp/element_exp.go (about)

     1  // Copyright 2020 ConsenSys Software Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Code generated by consensys/gnark-crypto DO NOT EDIT
    16  
    17  package fp
    18  
    19  // expBySqrtExp is equivalent to z.Exp(x, 400000000000008)
    20  //
    21  // uses github.com/mmcloughlin/addchain v0.4.0 to generate a shorter addition chain
    22  func (z *Element) expBySqrtExp(x Element) *Element {
    23  	// addition chain:
    24  	//
    25  	//	return  (1 << 55 + 1) << 3
    26  	//
    27  	// Operations: 58 squares 1 multiplies
    28  
    29  	// Allocate Temporaries.
    30  	var ()
    31  
    32  	// var
    33  	// Step 55: z = x^0x80000000000000
    34  	z.Square(&x)
    35  	for s := 1; s < 55; s++ {
    36  		z.Square(z)
    37  	}
    38  
    39  	// Step 56: z = x^0x80000000000001
    40  	z.Mul(&x, z)
    41  
    42  	// Step 59: z = x^0x400000000000008
    43  	for s := 0; s < 3; s++ {
    44  		z.Square(z)
    45  	}
    46  
    47  	return z
    48  }
    49  
    50  // expByLegendreExp is equivalent to z.Exp(x, 400000000000008800000000000000000000000000000000000000000000000)
    51  //
    52  // uses github.com/mmcloughlin/addchain v0.4.0 to generate a shorter addition chain
    53  func (z *Element) expByLegendreExp(x Element) *Element {
    54  	// addition chain:
    55  	//
    56  	//	return  ((1 << 55 + 1) << 4 + 1) << 191
    57  	//
    58  	// Operations: 250 squares 2 multiplies
    59  
    60  	// Allocate Temporaries.
    61  	var ()
    62  
    63  	// var
    64  	// Step 55: z = x^0x80000000000000
    65  	z.Square(&x)
    66  	for s := 1; s < 55; s++ {
    67  		z.Square(z)
    68  	}
    69  
    70  	// Step 56: z = x^0x80000000000001
    71  	z.Mul(&x, z)
    72  
    73  	// Step 60: z = x^0x800000000000010
    74  	for s := 0; s < 4; s++ {
    75  		z.Square(z)
    76  	}
    77  
    78  	// Step 61: z = x^0x800000000000011
    79  	z.Mul(&x, z)
    80  
    81  	// Step 252: z = x^0x400000000000008800000000000000000000000000000000000000000000000
    82  	for s := 0; s < 191; s++ {
    83  		z.Square(z)
    84  	}
    85  
    86  	return z
    87  }