-
Notifications
You must be signed in to change notification settings - Fork 163
/
suite.go
53 lines (43 loc) · 1.08 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
package nist
import (
"crypto/cipher"
"crypto/sha256"
"hash"
"io"
"reflect"
"github.com/dedis/crypto/abstract"
"github.com/dedis/crypto/cipher/sha3"
"github.com/dedis/crypto/random"
)
type suite128 struct {
p256
}
// SHA256 hash function
func (s *suite128) Hash() hash.Hash {
return sha256.New()
}
// SHA3/SHAKE128 Sponge Cipher
func (s *suite128) Cipher(key []byte, options ...interface{}) abstract.Cipher {
return sha3.NewShakeCipher128(key, options...)
}
func (s *suite128) Read(r io.Reader, objs ...interface{}) error {
return abstract.SuiteRead(s, r, objs)
}
func (s *suite128) Write(w io.Writer, objs ...interface{}) error {
return abstract.SuiteWrite(s, w, objs)
}
func (s *suite128) New(t reflect.Type) interface{} {
return abstract.SuiteNew(s, t)
}
func (s *suite128) NewKey(rand cipher.Stream) abstract.Scalar {
if rand == nil {
rand = random.Stream
}
return s.Scalar().Pick(rand)
}
// Ciphersuite based on AES-128, SHA-256, and the NIST P-256 elliptic curve.
func NewAES128SHA256P256() abstract.Suite {
suite := new(suite128)
suite.p256.Init()
return suite
}