forked from dedis/kyber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
suites.go
55 lines (47 loc) · 1.24 KB
/
suites.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
43
44
45
46
47
48
49
50
51
52
53
54
55
// Package suites allows callers to look up Kyber suites by name.
//
// Currently, only the "ed25519" suite is available by default. To
// have access to "curve25519" and the NIST suites (i.e. "P256"),
// one needs to call the "go" tool with the tag "vartime", such as:
//
// go build -tags vartime
// go install -tags vartime
// go test -tags vartime
package suites
import (
"errors"
"strings"
"github.com/dedis/kyber"
)
// Suite is the sum of all suites mix-ins in Kyber.
type Suite interface {
kyber.Encoding
kyber.Group
kyber.HashFactory
kyber.XOFFactory
kyber.Random
}
var suites = map[string]Suite{}
// register is called by suites to make themselves known to Kyber.
//
func register(s Suite) {
suites[strings.ToLower(s.String())] = s
}
// ErrUnknownSuite indicates that the suite was not one of the
// registered suites.
var ErrUnknownSuite = errors.New("unknown suite")
// Find looks up a suite by name.
func Find(name string) (Suite, error) {
if s, ok := suites[strings.ToLower(name)]; ok {
return s, nil
}
return nil, ErrUnknownSuite
}
// MustFind looks up a suite by name and panics if it is not found.
func MustFind(name string) Suite {
s, err := Find(name)
if err != nil {
panic("Suite " + name + " not found.")
}
return s
}