/
adapter.go
50 lines (42 loc) 路 1.2 KB
/
adapter.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
package en256
import (
"github.com/drand/kyber"
)
// SuiteBn256 is an adapter that implements the suites.Suite interface so that
// bn256 can be used as a common suite to generate key pairs for instance but
// still preserves the properties of the pairing (e.g. the Pair function).
//
// It's important to note that the Point function will generate a point
// compatible with public keys only (group G2) where the signature must be
// used as a point from the group G1.
type SuiteBn256 struct {
*Suite
kyber.Group
}
// NewSuiteBn256 makes a new BN256 suite
func NewSuiteBn256() *SuiteBn256 {
return &SuiteBn256{
Suite: NewSuite(),
}
}
// Point generates a point from the G2 group that can only be used
// for public keys
func (s *SuiteBn256) Point() kyber.Point {
return s.G2().Point()
}
// PointLen returns the length of a G2 point
func (s *SuiteBn256) PointLen() int {
return s.G2().PointLen()
}
// Scalar generates a scalar
func (s *SuiteBn256) Scalar() kyber.Scalar {
return s.G1().Scalar()
}
// ScalarLen returns the lenght of a scalar
func (s *SuiteBn256) ScalarLen() int {
return s.G1().ScalarLen()
}
// String returns the name of the suite
func (s *SuiteBn256) String() string {
return "bn256.adapter"
}