Skip to content

Commit

Permalink
Don't generate RSA keys <1024 bits (#10278)
Browse files Browse the repository at this point in the history
* Don't generate RSA keys <1024 bits

* Update CHANGELOG.rst
  • Loading branch information
alex authored Jan 28, 2024
1 parent 36368cc commit 83dcbc1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Changelog

.. note:: This version is not yet released and is under active development.

* :func:`~cryptography.hazmat.primitives.asymmetric.rsa.generate_private_key`
now enforces a minimum RSA key size of 1024-bit. Note that 1024-bit is still
considered insecure, users should generally use a key size of 2048-bits.


.. _v42-0-1:

42.0.1 - 2024-01-24
Expand Down
4 changes: 2 additions & 2 deletions src/cryptography/hazmat/primitives/asymmetric/rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ def _verify_rsa_parameters(public_exponent: int, key_size: int) -> None:
"65537. Almost everyone should choose 65537 here!"
)

if key_size < 512:
raise ValueError("key_size must be at least 512-bits.")
if key_size < 1024:
raise ValueError("key_size must be at least 1024-bits.")


def _modinv(e: int, m: int) -> int:
Expand Down

1 comment on commit 83dcbc1

@craigjbass
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We create purposefully insecure "test keys" for testing purposes. I get setting a blanket rule like this ensures better security, but it also means our test suite is turning the handle unnecessarily on entropy for assertions that don't require the highest cryptographic security.

Please sign in to comment.