aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2014-02-15 18:57:11 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2014-02-15 18:57:11 -0800
commitc5b0aa06a7cc843578523acb847646f3881df27f (patch)
treee663368d48377c6c61a264a9071734acfd5795fe /cryptography
parent1deb6872567a76a547274737b3d6348940d15e8b (diff)
parentb557045ae353e98e869088714e4f433383f87ce5 (diff)
downloadcryptography-c5b0aa06a7cc843578523acb847646f3881df27f.tar.gz
cryptography-c5b0aa06a7cc843578523acb847646f3881df27f.tar.bz2
cryptography-c5b0aa06a7cc843578523acb847646f3881df27f.zip
Merge pull request #605 from reaperhulk/add-crt-coefficients
Add RSA CRT Coefficients
Diffstat (limited to 'cryptography')
-rw-r--r--cryptography/hazmat/backends/openssl/backend.py3
-rw-r--r--cryptography/hazmat/primitives/asymmetric/rsa.py36
-rw-r--r--cryptography/hazmat/primitives/interfaces.py21
3 files changed, 59 insertions, 1 deletions
diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py
index ef34cb43..8a4aeac5 100644
--- a/cryptography/hazmat/backends/openssl/backend.py
+++ b/cryptography/hazmat/backends/openssl/backend.py
@@ -302,6 +302,9 @@ class Backend(object):
return rsa.RSAPrivateKey(
p=self._bn_to_int(ctx.p),
q=self._bn_to_int(ctx.q),
+ dmp1=self._bn_to_int(ctx.dmp1),
+ dmq1=self._bn_to_int(ctx.dmq1),
+ iqmp=self._bn_to_int(ctx.iqmp),
private_exponent=self._bn_to_int(ctx.d),
public_exponent=self._bn_to_int(ctx.e),
modulus=self._bn_to_int(ctx.n),
diff --git a/cryptography/hazmat/primitives/asymmetric/rsa.py b/cryptography/hazmat/primitives/asymmetric/rsa.py
index 60c5c807..01218592 100644
--- a/cryptography/hazmat/primitives/asymmetric/rsa.py
+++ b/cryptography/hazmat/primitives/asymmetric/rsa.py
@@ -72,10 +72,14 @@ class RSAPublicKey(object):
@utils.register_interface(interfaces.RSAPrivateKey)
class RSAPrivateKey(object):
- def __init__(self, p, q, private_exponent, public_exponent, modulus):
+ def __init__(self, p, q, private_exponent, dmp1, dmq1, iqmp,
+ public_exponent, modulus):
if (
not isinstance(p, six.integer_types) or
not isinstance(q, six.integer_types) or
+ not isinstance(dmp1, six.integer_types) or
+ not isinstance(dmq1, six.integer_types) or
+ not isinstance(iqmp, six.integer_types) or
not isinstance(private_exponent, six.integer_types) or
not isinstance(public_exponent, six.integer_types) or
not isinstance(modulus, six.integer_types)
@@ -91,6 +95,15 @@ class RSAPrivateKey(object):
if q >= modulus:
raise ValueError("q must be < modulus")
+ if dmp1 >= modulus:
+ raise ValueError("dmp1 must be < modulus")
+
+ if dmq1 >= modulus:
+ raise ValueError("dmq1 must be < modulus")
+
+ if iqmp >= modulus:
+ raise ValueError("iqmp must be < modulus")
+
if private_exponent >= modulus:
raise ValueError("private_exponent must be < modulus")
@@ -100,11 +113,20 @@ class RSAPrivateKey(object):
if public_exponent & 1 == 0:
raise ValueError("public_exponent must be odd")
+ if dmp1 & 1 == 0:
+ raise ValueError("dmp1 must be odd")
+
+ if dmq1 & 1 == 0:
+ raise ValueError("dmq1 must be odd")
+
if p * q != modulus:
raise ValueError("p*q must equal modulus")
self._p = p
self._q = q
+ self._dmp1 = dmp1
+ self._dmq1 = dmq1
+ self._iqmp = iqmp
self._private_exponent = private_exponent
self._public_exponent = public_exponent
self._modulus = modulus
@@ -145,6 +167,18 @@ class RSAPrivateKey(object):
return self.private_exponent
@property
+ def dmp1(self):
+ return self._dmp1
+
+ @property
+ def dmq1(self):
+ return self._dmq1
+
+ @property
+ def iqmp(self):
+ return self._iqmp
+
+ @property
def e(self):
return self.public_exponent
diff --git a/cryptography/hazmat/primitives/interfaces.py b/cryptography/hazmat/primitives/interfaces.py
index 460aab76..5ef469d0 100644
--- a/cryptography/hazmat/primitives/interfaces.py
+++ b/cryptography/hazmat/primitives/interfaces.py
@@ -228,6 +228,27 @@ class RSAPrivateKey(six.with_metaclass(abc.ABCMeta)):
"""
@abc.abstractproperty
+ def dmp1(self):
+ """
+ A Chinese remainder theorem coefficient used to speed up RSA
+ calculations. Calculated as: d mod (p-1)
+ """
+
+ @abc.abstractproperty
+ def dmq1(self):
+ """
+ A Chinese remainder theorem coefficient used to speed up RSA
+ calculations. Calculated as: d mod (q-1)
+ """
+
+ @abc.abstractproperty
+ def iqmp(self):
+ """
+ A Chinese remainder theorem coefficient used to speed up RSA
+ calculations. The modular inverse of q modulo p
+ """
+
+ @abc.abstractproperty
def e(self):
"""
The public exponent of the RSA key. Alias for public_exponent.