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
|
package brainpool
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"testing"
)
func testCurve(t *testing.T, curve elliptic.Curve) {
priv, err := ecdsa.GenerateKey(curve, rand.Reader)
if err != nil {
t.Fatal(err)
}
msg := []byte("test")
r, s, err := ecdsa.Sign(rand.Reader, priv, msg)
if err != nil {
t.Fatal(err)
}
if !ecdsa.Verify(&priv.PublicKey, msg, r, s) {
t.Fatal("signature didn't verify.")
}
}
func TestP256t1(t *testing.T) {
testCurve(t, P256t1())
}
func TestP256r1(t *testing.T) {
testCurve(t, P256r1())
}
func TestP384t1(t *testing.T) {
testCurve(t, P384t1())
}
func TestP384r1(t *testing.T) {
testCurve(t, P384r1())
}
func TestP512t1(t *testing.T) {
testCurve(t, P512t1())
}
func TestP512r1(t *testing.T) {
testCurve(t, P512r1())
}
|