You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
crypto/rsa: refuse to generate and/or use keys smaller than 1024 bits #68762
crypto/rsa is unusual in that it can be secure (used with a key size > 2048) or completely insecure (used with a key size such as 512 bits, which can be broken on a laptop). Small keys are sometimes useful in tests, but having an rsa.PrivateKey value that behaves and looks exactly like a secure one but actually provides no security at all is a significant footgun.
In production, if a 512-bit key is used, it's overwhelmingly likely that the operator thinks they have security and doesn't (this happens in the real world on a regular basis) as opposed to being intentional about using fake RSA, so this feels like one of those rare occasions where breaking them is justified.
I propose we do both the following in Go 1.24:
return an error from rsa.GenerateKey if bits is less than 1024
return an error from all Sign, Verify, Encrypt, and Decrypt methods if the key is smaller than 1024 bits
GODEBUG=rsa1024min=0 reverts to the old behavior.
OpenSSL sounds on the way to doing (1) in a minor release and (2) in a major release. openssl/openssl#25092
To avoid slow key generation in tests, we can recommend using the test keys in RFC 9500. If anyone has a good idea for how to expose them, we can even provide them ready to use.
We could also disable the restriction based on testing.Testing() but I would keep that as a fallback if the amount of tests that require fixing turns out to be truly unmanageable, because generally tests are supposed to test actual behavior.
Reacted by Lincoln Stoll, Giacomo Pope, Andrew Ayer, BenBE, Nicholas Capo, apreiml, Edoardo Spadolini, Jonathan Yu, sidpadture-stripe, Eric Lagergren and 44 more
Reacted by rittneje, Jeffrey Stiles and klimov-andre
Reacted by Helio Machado and Kent Gruber
Reacted by Jonathan Yu, Matthew McPherrin, Komu Wairagu, Helio Machado and Kent Gruber
changed the title [-]crypto/rsa: refuse to generate and/or use keys smaller than 1024 bits[/-][+]proposal: crypto/rsa: refuse to generate and/or use keys smaller than 1024 bits[/+]on Aug 7, 2024
For pyca/cryptography (most widely used Python cryptography library) in our last release (~3 weeks ago) we enforce a minimum of 1024-bit for RSA key generation (up from 512-bits in the previous release).
This has produced only one complaint, about a testing workload (where small keys were being used for performance).
We're also interested in enforcing key sizes in signing/verification (or perhaps in key loading), but haven't done so yet.
Reacted by Jonathan Yu, Komu Wairagu, Tom Thorogood, Julien Voisin, Diana and Oleg Kovalov
Reacted by Jonathan Yu, Komu Wairagu, Tom Thorogood, Diana and محمّد
To avoid slow key generation in tests, we can recommend using the test keys in RFC 9500. If anyone has a good idea for how to expose them, we can even provide them ready to use.
An easy answer to this is a GenerateKey or package-level example, for folks to copy-paste.
We could also disable the restriction based on testing.Testing() but I would keep that as a fallback if the amount of tests that require fixing turns out to be truly unmanageable, because generally tests are supposed to test actual behavior.
Actually, this is not a good idea. Packages can opt in to the equivalent behavior simply by doing
@FiloSottile Are you committing to supporting that GODEBUG forever? There are legitimate reasons to use smaller keys, and we shouldn't have to fork the Go standard library to work with them.
Also, I really don't think this should (only) be a GODEBUG. When smaller keys are intentional, it is going to be for some specific use case. Having this toggle for the entire application is too coarse grain. It would be far preferable to be able to opt-in per function/method call.
Reacted by Tom Thorogood, Jack Harrhy, Alex Forster, Luc Stepniewski, Robin Diddams, Julien Voisin, Lena, Diana, Graham Anderson, Sam and 1 more
Do you have an examples of those legitimate use-cases? I admit they may exist but besides test-case reasons, I am not aware of why you’d want to use RSA < 1024. Even 1024 is a stretch these days for anything that requires actual security. I almost want 1024 gated behind a GODEBUG too
Reacted by Tom Thorogood, Matt Layher, Jack Harrhy, bo0tzz, Lincoln Stoll, Luc Stepniewski and Lena
@mcpherrinm We have some edge devices that can only hardware accelerate 256-bit. I thought they were RSA, but turns out they are elliptic (P-256), so we're good!
Reacted by Matthew McPherrin, Jonathan Yu, Robin Diddams, Alona Enraght-Moony, Nic Klaassen and Tristan Stenner
Great: P-256 elliptic curves have strength greater than RSA-2048 and are well within the margin of safety today.
Confusion about key strength for different algorithms is one of the common reasons for accidental use of RSA-512. For example, hashicorp/consul#20112 defaulted to a key size of 256, which was suitable for P-256 but totally inappropriate if Consul was configured to use RSA but didn’t have a key size set.
This proposal would have prevented that issue.
Reacted by Tom Thorogood
Reacted by Jonathan Yu and Juan Pablo Villaseca Carrasco
A recent example of a real world security incident due to production usage of RSA 512-bit keys.
https://rya.nc/vpp-hack.html
(This incident prompted this proposal, but it was not public at the time.)
Reacted by Luc Stepniewski, Robin Diddams, r3vit, Carl Winbäck, Diana, Håkon, Tom Thorogood, Graham Anderson, Helio Machado, Juan Pablo Villaseca Carrasco and 2 more
Guys, I think this is a breaking change for some system. What if some systems depend on old API, and there is no way to ask the provider to upgrade theirs keys from 512 to 1024? While for go 1.23 it was working normally, for other version it will stop working without quick way of fixing it.
On October 10, 2025 12:24:11 PM GMT+01:00, Sergey ***@***.***> wrote:
quolpr left a comment (golang/go#68762)
Guys, I think this is a breaking change for some system. What if some systems depend on old API, and there is no way to ask the provider to upgrade theirs keys from 512 to 1024? While for go 1.23 it was working normally, for other version it will stop working without quick way of fixing it.
@ryancdotorg yeah, I understand. But I think the first step of moving to 1024 should be deprecation notice, so old legacy system will start migrating to the newer version. And then breaking change. We are living in the real world, where inertia of process is very often things.
@quolpr I'm afraid you're fairly late to the party. This went through the proposal process more than a year ago, and Go 1.24 release candidates already included this change. At this point I doubt it will be reconsidered because it landed in a stable release ten months ago.
However, note that you can get the old behavior back for now; search for rsa1024min in https://go.dev/doc/godebug.
Reacted by Sergey, Oleg Kovalov, Qualtrics Developer Advocacy and Joel Lau
Activity
[-]crypto/rsa: refuse to generate and/or use keys smaller than 1024 bits[/-][+]proposal: crypto/rsa: refuse to generate and/or use keys smaller than 1024 bits[/+]alex commentedon Aug 7, 2024
For pyca/cryptography (most widely used Python cryptography library) in our last release (~3 weeks ago) we enforce a minimum of 1024-bit for RSA key generation (up from 512-bits in the previous release).
This has produced only one complaint, about a testing workload (where small keys were being used for performance).
We're also interested in enforcing key sizes in signing/verification (or perhaps in key loading), but haven't done so yet.
FiloSottile commentedon Aug 7, 2024
An easy answer to this is a GenerateKey or package-level example, for folks to copy-paste.
Actually, this is not a good idea. Packages can opt in to the equivalent behavior simply by doing
in a test file (or an equivalent, test-scoped operation).
ericlagergren commentedon Aug 7, 2024
This also requires crypto/rsa to import testing, which isn't good.
rittneje commentedon Aug 7, 2024
@FiloSottile Are you committing to supporting that
GODEBUGforever? There are legitimate reasons to use smaller keys, and we shouldn't have to fork the Go standard library to work with them.Also, I really don't think this should (only) be a
GODEBUG. When smaller keys are intentional, it is going to be for some specific use case. Having this toggle for the entire application is too coarse grain. It would be far preferable to be able to opt-in per function/method call.mcpherrinm commentedon Aug 7, 2024
Do you have an examples of those legitimate use-cases? I admit they may exist but besides test-case reasons, I am not aware of why you’d want to use RSA < 1024. Even 1024 is a stretch these days for anything that requires actual security. I almost want 1024 gated behind a GODEBUG too
rittneje commentedon Aug 8, 2024
@mcpherrinm We have some edge devices that can only hardware accelerate 256-bit. I thought they were RSA, but turns out they are elliptic (P-256), so we're good!
mcpherrinm commentedon Aug 8, 2024
Great: P-256 elliptic curves have strength greater than RSA-2048 and are well within the margin of safety today.
Confusion about key strength for different algorithms is one of the common reasons for accidental use of RSA-512. For example, hashicorp/consul#20112 defaulted to a key size of 256, which was suitable for P-256 but totally inappropriate if Consul was configured to use RSA but didn’t have a key size set.
This proposal would have prevented that issue.
FiloSottile commentedon Aug 8, 2024
rsc commentedon Aug 13, 2024
No need for this in a test. Tests can write a line at the top of the source file:
28 remaining items
mauri870 commentedon Nov 14, 2024
Thanks @FiloSottile!
gopherbot commentedon Nov 20, 2024
Change https://go.dev/cl/629938 mentions this issue:
crypto/rsa: refuse to generate and/or use keys smaller than 1024 bitscrypto/rsa: refuse to generate and/or use keys smaller than 1024 bits
quolpr commentedon Oct 10, 2025
Guys, I think this is a breaking change for some system. What if some systems depend on old API, and there is no way to ask the provider to upgrade theirs keys from 512 to 1024? While for go 1.23 it was working normally, for other version it will stop working without quick way of fixing it.
ryancdotorg commentedon Oct 10, 2025
quolpr commentedon Oct 10, 2025
@ryancdotorg yeah, I understand. But I think the first step of moving to 1024 should be deprecation notice, so old legacy system will start migrating to the newer version. And then breaking change. We are living in the real world, where inertia of process is very often things.
mvdan commentedon Oct 10, 2025
@quolpr I'm afraid you're fairly late to the party. This went through the proposal process more than a year ago, and Go 1.24 release candidates already included this change. At this point I doubt it will be reconsidered because it landed in a stable release ten months ago.
However, note that you can get the old behavior back for now; search for
rsa1024minin https://go.dev/doc/godebug.