aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crypto/secp256k1/secp256.go4
-rw-r--r--crypto/secp256k1/secp256_test.go31
2 files changed, 17 insertions, 18 deletions
diff --git a/crypto/secp256k1/secp256.go b/crypto/secp256k1/secp256.go
index 41a5608a5..7f26f307c 100644
--- a/crypto/secp256k1/secp256.go
+++ b/crypto/secp256k1/secp256.go
@@ -96,7 +96,7 @@ func GenerateKeyPair() ([]byte, []byte) {
var output_len C.size_t
- C.secp256k1_ec_pubkey_serialize( // always returns 1
+ _ = C.secp256k1_ec_pubkey_serialize( // always returns 1
context,
pubkey65_ptr,
&output_len,
@@ -163,7 +163,7 @@ func Sign(msg []byte, seckey []byte) ([]byte, error) {
sig_serialized_ptr := (*C.uchar)(unsafe.Pointer(&sig_serialized[0]))
var recid C.int
- C.secp256k1_ecdsa_recoverable_signature_serialize_compact(
+ _ = C.secp256k1_ecdsa_recoverable_signature_serialize_compact(
context,
sig_serialized_ptr, // 64 byte compact signature
&recid,
diff --git a/crypto/secp256k1/secp256_test.go b/crypto/secp256k1/secp256_test.go
index cb71ea5e7..d3ff2223d 100644
--- a/crypto/secp256k1/secp256_test.go
+++ b/crypto/secp256k1/secp256_test.go
@@ -86,10 +86,7 @@ func TestSignAndRecover(t *testing.T) {
func TestRandomMessagesWithSameKey(t *testing.T) {
pubkey, seckey := GenerateKeyPair()
keys := func() ([]byte, []byte) {
- // Sign function zeroes the privkey so we need a new one in each call
- newkey := make([]byte, len(seckey))
- copy(newkey, seckey)
- return pubkey, newkey
+ return pubkey, seckey
}
signAndRecoverWithRandomMessages(t, keys)
}
@@ -209,30 +206,32 @@ func compactSigCheck(t *testing.T, sig []byte) {
}
}
-// godep go test -v -run=XXX -bench=BenchmarkSignRandomInputEachRound
+// godep go test -v -run=XXX -bench=BenchmarkSign
// add -benchtime=10s to benchmark longer for more accurate average
-func BenchmarkSignRandomInputEachRound(b *testing.B) {
+
+// to avoid compiler optimizing the benchmarked function call
+var err error
+
+func BenchmarkSign(b *testing.B) {
for i := 0; i < b.N; i++ {
- b.StopTimer()
_, seckey := GenerateKeyPair()
msg := randentropy.GetEntropyCSPRNG(32)
b.StartTimer()
- if _, err := Sign(msg, seckey); err != nil {
- b.Fatal(err)
- }
+ _, e := Sign(msg, seckey)
+ err = e
+ b.StopTimer()
}
}
-//godep go test -v -run=XXX -bench=BenchmarkRecoverRandomInputEachRound
-func BenchmarkRecoverRandomInputEachRound(b *testing.B) {
+//godep go test -v -run=XXX -bench=BenchmarkECRec
+func BenchmarkRecover(b *testing.B) {
for i := 0; i < b.N; i++ {
- b.StopTimer()
_, seckey := GenerateKeyPair()
msg := randentropy.GetEntropyCSPRNG(32)
sig, _ := Sign(msg, seckey)
b.StartTimer()
- if _, err := RecoverPubkey(msg, sig); err != nil {
- b.Fatal(err)
- }
+ _, e := RecoverPubkey(msg, sig)
+ err = e
+ b.StopTimer()
}
}