blob: 40b49a54dbe47e618dde77adfebb2219a262b849 [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
113 .. attribute:: public_key
114
115 :type: :class:`~cryptography.hazmat.primitives.interfaces.RSAPublicKey`
116
117 An RSA public key object corresponding to the values of the private key.
118
119 .. attribute:: modulus
120
121 :type: str
122
123 Hexadecimal representation of the public modulus. Alias for ``n``.
124
125 .. attribute:: public_exponent
126
127 :type: int
128
129 The public exponent. Alias for ``e``.
130
131 .. attribute:: key_length
132
133 :type: int
134
135 The bit length of the modulus.
136
137 .. attribute:: p
138
139 :type: str
140
141 Hexadecimal representation of ``p``, one of the two primes composing
142 ``n``.
143
144 .. attribute:: q
145
146 :type: str
147
148 Hexadecimal representation of ``q``, one of the two primes composing
149 ``n``.
150
151 .. attribute:: d
152
153 :type: str
154
155 Hexadecimal representation of ``d``, the private exponent.
156
157 .. attribute:: n
158
159 :type: str
160
161 Hexadecimal representation of the public modulus.
162
163 .. attribute:: e
164
165 :type: int
166
167 The public exponent.
168
169
170.. class:: RSAPublicKey
171
172 An `RSA`_ public key.
173
174 .. attribute:: modulus
175
176 :type: str
177
178 Hexadecimal representation of the public modulus. Alias for ``n``.
179
180 .. attribute:: key_length
181
182 :type: int
183
184 The bit length of the modulus.
185
186 .. attribute:: public_exponent
187
188 :type: int
189
190 The public exponent. Alias for ``e``.
191
192 .. attribute:: n
193
194 :type: str
195
196 Hexadecimal representation of the public modulus.
197
198 .. attribute:: e
199
200 :type: int
201
202 The public exponent.
203
204.. _`RSA`: http://en.wikipedia.org/wiki/RSA_(cryptosystem)