diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-01-18 09:42:58 -0600 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-01-18 09:47:30 -0600 |
commit | 836b830b155c1b04fbad40ab76f0de4339d8628c (patch) | |
tree | 13ca0ec7fc8ecfab82949289866c00938505f790 /tests/hazmat/primitives | |
parent | 2ca4a77d99960d225cd1b81d8ae6b8b1b14eda5f (diff) | |
download | cryptography-836b830b155c1b04fbad40ab76f0de4339d8628c.tar.gz cryptography-836b830b155c1b04fbad40ab76f0de4339d8628c.tar.bz2 cryptography-836b830b155c1b04fbad40ab76f0de4339d8628c.zip |
recover (p, q) given (n, e, d). fixes #975
Diffstat (limited to 'tests/hazmat/primitives')
-rw-r--r-- | tests/hazmat/primitives/test_rsa.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py index 095ed037..3de228bb 100644 --- a/tests/hazmat/primitives/test_rsa.py +++ b/tests/hazmat/primitives/test_rsa.py @@ -1698,3 +1698,36 @@ class TestRSANumbersEquality(object): 1, 2, 3, 4, 5, 6, RSAPublicNumbers(1, 3) ) assert num != object() + + +class TestRSAPrimeFactorRecovery(object): + @pytest.mark.parametrize( + "vector", + _flatten_pkcs1_examples(load_vectors_from_file( + os.path.join( + "asymmetric", "RSA", "pkcs1v15crypt-vectors.txt"), + load_pkcs1_vectors + )) + ) + def test_recover_prime_factors(self, vector): + private, public, example = vector + p, q = rsa.rsa_recover_prime_factors( + private["modulus"], + private["public_exponent"], + private["private_exponent"] + ) + # Unfortunately there is no convention on which prime should be p + # and which one q. The function we use always makes p < q, but the + # NIST vectors are not so consistent. Accordingly we verify we've + # recovered the proper (p, q) by being willing to match against either + # one and then altering the asserts accordingly. + if p == private["p"]: + assert p == private["p"] + assert q == private["q"] + else: + assert p == private["q"] + assert q == private["p"] + + def test_invalid_recover_prime_factors(self): + with pytest.raises(ValueError): + rsa.rsa_recover_prime_factors(34, 3, 7) |