Skip to content

Commit 83a2e17

Browse files
committed
chore: replace rand.Reader with nil in rsa/ecdsa GenerateKey calls in test files only
1 parent 055b129 commit 83a2e17

45 files changed

Lines changed: 128 additions & 128 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ca/ca_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ func TestNoteSignError(t *testing.T) {
943943

944944
func TestGenerateSKID(t *testing.T) {
945945
t.Parallel()
946-
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
946+
key, err := ecdsa.GenerateKey(elliptic.P256(), nil)
947947
test.AssertNotError(t, err, "Error generating key")
948948

949949
sha256skid, err := generateSKID(key.Public())
@@ -957,7 +957,7 @@ func TestVerifyTBSCertIsDeterministic(t *testing.T) {
957957
t.Parallel()
958958

959959
// Create first keypair and cert
960-
testKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
960+
testKey, err := ecdsa.GenerateKey(elliptic.P256(), nil)
961961
test.AssertNotError(t, err, "unable to generate ECDSA private key")
962962
template := &x509.Certificate{
963963
NotAfter: time.Now().Add(1 * time.Hour),
@@ -968,7 +968,7 @@ func TestVerifyTBSCertIsDeterministic(t *testing.T) {
968968
test.AssertNotError(t, err, "unable to create certificate")
969969

970970
// Create second keypair and cert
971-
testKey2, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
971+
testKey2, err := ecdsa.GenerateKey(elliptic.P256(), nil)
972972
test.AssertNotError(t, err, "unable to generate ECDSA private key")
973973
template2 := &x509.Certificate{
974974
NotAfter: time.Now().Add(2 * time.Hour),

ca/testdata/testcsr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
func main() {
16-
priv, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
16+
priv, err := ecdsa.GenerateKey(elliptic.P256(), nil)
1717
if err != nil {
1818
log.Fatalf("Failed to parse private key: %s", err)
1919
}

cmd/admin/cert_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestSerialsFromPrivateKey(t *testing.T) {
105105
fc := clock.NewFake()
106106
fc.Set(time.Now())
107107

108-
privKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
108+
privKey, err := ecdsa.GenerateKey(elliptic.P256(), nil)
109109
test.AssertNotError(t, err, "creating test private key")
110110
keyBytes, err := x509.MarshalPKCS8PrivateKey(privKey)
111111
test.AssertNotError(t, err, "marshalling test private key bytes")

cmd/admin/key_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ import (
3232

3333
func TestSPKIHashesFromPrivateKeys(t *testing.T) {
3434

35-
ecdsaKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
35+
ecdsaKey, err := ecdsa.GenerateKey(elliptic.P256(), nil)
3636
test.AssertNotError(t, err, "Generating ECDSA key")
3737
pkcs8ecdsa, err := x509.MarshalPKCS8PrivateKey(ecdsaKey)
3838
test.AssertNotError(t, err, "Marshalling PKCS8 private key")
3939

40-
rsaKey, err := rsa.GenerateKey(rand.Reader, 2048)
40+
rsaKey, err := rsa.GenerateKey(nil, 2048)
4141
test.AssertNotError(t, err, "Generating RSA key")
4242
pkcs8rsa, err := x509.MarshalPKCS8PrivateKey(rsaKey)
4343
test.AssertNotError(t, err, "Marshalling PKCS8 private key")
@@ -166,7 +166,7 @@ func TestBlockSPKIHash(t *testing.T) {
166166
log := blog.NewMock()
167167
msa := mockSARecordingBlocks{}
168168

169-
privKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
169+
privKey, err := ecdsa.GenerateKey(elliptic.P256(), nil)
170170
test.AssertNotError(t, err, "creating test private key")
171171
keyHash, err := core.KeyDigest(privKey.Public())
172172
test.AssertNotError(t, err, "computing test SPKI hash")

cmd/ceremony/cert_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ func TestGenerateCSR(t *testing.T) {
549549
Country: "country",
550550
}
551551

552-
signer, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
552+
signer, err := ecdsa.GenerateKey(elliptic.P256(), nil)
553553
test.AssertNotError(t, err, "failed to generate test key")
554554

555555
csrBytes, err := generateCSR(profile, &wrappedSigner{signer})

cmd/ceremony/crl_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (p wrappedSigner) Public() crypto.PublicKey {
6161
}
6262

6363
func TestGenerateCRLLints(t *testing.T) {
64-
k, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
64+
k, err := ecdsa.GenerateKey(elliptic.P256(), nil)
6565
test.AssertNotError(t, err, "failed to generate test key")
6666

6767
cert := &x509.Certificate{
@@ -102,7 +102,7 @@ func TestGenerateCRLLints(t *testing.T) {
102102
}
103103

104104
func TestGenerateCRL(t *testing.T) {
105-
k, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
105+
k, err := ecdsa.GenerateKey(elliptic.P256(), nil)
106106
test.AssertNotError(t, err, "failed to generate test key")
107107

108108
template := &x509.Certificate{

cmd/ceremony/ecdsa_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestECGenerate(t *testing.T) {
4040
ctx.GenerateRandomFunc = func(pkcs11.SessionHandle, int) ([]byte, error) {
4141
return []byte{1, 2, 3}, nil
4242
}
43-
priv, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
43+
priv, err := ecdsa.GenerateKey(elliptic.P256(), nil)
4444
test.AssertNotError(t, err, "Failed to generate a ECDSA test key")
4545

4646
// Test ecGenerate fails with unknown curve

cmd/ceremony/key_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestGenerateKeyRSA(t *testing.T) {
4646
tmp := t.TempDir()
4747

4848
ctx := setupCtx()
49-
rsaPriv, err := rsa.GenerateKey(rand.Reader, 1024)
49+
rsaPriv, err := rsa.GenerateKey(nil, 1024)
5050
test.AssertNotError(t, err, "Failed to generate a test RSA key")
5151
ctx.GetAttributeValueFunc = func(pkcs11.SessionHandle, pkcs11.ObjectHandle, []*pkcs11.Attribute) ([]*pkcs11.Attribute, error) {
5252
return []*pkcs11.Attribute{
@@ -74,7 +74,7 @@ func TestGenerateKeyRSA(t *testing.T) {
7474
}
7575

7676
func setECGenerateFuncs(ctx *pkcs11helpers.MockCtx) {
77-
ecPriv, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
77+
ecPriv, err := ecdsa.GenerateKey(elliptic.P256(), nil)
7878
if err != nil {
7979
panic(err)
8080
}

cmd/ceremony/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
func TestLoadPubKey(t *testing.T) {
2424
tmp := t.TempDir()
25-
key, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
25+
key, _ := ecdsa.GenerateKey(elliptic.P256(), nil)
2626

2727
_, _, err := loadPubKey(path.Join(tmp, "does", "not", "exist"))
2828
test.AssertError(t, err, "should fail on non-existent file")
@@ -1295,7 +1295,7 @@ func TestPostIssuanceLinting(t *testing.T) {
12951295
err := postIssuanceLinting(nil, nil)
12961296
test.AssertError(t, err, "should have failed because no certificate was provided")
12971297

1298-
testKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
1298+
testKey, err := ecdsa.GenerateKey(elliptic.P256(), nil)
12991299
test.AssertNotError(t, err, "unable to generate ECDSA private key")
13001300
template := &x509.Certificate{
13011301
NotAfter: clk.Now().Add(1 * time.Hour),

cmd/ceremony/rsa_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestRSAGenerate(t *testing.T) {
4444
return []byte{1, 2, 3}, nil
4545
}
4646

47-
priv, err := rsa.GenerateKey(rand.Reader, 1024)
47+
priv, err := rsa.GenerateKey(nil, 1024)
4848
test.AssertNotError(t, err, "Failed to generate a RSA test key")
4949

5050
// Test rsaGenerate fails when GenerateKeyPair fails

0 commit comments

Comments
 (0)