-
Notifications
You must be signed in to change notification settings - Fork 1
/
lms_benchmark_test.go
51 lines (44 loc) · 1.06 KB
/
lms_benchmark_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
package lms
import (
"testing"
"github.com/LoCCS/lmots"
"github.com/LoCCS/lmots/rand"
)
func BenchmarkNewMerkleAgent(b *testing.B) {
const H = 16
seed := make([]byte, lmots.N)
rand.Reader.Read(seed)
for i := 0; i < b.N; i++ {
if _, err := NewMerkleAgent(H, seed); nil != err {
b.Fatalf("unexpected error in NewMerkleAgent(%v,%x)", H, seed)
}
}
}
func BenchmarkLMSStdOps(b *testing.B) {
const H = 16 // large to ensure (1<<H)>b.N
seed := make([]byte, lmots.N)
rand.Reader.Read(seed)
merkleAgent, err := NewMerkleAgent(H, seed)
if nil != err {
b.Fatal("unexpected error in setting up")
}
b.ResetTimer()
msg := make([]byte, lmots.N)
rand.Reader.Read(msg)
// what if no more leaf to use in the Merkle agent
for i := 0; i < b.N; i++ {
_, sig, err := Sign(merkleAgent, msg)
if nil != err {
if ErrOutOfKeys == err {
b.Log("merkleAgent has been worn out, aborting...")
break
} else {
b.Fatalf("error in signing %x: %s", msg, err)
}
}
if !Verify(merkleAgent.Root, msg, sig) {
b.Log(i)
b.Fatal("verification failed")
}
}
}