github.com/consensys/gnark-crypto@v0.14.0/ecc/bw6-756/fr/iop/utils.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 iop
    18  
    19  import (
    20  	"github.com/consensys/gnark-crypto/ecc/bw6-756/fr"
    21  )
    22  
    23  //----------------------------------------------------
    24  // exp functions until 5
    25  
    26  func exp0(x fr.Element) fr.Element {
    27  	var res fr.Element
    28  	res.SetOne()
    29  	return res
    30  }
    31  
    32  func exp1(x fr.Element) fr.Element {
    33  	return x
    34  }
    35  
    36  func exp2(x fr.Element) fr.Element {
    37  	return *x.Square(&x)
    38  }
    39  
    40  func exp3(x fr.Element) fr.Element {
    41  	var res fr.Element
    42  	res.Square(&x).Mul(&res, &x)
    43  	return res
    44  }
    45  
    46  func exp4(x fr.Element) fr.Element {
    47  	x.Square(&x).Square(&x)
    48  	return x
    49  }
    50  
    51  func exp5(x fr.Element) fr.Element {
    52  	var res fr.Element
    53  	res.Square(&x).Square(&res).Mul(&res, &x)
    54  	return res
    55  }
    56  
    57  // doesn't return any errors, it is a private method, that
    58  // is assumed to be called with correct arguments.
    59  func smallExp(x fr.Element, n int) fr.Element {
    60  	if n == 0 {
    61  		return exp0(x)
    62  	}
    63  	if n == 1 {
    64  		return exp1(x)
    65  	}
    66  	if n == 2 {
    67  		return exp2(x)
    68  	}
    69  	if n == 3 {
    70  		return exp3(x)
    71  	}
    72  	if n == 4 {
    73  		return exp4(x)
    74  	}
    75  	if n == 5 {
    76  		return exp5(x)
    77  	}
    78  	return fr.Element{}
    79  }