summaryrefslogtreecommitdiff
path: root/libgo/go/crypto/ecdsa/ecdsa_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/crypto/ecdsa/ecdsa_test.go')
-rw-r--r--libgo/go/crypto/ecdsa/ecdsa_test.go37
1 files changed, 36 insertions, 1 deletions
diff --git a/libgo/go/crypto/ecdsa/ecdsa_test.go b/libgo/go/crypto/ecdsa/ecdsa_test.go
index 62a3fcc496..9546f67c68 100644
--- a/libgo/go/crypto/ecdsa/ecdsa_test.go
+++ b/libgo/go/crypto/ecdsa/ecdsa_test.go
@@ -54,6 +54,18 @@ func BenchmarkSignP256(b *testing.B) {
}
}
+func BenchmarkSignP384(b *testing.B) {
+ b.ResetTimer()
+ p384 := elliptic.P384()
+ hashed := []byte("testing")
+ priv, _ := GenerateKey(p384, rand.Reader)
+
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ _, _, _ = Sign(rand.Reader, priv, hashed)
+ }
+}
+
func BenchmarkVerifyP256(b *testing.B) {
b.ResetTimer()
p256 := elliptic.P256()
@@ -130,7 +142,7 @@ func testNonceSafety(t *testing.T, c elliptic.Curve, tag string) {
}
if r0.Cmp(r1) == 0 {
- t.Errorf("%s: the nonce used for two diferent messages was the same", tag)
+ t.Errorf("%s: the nonce used for two different messages was the same", tag)
}
}
@@ -296,3 +308,26 @@ func TestVectors(t *testing.T) {
}
}
}
+
+func testNegativeInputs(t *testing.T, curve elliptic.Curve, tag string) {
+ key, err := GenerateKey(curve, rand.Reader)
+ if err != nil {
+ t.Errorf("failed to generate key for %q", tag)
+ }
+
+ var hash [32]byte
+ r := new(big.Int).SetInt64(1)
+ r.Lsh(r, 550 /* larger than any supported curve */)
+ r.Neg(r)
+
+ if Verify(&key.PublicKey, hash[:], r, r) {
+ t.Errorf("bogus signature accepted for %q", tag)
+ }
+}
+
+func TestNegativeInputs(t *testing.T) {
+ testNegativeInputs(t, elliptic.P224(), "p224")
+ testNegativeInputs(t, elliptic.P256(), "p256")
+ testNegativeInputs(t, elliptic.P384(), "p384")
+ testNegativeInputs(t, elliptic.P521(), "p521")
+}