From 8e9c984d5d85db83c5fa45f6f2083d6b5e15326b Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Thu, 13 Feb 2014 12:23:27 -0600 Subject: expose dmp1, dmq1, iqmp getters on RSAPrivateKey --- cryptography/hazmat/primitives/asymmetric/rsa.py | 12 ++++++++++++ docs/hazmat/primitives/interfaces.rst | 24 +++++++++++++++++++++++- tests/hazmat/primitives/test_rsa.py | 6 +++--- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/cryptography/hazmat/primitives/asymmetric/rsa.py b/cryptography/hazmat/primitives/asymmetric/rsa.py index dbe56b47..01218592 100644 --- a/cryptography/hazmat/primitives/asymmetric/rsa.py +++ b/cryptography/hazmat/primitives/asymmetric/rsa.py @@ -166,6 +166,18 @@ class RSAPrivateKey(object): def d(self): 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/docs/hazmat/primitives/interfaces.rst b/docs/hazmat/primitives/interfaces.rst index cbca5ed6..df17e59d 100644 --- a/docs/hazmat/primitives/interfaces.rst +++ b/docs/hazmat/primitives/interfaces.rst @@ -160,6 +160,27 @@ Asymmetric Interfaces The private exponent. Alias for :attr:`private_exponent`. + .. attribute:: dmp1 + + :type: int + + A `Chinese remainder theorem`_ coefficient used to speed up RSA + operations. Calculated as: d mod (p-1) + + .. attribute:: dmq1 + + :type: int + + A `Chinese remainder theorem`_ coefficient used to speed up RSA + operations. Calculated as: d mod (q-1) + + .. attribute:: iqmp + + :type: int + + A `Chinese remainder theorem`_ coefficient used to speed up RSA + operations. Calculated as: q\ :sup:`-1` mod p + .. attribute:: n :type: int @@ -279,4 +300,5 @@ Key Derivation Functions something like checking whether a user's password attempt matches the stored derived key. -.. _`RSA`: http://en.wikipedia.org/wiki/RSA_(cryptosystem) +.. _`RSA`: https://en.wikipedia.org/wiki/RSA_(cryptosystem) +.. _`Chinese remainder theorem`: https://en.wikipedia.org/wiki/Chinese_remainder_theorem diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py index 9dc1a9e4..312d5a6f 100644 --- a/tests/hazmat/primitives/test_rsa.py +++ b/tests/hazmat/primitives/test_rsa.py @@ -45,9 +45,9 @@ def _check_rsa_private_key(skey): assert skey.private_exponent assert skey.p * skey.q == skey.modulus assert skey.key_size - assert skey._dmp1 == skey.d % (skey.p - 1) - assert skey._dmq1 == skey.d % (skey.q - 1) - assert skey._iqmp == _modinv(skey.q, skey.p) + assert skey.dmp1 == skey.d % (skey.p - 1) + assert skey.dmq1 == skey.d % (skey.q - 1) + assert skey.iqmp == _modinv(skey.q, skey.p) pkey = skey.public_key() assert pkey -- cgit v1.2.3