Skip to content

Commit

Permalink
Reject d, e values <= 1
Browse files Browse the repository at this point in the history
This avoids a potential infinite loop (e.g. with d=e=1 or d=e=-1).
  • Loading branch information
hannob committed Jan 12, 2025
1 parent d7596d0 commit 369b67c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cryptography/hazmat/primitives/asymmetric/rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ def rsa_recover_prime_factors(n: int, e: int, d: int) -> tuple[int, int]:
no more than two factors. This function is adapted from code in PyCrypto.
"""
# reject invalid values early
if d <= 1 or e <= 1:
raise ValueError("d, e can't be <= 1")
if 17 != pow(17, e * d, n):
raise ValueError("n, d, e don't match")
# See 8.2.2(i) in Handbook of Applied Cryptography.
Expand Down

0 comments on commit 369b67c

Please sign in to comment.