crypto/keys/internal: use crypto/rand.Reader for generating private key (#8742)
genPrivKey rejects invalid fieldelems, so we must use a real reader instead of the zero reader. Fixes #8741
This commit is contained in:
parent
585ffd6cff
commit
a193522f7e
|
@ -1,6 +1,7 @@
|
|||
package benchmarking
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue