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