-
Notifications
You must be signed in to change notification settings - Fork 136
/
mode1.go
87 lines (70 loc) · 1.91 KB
/
mode1.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Code generated from mode.templ.go. DO NOT EDIT.
package mayo
import (
"fmt"
"io"
"github.com/cloudflare/circl/sign/mayo/mode1"
)
// implMode1 implements the mode.Mode interface for MAYO_1.
type implMode1 struct{}
// Mode1 is MAYO in mode "MAYO_1".
var Mode1 Mode = &implMode1{}
func (m *implMode1) GenerateKey(rand io.Reader) (
PublicKey, PrivateKey, error) {
return mode1.GenerateKey(rand)
}
func (m *implMode1) NewKeyFromSeed(seed []byte) (PublicKey,
PrivateKey) {
if len(seed) != mode1.SeedSize {
panic(fmt.Sprintf("seed must be of length %d", mode1.SeedSize))
}
seedBuf := [mode1.SeedSize]byte{}
copy(seedBuf[:], seed)
return mode1.NewKeyFromSeed(&seedBuf)
}
func (m *implMode1) Sign(sk PrivateKey, msg []byte, rand io.Reader) ([]byte, error) {
isk := sk.(*mode1.PrivateKey)
return mode1.Sign(isk, msg, rand)
}
func (m *implMode1) Verify(pk PublicKey, msg []byte, signature []byte) bool {
ipk := pk.(*mode1.PublicKey)
return mode1.Verify(ipk, msg, signature)
}
func (m *implMode1) PublicKeyFromBytes(data []byte) PublicKey {
var ret mode1.PublicKey
if len(data) != mode1.PublicKeySize {
panic("packed public key must be of mode1.PublicKeySize bytes")
}
var buf [mode1.PublicKeySize]byte
copy(buf[:], data)
ret.Unpack(&buf)
return &ret
}
func (m *implMode1) PrivateKeyFromBytes(data []byte) PrivateKey {
var ret mode1.PrivateKey
if len(data) != mode1.PrivateKeySize {
panic("packed public key must be of mode1.PrivateKeySize bytes")
}
var buf [mode1.PrivateKeySize]byte
copy(buf[:], data)
ret.Unpack(&buf)
return &ret
}
func (m *implMode1) SeedSize() int {
return mode1.SeedSize
}
func (m *implMode1) PublicKeySize() int {
return mode1.PublicKeySize
}
func (m *implMode1) PrivateKeySize() int {
return mode1.PrivateKeySize
}
func (m *implMode1) SignatureSize() int {
return mode1.SignatureSize
}
func (m *implMode1) Name() string {
return "MAYO_1"
}
func init() {
modes["MAYO_1"] = Mode1
}