diff options
Diffstat (limited to 'libgo/go/crypto/ecdsa/ecdsa_test.go')
-rw-r--r-- | libgo/go/crypto/ecdsa/ecdsa_test.go | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/libgo/go/crypto/ecdsa/ecdsa_test.go b/libgo/go/crypto/ecdsa/ecdsa_test.go index 169944dfb27..62a3fcc4964 100644 --- a/libgo/go/crypto/ecdsa/ecdsa_test.go +++ b/libgo/go/crypto/ecdsa/ecdsa_test.go @@ -42,6 +42,41 @@ func TestKeyGeneration(t *testing.T) { testKeyGeneration(t, elliptic.P521(), "p521") } +func BenchmarkSignP256(b *testing.B) { + b.ResetTimer() + p256 := elliptic.P256() + hashed := []byte("testing") + priv, _ := GenerateKey(p256, 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() + hashed := []byte("testing") + priv, _ := GenerateKey(p256, rand.Reader) + r, s, _ := Sign(rand.Reader, priv, hashed) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + Verify(&priv.PublicKey, hashed, r, s) + } +} + +func BenchmarkKeyGeneration(b *testing.B) { + b.ResetTimer() + p256 := elliptic.P256() + + b.ResetTimer() + for i := 0; i < b.N; i++ { + GenerateKey(p256, rand.Reader) + } +} + func testSignAndVerify(t *testing.T, c elliptic.Curve, tag string) { priv, _ := GenerateKey(c, rand.Reader) @@ -91,11 +126,11 @@ func testNonceSafety(t *testing.T, c elliptic.Curve, tag string) { if s0.Cmp(s1) == 0 { // This should never happen. - t.Errorf("%s: the signatures on two different messages were the same") + t.Errorf("%s: the signatures on two different messages were the same", tag) } if r0.Cmp(r1) == 0 { - t.Errorf("%s: the nonce used for two diferent messages was the same") + t.Errorf("%s: the nonce used for two diferent messages was the same", tag) } } @@ -126,11 +161,11 @@ func testINDCCA(t *testing.T, c elliptic.Curve, tag string) { } if s0.Cmp(s1) == 0 { - t.Errorf("%s: two signatures of the same message produced the same result") + t.Errorf("%s: two signatures of the same message produced the same result", tag) } if r0.Cmp(r1) == 0 { - t.Errorf("%s: two signatures of the same message produced the same nonce") + t.Errorf("%s: two signatures of the same message produced the same nonce", tag) } } |