-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecdsa_test.go
41 lines (37 loc) · 859 Bytes
/
ecdsa_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
package ecc
import (
"crypto/rand"
"testing"
)
func TestSignAndVerify(t *testing.T) {
testAllCurves(t, func(t *testing.T, curve *Curve) {
priv, pubX, pubY, err := curve.GenerateKey(rand.Reader)
if err != nil {
t.Errorf("GeneateKey failed: %v", err)
return
}
hashed := []byte("testing")
r, s := curve.Sign(priv, hashed)
if !curve.Verify(pubX, pubY, hashed, r, s) {
t.Errorf("Verify failed")
return
}
})
}
func BenchmarkSignAndVerify(b *testing.B) {
benchmarkAllCurves(b, func(b *testing.B, curve *Curve) {
priv, pubX, pubY, err := curve.GenerateKey(rand.Reader)
if err != nil {
b.Fatal(err)
}
hashed := []byte("testing")
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
r, s := curve.Sign(priv, hashed)
if !curve.Verify(pubX, pubY, hashed, r, s) {
b.Fatal("verify failed")
}
}
})
}