github.com/onflow/flow-go/crypto@v0.24.8/sign_relic.go (about) 1 //go:build relic 2 // +build relic 3 4 package crypto 5 6 import ( 7 "fmt" 8 ) 9 10 // newSigner chooses and initializes a signature scheme 11 func newSigner(algo SigningAlgorithm) (signer, error) { 12 // try Relic algos 13 if signer := relicSigner(algo); signer != nil { 14 return signer, nil 15 } 16 // return a non-Relic algo 17 return newNonRelicSigner(algo) 18 } 19 20 // relicSigner returns a signer that depends on Relic library. 21 func relicSigner(algo SigningAlgorithm) signer { 22 if algo == BLSBLS12381 { 23 return blsInstance 24 } 25 return nil 26 } 27 28 // Initialize Relic with the BLS context on BLS 12-381 29 func init() { 30 initRelic() 31 initNonRelic() 32 } 33 34 // Initialize the context of all algos requiring Relic 35 func initRelic() { 36 blsInstance = &blsBLS12381Algo{ 37 algo: BLSBLS12381, 38 } 39 if err := blsInstance.init(); err != nil { 40 panic(fmt.Sprintf("initialization of BLS failed: %s", err.Error())) 41 } 42 }