github.com/consensys/gnark-crypto@v0.14.0/ecc/bls24-317/internal/fptower/generators_test.go (about) 1 package fptower 2 3 import ( 4 "github.com/consensys/gnark-crypto/ecc/bls24-317/fp" 5 "github.com/leanovate/gopter" 6 ) 7 8 // Fp generates an Fp element 9 func GenFp() gopter.Gen { 10 return func(genParams *gopter.GenParameters) *gopter.GenResult { 11 var elmt fp.Element 12 13 if _, err := elmt.SetRandom(); err != nil { 14 panic(err) 15 } 16 genResult := gopter.NewGenResult(elmt, gopter.NoShrinker) 17 return genResult 18 } 19 } 20 21 // E2 generates an E2 elmt 22 func GenE2() gopter.Gen { 23 return gopter.CombineGens( 24 GenFp(), 25 GenFp(), 26 ).Map(func(values []interface{}) *E2 { 27 return &E2{A0: values[0].(fp.Element), A1: values[1].(fp.Element)} 28 }) 29 } 30 31 // E4 generates an E4 elmt 32 func GenE4() gopter.Gen { 33 return gopter.CombineGens( 34 GenE2(), 35 GenE2(), 36 ).Map(func(values []interface{}) *E4 { 37 return &E4{B0: *values[0].(*E2), B1: *values[1].(*E2)} 38 }) 39 } 40 41 // E12 generates an E12 elmt 42 func GenE12() gopter.Gen { 43 return gopter.CombineGens( 44 GenE4(), 45 GenE4(), 46 GenE4(), 47 ).Map(func(values []interface{}) *E12 { 48 return &E12{C0: *values[0].(*E4), C1: *values[1].(*E4), C2: *values[2].(*E4)} 49 }) 50 } 51 52 // E24 generates an E24 elmt 53 func GenE24() gopter.Gen { 54 return gopter.CombineGens( 55 GenE12(), 56 GenE12(), 57 ).Map(func(values []interface{}) *E24 { 58 return &E24{D0: *values[0].(*E12), D1: *values[1].(*E12)} 59 }) 60 }