aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-06-10 08:07:29 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-06-12 09:41:20 -0500
commitafdd90a1f33b54085d0ff99bdc6f7e5082f6f7f0 (patch)
tree2b28a39c9f316b45bbe43a256638290ea22c2619
parentbd6768c0b187e49e74d0c57eeaa73b300603ad38 (diff)
downloadcryptography-afdd90a1f33b54085d0ff99bdc6f7e5082f6f7f0.tar.gz
cryptography-afdd90a1f33b54085d0ff99bdc6f7e5082f6f7f0.tar.bz2
cryptography-afdd90a1f33b54085d0ff99bdc6f7e5082f6f7f0.zip
modify rsa.RSAPrivateKey to build old style key from numbers
-rw-r--r--cryptography/hazmat/backends/openssl/backend.py17
-rw-r--r--cryptography/hazmat/primitives/asymmetric/rsa.py15
2 files changed, 13 insertions, 19 deletions
diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py
index 770b2af4..eaa5dc1c 100644
--- a/cryptography/hazmat/backends/openssl/backend.py
+++ b/cryptography/hazmat/backends/openssl/backend.py
@@ -363,23 +363,6 @@ class Backend(object):
def generate_rsa_private_key(self, public_exponent, key_size):
rsa._verify_rsa_parameters(public_exponent, key_size)
- ctx = self._lib.RSA_new()
- assert ctx != self._ffi.NULL
- ctx = self._ffi.gc(ctx, self._lib.RSA_free)
-
- bn = self._int_to_bn(public_exponent)
- bn = self._ffi.gc(bn, self._lib.BN_free)
-
- res = self._lib.RSA_generate_key_ex(
- ctx, key_size, bn, self._ffi.NULL
- )
- assert res == 1
-
- return self._rsa_cdata_to_private_key(ctx)
-
- def _generate_rsa_private_key(self, public_exponent, key_size):
- rsa._verify_rsa_parameters(public_exponent, key_size)
-
rsa_cdata = self._lib.RSA_new()
assert rsa_cdata != self._ffi.NULL
rsa_cdata = self._ffi.gc(rsa_cdata, self._lib.RSA_free)
diff --git a/cryptography/hazmat/primitives/asymmetric/rsa.py b/cryptography/hazmat/primitives/asymmetric/rsa.py
index dee2d7a5..18ca0db2 100644
--- a/cryptography/hazmat/primitives/asymmetric/rsa.py
+++ b/cryptography/hazmat/primitives/asymmetric/rsa.py
@@ -29,7 +29,7 @@ def generate_private_key(public_exponent, key_size, backend):
)
_verify_rsa_parameters(public_exponent, key_size)
- return backend._generate_rsa_private_key(public_exponent, key_size)
+ return backend.generate_rsa_private_key(public_exponent, key_size)
def _verify_rsa_parameters(public_exponent, key_size):
@@ -220,7 +220,18 @@ class RSAPrivateKey(object):
)
_verify_rsa_parameters(public_exponent, key_size)
- return backend.generate_rsa_private_key(public_exponent, key_size)
+ key = backend.generate_rsa_private_key(public_exponent, key_size)
+ private_numbers = key.private_numbers()
+ return RSAPrivateKey(
+ p=private_numbers.p,
+ q=private_numbers.q,
+ dmp1=private_numbers.dmp1,
+ dmq1=private_numbers.dmq1,
+ iqmp=private_numbers.iqmp,
+ private_exponent=private_numbers.d,
+ public_exponent=private_numbers.public_numbers.e,
+ modulus=private_numbers.public_numbers.n
+ )
def signer(self, padding, algorithm, backend):
if not isinstance(backend, RSABackend):