aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Stapleton <alexs@prol.etari.at>2014-02-07 07:49:17 +0000
committerAlex Stapleton <alexs@prol.etari.at>2014-02-07 07:55:05 +0000
commita3b85506a5ca19d4469679e2cbc665f423066baf (patch)
treedb55f6e962fae04770880e892ae9271fc85012ee
parente237637231018ce571ab336e9885438902ece99e (diff)
downloadcryptography-a3b85506a5ca19d4469679e2cbc665f423066baf.tar.gz
cryptography-a3b85506a5ca19d4469679e2cbc665f423066baf.tar.bz2
cryptography-a3b85506a5ca19d4469679e2cbc665f423066baf.zip
Check that public_exponent is odd
-rw-r--r--cryptography/hazmat/primitives/asymmetric/rsa.py6
-rw-r--r--tests/hazmat/primitives/test_rsa.py32
2 files changed, 26 insertions, 12 deletions
diff --git a/cryptography/hazmat/primitives/asymmetric/rsa.py b/cryptography/hazmat/primitives/asymmetric/rsa.py
index 9124757a..1b33eaab 100644
--- a/cryptography/hazmat/primitives/asymmetric/rsa.py
+++ b/cryptography/hazmat/primitives/asymmetric/rsa.py
@@ -43,6 +43,9 @@ class RSAPublicKey(object):
if public_exponent < 3 or public_exponent >= modulus:
raise ValueError("public_exponent must be >= 3 and < modulus")
+ if public_exponent & 1 == 0:
+ raise ValueError("public_exponent must be odd")
+
self._public_exponent = public_exponent
self._modulus = modulus
@@ -94,6 +97,9 @@ class RSAPrivateKey(object):
if public_exponent < 3 or public_exponent >= modulus:
raise ValueError("public_exponent must be >= 3 and < modulus")
+ if public_exponent & 1 == 0:
+ raise ValueError("public_exponent must be odd")
+
if p * q != modulus:
raise ValueError("p*q must equal modulus")
diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py
index 50b3f7a7..b89daac3 100644
--- a/tests/hazmat/primitives/test_rsa.py
+++ b/tests/hazmat/primitives/test_rsa.py
@@ -69,46 +69,54 @@ class TestRSA(object):
def test_invalid_argument_values(self):
# tiny example key
- rsa.RSAPrivateKey(3, 5, 14, 8, 15)
+ rsa.RSAPrivateKey(3, 5, 14, 7, 15)
# modulus too small
with pytest.raises(ValueError):
- rsa.RSAPrivateKey(3, 5, 14, 8, 2)
+ rsa.RSAPrivateKey(3, 5, 14, 7, 2)
# modulus wrong
with pytest.raises(ValueError):
- rsa.RSAPrivateKey(3, 5, 14, 8, 16)
+ rsa.RSAPrivateKey(3, 5, 14, 7, 16)
# p too high
with pytest.raises(ValueError):
- rsa.RSAPrivateKey(16, 5, 14, 8, 15)
+ rsa.RSAPrivateKey(16, 5, 14, 7, 15)
# q too high
with pytest.raises(ValueError):
- rsa.RSAPrivateKey(3, 16, 14, 8, 15)
+ rsa.RSAPrivateKey(3, 16, 14, 7, 15)
# private exp too high
with pytest.raises(ValueError):
- rsa.RSAPrivateKey(3, 5, 16, 8, 15)
+ rsa.RSAPrivateKey(3, 5, 16, 7, 15)
# public exp too low
with pytest.raises(ValueError):
- rsa.RSAPrivateKey(3, 5, 14, 2, 15)
+ rsa.RSAPrivateKey(3, 5, 14, 1, 15)
# public exp too high
with pytest.raises(ValueError):
- rsa.RSAPrivateKey(3, 5, 14, 16, 15)
+ rsa.RSAPrivateKey(3, 5, 14, 17, 15)
- rsa.RSAPublicKey(8, 15)
+ # public exp not odd
+ with pytest.raises(ValueError):
+ rsa.RSAPrivateKey(3, 5, 14, 8, 15)
+
+ rsa.RSAPublicKey(7, 15)
# modulus too small
with pytest.raises(ValueError):
- rsa.RSAPublicKey(8, 2)
+ rsa.RSAPublicKey(7, 2)
# public exp too low
with pytest.raises(ValueError):
- rsa.RSAPublicKey(2, 15)
+ rsa.RSAPublicKey(1, 15)
# public exp too high
with pytest.raises(ValueError):
- rsa.RSAPublicKey(16, 15)
+ rsa.RSAPublicKey(17, 15)
+
+ # public exp not odd
+ with pytest.raises(ValueError):
+ rsa.RSAPublicKey(8, 15)