blob: 4925366a8c9b268ee29e2ad630bca5b1285eb4fa [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.
23 Using an RSA that you do not trust or with incorrect parameters may
24 lead to insecure operation, crashes, and other undefined behavior. We
25 recommend that you only ever load private keys that were generated with
26 software you trust.
27
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 Stapleton4eaab172014-02-06 21:06:18 +000035 :raises ValueError: This is raised when the values of `p`, `q`,
Paul Kehrerb393bdc2014-02-12 23:59:59 -060036 `private_exponent`, `public_exponent` or `modulus` do
Alex Stapleton4eaab172014-02-06 21:06:18 +000037 not match the bounds specified in `RFC 3447`_.
Alex Stapleton940eee22014-02-05 20:25:30 +000038
Alex Stapletonb232d742014-02-08 14:18:59 +000039 .. classmethod:: generate(public_exponent, key_size, backend)
40
41 Generate a new ``RSAPrivateKey`` instance using ``backend``.
42
43 :param int public_exponent: The public exponent of the new key.
44 Usually one of the small Fermat primes 3, 5, 17, 257, 65537. If in
45 doubt you should `use 65537`_.
46 :param int key_size: The length of the modulus in bits. For keys
47 generated in 2014 this should be `at least 2048`_. (See page 41.)
48 Must be at least 512. Some backends may have additional
49 limitations.
50 :param backend: A
51 :class:`~cryptography.hazmat.backends.interfaces.RSABackend`
52 provider.
53 :return: A new instance of ``RSAPrivateKey``.
54
Alex Stapleton940eee22014-02-05 20:25:30 +000055.. class:: RSAPublicKey(public_exponent, modulus)
Paul Kehrerb393bdc2014-02-12 23:59:59 -060056
Alex Stapleton940eee22014-02-05 20:25:30 +000057 .. versionadded:: 0.2
58
59 An RSA public key is required for encryption and verification of messages.
60
61 Normally you do not need to directly construct public keys because you'll
62 be loading them from a file, generating them automatically or receiving
63 them from a 3rd party.
64
65 This class conforms to the
66 :class:`~cryptography.hazmat.primitives.interfaces.RSAPublicKey`
67 interface.
68
Paul Kehrerb393bdc2014-02-12 23:59:59 -060069 :raises TypeError: This is raised when the arguments are not all integers.
Alex Stapleton940eee22014-02-05 20:25:30 +000070
71 :raises ValueError: This is raised when the values of `public_exponent` or
72 `modulus` do not match the bounds specified in
Alex Stapletonf44b6a92014-02-07 18:28:47 +000073 `RFC 3447`_.
Alex Stapleton940eee22014-02-05 20:25:30 +000074
75.. _`RSA`: https://en.wikipedia.org/wiki/RSA_(cryptosystem)
76.. _`public-key`: https://en.wikipedia.org/wiki/Public-key_cryptography
77.. _`RFC 3447`: https://tools.ietf.org/html/rfc3447
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