From 01cdfb209158cf77866959ed64c85a469b48e079 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Tue, 15 Apr 2014 11:27:03 -0400 Subject: add missing sign/verify/generate docs for the RSA interfaces --- docs/hazmat/primitives/interfaces.rst | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/docs/hazmat/primitives/interfaces.rst b/docs/hazmat/primitives/interfaces.rst index cdb925ee..d39898ee 100644 --- a/docs/hazmat/primitives/interfaces.rst +++ b/docs/hazmat/primitives/interfaces.rst @@ -112,6 +112,43 @@ Asymmetric interfaces An `RSA`_ private key. + .. classmethod:: generate(public_exponent, key_size, backend) + + Generate a new ``RSAPrivateKey`` instance using ``backend``. + + :param int public_exponent: The public exponent of the new key. + Usually one of the small Fermat primes 3, 5, 17, 257, 65537. If in + doubt you should `use 65537`_. + :param int key_size: The length of the modulus in bits. For keys + generated in 2014 it is strongly recommended to be + `at least 2048`_ (See page 41). It must not be less than 512. + Some backends may have additional limitations. + :param backend: A + :class:`~cryptography.hazmat.backends.interfaces.RSABackend` + provider. + :return: A new instance of ``RSAPrivateKey``. + + .. method:: signer(padding, algorithm, backend) + + .. versionadded:: 0.3 + + Sign data which can be verified later by others using the public key. + + :param padding: An instance of a + :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricPadding` + provider. + + :param algorithm: An instance of a + :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` + provider. + + :param backend: A + :class:`~cryptography.hazmat.backends.interfaces.RSABackend` + provider. + + :returns: + :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricSignatureContext` + .. method:: public_key() :return: :class:`~cryptography.hazmat.primitives.interfaces.RSAPublicKey` @@ -200,6 +237,31 @@ Asymmetric interfaces An `RSA`_ public key. + .. method:: verifier(signature, padding, algorithm, backend) + + .. versionadded:: 0.3 + + Verify data was signed by the private key associated with this public + key. + + :param bytes signature: The signature to verify. + + :param padding: An instance of a + :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricPadding` + provider. + + :param algorithm: An instance of a + :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` + provider. + + :param backend: A + :class:`~cryptography.hazmat.backends.interfaces.RSABackend` + provider. + + :returns: + :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricVerificationContext` + + .. attribute:: modulus :type: int @@ -470,3 +532,5 @@ Key derivation functions .. _`RSA`: https://en.wikipedia.org/wiki/RSA_(cryptosystem) .. _`Chinese remainder theorem`: https://en.wikipedia.org/wiki/Chinese_remainder_theorem .. _`DSA`: https://en.wikipedia.org/wiki/Digital_Signature_Algorithm +.. _`use 65537`: http://www.daemonology.net/blog/2009-06-11-cryptographic-right-answers.html +.. _`at least 2048`: http://www.ecrypt.eu.org/documents/D.SPA.20.pdf -- cgit v1.2.3 From 0d8583168bb2bba872708d2913002a47633362d1 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Tue, 15 Apr 2014 11:29:00 -0400 Subject: we don't need to doc generate in the interface --- docs/hazmat/primitives/interfaces.rst | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/docs/hazmat/primitives/interfaces.rst b/docs/hazmat/primitives/interfaces.rst index d39898ee..af695f07 100644 --- a/docs/hazmat/primitives/interfaces.rst +++ b/docs/hazmat/primitives/interfaces.rst @@ -112,22 +112,6 @@ Asymmetric interfaces An `RSA`_ private key. - .. classmethod:: generate(public_exponent, key_size, backend) - - Generate a new ``RSAPrivateKey`` instance using ``backend``. - - :param int public_exponent: The public exponent of the new key. - Usually one of the small Fermat primes 3, 5, 17, 257, 65537. If in - doubt you should `use 65537`_. - :param int key_size: The length of the modulus in bits. For keys - generated in 2014 it is strongly recommended to be - `at least 2048`_ (See page 41). It must not be less than 512. - Some backends may have additional limitations. - :param backend: A - :class:`~cryptography.hazmat.backends.interfaces.RSABackend` - provider. - :return: A new instance of ``RSAPrivateKey``. - .. method:: signer(padding, algorithm, backend) .. versionadded:: 0.3 -- cgit v1.2.3 From 969e27a8c0cda40b1ac3bb5bef99ac86eecad1c1 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Tue, 15 Apr 2014 11:40:17 -0400 Subject: add signer/verifier to the abcs --- cryptography/hazmat/primitives/interfaces.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cryptography/hazmat/primitives/interfaces.py b/cryptography/hazmat/primitives/interfaces.py index e70338ba..4d92ef27 100644 --- a/cryptography/hazmat/primitives/interfaces.py +++ b/cryptography/hazmat/primitives/interfaces.py @@ -185,6 +185,12 @@ class HashContext(object): @six.add_metaclass(abc.ABCMeta) class RSAPrivateKey(object): + @abc.abstractmethod + def signer(self, padding, algorithm, backend): + """ + Returns an AsymmetricSignatureContext used for signing data. + """ + @abc.abstractproperty def modulus(self): """ @@ -270,6 +276,12 @@ class RSAPrivateKey(object): @six.add_metaclass(abc.ABCMeta) class RSAPublicKey(object): + @abc.abstractmethod + def verifier(self, signature, padding, algorithm, backend): + """ + Returns an AsymmetricVerificationContext used for verifying signatures. + """ + @abc.abstractproperty def modulus(self): """ -- cgit v1.2.3 From 96c9981e8e4867610216890d9386ee2d8f12e6dd Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Tue, 15 Apr 2014 12:12:17 -0400 Subject: remove links we don't need... --- docs/hazmat/primitives/interfaces.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/hazmat/primitives/interfaces.rst b/docs/hazmat/primitives/interfaces.rst index af695f07..f4fb8ded 100644 --- a/docs/hazmat/primitives/interfaces.rst +++ b/docs/hazmat/primitives/interfaces.rst @@ -516,5 +516,3 @@ Key derivation functions .. _`RSA`: https://en.wikipedia.org/wiki/RSA_(cryptosystem) .. _`Chinese remainder theorem`: https://en.wikipedia.org/wiki/Chinese_remainder_theorem .. _`DSA`: https://en.wikipedia.org/wiki/Digital_Signature_Algorithm -.. _`use 65537`: http://www.daemonology.net/blog/2009-06-11-cryptographic-right-answers.html -.. _`at least 2048`: http://www.ecrypt.eu.org/documents/D.SPA.20.pdf -- cgit v1.2.3