aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Reid <dreid@dreid.org>2014-05-07 19:57:07 -0700
committerDavid Reid <dreid@dreid.org>2014-06-03 10:05:38 -0700
commiteeb5fbc368d05de41121893a7c536fcc59a5a6bd (patch)
treefb1627d73b02bd14d8969cb025fbbeccdf848a18 /tests
parent587e5a24b5eb56c060fd1d374c1a5d3c8671efec (diff)
downloadcryptography-eeb5fbc368d05de41121893a7c536fcc59a5a6bd.tar.gz
cryptography-eeb5fbc368d05de41121893a7c536fcc59a5a6bd.tar.bz2
cryptography-eeb5fbc368d05de41121893a7c536fcc59a5a6bd.zip
Implement load_rsa_numbers on the openssl backend.
Diffstat (limited to 'tests')
-rw-r--r--tests/hazmat/primitives/test_rsa.py248
1 files changed, 248 insertions, 0 deletions
diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py
index ba668bff..a1652594 100644
--- a/tests/hazmat/primitives/test_rsa.py
+++ b/tests/hazmat/primitives/test_rsa.py
@@ -1666,6 +1666,7 @@ class TestRSAEncryption(object):
)
+@pytest.mark.rsa
class TestRSANumbers(object):
def test_rsa_public_numbers(self):
public_numbers = rsa.RSAPublicNumbers(e=1, n=15)
@@ -1778,3 +1779,250 @@ class TestRSANumbers(object):
iqmp=2,
public_numbers=None
)
+
+ def test_invalid_public_numbers_argument_values(self, backend):
+ # Start with public_exponent=7, modulus=15. Then change one value at a
+ # time to test the bounds.
+
+ # Test a modulus < 3.
+
+ with pytest.raises(ValueError):
+ backend.load_rsa_numbers(rsa.RSAPublicNumbers(e=7, n=2))
+
+ # Test a public_exponent < 3
+ with pytest.raises(ValueError):
+ backend.load_rsa_numbers(rsa.RSAPublicNumbers(e=1, n=15))
+
+ # Test a public_exponent > modulus
+ with pytest.raises(ValueError):
+ backend.load_rsa_numbers(rsa.RSAPublicNumbers(e=17, n=15))
+
+ # Test a public_exponent that is not odd.
+ with pytest.raises(ValueError):
+ backend.load_rsa_numbers(rsa.RSAPublicNumbers(e=16, n=15))
+
+ def test_invalid_private_numbers_argument_values(self, backend):
+ # Start with p=3, q=11, private_exponent=3, public_exponent=7,
+ # modulus=33, dmp1=1, dmq1=3, iqmp=2. Then change one value at
+ # a time to test the bounds.
+
+ # Test a modulus < 3.
+ with pytest.raises(ValueError):
+ backend.load_rsa_numbers(
+ rsa.RSAPrivateNumbers(
+ p=3,
+ q=11,
+ d=3,
+ dmp1=1,
+ dmq1=3,
+ iqmp=2,
+ public_numbers=rsa.RSAPublicNumbers(
+ e=7,
+ n=2
+ )
+ )
+ )
+
+ # Test a modulus != p * q.
+ with pytest.raises(ValueError):
+ backend.load_rsa_numbers(
+ rsa.RSAPrivateNumbers(
+ p=3,
+ q=11,
+ d=3,
+ dmp1=1,
+ dmq1=3,
+ iqmp=2,
+ public_numbers=rsa.RSAPublicNumbers(
+ e=7,
+ n=35
+ )
+ )
+ )
+
+ # Test a p > modulus.
+ with pytest.raises(ValueError):
+ backend.load_rsa_numbers(
+ rsa.RSAPrivateNumbers(
+ p=37,
+ q=11,
+ d=3,
+ dmp1=1,
+ dmq1=3,
+ iqmp=2,
+ public_numbers=rsa.RSAPublicNumbers(
+ e=7,
+ n=33
+ )
+ )
+ )
+
+ # Test a q > modulus.
+ with pytest.raises(ValueError):
+ backend.load_rsa_numbers(
+ rsa.RSAPrivateNumbers(
+ p=3,
+ q=37,
+ d=3,
+ dmp1=1,
+ dmq1=3,
+ iqmp=2,
+ public_numbers=rsa.RSAPublicNumbers(
+ e=7,
+ n=33
+ )
+ )
+ )
+
+ # Test a dmp1 > modulus.
+ with pytest.raises(ValueError):
+ backend.load_rsa_numbers(
+ rsa.RSAPrivateNumbers(
+ p=3,
+ q=11,
+ d=3,
+ dmp1=35,
+ dmq1=3,
+ iqmp=2,
+ public_numbers=rsa.RSAPublicNumbers(
+ e=7,
+ n=33
+ )
+ )
+ )
+
+ # Test a dmq1 > modulus.
+ with pytest.raises(ValueError):
+ backend.load_rsa_numbers(
+ rsa.RSAPrivateNumbers(
+ p=3,
+ q=11,
+ d=3,
+ dmp1=1,
+ dmq1=35,
+ iqmp=2,
+ public_numbers=rsa.RSAPublicNumbers(
+ e=7,
+ n=33
+ )
+ )
+ )
+
+ # Test an iqmp > modulus.
+ with pytest.raises(ValueError):
+ backend.load_rsa_numbers(
+ rsa.RSAPrivateNumbers(
+ p=3,
+ q=11,
+ d=3,
+ dmp1=1,
+ dmq1=3,
+ iqmp=35,
+ public_numbers=rsa.RSAPublicNumbers(
+ e=7,
+ n=33
+ )
+ )
+ )
+
+ # Test a private_exponent > modulus
+ with pytest.raises(ValueError):
+ backend.load_rsa_numbers(
+ rsa.RSAPrivateNumbers(
+ p=3,
+ q=11,
+ d=37,
+ dmp1=1,
+ dmq1=3,
+ iqmp=2,
+ public_numbers=rsa.RSAPublicNumbers(
+ e=7,
+ n=33
+ )
+ )
+ )
+
+ # Test a public_exponent < 3
+ with pytest.raises(ValueError):
+ backend.load_rsa_numbers(
+ rsa.RSAPrivateNumbers(
+ p=3,
+ q=11,
+ d=3,
+ dmp1=1,
+ dmq1=3,
+ iqmp=2,
+ public_numbers=rsa.RSAPublicNumbers(
+ e=1,
+ n=33
+ )
+ )
+ )
+
+ # Test a public_exponent > modulus
+ with pytest.raises(ValueError):
+ backend.load_rsa_numbers(
+ rsa.RSAPrivateNumbers(
+ p=3,
+ q=11,
+ d=3,
+ dmp1=1,
+ dmq1=3,
+ iqmp=35,
+ public_numbers=rsa.RSAPublicNumbers(
+ e=65537,
+ n=33
+ )
+ )
+ )
+
+ # Test a public_exponent that is not odd.
+ with pytest.raises(ValueError):
+ backend.load_rsa_numbers(
+ rsa.RSAPrivateNumbers(
+ p=3,
+ q=11,
+ d=3,
+ dmp1=1,
+ dmq1=3,
+ iqmp=2,
+ public_numbers=rsa.RSAPublicNumbers(
+ e=6,
+ n=33
+ )
+ )
+ )
+
+ # Test a dmp1 that is not odd.
+ with pytest.raises(ValueError):
+ backend.load_rsa_numbers(
+ rsa.RSAPrivateNumbers(
+ p=3,
+ q=11,
+ d=3,
+ dmp1=2,
+ dmq1=3,
+ iqmp=2,
+ public_numbers=rsa.RSAPublicNumbers(
+ e=7,
+ n=33
+ )
+ )
+ )
+
+ # Test a dmq1 that is not odd.
+ with pytest.raises(ValueError):
+ backend.load_rsa_numbers(
+ rsa.RSAPrivateNumbers(
+ p=3,
+ q=11,
+ d=3,
+ dmp1=1,
+ dmq1=4,
+ iqmp=2,
+ public_numbers=rsa.RSAPublicNumbers(
+ e=7,
+ n=33
+ )
+ )
+ )