aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2017-09-13 23:07:38 -0400
committerRuss Cox <rsc@golang.org>2017-09-22 20:08:16 +0000
commit0c014879887c2414eff89d7625205d336c47bd96 (patch)
tree77113379f9733ea59b787eee43433df5c4e72d46
parentdeabc8dc4419b2e65a90ca9f6dc099727b261192 (diff)
downloadgo-0c014879887c2414eff89d7625205d336c47bd96.tar.gz
go-0c014879887c2414eff89d7625205d336c47bd96.zip
[dev.boringcrypto.go1.8] crypto/rsa: fix boring GenerateKey to set non-nil Precomputed.CRTValues
This matches the standard GenerateKey and more importantly Precompute, so that if you generate a key and then store it, read it back, call Precompute on the new copy, and then do reflect.DeepEqual on the two copies, they will match. Before this CL, the original key had CRTValues == nil and the reconstituted key has CRTValues != nil (but len(CRTValues) == 0). Change-Id: I1ddc64342a50a1b65a48d827e4d564f1faab1945 Reviewed-on: https://go-review.googlesource.com/63914 Reviewed-by: Adam Langley <agl@golang.org> Reviewed-on: https://go-review.googlesource.com/65485 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
-rw-r--r--src/crypto/rsa/boring_test.go5
-rw-r--r--src/crypto/rsa/rsa.go7
2 files changed, 9 insertions, 3 deletions
diff --git a/src/crypto/rsa/boring_test.go b/src/crypto/rsa/boring_test.go
index b2395ee3ee..d6203c22a1 100644
--- a/src/crypto/rsa/boring_test.go
+++ b/src/crypto/rsa/boring_test.go
@@ -157,6 +157,11 @@ func TestBoringRandGenerateKey(t *testing.T) {
t.Fatalf("GenerateKey: wrong N\nhave %x\nwant %x", k.N, n)
}
r.checkOffset(35200)
+
+ // Non-Boring GenerateKey always sets CRTValues to a non-nil (possibly empty) slice.
+ if k.Precomputed.CRTValues == nil {
+ t.Fatalf("GenerateKey: Precomputed.CRTValues = nil")
+ }
}
func TestBoringRandGenerateMultiPrimeKey(t *testing.T) {
diff --git a/src/crypto/rsa/rsa.go b/src/crypto/rsa/rsa.go
index 2fd25dddcc..5b3124401c 100644
--- a/src/crypto/rsa/rsa.go
+++ b/src/crypto/rsa/rsa.go
@@ -233,9 +233,10 @@ func GenerateMultiPrimeKey(random io.Reader, nprimes int, bits int) (*PrivateKey
D: D,
Primes: []*big.Int{P, Q},
Precomputed: PrecomputedValues{
- Dp: Dp,
- Dq: Dq,
- Qinv: Qinv,
+ Dp: Dp,
+ Dq: Dq,
+ Qinv: Qinv,
+ CRTValues: make([]CRTValue, 0), // non-nil, to match Precompute
},
}
return key, nil