blob: 57a8412071ed751402bd72c3efd4656d8aad4f25 [file] [log] [blame]
David Reid30722b92013-11-07 13:03:39 -08001.. hazmat::
2
3Interfaces
4==========
5
6
7``cryptography`` uses `Abstract Base Classes`_ as interfaces to describe the
David Reidbd18bcd2013-11-07 13:13:30 -08008properties and methods of most primitive constructs. Backends may also use
9this information to influence their operation. Interfaces should also be used
David Reid30722b92013-11-07 13:03:39 -080010to document argument and return types.
11
David Reid9ed25e42013-11-07 13:15:27 -080012.. _`Abstract Base Classes`: http://docs.python.org/3.2/library/abc.html
David Reid30722b92013-11-07 13:03:39 -080013
14
David Reid0a394df2013-11-15 16:19:50 -080015Symmetric Ciphers
16~~~~~~~~~~~~~~~~~
David Reid30722b92013-11-07 13:03:39 -080017
18.. currentmodule:: cryptography.hazmat.primitives.interfaces
19
David Reid0a394df2013-11-15 16:19:50 -080020
21.. class:: CipherAlgorithm
22
23 A named symmetric encryption algorithm.
24
25 .. attribute:: name
26
27 :type: str
28
29 The standard name for the mode, for example, "AES", "Camellia", or
30 "Blowfish".
31
32 .. attribute:: key_size
33
34 :type: int
35
36 The number of bits in the key being used.
37
38
David Reid668d4802013-12-17 11:53:43 -080039.. class:: BlockCipherAlgorithm
40
41 A block cipher algorithm.
42
43 .. attribute:: block_size
44
45 :type: int
46
47 The number of bits in a block.
48
49
David Reid0a394df2013-11-15 16:19:50 -080050Cipher Modes
51------------
52
David Reid30722b92013-11-07 13:03:39 -080053Interfaces used by the symmetric cipher modes described in
54:ref:`Symmetric Encryption Modes <symmetric-encryption-modes>`.
55
56.. class:: Mode
57
58 A named cipher mode.
59
60 .. attribute:: name
61
62 :type: str
63
64 This should be the standard shorthand name for the mode, for example
65 Cipher-Block Chaining mode is "CBC".
66
67 The name may be used by a backend to influence the operation of a
68 cipher in conjunction with the algorithm's name.
69
Alex Gaynor9626b5a2013-11-19 16:49:26 -080070 .. method:: validate_for_algorithm(algorithm)
71
72 :param CipherAlgorithm algorithm:
73
74 Checks that the combination of this mode with the provided algorithm
75 meets any necessary invariants. This should raise an exception if they
76 are not met.
77
78 For example, the :class:`~cryptography.hazmat.primitives.modes.CBC`
79 mode uses this method to check that the provided initialization
80 vector's length matches the block size of the algorithm.
81
David Reid30722b92013-11-07 13:03:39 -080082
83.. class:: ModeWithInitializationVector
84
85 A cipher mode with an initialization vector.
86
87 .. attribute:: initialization_vector
88
89 :type: bytes
90
91 Exact requirements of the initialization are described by the
92 documentation of individual modes.
93
94
95.. class:: ModeWithNonce
96
97 A cipher mode with a nonce.
98
99 .. attribute:: nonce
100
101 :type: bytes
102
103 Exact requirements of the nonce are described by the documentation of
104 individual modes.
Paul Kehrerac423232014-01-25 14:13:09 -0600105
106Asymmetric Interfaces
107~~~~~~~~~~~~~~~~~~~~~
108
109.. class:: RSAPrivateKey
110
111 An `RSA`_ private key.
112
Paul Kehrer0e94fbe2014-01-26 11:47:21 -0600113 .. method:: public_key()
Paul Kehrerac423232014-01-25 14:13:09 -0600114
Paul Kehrer359b9462014-01-26 12:03:05 -0600115 :return: :class:`~cryptography.hazmat.primitives.interfaces.RSAPublicKey`
Paul Kehrerac423232014-01-25 14:13:09 -0600116
117 An RSA public key object corresponding to the values of the private key.
118
119 .. attribute:: modulus
120
Paul Kehrerd527b302014-01-26 11:41:38 -0600121 :type: int
Paul Kehrerac423232014-01-25 14:13:09 -0600122
Paul Kehrer0e94fbe2014-01-26 11:47:21 -0600123 The public modulus.
Paul Kehrerac423232014-01-25 14:13:09 -0600124
125 .. attribute:: public_exponent
126
127 :type: int
128
Paul Kehrer0e94fbe2014-01-26 11:47:21 -0600129 The public exponent.
Paul Kehrerac423232014-01-25 14:13:09 -0600130
131 .. attribute:: key_length
132
133 :type: int
134
135 The bit length of the modulus.
136
137 .. attribute:: p
138
Paul Kehrerd527b302014-01-26 11:41:38 -0600139 :type: int
Paul Kehrerac423232014-01-25 14:13:09 -0600140
Paul Kehrerd527b302014-01-26 11:41:38 -0600141 ``p``, one of the two primes composing ``n``.
Paul Kehrerac423232014-01-25 14:13:09 -0600142
143 .. attribute:: q
144
Paul Kehrerd527b302014-01-26 11:41:38 -0600145 :type: int
Paul Kehrerac423232014-01-25 14:13:09 -0600146
Paul Kehrerd527b302014-01-26 11:41:38 -0600147 ``q``, one of the two primes composing ``n``.
Paul Kehrerac423232014-01-25 14:13:09 -0600148
149 .. attribute:: d
150
Paul Kehrerd527b302014-01-26 11:41:38 -0600151 :type: int
Paul Kehrerac423232014-01-25 14:13:09 -0600152
Paul Kehrerd527b302014-01-26 11:41:38 -0600153 The private exponent.
Paul Kehrerac423232014-01-25 14:13:09 -0600154
155 .. attribute:: n
156
Paul Kehrerd527b302014-01-26 11:41:38 -0600157 :type: int
Paul Kehrerac423232014-01-25 14:13:09 -0600158
Paul Kehrer0e94fbe2014-01-26 11:47:21 -0600159 The public modulus. Alias for ``modulus``.
Paul Kehrerac423232014-01-25 14:13:09 -0600160
161 .. attribute:: e
162
163 :type: int
164
Paul Kehrer0e94fbe2014-01-26 11:47:21 -0600165 The public exponent. Alias for ``public_exponent``.
Paul Kehrerac423232014-01-25 14:13:09 -0600166
167
168.. class:: RSAPublicKey
169
170 An `RSA`_ public key.
171
172 .. attribute:: modulus
173
Paul Kehrerd527b302014-01-26 11:41:38 -0600174 :type: int
Paul Kehrerac423232014-01-25 14:13:09 -0600175
Paul Kehrer0e94fbe2014-01-26 11:47:21 -0600176 The public modulus.
Paul Kehrerac423232014-01-25 14:13:09 -0600177
178 .. attribute:: key_length
179
180 :type: int
181
182 The bit length of the modulus.
183
184 .. attribute:: public_exponent
185
186 :type: int
187
Paul Kehrer0e94fbe2014-01-26 11:47:21 -0600188 The public exponent.
Paul Kehrerac423232014-01-25 14:13:09 -0600189
190 .. attribute:: n
191
Paul Kehrerd527b302014-01-26 11:41:38 -0600192 :type: int
Paul Kehrerac423232014-01-25 14:13:09 -0600193
Paul Kehrer0e94fbe2014-01-26 11:47:21 -0600194 The public modulus. Alias for ``modulus``.
Paul Kehrerac423232014-01-25 14:13:09 -0600195
196 .. attribute:: e
197
198 :type: int
199
Paul Kehrer0e94fbe2014-01-26 11:47:21 -0600200 The public exponent. Alias for ``public_exponent``.
Paul Kehrerac423232014-01-25 14:13:09 -0600201
202.. _`RSA`: http://en.wikipedia.org/wiki/RSA_(cryptosystem)