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 | f2fb02a | 2014-06-19 10:16:42 -0600 | [diff] [blame^] | 115 | .. method:: signer(padding, algorithm) |
Paul Kehrer | 01cdfb2 | 2014-04-15 11:27:03 -0400 | [diff] [blame] | 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 | |
Paul Kehrer | 01cdfb2 | 2014-04-15 11:27:03 -0400 | [diff] [blame] | 129 | :returns: |
| 130 | :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricSignatureContext` |
| 131 | |
Paul Kehrer | f2fb02a | 2014-06-19 10:16:42 -0600 | [diff] [blame^] | 132 | .. method:: decrypt(ciphertext, padding) |
Paul Kehrer | 27f9ca6 | 2014-04-15 17:59:27 -0400 | [diff] [blame] | 133 | |
| 134 | .. versionadded:: 0.4 |
| 135 | |
| 136 | Decrypt data that was encrypted via the public key. |
| 137 | |
| 138 | :param bytes ciphertext: The ciphertext to decrypt. |
| 139 | |
| 140 | :param padding: An instance of a |
| 141 | :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricPadding` |
| 142 | provider. |
| 143 | |
Paul Kehrer | 27f9ca6 | 2014-04-15 17:59:27 -0400 | [diff] [blame] | 144 | :return bytes: Decrypted data. |
| 145 | |
Paul Kehrer | 0e94fbe | 2014-01-26 11:47:21 -0600 | [diff] [blame] | 146 | .. method:: public_key() |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 147 | |
Paul Kehrer | 359b946 | 2014-01-26 12:03:05 -0600 | [diff] [blame] | 148 | :return: :class:`~cryptography.hazmat.primitives.interfaces.RSAPublicKey` |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 149 | |
| 150 | An RSA public key object corresponding to the values of the private key. |
| 151 | |
Alex Stapleton | ee3e6bf | 2014-02-02 21:13:48 +0000 | [diff] [blame] | 152 | .. attribute:: key_size |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 153 | |
| 154 | :type: int |
| 155 | |
| 156 | The bit length of the modulus. |
| 157 | |
Paul Kehrer | f0a48c6 | 2014-06-07 17:04:13 -0500 | [diff] [blame] | 158 | .. class:: RSAPrivateKeyWithNumbers |
| 159 | |
| 160 | .. versionadded:: 0.5 |
| 161 | |
| 162 | Extends :class:`RSAPrivateKey`. |
| 163 | |
| 164 | .. method:: private_numbers() |
| 165 | |
| 166 | Create a |
| 167 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateNumbers` |
| 168 | object. |
| 169 | |
| 170 | :returns: An |
| 171 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateNumbers` |
| 172 | instance. |
| 173 | |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 174 | |
| 175 | .. class:: RSAPublicKey |
| 176 | |
Paul Kehrer | 46688b1 | 2014-01-26 13:23:13 -0600 | [diff] [blame] | 177 | .. versionadded:: 0.2 |
Paul Kehrer | 82629f4 | 2014-01-26 12:25:02 -0600 | [diff] [blame] | 178 | |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 179 | An `RSA`_ public key. |
| 180 | |
Paul Kehrer | f2fb02a | 2014-06-19 10:16:42 -0600 | [diff] [blame^] | 181 | .. method:: verifier(signature, padding, algorithm) |
Paul Kehrer | 01cdfb2 | 2014-04-15 11:27:03 -0400 | [diff] [blame] | 182 | |
| 183 | .. versionadded:: 0.3 |
| 184 | |
| 185 | Verify data was signed by the private key associated with this public |
| 186 | key. |
| 187 | |
| 188 | :param bytes signature: The signature to verify. |
| 189 | |
| 190 | :param padding: An instance of a |
| 191 | :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricPadding` |
| 192 | provider. |
| 193 | |
| 194 | :param algorithm: An instance of a |
| 195 | :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 196 | provider. |
| 197 | |
Paul Kehrer | 01cdfb2 | 2014-04-15 11:27:03 -0400 | [diff] [blame] | 198 | :returns: |
| 199 | :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricVerificationContext` |
| 200 | |
Paul Kehrer | f2fb02a | 2014-06-19 10:16:42 -0600 | [diff] [blame^] | 201 | .. method:: encrypt(plaintext, padding) |
Paul Kehrer | 4e602f3 | 2014-04-24 12:07:54 -0500 | [diff] [blame] | 202 | |
| 203 | .. versionadded:: 0.4 |
| 204 | |
| 205 | Encrypt data with the public key. |
| 206 | |
| 207 | :param bytes plaintext: The plaintext to encrypt. |
| 208 | |
| 209 | :param padding: An instance of a |
| 210 | :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricPadding` |
| 211 | provider. |
| 212 | |
Paul Kehrer | 4e602f3 | 2014-04-24 12:07:54 -0500 | [diff] [blame] | 213 | :return bytes: Encrypted data. |
Paul Kehrer | 01cdfb2 | 2014-04-15 11:27:03 -0400 | [diff] [blame] | 214 | |
Alex Stapleton | ee3e6bf | 2014-02-02 21:13:48 +0000 | [diff] [blame] | 215 | .. attribute:: key_size |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 216 | |
| 217 | :type: int |
| 218 | |
| 219 | The bit length of the modulus. |
| 220 | |
Paul Kehrer | ac42323 | 2014-01-25 14:13:09 -0600 | [diff] [blame] | 221 | |
Paul Kehrer | f0a48c6 | 2014-06-07 17:04:13 -0500 | [diff] [blame] | 222 | .. class:: RSAPublicKeyWithNumbers |
| 223 | |
| 224 | .. versionadded:: 0.5 |
| 225 | |
| 226 | Extends :class:`RSAPublicKey`. |
| 227 | |
| 228 | .. method:: public_numbers() |
| 229 | |
| 230 | Create a |
| 231 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicNumbers` |
| 232 | object. |
| 233 | |
| 234 | :returns: An |
| 235 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicNumbers` |
| 236 | instance. |
| 237 | |
| 238 | |
Mohammed Attia | 71acc67 | 2014-03-04 19:20:45 +0200 | [diff] [blame] | 239 | .. class:: DSAParameters |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 240 | |
| 241 | .. versionadded:: 0.3 |
| 242 | |
| 243 | `DSA`_ parameters. |
| 244 | |
| 245 | .. attribute:: modulus |
| 246 | |
| 247 | :type: int |
| 248 | |
Mohammed Attia | 7a1738a | 2014-03-04 19:17:24 +0200 | [diff] [blame] | 249 | 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] | 250 | in the DSA signing and verification processes. |
| 251 | |
| 252 | .. attribute:: subgroup_order |
| 253 | |
| 254 | :type: int |
| 255 | |
Mohammed Attia | 7a1738a | 2014-03-04 19:17:24 +0200 | [diff] [blame] | 256 | The subgroup order that is used in generating the DSA key pair |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 257 | by the generator and used in the DSA signing and verification |
| 258 | processes. |
| 259 | |
| 260 | .. attribute:: generator |
| 261 | |
| 262 | :type: int |
| 263 | |
Mohammed Attia | cb9a6c2 | 2014-03-04 04:16:35 +0200 | [diff] [blame] | 264 | 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] | 265 | in the DSA signing and verification processes. |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 266 | |
| 267 | .. attribute:: p |
| 268 | |
| 269 | :type: int |
| 270 | |
Mohammed Attia | 7a1738a | 2014-03-04 19:17:24 +0200 | [diff] [blame] | 271 | 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] | 272 | in the DSA signing and verification processes. Alias for :attr:`modulus`. |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 273 | |
| 274 | .. attribute:: q |
| 275 | |
| 276 | :type: int |
| 277 | |
Mohammed Attia | 7a1738a | 2014-03-04 19:17:24 +0200 | [diff] [blame] | 278 | The subgroup order that is used in generating the DSA key pair |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 279 | by the generator and used in the DSA signing and verification |
Mohammed Attia | 7032451 | 2014-03-04 03:34:39 +0200 | [diff] [blame] | 280 | processes. Alias for :attr:`subgroup_order`. |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 281 | |
| 282 | .. attribute:: g |
| 283 | |
| 284 | :type: int |
| 285 | |
Mohammed Attia | cb9a6c2 | 2014-03-04 04:16:35 +0200 | [diff] [blame] | 286 | 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] | 287 | in the DSA signing and verification processes. Alias for :attr:`generator`. |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 288 | |
| 289 | |
| 290 | .. class:: DSAPrivateKey |
| 291 | |
| 292 | .. versionadded:: 0.3 |
| 293 | |
Mohammed Attia | 7a1738a | 2014-03-04 19:17:24 +0200 | [diff] [blame] | 294 | A `DSA`_ private key. |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 295 | |
| 296 | .. method:: public_key() |
| 297 | |
| 298 | :return: :class:`~cryptography.hazmat.primitives.interfaces.DSAPublicKey` |
| 299 | |
| 300 | An DSA public key object corresponding to the values of the private key. |
| 301 | |
| 302 | .. method:: parameters() |
| 303 | |
Mohammed Attia | 71acc67 | 2014-03-04 19:20:45 +0200 | [diff] [blame] | 304 | :return: :class:`~cryptography.hazmat.primitives.interfaces.DSAParameters` |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 305 | |
Mohammed Attia | 71acc67 | 2014-03-04 19:20:45 +0200 | [diff] [blame] | 306 | The DSAParameters object associated with this private key. |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 307 | |
Paul Kehrer | 0b3ff3b | 2014-05-01 15:34:42 -0500 | [diff] [blame] | 308 | .. method:: signer(algorithm, backend) |
| 309 | |
| 310 | .. versionadded:: 0.4 |
| 311 | |
| 312 | Sign data which can be verified later by others using the public key. |
| 313 | |
| 314 | :param algorithm: An instance of a |
| 315 | :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 316 | provider. |
| 317 | |
| 318 | :param backend: A |
| 319 | :class:`~cryptography.hazmat.backends.interfaces.DSABackend` |
| 320 | provider. |
| 321 | |
| 322 | :returns: |
| 323 | :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricSignatureContext` |
| 324 | |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 325 | .. attribute:: key_size |
| 326 | |
| 327 | :type: int |
| 328 | |
| 329 | The bit length of the modulus. |
| 330 | |
| 331 | .. attribute:: x |
| 332 | |
| 333 | :type: int |
| 334 | |
| 335 | The private key. |
| 336 | |
| 337 | .. attribute:: y |
| 338 | |
| 339 | :type: int |
| 340 | |
| 341 | The public key. |
| 342 | |
| 343 | |
| 344 | .. class:: DSAPublicKey |
| 345 | |
| 346 | .. versionadded:: 0.3 |
| 347 | |
Mohammed Attia | edacb14 | 2014-03-17 12:28:23 +0200 | [diff] [blame] | 348 | A `DSA`_ public key. |
| 349 | |
| 350 | .. attribute:: key_size |
| 351 | |
| 352 | :type: int |
| 353 | |
| 354 | The bit length of the modulus. |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 355 | |
Mohammed Attia | 59edb61 | 2014-04-25 22:44:40 +0200 | [diff] [blame] | 356 | .. attribute:: y |
| 357 | |
| 358 | :type: int |
| 359 | |
| 360 | The public key. |
| 361 | |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 362 | .. method:: parameters() |
| 363 | |
Mohammed Attia | 71acc67 | 2014-03-04 19:20:45 +0200 | [diff] [blame] | 364 | :return: :class:`~cryptography.hazmat.primitives.interfaces.DSAParameters` |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 365 | |
Mohammed Attia | 71acc67 | 2014-03-04 19:20:45 +0200 | [diff] [blame] | 366 | The DSAParameters object associated with this public key. |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 367 | |
Mohammed Attia | 59edb61 | 2014-04-25 22:44:40 +0200 | [diff] [blame] | 368 | .. method:: verifier(signature, algorithm, backend) |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 369 | |
Mohammed Attia | 59edb61 | 2014-04-25 22:44:40 +0200 | [diff] [blame] | 370 | .. versionadded:: 0.4 |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 371 | |
Mohammed Attia | 59edb61 | 2014-04-25 22:44:40 +0200 | [diff] [blame] | 372 | Verify data was signed by the private key associated with this public |
| 373 | key. |
| 374 | |
Paul Kehrer | e0aeaf8 | 2014-05-01 11:58:23 -0500 | [diff] [blame] | 375 | :param bytes signature: The signature to verify. DER encoded as |
| 376 | specified in :rfc:`6979`. |
Mohammed Attia | 59edb61 | 2014-04-25 22:44:40 +0200 | [diff] [blame] | 377 | |
| 378 | :param algorithm: An instance of a |
| 379 | :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 380 | provider. |
| 381 | |
| 382 | :param backend: A |
| 383 | :class:`~cryptography.hazmat.backends.interfaces.DSABackend` |
| 384 | provider. |
| 385 | |
| 386 | :returns: |
| 387 | :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricVerificationContext` |
Mohammed Attia | b416715 | 2014-03-04 03:29:56 +0200 | [diff] [blame] | 388 | |
| 389 | |
Alex Stapleton | 085f378 | 2014-04-01 16:18:17 +0100 | [diff] [blame] | 390 | .. class:: EllipticCurve |
| 391 | |
Alex Stapleton | 20c9903 | 2014-05-03 21:06:46 +0100 | [diff] [blame] | 392 | .. versionadded:: 0.5 |
Alex Stapleton | 085f378 | 2014-04-01 16:18:17 +0100 | [diff] [blame] | 393 | |
| 394 | A named elliptic curve. |
| 395 | |
| 396 | .. attribute:: name |
| 397 | |
| 398 | :type: string |
| 399 | |
| 400 | The name of the curve. Usually the name used for the ASN.1 OID such as |
Alex Stapleton | 6e52674 | 2014-05-23 22:06:06 +0100 | [diff] [blame] | 401 | ``secp256k1``. |
Alex Stapleton | 085f378 | 2014-04-01 16:18:17 +0100 | [diff] [blame] | 402 | |
| 403 | .. attribute:: key_size |
| 404 | |
| 405 | :type: int |
| 406 | |
Alex Stapleton | d436569 | 2014-05-26 09:25:25 +0100 | [diff] [blame] | 407 | The bit length of the curve's base point. |
Alex Stapleton | 085f378 | 2014-04-01 16:18:17 +0100 | [diff] [blame] | 408 | |
| 409 | |
Alex Stapleton | a1853f9 | 2014-04-18 11:38:28 +0100 | [diff] [blame] | 410 | .. class:: EllipticCurveSignatureAlgorithm |
| 411 | |
Alex Stapleton | 20c9903 | 2014-05-03 21:06:46 +0100 | [diff] [blame] | 412 | .. versionadded:: 0.5 |
Alex Stapleton | a1853f9 | 2014-04-18 11:38:28 +0100 | [diff] [blame] | 413 | |
| 414 | A signature algorithm for use with elliptic curve keys. |
| 415 | |
Alex Stapleton | 80228a1 | 2014-04-20 16:44:26 +0100 | [diff] [blame] | 416 | .. attribute:: algorithm |
| 417 | |
| 418 | :type: :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 419 | |
| 420 | The digest algorithm to be used with the signature scheme. |
| 421 | |
Alex Stapleton | a1853f9 | 2014-04-18 11:38:28 +0100 | [diff] [blame] | 422 | |
Alex Stapleton | 085f378 | 2014-04-01 16:18:17 +0100 | [diff] [blame] | 423 | .. class:: EllipticCurvePrivateKey |
| 424 | |
Alex Stapleton | 20c9903 | 2014-05-03 21:06:46 +0100 | [diff] [blame] | 425 | .. versionadded:: 0.5 |
Alex Stapleton | 085f378 | 2014-04-01 16:18:17 +0100 | [diff] [blame] | 426 | |
| 427 | An elliptic curve private key for use with an algorithm such as `ECDSA`_ or |
| 428 | `EdDSA`_. |
| 429 | |
Alex Stapleton | 33c9d83 | 2014-05-23 21:31:51 +0100 | [diff] [blame] | 430 | .. classmethod:: signer(signature_algorithm) |
Alex Stapleton | a1853f9 | 2014-04-18 11:38:28 +0100 | [diff] [blame] | 431 | Sign data which can be verified later by others using the public key. |
| 432 | |
| 433 | :param signature_algorithm: An instance of a |
| 434 | :class:`~cryptography.hazmat.primitives.interfaces.EllipticCurveSignatureAlgorithm` |
| 435 | provider. |
| 436 | |
Alex Stapleton | a1853f9 | 2014-04-18 11:38:28 +0100 | [diff] [blame] | 437 | :returns: |
| 438 | :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricSignatureContext` |
| 439 | |
Alex Stapleton | 085f378 | 2014-04-01 16:18:17 +0100 | [diff] [blame] | 440 | |
| 441 | :type: :class:`~cryptography.hazmat.primitives.interfaces.EllipticCurve` |
| 442 | |
| 443 | The elliptic curve for this key. |
| 444 | |
Alex Stapleton | 085f378 | 2014-04-01 16:18:17 +0100 | [diff] [blame] | 445 | .. method:: public_key() |
| 446 | |
| 447 | :return: :class:`~cryptography.hazmat.primitives.interfaces.EllipticCurvePublicKey` |
| 448 | |
| 449 | The EllipticCurvePublicKey object for this private key. |
| 450 | |
| 451 | |
| 452 | .. class:: EllipticCurvePublicKey |
| 453 | |
Alex Stapleton | 20c9903 | 2014-05-03 21:06:46 +0100 | [diff] [blame] | 454 | .. versionadded:: 0.5 |
Alex Stapleton | 085f378 | 2014-04-01 16:18:17 +0100 | [diff] [blame] | 455 | |
| 456 | An elliptic curve public key. |
| 457 | |
Alex Stapleton | e47bafb | 2014-05-17 13:19:15 +0100 | [diff] [blame] | 458 | .. classmethod:: verifier(signature, signature_algorithm) |
Alex Stapleton | a1853f9 | 2014-04-18 11:38:28 +0100 | [diff] [blame] | 459 | Verify data was signed by the private key associated with this public |
| 460 | key. |
| 461 | |
Alex Stapleton | 80228a1 | 2014-04-20 16:44:26 +0100 | [diff] [blame] | 462 | :param bytes signature: The signature to verify. |
| 463 | |
Alex Stapleton | a1853f9 | 2014-04-18 11:38:28 +0100 | [diff] [blame] | 464 | :param signature_algorithm: An instance of a |
| 465 | :class:`~cryptography.hazmat.primitives.interfaces.EllipticCurveSignatureAlgorithm` |
| 466 | provider. |
| 467 | |
Alex Stapleton | a1853f9 | 2014-04-18 11:38:28 +0100 | [diff] [blame] | 468 | :returns: |
| 469 | :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricSignatureContext` |
| 470 | |
Alex Stapleton | 085f378 | 2014-04-01 16:18:17 +0100 | [diff] [blame] | 471 | .. attribute:: curve |
| 472 | |
| 473 | :type: :class:`~cryptography.hazmat.primitives.interfaces.EllipticCurve` |
| 474 | |
| 475 | The elliptic curve for this key. |
| 476 | |
Alex Stapleton | 085f378 | 2014-04-01 16:18:17 +0100 | [diff] [blame] | 477 | |
Paul Kehrer | eda558c | 2014-02-17 21:18:13 -0600 | [diff] [blame] | 478 | .. class:: AsymmetricSignatureContext |
Paul Kehrer | e0f0f34 | 2014-02-17 19:20:51 -0600 | [diff] [blame] | 479 | |
| 480 | .. versionadded:: 0.2 |
| 481 | |
| 482 | .. method:: update(data) |
| 483 | |
Paul Kehrer | eda558c | 2014-02-17 21:18:13 -0600 | [diff] [blame] | 484 | :param bytes data: The data you want to sign. |
Paul Kehrer | e0f0f34 | 2014-02-17 19:20:51 -0600 | [diff] [blame] | 485 | |
| 486 | .. method:: finalize() |
| 487 | |
| 488 | :return bytes signature: The signature. |
| 489 | |
| 490 | |
Paul Kehrer | 430202d | 2014-02-18 13:36:53 -0600 | [diff] [blame] | 491 | .. class:: AsymmetricVerificationContext |
Paul Kehrer | e0f0f34 | 2014-02-17 19:20:51 -0600 | [diff] [blame] | 492 | |
| 493 | .. versionadded:: 0.2 |
| 494 | |
| 495 | .. method:: update(data) |
| 496 | |
Paul Kehrer | eda558c | 2014-02-17 21:18:13 -0600 | [diff] [blame] | 497 | :param bytes data: The data you wish to verify using the signature. |
Paul Kehrer | e0f0f34 | 2014-02-17 19:20:51 -0600 | [diff] [blame] | 498 | |
Paul Kehrer | dd3780a | 2014-02-18 13:17:53 -0600 | [diff] [blame] | 499 | .. method:: verify() |
Paul Kehrer | e0f0f34 | 2014-02-17 19:20:51 -0600 | [diff] [blame] | 500 | |
Paul Kehrer | fef1fbd | 2014-02-26 23:39:37 -0400 | [diff] [blame] | 501 | :raises cryptography.exceptions.InvalidSignature: If the signature does |
| 502 | not validate. |
Paul Kehrer | e0f0f34 | 2014-02-17 19:20:51 -0600 | [diff] [blame] | 503 | |
| 504 | |
| 505 | .. class:: AsymmetricPadding |
| 506 | |
Paul Kehrer | 19f32d5 | 2014-02-17 19:23:06 -0600 | [diff] [blame] | 507 | .. versionadded:: 0.2 |
Paul Kehrer | e0f0f34 | 2014-02-17 19:20:51 -0600 | [diff] [blame] | 508 | |
| 509 | .. attribute:: name |
| 510 | |
David Reid | 3e0c21e | 2014-05-13 14:30:45 -0700 | [diff] [blame] | 511 | |
Alex Stapleton | c5fffd3 | 2014-03-18 15:29:00 +0000 | [diff] [blame] | 512 | Hash algorithms |
Paul Kehrer | e51a2db | 2014-01-29 11:49:35 -0600 | [diff] [blame] | 513 | ~~~~~~~~~~~~~~~ |
| 514 | |
| 515 | .. class:: HashAlgorithm |
| 516 | |
Paul Kehrer | e51a2db | 2014-01-29 11:49:35 -0600 | [diff] [blame] | 517 | .. attribute:: name |
| 518 | |
| 519 | :type: str |
| 520 | |
Paul Kehrer | 4c75a8c | 2014-01-29 12:20:37 -0600 | [diff] [blame] | 521 | The standard name for the hash algorithm, for example: ``"sha256"`` or |
| 522 | ``"whirlpool"``. |
Paul Kehrer | e51a2db | 2014-01-29 11:49:35 -0600 | [diff] [blame] | 523 | |
| 524 | .. attribute:: digest_size |
| 525 | |
| 526 | :type: int |
| 527 | |
| 528 | The size of the resulting digest in bytes. |
| 529 | |
| 530 | .. attribute:: block_size |
| 531 | |
| 532 | :type: int |
| 533 | |
| 534 | The internal block size of the hash algorithm in bytes. |
| 535 | |
| 536 | |
Ayrx | a0f9850 | 2014-04-15 19:17:03 +0800 | [diff] [blame] | 537 | .. class:: HashContext |
| 538 | |
| 539 | .. attribute:: algorithm |
| 540 | |
| 541 | A :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` that |
| 542 | will be used by this context. |
| 543 | |
| 544 | .. method:: update(data) |
| 545 | |
| 546 | :param data bytes: The data you want to hash. |
| 547 | |
| 548 | .. method:: finalize() |
| 549 | |
| 550 | :return: The final digest as bytes. |
| 551 | |
| 552 | .. method:: copy() |
| 553 | |
| 554 | :return: A :class:`~cryptography.hazmat.primitives.interfaces.HashContext` |
| 555 | that is a copy of the current context. |
| 556 | |
| 557 | |
Alex Stapleton | c5fffd3 | 2014-03-18 15:29:00 +0000 | [diff] [blame] | 558 | Key derivation functions |
Alex Gaynor | b2774f5 | 2014-01-27 11:05:29 -0800 | [diff] [blame] | 559 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 560 | |
| 561 | .. class:: KeyDerivationFunction |
| 562 | |
Alex Gaynor | 8454c51 | 2014-01-28 07:01:54 -0800 | [diff] [blame] | 563 | .. versionadded:: 0.2 |
| 564 | |
Alex Gaynor | b2774f5 | 2014-01-27 11:05:29 -0800 | [diff] [blame] | 565 | .. method:: derive(key_material) |
| 566 | |
Alex Gaynor | 5484f72 | 2014-01-28 05:46:15 -0800 | [diff] [blame] | 567 | :param key_material bytes: The input key material. Depending on what |
| 568 | key derivation function you are using this |
| 569 | could be either random material, or a user |
Alex Gaynor | b2774f5 | 2014-01-27 11:05:29 -0800 | [diff] [blame] | 570 | supplied password. |
Alex Gaynor | 5484f72 | 2014-01-28 05:46:15 -0800 | [diff] [blame] | 571 | :return: The new key. |
Alex Gaynor | e19e89f | 2014-01-28 06:58:43 -0800 | [diff] [blame] | 572 | :raises cryptography.exceptions.AlreadyFinalized: This is raised when |
| 573 | :meth:`derive` or |
| 574 | :meth:`verify` is |
| 575 | called more than |
| 576 | once. |
Alex Gaynor | b2774f5 | 2014-01-27 11:05:29 -0800 | [diff] [blame] | 577 | |
Alex Gaynor | 5484f72 | 2014-01-28 05:46:15 -0800 | [diff] [blame] | 578 | This generates and returns a new key from the supplied key material. |
Alex Gaynor | b2774f5 | 2014-01-27 11:05:29 -0800 | [diff] [blame] | 579 | |
| 580 | .. method:: verify(key_material, expected_key) |
| 581 | |
Alex Gaynor | 5484f72 | 2014-01-28 05:46:15 -0800 | [diff] [blame] | 582 | :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] | 583 | ``key_material`` in :meth:`derive`. |
Alex Gaynor | 5484f72 | 2014-01-28 05:46:15 -0800 | [diff] [blame] | 584 | :param expected_key bytes: The expected result of deriving a new key, |
| 585 | this is the same as the return value of |
| 586 | :meth:`derive`. |
Alex Gaynor | b2774f5 | 2014-01-27 11:05:29 -0800 | [diff] [blame] | 587 | :raises cryptography.exceptions.InvalidKey: This is raised when the |
| 588 | derived key does not match |
| 589 | the expected key. |
Alex Gaynor | e19e89f | 2014-01-28 06:58:43 -0800 | [diff] [blame] | 590 | :raises cryptography.exceptions.AlreadyFinalized: This is raised when |
| 591 | :meth:`derive` or |
| 592 | :meth:`verify` is |
| 593 | called more than |
| 594 | once. |
Alex Gaynor | b2774f5 | 2014-01-27 11:05:29 -0800 | [diff] [blame] | 595 | |
Alex Gaynor | 5484f72 | 2014-01-28 05:46:15 -0800 | [diff] [blame] | 596 | This checks whether deriving a new key from the supplied |
| 597 | ``key_material`` generates the same key as the ``expected_key``, and |
| 598 | raises an exception if they do not match. This can be used for |
| 599 | something like checking whether a user's password attempt matches the |
| 600 | stored derived key. |
Alex Gaynor | b2774f5 | 2014-01-27 11:05:29 -0800 | [diff] [blame] | 601 | |
Ayrx | c812170 | 2014-04-15 19:02:05 +0800 | [diff] [blame] | 602 | |
Ayrx | 83cd3f8 | 2014-04-15 21:56:32 +0800 | [diff] [blame] | 603 | `CMAC`_ |
| 604 | ~~~~~~~ |
Ayrx | c812170 | 2014-04-15 19:02:05 +0800 | [diff] [blame] | 605 | |
| 606 | .. class:: CMACContext |
| 607 | |
| 608 | .. versionadded:: 0.4 |
| 609 | |
| 610 | .. method:: update(data) |
| 611 | |
| 612 | :param data bytes: The data you want to authenticate. |
| 613 | |
| 614 | .. method:: finalize() |
| 615 | |
Ayrx | 7964c17 | 2014-04-15 21:50:58 +0800 | [diff] [blame] | 616 | :return: The message authentication code. |
Ayrx | c812170 | 2014-04-15 19:02:05 +0800 | [diff] [blame] | 617 | |
| 618 | .. method:: copy() |
| 619 | |
| 620 | :return: A :class:`~cryptography.hazmat.primitives.interfaces.CMACContext` |
| 621 | that is a copy of the current context. |
| 622 | |
| 623 | |
Paul Kehrer | 8e9c984 | 2014-02-13 12:23:27 -0600 | [diff] [blame] | 624 | .. _`RSA`: https://en.wikipedia.org/wiki/RSA_(cryptosystem) |
| 625 | .. _`Chinese remainder theorem`: https://en.wikipedia.org/wiki/Chinese_remainder_theorem |
Mohammed Attia | 604c78f | 2014-03-04 03:56:08 +0200 | [diff] [blame] | 626 | .. _`DSA`: https://en.wikipedia.org/wiki/Digital_Signature_Algorithm |
Ayrx | 83cd3f8 | 2014-04-15 21:56:32 +0800 | [diff] [blame] | 627 | .. _`CMAC`: https://en.wikipedia.org/wiki/CMAC |
Alex Stapleton | 085f378 | 2014-04-01 16:18:17 +0100 | [diff] [blame] | 628 | .. _`ECDSA`: http://en.wikipedia.org/wiki/ECDSA |
| 629 | .. _`EdDSA`: http://en.wikipedia.org/wiki/EdDSA |