forked from dedis/kyber
/
suite.go
63 lines (53 loc) · 1.71 KB
/
suite.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
56
57
58
59
60
61
62
63
package curve25519
import (
"crypto/cipher"
"crypto/sha256"
"hash"
"io"
"reflect"
"go.dedis.ch/fixbuf"
"github.com/annchain/kyber/v3"
"github.com/annchain/kyber/v3/group/internal/marshalling"
"github.com/annchain/kyber/v3/util/random"
"github.com/annchain/kyber/v3/xof/blake2xb"
)
// SuiteCurve25519 is the suite for the 25519 curve
type SuiteCurve25519 struct {
ProjectiveCurve
}
// Hash returns the instance associated with the suite
func (s *SuiteCurve25519) Hash() hash.Hash {
return sha256.New()
}
// XOF creates the XOF associated with the suite
func (s *SuiteCurve25519) XOF(seed []byte) kyber.XOF {
return blake2xb.New(seed)
}
func (s *SuiteCurve25519) Read(r io.Reader, objs ...interface{}) error {
return fixbuf.Read(r, s, objs)
}
func (s *SuiteCurve25519) Write(w io.Writer, objs ...interface{}) error {
return fixbuf.Write(w, objs)
}
// New implements the kyber.encoding interface
func (s *SuiteCurve25519) New(t reflect.Type) interface{} {
return marshalling.GroupNew(s, t)
}
// RandomStream returns a cipher.Stream that returns a key stream
// from crypto/rand.
func (s *SuiteCurve25519) RandomStream() cipher.Stream {
return random.New()
}
// NewBlakeSHA256Curve25519 returns a cipher suite based on package
// github.com/annchain/kyber/v3/xof/blake2xb, SHA-256, and Curve25519.
//
// If fullGroup is false, then the group is the prime-order subgroup.
//
// The scalars created by this group implement kyber.Scalar's SetBytes
// method, interpreting the bytes as a big-endian integer, so as to be
// compatible with the Go standard library's big.Int type.
func NewBlakeSHA256Curve25519(fullGroup bool) *SuiteCurve25519 {
suite := new(SuiteCurve25519)
suite.Init(Param25519(), fullGroup)
return suite
}