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:
Cuong Manh Le 2021-03-02 16:56:51 +07:00 committed by GitHub
parent 585ffd6cff
commit a193522f7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 11 deletions

View File

@ -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)
}
}