diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2015-01-18 17:33:27 -0500 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2015-01-18 17:33:27 -0500 |
commit | 7b672cace5c59a682e20854eac423e7e8c427531 (patch) | |
tree | b802941c4df92418bc672376bbff0aa80bb86523 /tests/hazmat/primitives/test_rsa.py | |
parent | 2ca4a77d99960d225cd1b81d8ae6b8b1b14eda5f (diff) | |
parent | 65637eb7dc466e4b715bddf1188a6d04845167a1 (diff) | |
download | cryptography-7b672cace5c59a682e20854eac423e7e8c427531.tar.gz cryptography-7b672cace5c59a682e20854eac423e7e8c427531.tar.bz2 cryptography-7b672cace5c59a682e20854eac423e7e8c427531.zip |
Merge pull request #1633 from reaperhulk/fix-975
recover (p, q) given (n, e, d)
Diffstat (limited to 'tests/hazmat/primitives/test_rsa.py')
-rw-r--r-- | tests/hazmat/primitives/test_rsa.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py index 095ed037..33e5373b 100644 --- a/tests/hazmat/primitives/test_rsa.py +++ b/tests/hazmat/primitives/test_rsa.py @@ -1698,3 +1698,30 @@ 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 sorting them and asserting on that. + assert sorted([p, q]) == sorted([private["p"], private["q"]]) + + def test_invalid_recover_prime_factors(self): + with pytest.raises(ValueError): + rsa.rsa_recover_prime_factors(34, 3, 7) |