]> Cypherpunks repositories - gostls13.git/commit
crypto/rsa: move precomputation to crypto/internal/fips140/rsa
authorFilippo Valsorda <filippo@golang.org>
Fri, 29 Nov 2024 12:15:11 +0000 (13:15 +0100)
committerGopher Robot <gobot@golang.org>
Sat, 30 Nov 2024 01:49:31 +0000 (01:49 +0000)
commit7d7192e54f4d4eb51018ad128c25d52e26f02a3f
treeefc4beb3c4521651da3949cbde9e1b59f8f09b01
parentfa38b41be94f66d3d49e10f673643105f44fe540
crypto/rsa: move precomputation to crypto/internal/fips140/rsa

We are severely limited by the crypto/rsa API in a few ways:

 - Precompute doesn't return an error, but is the only function allowed
   to modify a PrivateKey.

 - Clients presumably expect the PrecomputedValues big.Ints to be
   populated after Precompute.

 - MarshalPKCS1PrivateKey requires the precomputed values, and doesn't
   have an error return.

 - PrivateKeys with only N, e, and D have worked so far, so they might
   have to keep working.

To move precomputation to the FIPS module, we focus on the happy path of
a PrivateKey with two primes where Precompute is called before anything
else, which match ParsePKCS1PrivateKey and GenerateKey.

There is a significant slowdown in the Parse benchmark due to the
constant-time inversion of qInv. This will be addressed in a follow-up
CL that will use (and check) the value in the ASN.1.

Note that the prime product check now moved to checkPrivateKey is broken
(Π should start at 1 not 0) and fixed in CL 632478.

Updates #69799
For #69536

Change-Id: I95a8bc1244755c6d15d7c4eb179135a15608ddd6
Reviewed-on: https://go-review.googlesource.com/c/go/+/632476
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
doc/next/6-stdlib/99-minor/crypto/x509/69799.md [new file with mode: 0644]
src/crypto/internal/fips140/bigmod/nat.go
src/crypto/internal/fips140/rsa/rsa.go
src/crypto/rsa/rsa.go
src/crypto/x509/pkcs1.go
src/crypto/x509/pkcs8.go
src/crypto/x509/x509_test.go