diff options
author | Alex Stapleton <alexs@prol.etari.at> | 2014-02-05 19:47:00 +0000 |
---|---|---|
committer | Alex Stapleton <alexs@prol.etari.at> | 2014-02-05 19:51:27 +0000 |
commit | 5d17ab3b354fe96e94689ad012163f42cc598a27 (patch) | |
tree | 6a6f64e20e39b78dd3be973ac3d24fdfe15ee643 /cryptography | |
parent | 52026b85c3df15476d38f308cee59a29a9b43195 (diff) | |
download | cryptography-5d17ab3b354fe96e94689ad012163f42cc598a27.tar.gz cryptography-5d17ab3b354fe96e94689ad012163f42cc598a27.tar.bz2 cryptography-5d17ab3b354fe96e94689ad012163f42cc598a27.zip |
Sanity check keys.
Taken from RFC 3447.
Diffstat (limited to 'cryptography')
-rw-r--r-- | cryptography/hazmat/primitives/asymmetric/rsa.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/cryptography/hazmat/primitives/asymmetric/rsa.py b/cryptography/hazmat/primitives/asymmetric/rsa.py index aa24aee4..c5fecbc1 100644 --- a/cryptography/hazmat/primitives/asymmetric/rsa.py +++ b/cryptography/hazmat/primitives/asymmetric/rsa.py @@ -35,6 +35,12 @@ class RSAPublicKey(object): ): raise TypeError("RSAPublicKey arguments must be integers") + if modulus < 3: + raise ValueError("modulus must be >= 3") + + if public_exponent < 3 or public_exponent >= modulus: + raise ValueError("public_exponent must be >= 3 and < modulus") + self._public_exponent = public_exponent self._modulus = modulus @@ -71,6 +77,15 @@ class RSAPrivateKey(object): ): raise TypeError("RSAPrivateKey arguments must be integers") + if modulus < 3: + raise ValueError("modulus must be >= 3") + + if private_exponent >= modulus: + raise ValueError("private_exponent must be < modulus") + + if public_exponent < 3 or public_exponent >= modulus: + raise ValueError("public_exponent must be >= 3 and < modulus") + self._p = p self._q = q self._private_exponent = private_exponent |