...
1 package brainpool
2
3 import (
4 "crypto/ecdsa"
5 "crypto/elliptic"
6 "crypto/rand"
7 "testing"
8 )
9
10 func testCurve(t *testing.T, curve elliptic.Curve) {
11 priv, err := ecdsa.GenerateKey(curve, rand.Reader)
12 if err != nil {
13 t.Fatal(err)
14 }
15
16 msg := []byte("test")
17 r, s, err := ecdsa.Sign(rand.Reader, priv, msg)
18 if err != nil {
19 t.Fatal(err)
20 }
21
22 if !ecdsa.Verify(&priv.PublicKey, msg, r, s) {
23 t.Fatal("signature didn't verify.")
24 }
25 }
26
27 func TestP256t1(t *testing.T) {
28 testCurve(t, P256t1())
29 }
30
31 func TestP256r1(t *testing.T) {
32 testCurve(t, P256r1())
33 }
34
35 func TestP384t1(t *testing.T) {
36 testCurve(t, P384t1())
37 }
38
39 func TestP384r1(t *testing.T) {
40 testCurve(t, P384r1())
41 }
42
43 func TestP512t1(t *testing.T) {
44 testCurve(t, P512t1())
45 }
46
47 func TestP512r1(t *testing.T) {
48 testCurve(t, P512r1())
49 }
50
View as plain text