forked from nspcc-dev/dbft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypto.go
49 lines (39 loc) · 1.03 KB
/
crypto.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
package crypto
import (
"encoding"
"io"
)
type (
// PublicKey is a generic public key interface used by dbft.
PublicKey interface {
encoding.BinaryMarshaler
encoding.BinaryUnmarshaler
// Verify verifies if sig is indeed msg's signature.
Verify(msg, sig []byte) error
}
// PrivateKey is a generic private key interface used by dbft.
PrivateKey interface {
// Sign returns msg's signature and error on failure.
Sign(msg []byte) (sig []byte, err error)
}
)
type suiteType byte
const (
// SuiteECDSA is a ECDSA suite over P-256 curve
// with 64-byte uncompressed signatures.
SuiteECDSA suiteType = 1 + iota
)
const defaultSuite = SuiteECDSA
// Generate generates new key pair using r
// as a source of entropy.
func Generate(r io.Reader) (PrivateKey, PublicKey) {
return GenerateWith(defaultSuite, r)
}
// GenerateWith generates new key pair for suite t
// using r as a source of entropy.
func GenerateWith(t suiteType, r io.Reader) (PrivateKey, PublicKey) {
if t == SuiteECDSA {
return generateECDSA(r)
}
return nil, nil
}