diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-05-25 22:01:20 -0500 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-05-25 22:10:58 -0500 |
commit | 342d2e4cd83519d80abb12de16b7d893769a7c32 (patch) | |
tree | 2893a517b7b190e6725d26585a0fc35bdb256629 /cryptography | |
parent | bf308598c2a588f67963decb69f09a2f5b8b7070 (diff) | |
download | cryptography-342d2e4cd83519d80abb12de16b7d893769a7c32.tar.gz cryptography-342d2e4cd83519d80abb12de16b7d893769a7c32.tar.bz2 cryptography-342d2e4cd83519d80abb12de16b7d893769a7c32.zip |
add generate_rsa_parameters_supported to RSABackend
Diffstat (limited to 'cryptography')
-rw-r--r-- | cryptography/hazmat/backends/interfaces.py | 7 | ||||
-rw-r--r-- | cryptography/hazmat/backends/multibackend.py | 8 | ||||
-rw-r--r-- | cryptography/hazmat/backends/openssl/backend.py | 4 |
3 files changed, 19 insertions, 0 deletions
diff --git a/cryptography/hazmat/backends/interfaces.py b/cryptography/hazmat/backends/interfaces.py index 11b13788..97a7a4fd 100644 --- a/cryptography/hazmat/backends/interfaces.py +++ b/cryptography/hazmat/backends/interfaces.py @@ -135,6 +135,13 @@ class RSABackend(object): Returns True if the backend supports the given padding options. """ + @abc.abstractmethod + def generate_rsa_parameters_supported(self, public_exponent, key_size): + """ + Returns True if the backend supports the given parameters for key + generation. + """ + @six.add_metaclass(abc.ABCMeta) class DSABackend(object): diff --git a/cryptography/hazmat/backends/multibackend.py b/cryptography/hazmat/backends/multibackend.py index 21630ba8..b4cb6889 100644 --- a/cryptography/hazmat/backends/multibackend.py +++ b/cryptography/hazmat/backends/multibackend.py @@ -132,6 +132,14 @@ class MultiBackend(object): raise UnsupportedAlgorithm("RSA is not supported by the backend.", _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM) + def generate_rsa_parameters_supported(self, public_exponent, key_size): + for b in self._filtered_backends(RSABackend): + return b.generate_rsa_parameters_supported( + public_exponent, key_size + ) + raise UnsupportedAlgorithm("RSA is not supported by the backend.", + _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM) + def create_rsa_signature_ctx(self, private_key, padding, algorithm): for b in self._filtered_backends(RSABackend): return b.create_rsa_signature_ctx(private_key, padding, algorithm) diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py index e5d6eaa1..8d76160d 100644 --- a/cryptography/hazmat/backends/openssl/backend.py +++ b/cryptography/hazmat/backends/openssl/backend.py @@ -378,6 +378,10 @@ class Backend(object): return self._rsa_cdata_to_private_key(ctx) + def generate_rsa_parameters_supported(self, public_exponent, key_size): + return (public_exponent >= 3 and public_exponent & 1 != 0 and + key_size >= 512) + def _new_evp_pkey(self): evp_pkey = self._lib.EVP_PKEY_new() assert evp_pkey != self._ffi.NULL |