blob: e7ec4749a46d699f712be791f4748dd1df9701dc [file] [log] [blame]
Alex Stapleton940eee22014-02-05 20:25:30 +00001.. hazmat::
2
3RSA
4===
5
6.. currentmodule:: cryptography.hazmat.primitives.asymmetric.rsa
7
8`RSA`_ is a `public-key`_ algorithm for encrypting and signing messages.
9
Paul Kehrerb393bdc2014-02-12 23:59:59 -060010.. class:: RSAPrivateKey(p, q, private_exponent, dmp1, dmq1, iqmp,
11 public_exponent, modulus)
12
Alex Stapleton940eee22014-02-05 20:25:30 +000013 .. versionadded:: 0.2
14
15 An RSA private key is required for decryption and signing of messages.
16
Alex Stapletonb232d742014-02-08 14:18:59 +000017 You should use
18 :meth:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey.generate`
19 to generate new keys.
Paul Kehrerb393bdc2014-02-12 23:59:59 -060020
Alex Stapletonbe5da2d2014-02-07 08:15:39 +000021 .. warning::
22 This method only checks a limited set of properties of its arguments.
Alex Gaynor14971b72014-02-13 12:56:14 -080023 Using an RSA private key that you do not trust or with incorrect
24 parameters may lead to insecure operation, crashes, and other undefined
25 behavior. We recommend that you only ever load private keys that were
26 generated with software you trust.
Alex Stapletonbe5da2d2014-02-07 08:15:39 +000027
Alex Stapletonb232d742014-02-08 14:18:59 +000028
Alex Stapleton940eee22014-02-05 20:25:30 +000029 This class conforms to the
30 :class:`~cryptography.hazmat.primitives.interfaces.RSAPrivateKey`
31 interface.
32
Paul Kehrerb393bdc2014-02-12 23:59:59 -060033 :raises TypeError: This is raised when the arguments are not all integers.
Alex Stapleton940eee22014-02-05 20:25:30 +000034
Alex Gaynora9d802a2014-02-13 12:57:57 -080035 :raises ValueError: This is raised when the values of ``p``, ``q``,
36 ``private_exponent``, ``public_exponent``, or
37 ``modulus`` do not match the bounds specified in
38 :rfc:`3447`.
Alex Stapleton940eee22014-02-05 20:25:30 +000039
Alex Stapletonb232d742014-02-08 14:18:59 +000040 .. classmethod:: generate(public_exponent, key_size, backend)
41
42 Generate a new ``RSAPrivateKey`` instance using ``backend``.
43
44 :param int public_exponent: The public exponent of the new key.
45 Usually one of the small Fermat primes 3, 5, 17, 257, 65537. If in
46 doubt you should `use 65537`_.
47 :param int key_size: The length of the modulus in bits. For keys
48 generated in 2014 this should be `at least 2048`_. (See page 41.)
49 Must be at least 512. Some backends may have additional
50 limitations.
51 :param backend: A
52 :class:`~cryptography.hazmat.backends.interfaces.RSABackend`
53 provider.
54 :return: A new instance of ``RSAPrivateKey``.
55
Alex Stapleton940eee22014-02-05 20:25:30 +000056.. class:: RSAPublicKey(public_exponent, modulus)
Paul Kehrerb393bdc2014-02-12 23:59:59 -060057
Alex Stapleton940eee22014-02-05 20:25:30 +000058 .. versionadded:: 0.2
59
60 An RSA public key is required for encryption and verification of messages.
61
62 Normally you do not need to directly construct public keys because you'll
63 be loading them from a file, generating them automatically or receiving
64 them from a 3rd party.
65
66 This class conforms to the
67 :class:`~cryptography.hazmat.primitives.interfaces.RSAPublicKey`
68 interface.
69
Paul Kehrerb393bdc2014-02-12 23:59:59 -060070 :raises TypeError: This is raised when the arguments are not all integers.
Alex Stapleton940eee22014-02-05 20:25:30 +000071
Alex Gaynora9d802a2014-02-13 12:57:57 -080072 :raises ValueError: This is raised when the values of ``public_exponent``
73 or ``modulus`` do not match the bounds specified in
74 :rfc:`3447`.
Alex Stapleton940eee22014-02-05 20:25:30 +000075
76.. _`RSA`: https://en.wikipedia.org/wiki/RSA_(cryptosystem)
77.. _`public-key`: https://en.wikipedia.org/wiki/Public-key_cryptography
Alex Stapletonb232d742014-02-08 14:18:59 +000078.. _`use 65537`: http://www.daemonology.net/blog/2009-06-11-cryptographic-right-answers.html
79.. _`at least 2048`: http://www.ecrypt.eu.org/documents/D.SPA.20.pdf