-
Notifications
You must be signed in to change notification settings - Fork 166
Tolerate differences in RSA private key libraries #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
2d07bc6
to
c0eb29b
Compare
+CC @AlexandreEXFO FYI, in case you find this helpful for your environment |
Not sure you need the import of cmp to handle slice order here. You passed Primes[0] into the TPM struct and then used that field as Primes[0] on the way out too. If they came out reversed that would be a surprise indeed! Otherwise LGTM. |
Ha, of course. Too paranoid. I've simplified this, thanks! |
This has no practical advantage, and requires extra variable time code, but is an explicit FIPS 186-5 requirement. Note that the new behavior is consistent with Go+BoringCrypto, but not with Go 1.23. The resulting keys are essentially interchangeable, but it's not impossible for applications to notice (google/go-tpm#383). gcd_lcm_tests.txt is from BoringSSL. Change-Id: I6a6a4656fd5e92912c87bedc667456d0e8787023 Reviewed-on: https://go-review.googlesource.com/c/go/+/639936 Reviewed-by: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Roland Shoemaker <roland@golang.org> Auto-Submit: Filippo Valsorda <filippo@golang.org>
This has no practical advantage, and requires extra variable time code, but is an explicit FIPS 186-5 requirement. Note that the new behavior is consistent with Go+BoringCrypto, but not with Go 1.23. The resulting keys are essentially interchangeable, but it's not impossible for applications to notice (google/go-tpm#383). gcd_lcm_tests.txt is from BoringSSL. Change-Id: I6a6a4656fd5e92912c87bedc667456d0e8787023 Reviewed-on: https://go-review.googlesource.com/c/go/+/639936 Reviewed-by: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Roland Shoemaker <roland@golang.org> Auto-Submit: Filippo Valsorda <filippo@golang.org> # Conflicts: # nat.go # src/crypto/internal/fips140/rsa/keygen.go # src/crypto/internal/fips140/rsa/keygen_test.go # src/crypto/internal/fips140/rsa/rsa.go
This has no practical advantage, and requires extra variable time code, but is an explicit FIPS 186-5 requirement. Note that the new behavior is consistent with Go+BoringCrypto, but not with Go 1.23. The resulting keys are essentially interchangeable, but it's not impossible for applications to notice (google/go-tpm#383). gcd_lcm_tests.txt is from BoringSSL. Change-Id: I6a6a4656fd5e92912c87bedc667456d0e8787023 Reviewed-on: https://go-review.googlesource.com/c/go/+/639936 Reviewed-by: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Roland Shoemaker <roland@golang.org> Auto-Submit: Filippo Valsorda <filippo@golang.org> # Conflicts: # nat.go # src/crypto/internal/fips140/rsa/keygen.go # src/crypto/internal/fips140/rsa/keygen_test.go # src/crypto/internal/fips140/rsa/rsa.go
This has no practical advantage, and requires extra variable time code, but is an explicit FIPS 186-5 requirement. Note that the new behavior is consistent with Go+BoringCrypto, but not with Go 1.23. The resulting keys are essentially interchangeable, but it's not impossible for applications to notice (google/go-tpm#383). gcd_lcm_tests.txt is from BoringSSL. Change-Id: I6a6a4656fd5e92912c87bedc667456d0e8787023 Reviewed-on: https://go-review.googlesource.com/c/go/+/639936 Reviewed-by: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Roland Shoemaker <roland@golang.org> Auto-Submit: Filippo Valsorda <filippo@golang.org> # Conflicts: # nat.go # src/crypto/internal/fips140/rsa/keygen.go # src/crypto/internal/fips140/rsa/keygen_test.go # src/crypto/internal/fips140/rsa/rsa.go
GOEXPERIMENT=boringcrypto go test ./... --test.run TestPriv/valid_rsa
fails occasionally due to the fact that the boringcrypto implementation uses the Carmichael function (lambda(N)) instead of Euler's totient function (phi(N)). Sometimes we get lucky (where phi(N) == lambda(N)) and sometimes we don't.Unfortunately, the TPM RSA private key structure only contains a prime, for compactness. This means that when importing TPM RSA private keys, we have to compute D from the factorization of N ourselves (see crypto.go). This test generates a key in software, converts it into a TPM private key structure, and then checks that the import function returns the same key. Unfortunately, the software key-generation algorithm may disagree with crypto.go's technique (which is currently to use phi(N)).
This change introduces a helper function to the test for comparing RSA private keys by public exponent, modulus, and primes only.