Skip to content

Commit

Permalink
fix lint benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
matteosz committed Jul 2, 2024
1 parent 38e3744 commit 4fba34d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,6 @@ issues:
linters:
- errcheck
text: "Error return value is not checked"
- path: "benchmark/*"
linters:
- forbidigo
4 changes: 3 additions & 1 deletion benchmark/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ func benchmarkSign(sigType string) map[string]interface{} {
// Generate keys
for _, i := range keys {
results["keygen"][fmt.Sprintf("%d", i)] = testing.Benchmark(func(b *testing.B) {
anon.BenchGenKeys(edwards25519.NewBlakeSHA256Ed25519(), i)
for j := 0; j < b.N; j++ {
anon.BenchGenKeys(edwards25519.NewBlakeSHA256Ed25519(), i)
}
})
}
benchPubEd25519, benchPriEd25519 := anon.BenchGenKeys(edwards25519.NewBlakeSHA256Ed25519(), keys[len(keys)-1])
Expand Down
19 changes: 13 additions & 6 deletions util/test/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/rand"
"testing"

"github.com/stretchr/testify/require"
"go.dedis.ch/kyber/v4"
"go.dedis.ch/kyber/v4/pairing/bn256"
"go.dedis.ch/kyber/v4/sign"
Expand All @@ -24,16 +25,19 @@ func PrepareBLS(numSigs int) (suite *bn256.Suite, scheme sign.AggregatableScheme
private, public := scheme.NewKeyPair(random.New())
publics[i] = public
privates[i] = private
msg := make([]byte, 64, 64)
rand.Read(msg)
msg := make([]byte, 64)
_, err := rand.Read(msg)
if err != nil {
panic(err)
}
msgs[i] = msg
sig, err := scheme.Sign(private, msg)
if err != nil {
panic(err)
}
sigs[i] = sig
}
return
return suite, scheme, publics, privates, msgs, sigs
}

func BenchCreateKeys(b *testing.B, scheme sign.AggregatableScheme, n int) {
Expand All @@ -49,15 +53,18 @@ func BenchSign(b *testing.B, scheme sign.AggregatableScheme, msg []byte, private
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, private := range privates {
scheme.Sign(private, msg)
_, err := scheme.Sign(private, msg)
require.NoError(b, err)
}
}
}

func BLSBenchVerify(b *testing.B, sigs [][]byte, scheme sign.AggregatableScheme, suite *bn256.Suite, publics []kyber.Point, msgs [][]byte) {
func BLSBenchVerify(b *testing.B, sigs [][]byte, scheme sign.AggregatableScheme,
suite *bn256.Suite, publics []kyber.Point, msgs [][]byte) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
aggregateSig, _ := scheme.AggregateSignatures(sigs...)
bls.BatchVerify(suite, publics, msgs, aggregateSig)
err := bls.BatchVerify(suite, publics, msgs, aggregateSig)
require.NoError(b, err)
}
}

0 comments on commit 4fba34d

Please sign in to comment.