-
Notifications
You must be signed in to change notification settings - Fork 0
/
lamport_test.go
68 lines (53 loc) · 1.43 KB
/
lamport_test.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
package lamport_test
import (
"crypto"
"crypto/rand"
"crypto/sha256"
_ "crypto/sha256"
"testing"
"github.com/ureeves/lamport"
)
var messageHash = sha256.Sum256([]byte("message to sign"))
func TestLamport(t *testing.T) {
k, err := lamport.GenerateKey(rand.Reader, crypto.SHA256)
if err != nil {
t.Fatalf("failed generating key: %s", err)
}
sig, err := lamport.Sign(k, messageHash[:])
if err != nil {
t.Fatalf("failed signing with key")
}
if err := lamport.Verify(&k.PublicKey, messageHash[:], sig); err != nil {
t.Fatalf("signature generated was invalid: %s", err)
}
}
func BenchmarkGenerate(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
lamport.GenerateKey(rand.Reader, crypto.SHA256) // nolint, only for benchmark purposes
}
}
func BenchmarkSign(b *testing.B) {
k, err := lamport.GenerateKey(rand.Reader, crypto.SHA256)
if err != nil {
b.Fatalf("failed generating key: %s", err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
lamport.Sign(k, messageHash[:]) // nolint, only for benchmark purposes
}
}
func BenchmarkVerify(b *testing.B) {
k, err := lamport.GenerateKey(rand.Reader, crypto.SHA256)
if err != nil {
b.Fatalf("failed generating key: %s", err)
}
sig, err := lamport.Sign(k, messageHash[:])
if err != nil {
b.Fatalf("failed signing with key")
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
lamport.Verify(&k.PublicKey, messageHash[:], sig) // nolint, only for benchmark purposes
}
}