Check that public_exponent is odd
diff --git a/cryptography/hazmat/primitives/asymmetric/rsa.py b/cryptography/hazmat/primitives/asymmetric/rsa.py
index 9124757..1b33eaa 100644
--- a/cryptography/hazmat/primitives/asymmetric/rsa.py
+++ b/cryptography/hazmat/primitives/asymmetric/rsa.py
@@ -43,6 +43,9 @@
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 @@
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 50b3f7a..b89daac 100644
--- a/tests/hazmat/primitives/test_rsa.py
+++ b/tests/hazmat/primitives/test_rsa.py
@@ -69,46 +69,54 @@
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)