Skip to content

Commit

Permalink
crypto/keys/internal: use crypto/rand.Reader for generating private k…
Browse files Browse the repository at this point in the history
…ey (cosmos#8742)

genPrivKey rejects invalid fieldelems, so we must use a real reader
instead of the zero reader.

Fixes cosmos#8741
  • Loading branch information
cuonglm authored Mar 2, 2021
1 parent 585ffd6 commit a193522
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions crypto/keys/internal/benchmarking/bench.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package benchmarking

import (
"crypto/rand"
"io"
"testing"

Expand All @@ -13,22 +14,12 @@ import (
// Use of this source code is governed by a BSD-style
// license that can be found at the bottom of this file.

type zeroReader struct{}

func (zeroReader) Read(buf []byte) (int, error) {
for i := range buf {
buf[i] = 0
}
return len(buf), nil
}

// BenchmarkKeyGeneration benchmarks the given key generation algorithm using
// a dummy reader.
func BenchmarkKeyGeneration(b *testing.B, generateKey func(reader io.Reader) types.PrivKey) {
b.ReportAllocs()
var zero zeroReader
for i := 0; i < b.N; i++ {
generateKey(zero)
generateKey(rand.Reader)
}
}

Expand Down

0 comments on commit a193522

Please sign in to comment.