David Reid | 30722b9 | 2013-11-07 13:03:39 -0800 | [diff] [blame] | 1 | .. hazmat:: |
| 2 | |
| 3 | Interfaces |
| 4 | ========== |
| 5 | |
| 6 | |
| 7 | ``cryptography`` uses `Abstract Base Classes`_ as interfaces to describe the |
David Reid | bd18bcd | 2013-11-07 13:13:30 -0800 | [diff] [blame] | 8 | properties and methods of most primitive constructs. Backends may also use |
| 9 | this information to influence their operation. Interfaces should also be used |
David Reid | 30722b9 | 2013-11-07 13:03:39 -0800 | [diff] [blame] | 10 | to document argument and return types. |
| 11 | |
David Reid | 9ed25e4 | 2013-11-07 13:15:27 -0800 | [diff] [blame] | 12 | .. _`Abstract Base Classes`: http://docs.python.org/3.2/library/abc.html |
David Reid | 30722b9 | 2013-11-07 13:03:39 -0800 | [diff] [blame] | 13 | |
| 14 | |
Alex Stapleton | c5fffd3 | 2014-03-18 15:29:00 +0000 | [diff] [blame] | 15 | Symmetric ciphers |
David Reid | 0a394df | 2013-11-15 16:19:50 -0800 | [diff] [blame] | 16 | ~~~~~~~~~~~~~~~~~ |
David Reid | 30722b9 | 2013-11-07 13:03:39 -0800 | [diff] [blame] | 17 | |
| 18 | .. currentmodule:: cryptography.hazmat.primitives.interfaces |
| 19 | |
David Reid | 0a394df | 2013-11-15 16:19:50 -0800 | [diff] [blame] | 20 | |
| 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 Reid | 668d480 | 2013-12-17 11:53:43 -0800 | [diff] [blame] | 39 | .. 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 | |
Alex Stapleton | c5fffd3 | 2014-03-18 15:29:00 +0000 | [diff] [blame] | 50 | Cipher modes |
David Reid | 0a394df | 2013-11-15 16:19:50 -0800 | [diff] [blame] | 51 | ------------ |
| 52 | |
David Reid | 30722b9 | 2013-11-07 13:03:39 -0800 | [diff] [blame] | 53 | Interfaces 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 Gaynor | 9626b5a | 2013-11-19 16:49:26 -0800 | [diff] [blame] | 70 | .. 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 Reid | 30722b9 | 2013-11-07 13:03:39 -0800 | [diff] [blame] | 82 | |
| 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 Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 105 | |
Alex Stapleton | c5fffd3 | 2014-03-18 15:29:00 +0000 | [diff] [blame] | 106 | Asymmetric interfaces |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 107 | ~~~~~~~~~~~~~~~~~~~~~ |
| 108 | |
| 109 | .. class:: RSAPrivateKey |
| 110 | |
Paul Kehrer | 46688b1 | 2014-01-26 13:23:13 -0600 | [diff] [blame] | 111 | .. versionadded:: 0.2 |
Paul Kehrer | 82629f4 | 2014-01-26 12:25:02 -0600 | [diff] [blame] | 112 | |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 113 | An `RSA`_ private key. |
| 114 | |
Paul Kehrer | 01cdfb2 | 2014-04-15 11:27:03 -0400 | [diff] [blame] | 115 | .. method:: signer(padding, algorithm, backend) |
| 116 | |
| 117 | .. versionadded:: 0.3 |
| 118 | |
| 119 | Sign data which can be verified later by others using the public key. |
| 120 | |
| 121 | :param padding: An instance of a |
| 122 | :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricPadding` |
| 123 | provider. |
| 124 | |
| 125 | :param algorithm: An instance of a |
| 126 | :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 127 | provider. |
| 128 | |
| 129 | :param backend: A |
| 130 | :class:`~cryptography.hazmat.backends.interfaces.RSABackend` |
| 131 | provider. |
| 132 | |
| 133 | :returns: |
| 134 | :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricSignatureContext` |
| 135 | |
Paul Kehrer | 0e94fbe | 2014-01-26 11:47:21 -0600 | [diff] [blame] | 136 | .. method:: public_key() |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 137 | |
Paul Kehrer | 359b946 | 2014-01-26 12:03:05 -0600 | [diff] [blame] | 138 | :return: :class:`~cryptography.hazmat.primitives.interfaces.RSAPublicKey` |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 139 | |
| 140 | An RSA public key object corresponding to the values of the private key. |
| 141 | |
| 142 | .. attribute:: modulus |
| 143 | |
Paul Kehrer | d527b30 | 2014-01-26 11:41:38 -0600 | [diff] [blame] | 144 | :type: int |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 145 | |
Paul Kehrer | 0e94fbe | 2014-01-26 11:47:21 -0600 | [diff] [blame] | 146 | The public modulus. |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 147 | |
| 148 | .. attribute:: public_exponent |
| 149 | |
| 150 | :type: int |
| 151 | |
Paul Kehrer | 0e94fbe | 2014-01-26 11:47:21 -0600 | [diff] [blame] | 152 | The public exponent. |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 153 | |
Alex Gaynor | 2649a69 | 2014-02-03 07:14:16 -0800 | [diff] [blame] | 154 | .. attribute:: private_exponent |
| 155 | |
| 156 | :type: int |
| 157 | |
| 158 | The private exponent. |
| 159 | |
Alex Stapleton | ee3e6bf | 2014-02-02 21:13:48 +0000 | [diff] [blame] | 160 | .. attribute:: key_size |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 161 | |
| 162 | :type: int |
| 163 | |
| 164 | The bit length of the modulus. |
| 165 | |
| 166 | .. attribute:: p |
| 167 | |
Paul Kehrer | d527b30 | 2014-01-26 11:41:38 -0600 | [diff] [blame] | 168 | :type: int |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 169 | |
Alex Gaynor | 2a91874 | 2014-01-26 16:53:44 -0600 | [diff] [blame] | 170 | ``p``, one of the two primes composing the :attr:`modulus`. |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 171 | |
| 172 | .. attribute:: q |
| 173 | |
Paul Kehrer | d527b30 | 2014-01-26 11:41:38 -0600 | [diff] [blame] | 174 | :type: int |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 175 | |
Alex Gaynor | 2a91874 | 2014-01-26 16:53:44 -0600 | [diff] [blame] | 176 | ``q``, one of the two primes composing the :attr:`modulus`. |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 177 | |
| 178 | .. attribute:: d |
| 179 | |
Paul Kehrer | d527b30 | 2014-01-26 11:41:38 -0600 | [diff] [blame] | 180 | :type: int |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 181 | |
Alex Gaynor | 2649a69 | 2014-02-03 07:14:16 -0800 | [diff] [blame] | 182 | The private exponent. Alias for :attr:`private_exponent`. |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 183 | |
Paul Kehrer | 8e9c984 | 2014-02-13 12:23:27 -0600 | [diff] [blame] | 184 | .. attribute:: dmp1 |
| 185 | |
| 186 | :type: int |
| 187 | |
| 188 | A `Chinese remainder theorem`_ coefficient used to speed up RSA |
| 189 | operations. Calculated as: d mod (p-1) |
| 190 | |
| 191 | .. attribute:: dmq1 |
| 192 | |
| 193 | :type: int |
| 194 | |
| 195 | A `Chinese remainder theorem`_ coefficient used to speed up RSA |
| 196 | operations. Calculated as: d mod (q-1) |
| 197 | |
| 198 | .. attribute:: iqmp |
| 199 | |
| 200 | :type: int |
| 201 | |
| 202 | A `Chinese remainder theorem`_ coefficient used to speed up RSA |
| 203 | operations. Calculated as: q\ :sup:`-1` mod p |
| 204 | |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 205 | .. attribute:: n |
| 206 | |
Paul Kehrer | d527b30 | 2014-01-26 11:41:38 -0600 | [diff] [blame] | 207 | :type: int |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 208 | |
Alex Gaynor | 2a91874 | 2014-01-26 16:53:44 -0600 | [diff] [blame] | 209 | The public modulus. Alias for :attr:`modulus`. |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 210 | |
| 211 | .. attribute:: e |
| 212 | |
| 213 | :type: int |
| 214 | |
Alex Gaynor | 2a91874 | 2014-01-26 16:53:44 -0600 | [diff] [blame] | 215 | The public exponent. Alias for :attr:`public_exponent`. |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 216 | |
| 217 | |
| 218 | .. class:: RSAPublicKey |
| 219 | |
Paul Kehrer | 46688b1 | 2014-01-26 13:23:13 -0600 | [diff] [blame] | 220 | .. versionadded:: 0.2 |
Paul Kehrer | 82629f4 | 2014-01-26 12:25:02 -0600 | [diff] [blame] | 221 | |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 222 | An `RSA`_ public key. |
| 223 | |
Paul Kehrer | 01cdfb2 | 2014-04-15 11:27:03 -0400 | [diff] [blame] | 224 | .. method:: verifier(signature, padding, algorithm, backend) |
| 225 | |
| 226 | .. versionadded:: 0.3 |
| 227 | |
| 228 | Verify data was signed by the private key associated with this public |
| 229 | key. |
| 230 | |
| 231 | :param bytes signature: The signature to verify. |
| 232 | |
| 233 | :param padding: An instance of a |
| 234 | :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricPadding` |
| 235 | provider. |
| 236 | |
| 237 | :param algorithm: An instance of a |
| 238 | :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 239 | provider. |
| 240 | |
| 241 | :param backend: A |
| 242 | :class:`~cryptography.hazmat.backends.interfaces.RSABackend` |
| 243 | provider. |
| 244 | |
| 245 | :returns: |
| 246 | :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricVerificationContext` |
| 247 | |
| 248 | |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 249 | .. attribute:: modulus |
| 250 | |
Paul Kehrer | d527b30 | 2014-01-26 11:41:38 -0600 | [diff] [blame] | 251 | :type: int |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 252 | |
Paul Kehrer | 0e94fbe | 2014-01-26 11:47:21 -0600 | [diff] [blame] | 253 | The public modulus. |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 254 | |
Alex Stapleton | ee3e6bf | 2014-02-02 21:13:48 +0000 | [diff] [blame] | 255 | .. attribute:: key_size |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 256 | |
| 257 | :type: int |
| 258 | |
| 259 | The bit length of the modulus. |
| 260 | |
| 261 | .. attribute:: public_exponent |
| 262 | |
| 263 | :type: int |
| 264 | |
Paul Kehrer | 0e94fbe | 2014-01-26 11:47:21 -0600 | [diff] [blame] | 265 | The public exponent. |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 266 | |
| 267 | .. attribute:: n |
| 268 | |
Paul Kehrer | d527b30 | 2014-01-26 11:41:38 -0600 | [diff] [blame] | 269 | :type: int |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 270 | |
Alex Gaynor | 2a91874 | 2014-01-26 16:53:44 -0600 | [diff] [blame] | 271 | The public modulus. Alias for :attr:`modulus`. |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 272 | |
| 273 | .. attribute:: e |
| 274 | |
| 275 | :type: int |
| 276 | |
Alex Gaynor | 2a91874 | 2014-01-26 16:53:44 -0600 | [diff] [blame] | 277 | The public exponent. Alias for :attr:`public_exponent`. |
| 278 | |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 279 | |
Mohammed Attia | 71acc67 | 2014-03-04 19:20:45 +0200 | [diff] [blame] | 280 | .. class:: DSAParameters |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 281 | |
| 282 | .. versionadded:: 0.3 |
| 283 | |
| 284 | `DSA`_ parameters. |
| 285 | |
| 286 | .. attribute:: modulus |
| 287 | |
| 288 | :type: int |
| 289 | |
Mohammed Attia | 7a1738a | 2014-03-04 19:17:24 +0200 | [diff] [blame] | 290 | The prime modulus that is used in generating the DSA key pair and used |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 291 | in the DSA signing and verification processes. |
| 292 | |
| 293 | .. attribute:: subgroup_order |
| 294 | |
| 295 | :type: int |
| 296 | |
Mohammed Attia | 7a1738a | 2014-03-04 19:17:24 +0200 | [diff] [blame] | 297 | The subgroup order that is used in generating the DSA key pair |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 298 | by the generator and used in the DSA signing and verification |
| 299 | processes. |
| 300 | |
| 301 | .. attribute:: generator |
| 302 | |
| 303 | :type: int |
| 304 | |
Mohammed Attia | cb9a6c2 | 2014-03-04 04:16:35 +0200 | [diff] [blame] | 305 | The generator that is used in generating the DSA key pair and used |
Mohammed Attia | 7a1738a | 2014-03-04 19:17:24 +0200 | [diff] [blame] | 306 | in the DSA signing and verification processes. |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 307 | |
| 308 | .. attribute:: p |
| 309 | |
| 310 | :type: int |
| 311 | |
Mohammed Attia | 7a1738a | 2014-03-04 19:17:24 +0200 | [diff] [blame] | 312 | The prime modulus that is used in generating the DSA key pair and used |
Mohammed Attia | 7032451 | 2014-03-04 03:34:39 +0200 | [diff] [blame] | 313 | in the DSA signing and verification processes. Alias for :attr:`modulus`. |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 314 | |
| 315 | .. attribute:: q |
| 316 | |
| 317 | :type: int |
| 318 | |
Mohammed Attia | 7a1738a | 2014-03-04 19:17:24 +0200 | [diff] [blame] | 319 | The subgroup order that is used in generating the DSA key pair |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 320 | by the generator and used in the DSA signing and verification |
Mohammed Attia | 7032451 | 2014-03-04 03:34:39 +0200 | [diff] [blame] | 321 | processes. Alias for :attr:`subgroup_order`. |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 322 | |
| 323 | .. attribute:: g |
| 324 | |
| 325 | :type: int |
| 326 | |
Mohammed Attia | cb9a6c2 | 2014-03-04 04:16:35 +0200 | [diff] [blame] | 327 | The generator that is used in generating the DSA key pair and used |
Mohammed Attia | 7032451 | 2014-03-04 03:34:39 +0200 | [diff] [blame] | 328 | in the DSA signing and verification processes. Alias for :attr:`generator`. |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 329 | |
| 330 | |
| 331 | .. class:: DSAPrivateKey |
| 332 | |
| 333 | .. versionadded:: 0.3 |
| 334 | |
Mohammed Attia | 7a1738a | 2014-03-04 19:17:24 +0200 | [diff] [blame] | 335 | A `DSA`_ private key. |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 336 | |
| 337 | .. method:: public_key() |
| 338 | |
| 339 | :return: :class:`~cryptography.hazmat.primitives.interfaces.DSAPublicKey` |
| 340 | |
| 341 | An DSA public key object corresponding to the values of the private key. |
| 342 | |
| 343 | .. method:: parameters() |
| 344 | |
Mohammed Attia | 71acc67 | 2014-03-04 19:20:45 +0200 | [diff] [blame] | 345 | :return: :class:`~cryptography.hazmat.primitives.interfaces.DSAParameters` |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 346 | |
Mohammed Attia | 71acc67 | 2014-03-04 19:20:45 +0200 | [diff] [blame] | 347 | The DSAParameters object associated with this private key. |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 348 | |
| 349 | .. attribute:: key_size |
| 350 | |
| 351 | :type: int |
| 352 | |
| 353 | The bit length of the modulus. |
| 354 | |
| 355 | .. attribute:: x |
| 356 | |
| 357 | :type: int |
| 358 | |
| 359 | The private key. |
| 360 | |
| 361 | .. attribute:: y |
| 362 | |
| 363 | :type: int |
| 364 | |
| 365 | The public key. |
| 366 | |
| 367 | |
| 368 | .. class:: DSAPublicKey |
| 369 | |
| 370 | .. versionadded:: 0.3 |
| 371 | |
Mohammed Attia | edacb14 | 2014-03-17 12:28:23 +0200 | [diff] [blame] | 372 | A `DSA`_ public key. |
| 373 | |
| 374 | .. attribute:: key_size |
| 375 | |
| 376 | :type: int |
| 377 | |
| 378 | The bit length of the modulus. |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 379 | |
| 380 | .. method:: parameters() |
| 381 | |
Mohammed Attia | 71acc67 | 2014-03-04 19:20:45 +0200 | [diff] [blame] | 382 | :return: :class:`~cryptography.hazmat.primitives.interfaces.DSAParameters` |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 383 | |
Mohammed Attia | 71acc67 | 2014-03-04 19:20:45 +0200 | [diff] [blame] | 384 | The DSAParameters object associated with this public key. |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 385 | |
| 386 | .. attribute:: y |
| 387 | |
| 388 | :type: int |
| 389 | |
| 390 | The public key. |
| 391 | |
| 392 | |
Paul Kehrer | eda558c | 2014-02-17 21:18:13 -0600 | [diff] [blame] | 393 | .. class:: AsymmetricSignatureContext |
Paul Kehrer | e0f0f34 | 2014-02-17 19:20:51 -0600 | [diff] [blame] | 394 | |
| 395 | .. versionadded:: 0.2 |
| 396 | |
| 397 | .. method:: update(data) |
| 398 | |
Paul Kehrer | eda558c | 2014-02-17 21:18:13 -0600 | [diff] [blame] | 399 | :param bytes data: The data you want to sign. |
Paul Kehrer | e0f0f34 | 2014-02-17 19:20:51 -0600 | [diff] [blame] | 400 | |
| 401 | .. method:: finalize() |
| 402 | |
| 403 | :return bytes signature: The signature. |
| 404 | |
| 405 | |
Paul Kehrer | 430202d | 2014-02-18 13:36:53 -0600 | [diff] [blame] | 406 | .. class:: AsymmetricVerificationContext |
Paul Kehrer | e0f0f34 | 2014-02-17 19:20:51 -0600 | [diff] [blame] | 407 | |
| 408 | .. versionadded:: 0.2 |
| 409 | |
| 410 | .. method:: update(data) |
| 411 | |
Paul Kehrer | eda558c | 2014-02-17 21:18:13 -0600 | [diff] [blame] | 412 | :param bytes data: The data you wish to verify using the signature. |
Paul Kehrer | e0f0f34 | 2014-02-17 19:20:51 -0600 | [diff] [blame] | 413 | |
Paul Kehrer | dd3780a | 2014-02-18 13:17:53 -0600 | [diff] [blame] | 414 | .. method:: verify() |
Paul Kehrer | e0f0f34 | 2014-02-17 19:20:51 -0600 | [diff] [blame] | 415 | |
Paul Kehrer | fef1fbd | 2014-02-26 23:39:37 -0400 | [diff] [blame] | 416 | :raises cryptography.exceptions.InvalidSignature: If the signature does |
| 417 | not validate. |
Paul Kehrer | e0f0f34 | 2014-02-17 19:20:51 -0600 | [diff] [blame] | 418 | |
| 419 | |
| 420 | .. class:: AsymmetricPadding |
| 421 | |
Paul Kehrer | 19f32d5 | 2014-02-17 19:23:06 -0600 | [diff] [blame] | 422 | .. versionadded:: 0.2 |
Paul Kehrer | e0f0f34 | 2014-02-17 19:20:51 -0600 | [diff] [blame] | 423 | |
| 424 | .. attribute:: name |
| 425 | |
Alex Stapleton | c5fffd3 | 2014-03-18 15:29:00 +0000 | [diff] [blame] | 426 | Hash algorithms |
Paul Kehrer | e51a2db | 2014-01-29 11:49:35 -0600 | [diff] [blame] | 427 | ~~~~~~~~~~~~~~~ |
| 428 | |
| 429 | .. class:: HashAlgorithm |
| 430 | |
Paul Kehrer | e51a2db | 2014-01-29 11:49:35 -0600 | [diff] [blame] | 431 | .. attribute:: name |
| 432 | |
| 433 | :type: str |
| 434 | |
Paul Kehrer | 4c75a8c | 2014-01-29 12:20:37 -0600 | [diff] [blame] | 435 | The standard name for the hash algorithm, for example: ``"sha256"`` or |
| 436 | ``"whirlpool"``. |
Paul Kehrer | e51a2db | 2014-01-29 11:49:35 -0600 | [diff] [blame] | 437 | |
| 438 | .. attribute:: digest_size |
| 439 | |
| 440 | :type: int |
| 441 | |
| 442 | The size of the resulting digest in bytes. |
| 443 | |
| 444 | .. attribute:: block_size |
| 445 | |
| 446 | :type: int |
| 447 | |
| 448 | The internal block size of the hash algorithm in bytes. |
| 449 | |
| 450 | |
Ayrx | a0f9850 | 2014-04-15 19:17:03 +0800 | [diff] [blame] | 451 | .. class:: HashContext |
| 452 | |
| 453 | .. attribute:: algorithm |
| 454 | |
| 455 | A :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` that |
| 456 | will be used by this context. |
| 457 | |
| 458 | .. method:: update(data) |
| 459 | |
| 460 | :param data bytes: The data you want to hash. |
| 461 | |
| 462 | .. method:: finalize() |
| 463 | |
| 464 | :return: The final digest as bytes. |
| 465 | |
| 466 | .. method:: copy() |
| 467 | |
| 468 | :return: A :class:`~cryptography.hazmat.primitives.interfaces.HashContext` |
| 469 | that is a copy of the current context. |
| 470 | |
| 471 | |
Alex Stapleton | c5fffd3 | 2014-03-18 15:29:00 +0000 | [diff] [blame] | 472 | Key derivation functions |
Alex Gaynor | b2774f5 | 2014-01-27 11:05:29 -0800 | [diff] [blame] | 473 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 474 | |
| 475 | .. class:: KeyDerivationFunction |
| 476 | |
Alex Gaynor | 8454c51 | 2014-01-28 07:01:54 -0800 | [diff] [blame] | 477 | .. versionadded:: 0.2 |
| 478 | |
Alex Gaynor | b2774f5 | 2014-01-27 11:05:29 -0800 | [diff] [blame] | 479 | .. method:: derive(key_material) |
| 480 | |
Alex Gaynor | 5484f72 | 2014-01-28 05:46:15 -0800 | [diff] [blame] | 481 | :param key_material bytes: The input key material. Depending on what |
| 482 | key derivation function you are using this |
| 483 | could be either random material, or a user |
Alex Gaynor | b2774f5 | 2014-01-27 11:05:29 -0800 | [diff] [blame] | 484 | supplied password. |
Alex Gaynor | 5484f72 | 2014-01-28 05:46:15 -0800 | [diff] [blame] | 485 | :return: The new key. |
Alex Gaynor | e19e89f | 2014-01-28 06:58:43 -0800 | [diff] [blame] | 486 | :raises cryptography.exceptions.AlreadyFinalized: This is raised when |
| 487 | :meth:`derive` or |
| 488 | :meth:`verify` is |
| 489 | called more than |
| 490 | once. |
Alex Gaynor | b2774f5 | 2014-01-27 11:05:29 -0800 | [diff] [blame] | 491 | |
Alex Gaynor | 5484f72 | 2014-01-28 05:46:15 -0800 | [diff] [blame] | 492 | This generates and returns a new key from the supplied key material. |
Alex Gaynor | b2774f5 | 2014-01-27 11:05:29 -0800 | [diff] [blame] | 493 | |
| 494 | .. method:: verify(key_material, expected_key) |
| 495 | |
Alex Gaynor | 5484f72 | 2014-01-28 05:46:15 -0800 | [diff] [blame] | 496 | :param key_material bytes: The input key material. This is the same as |
Alex Gaynor | b2774f5 | 2014-01-27 11:05:29 -0800 | [diff] [blame] | 497 | ``key_material`` in :meth:`derive`. |
Alex Gaynor | 5484f72 | 2014-01-28 05:46:15 -0800 | [diff] [blame] | 498 | :param expected_key bytes: The expected result of deriving a new key, |
| 499 | this is the same as the return value of |
| 500 | :meth:`derive`. |
Alex Gaynor | b2774f5 | 2014-01-27 11:05:29 -0800 | [diff] [blame] | 501 | :raises cryptography.exceptions.InvalidKey: This is raised when the |
| 502 | derived key does not match |
| 503 | the expected key. |
Alex Gaynor | e19e89f | 2014-01-28 06:58:43 -0800 | [diff] [blame] | 504 | :raises cryptography.exceptions.AlreadyFinalized: This is raised when |
| 505 | :meth:`derive` or |
| 506 | :meth:`verify` is |
| 507 | called more than |
| 508 | once. |
Alex Gaynor | b2774f5 | 2014-01-27 11:05:29 -0800 | [diff] [blame] | 509 | |
Alex Gaynor | 5484f72 | 2014-01-28 05:46:15 -0800 | [diff] [blame] | 510 | This checks whether deriving a new key from the supplied |
| 511 | ``key_material`` generates the same key as the ``expected_key``, and |
| 512 | raises an exception if they do not match. This can be used for |
| 513 | something like checking whether a user's password attempt matches the |
| 514 | stored derived key. |
Alex Gaynor | b2774f5 | 2014-01-27 11:05:29 -0800 | [diff] [blame] | 515 | |
Ayrx | c812170 | 2014-04-15 19:02:05 +0800 | [diff] [blame] | 516 | |
Ayrx | 83cd3f8 | 2014-04-15 21:56:32 +0800 | [diff] [blame] | 517 | `CMAC`_ |
| 518 | ~~~~~~~ |
Ayrx | c812170 | 2014-04-15 19:02:05 +0800 | [diff] [blame] | 519 | |
| 520 | .. class:: CMACContext |
| 521 | |
| 522 | .. versionadded:: 0.4 |
| 523 | |
| 524 | .. method:: update(data) |
| 525 | |
| 526 | :param data bytes: The data you want to authenticate. |
| 527 | |
| 528 | .. method:: finalize() |
| 529 | |
Ayrx | 7964c17 | 2014-04-15 21:50:58 +0800 | [diff] [blame] | 530 | :return: The message authentication code. |
Ayrx | c812170 | 2014-04-15 19:02:05 +0800 | [diff] [blame] | 531 | |
| 532 | .. method:: copy() |
| 533 | |
| 534 | :return: A :class:`~cryptography.hazmat.primitives.interfaces.CMACContext` |
| 535 | that is a copy of the current context. |
| 536 | |
| 537 | |
Paul Kehrer | 8e9c984 | 2014-02-13 12:23:27 -0600 | [diff] [blame] | 538 | .. _`RSA`: https://en.wikipedia.org/wiki/RSA_(cryptosystem) |
| 539 | .. _`Chinese remainder theorem`: https://en.wikipedia.org/wiki/Chinese_remainder_theorem |
Mohammed Attia | 604c78f | 2014-03-04 03:56:08 +0200 | [diff] [blame] | 540 | .. _`DSA`: https://en.wikipedia.org/wiki/Digital_Signature_Algorithm |
Ayrx | 83cd3f8 | 2014-04-15 21:56:32 +0800 | [diff] [blame] | 541 | .. _`CMAC`: https://en.wikipedia.org/wiki/CMAC |