github.com/consensys/gnark-crypto@v0.14.0/ecc/bw6-756/fr/generator.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 fr 18 19 import ( 20 "fmt" 21 "math/big" 22 "math/bits" 23 24 "github.com/consensys/gnark-crypto/ecc" 25 ) 26 27 // Generator returns a generator for Z/2^(log(m))Z 28 // or an error if m is too big (required root of unity doesn't exist) 29 func Generator(m uint64) (Element, error) { 30 x := ecc.NextPowerOfTwo(m) 31 32 var rootOfUnity Element 33 34 rootOfUnity.SetString("199251335866470442271346949249090720992237796757894062992204115206570647302191425225605716521843542790404563904580") 35 const maxOrderRoot uint64 = 41 36 37 // find generator for Z/2^(log(m))Z 38 logx := uint64(bits.TrailingZeros64(x)) 39 if logx > maxOrderRoot { 40 return Element{}, fmt.Errorf("m (%d) is too big: the required root of unity does not exist", m) 41 } 42 43 expo := uint64(1 << (maxOrderRoot - logx)) 44 var generator Element 45 generator.Exp(rootOfUnity, big.NewInt(int64(expo))) // order x 46 return generator, nil 47 }