From ab14c30fe12c9b27f0b5dad1ed2a5c619ff21887 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Mon, 23 Dec 2013 17:24:01 -0600 Subject: [PATCH] Add benchmark for signature verifies. --- bench_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/bench_test.go b/bench_test.go index 8ca65466..d627e6e0 100644 --- a/bench_test.go +++ b/bench_test.go @@ -5,6 +5,7 @@ package btcec_test import ( + "crypto/ecdsa" "github.com/conformal/btcec" "testing" ) @@ -29,3 +30,31 @@ func BenchmarkScalarMult(b *testing.B) { curve.ScalarMult(x, y, k.Bytes()) } } + +// BenchmarkSigVerify benchmarks how long it takes the secp256k1 curve to +// verify signatures. +func BenchmarkSigVerify(b *testing.B) { + b.StopTimer() + // Randomly generated keypair. + // Private key: 9e0699c91ca1e3b7e3c9ba71eb71c89890872be97576010fe593fbf3fd57e66d + pubKey := ecdsa.PublicKey{ + Curve: btcec.S256(), + X: fromHex("d2e670a19c6d753d1a6d8b20bd045df8a08fb162cf508956c31268c6d81ffdab"), + Y: fromHex("ab65528eefbb8057aa85d597258a3fbd481a24633bc9b47a9aa045c91371de52"), + } + + // Double sha256 of []byte{0x01, 0x02, 0x03, 0x04} + msgHash := fromHex("8de472e2399610baaa7f84840547cd409434e31f5d3bd71e4d947f283874f9c0") + sigR := fromHex("fef45d2892953aa5bbcdb057b5e98b208f1617a7498af7eb765574e29b5d9c2c") + sigS := fromHex("d47563f52aac6b04b55de236b7c515eb9311757db01e02cff079c3ca6efb063f") + + if !ecdsa.Verify(&pubKey, msgHash.Bytes(), sigR, sigS) { + b.Errorf("Signature failed to verify") + return + } + b.StartTimer() + + for i := 0; i < b.N; i++ { + ecdsa.Verify(&pubKey, msgHash.Bytes(), sigR, sigS) + } +}