github.com/consensys/gnark-crypto@v0.14.0/ecc/bls24-315/twistededwards/curve.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 twistededwards
    18  
    19  import (
    20  	"math/big"
    21  	"sync"
    22  
    23  	"github.com/consensys/gnark-crypto/ecc/bls24-315/fr"
    24  )
    25  
    26  // CurveParams curve parameters: ax^2 + y^2 = 1 + d*x^2*y^2
    27  type CurveParams struct {
    28  	A, D     fr.Element
    29  	Cofactor fr.Element
    30  	Order    big.Int
    31  	Base     PointAffine
    32  }
    33  
    34  // GetEdwardsCurve returns the twisted Edwards curve on bls24-315/Fr
    35  func GetEdwardsCurve() CurveParams {
    36  	initOnce.Do(initCurveParams)
    37  	// copy to keep Order private
    38  	var res CurveParams
    39  
    40  	res.A.Set(&curveParams.A)
    41  	res.D.Set(&curveParams.D)
    42  	res.Cofactor.Set(&curveParams.Cofactor)
    43  	res.Order.Set(&curveParams.Order)
    44  	res.Base.Set(&curveParams.Base)
    45  
    46  	return res
    47  }
    48  
    49  var (
    50  	initOnce    sync.Once
    51  	curveParams CurveParams
    52  )
    53  
    54  func initCurveParams() {
    55  	curveParams.A.SetString("-1")
    56  	curveParams.D.SetString("8771873785799030510227956919069912715983412030268481769609515223557738569779")
    57  	curveParams.Cofactor.SetString("8")
    58  	curveParams.Order.SetString("1437753473921907580703509300571927811987591765799164617677716990775193563777", 10)
    59  
    60  	curveParams.Base.X.SetString("750878639751052675245442739791837325424717022593512121860796337974109802674")
    61  	curveParams.Base.Y.SetString("1210739767513185331118744674165833946943116652645479549122735386298364723201")
    62  }
    63  
    64  // mulByA multiplies fr.Element by curveParams.A
    65  func mulByA(x *fr.Element) {
    66  	x.Neg(x)
    67  }