blob: 029c4c1fae6d4b9ced8ea27cbec33e6fecced480 [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
Alex Stapletonc5fffd32014-03-18 15:29:00 +000015Symmetric ciphers
David Reid0a394df2013-11-15 16:19:50 -080016~~~~~~~~~~~~~~~~~
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
Alex Stapletonc5fffd32014-03-18 15:29:00 +000050Cipher modes
David Reid0a394df2013-11-15 16:19:50 -080051------------
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
Alex Stapletonc5fffd32014-03-18 15:29:00 +0000106Asymmetric interfaces
Paul Kehrerac423232014-01-25 14:13:09 -0600107~~~~~~~~~~~~~~~~~~~~~
108
109.. class:: RSAPrivateKey
110
Paul Kehrer46688b12014-01-26 13:23:13 -0600111 .. versionadded:: 0.2
Paul Kehrer82629f42014-01-26 12:25:02 -0600112
Paul Kehrerac423232014-01-25 14:13:09 -0600113 An `RSA`_ private key.
114
Paul Kehrerf2fb02a2014-06-19 10:16:42 -0600115 .. method:: signer(padding, algorithm)
Paul Kehrer01cdfb22014-04-15 11:27:03 -0400116
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 Kehrer01cdfb22014-04-15 11:27:03 -0400129 :returns:
130 :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricSignatureContext`
131
Paul Kehrerf2fb02a2014-06-19 10:16:42 -0600132 .. method:: decrypt(ciphertext, padding)
Paul Kehrer27f9ca62014-04-15 17:59:27 -0400133
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 Kehrer27f9ca62014-04-15 17:59:27 -0400144 :return bytes: Decrypted data.
145
Paul Kehrer0e94fbe2014-01-26 11:47:21 -0600146 .. method:: public_key()
Paul Kehrerac423232014-01-25 14:13:09 -0600147
Paul Kehrer359b9462014-01-26 12:03:05 -0600148 :return: :class:`~cryptography.hazmat.primitives.interfaces.RSAPublicKey`
Paul Kehrerac423232014-01-25 14:13:09 -0600149
150 An RSA public key object corresponding to the values of the private key.
151
Alex Stapletonee3e6bf2014-02-02 21:13:48 +0000152 .. attribute:: key_size
Paul Kehrerac423232014-01-25 14:13:09 -0600153
154 :type: int
155
156 The bit length of the modulus.
157
Paul Kehrerf0a48c62014-06-07 17:04:13 -0500158.. 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 Kehrerac423232014-01-25 14:13:09 -0600174
175.. class:: RSAPublicKey
176
Paul Kehrer46688b12014-01-26 13:23:13 -0600177 .. versionadded:: 0.2
Paul Kehrer82629f42014-01-26 12:25:02 -0600178
Paul Kehrerac423232014-01-25 14:13:09 -0600179 An `RSA`_ public key.
180
Paul Kehrerf2fb02a2014-06-19 10:16:42 -0600181 .. method:: verifier(signature, padding, algorithm)
Paul Kehrer01cdfb22014-04-15 11:27:03 -0400182
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 Kehrer01cdfb22014-04-15 11:27:03 -0400198 :returns:
199 :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricVerificationContext`
200
Paul Kehrerf2fb02a2014-06-19 10:16:42 -0600201 .. method:: encrypt(plaintext, padding)
Paul Kehrer4e602f32014-04-24 12:07:54 -0500202
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 Kehrer4e602f32014-04-24 12:07:54 -0500213 :return bytes: Encrypted data.
Paul Kehrer01cdfb22014-04-15 11:27:03 -0400214
Alex Stapletonee3e6bf2014-02-02 21:13:48 +0000215 .. attribute:: key_size
Paul Kehrerac423232014-01-25 14:13:09 -0600216
217 :type: int
218
219 The bit length of the modulus.
220
Paul Kehrerac423232014-01-25 14:13:09 -0600221
Paul Kehrerf0a48c62014-06-07 17:04:13 -0500222.. 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 Attia71acc672014-03-04 19:20:45 +0200239.. class:: DSAParameters
Mohammed Attiab4167152014-03-04 03:29:56 +0200240
241 .. versionadded:: 0.3
242
243 `DSA`_ parameters.
244
245 .. attribute:: modulus
246
247 :type: int
248
Mohammed Attia7a1738a2014-03-04 19:17:24 +0200249 The prime modulus that is used in generating the DSA key pair and used
Mohammed Attiab4167152014-03-04 03:29:56 +0200250 in the DSA signing and verification processes.
251
252 .. attribute:: subgroup_order
253
254 :type: int
255
Mohammed Attia7a1738a2014-03-04 19:17:24 +0200256 The subgroup order that is used in generating the DSA key pair
Mohammed Attiab4167152014-03-04 03:29:56 +0200257 by the generator and used in the DSA signing and verification
258 processes.
259
260 .. attribute:: generator
261
262 :type: int
263
Mohammed Attiacb9a6c22014-03-04 04:16:35 +0200264 The generator that is used in generating the DSA key pair and used
Mohammed Attia7a1738a2014-03-04 19:17:24 +0200265 in the DSA signing and verification processes.
Mohammed Attiab4167152014-03-04 03:29:56 +0200266
267 .. attribute:: p
268
269 :type: int
270
Mohammed Attia7a1738a2014-03-04 19:17:24 +0200271 The prime modulus that is used in generating the DSA key pair and used
Mohammed Attia70324512014-03-04 03:34:39 +0200272 in the DSA signing and verification processes. Alias for :attr:`modulus`.
Mohammed Attiab4167152014-03-04 03:29:56 +0200273
274 .. attribute:: q
275
276 :type: int
277
Mohammed Attia7a1738a2014-03-04 19:17:24 +0200278 The subgroup order that is used in generating the DSA key pair
Mohammed Attiab4167152014-03-04 03:29:56 +0200279 by the generator and used in the DSA signing and verification
Mohammed Attia70324512014-03-04 03:34:39 +0200280 processes. Alias for :attr:`subgroup_order`.
Mohammed Attiab4167152014-03-04 03:29:56 +0200281
282 .. attribute:: g
283
284 :type: int
285
Mohammed Attiacb9a6c22014-03-04 04:16:35 +0200286 The generator that is used in generating the DSA key pair and used
Mohammed Attia70324512014-03-04 03:34:39 +0200287 in the DSA signing and verification processes. Alias for :attr:`generator`.
Mohammed Attiab4167152014-03-04 03:29:56 +0200288
289
290.. class:: DSAPrivateKey
291
292 .. versionadded:: 0.3
293
Mohammed Attia7a1738a2014-03-04 19:17:24 +0200294 A `DSA`_ private key.
Mohammed Attiab4167152014-03-04 03:29:56 +0200295
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 Attia71acc672014-03-04 19:20:45 +0200304 :return: :class:`~cryptography.hazmat.primitives.interfaces.DSAParameters`
Mohammed Attiab4167152014-03-04 03:29:56 +0200305
Mohammed Attia71acc672014-03-04 19:20:45 +0200306 The DSAParameters object associated with this private key.
Mohammed Attiab4167152014-03-04 03:29:56 +0200307
Paul Kehrer0b3ff3b2014-05-01 15:34:42 -0500308 .. 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 Attiab4167152014-03-04 03:29:56 +0200325 .. 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 Attiaedacb142014-03-17 12:28:23 +0200348 A `DSA`_ public key.
349
350 .. attribute:: key_size
351
352 :type: int
353
354 The bit length of the modulus.
Mohammed Attiab4167152014-03-04 03:29:56 +0200355
Mohammed Attia59edb612014-04-25 22:44:40 +0200356 .. attribute:: y
357
358 :type: int
359
360 The public key.
361
Mohammed Attiab4167152014-03-04 03:29:56 +0200362 .. method:: parameters()
363
Mohammed Attia71acc672014-03-04 19:20:45 +0200364 :return: :class:`~cryptography.hazmat.primitives.interfaces.DSAParameters`
Mohammed Attiab4167152014-03-04 03:29:56 +0200365
Mohammed Attia71acc672014-03-04 19:20:45 +0200366 The DSAParameters object associated with this public key.
Mohammed Attiab4167152014-03-04 03:29:56 +0200367
Mohammed Attia59edb612014-04-25 22:44:40 +0200368 .. method:: verifier(signature, algorithm, backend)
Mohammed Attiab4167152014-03-04 03:29:56 +0200369
Mohammed Attia59edb612014-04-25 22:44:40 +0200370 .. versionadded:: 0.4
Mohammed Attiab4167152014-03-04 03:29:56 +0200371
Mohammed Attia59edb612014-04-25 22:44:40 +0200372 Verify data was signed by the private key associated with this public
373 key.
374
Paul Kehrere0aeaf82014-05-01 11:58:23 -0500375 :param bytes signature: The signature to verify. DER encoded as
376 specified in :rfc:`6979`.
Mohammed Attia59edb612014-04-25 22:44:40 +0200377
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 Attiab4167152014-03-04 03:29:56 +0200388
389
Alex Stapleton085f3782014-04-01 16:18:17 +0100390.. class:: EllipticCurve
391
Alex Stapleton20c99032014-05-03 21:06:46 +0100392 .. versionadded:: 0.5
Alex Stapleton085f3782014-04-01 16:18:17 +0100393
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 Stapleton6e526742014-05-23 22:06:06 +0100401 ``secp256k1``.
Alex Stapleton085f3782014-04-01 16:18:17 +0100402
403 .. attribute:: key_size
404
405 :type: int
406
Alex Stapletond4365692014-05-26 09:25:25 +0100407 The bit length of the curve's base point.
Alex Stapleton085f3782014-04-01 16:18:17 +0100408
409
Alex Stapletona1853f92014-04-18 11:38:28 +0100410.. class:: EllipticCurveSignatureAlgorithm
411
Alex Stapleton20c99032014-05-03 21:06:46 +0100412 .. versionadded:: 0.5
Alex Stapletona1853f92014-04-18 11:38:28 +0100413
414 A signature algorithm for use with elliptic curve keys.
415
Alex Stapleton80228a12014-04-20 16:44:26 +0100416 .. 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 Stapletona1853f92014-04-18 11:38:28 +0100422
Alex Stapleton085f3782014-04-01 16:18:17 +0100423.. class:: EllipticCurvePrivateKey
424
Alex Stapleton20c99032014-05-03 21:06:46 +0100425 .. versionadded:: 0.5
Alex Stapleton085f3782014-04-01 16:18:17 +0100426
427 An elliptic curve private key for use with an algorithm such as `ECDSA`_ or
428 `EdDSA`_.
429
Alex Stapleton33c9d832014-05-23 21:31:51 +0100430 .. classmethod:: signer(signature_algorithm)
Alex Stapletona1853f92014-04-18 11:38:28 +0100431 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 Stapletona1853f92014-04-18 11:38:28 +0100437 :returns:
438 :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricSignatureContext`
439
Alex Stapleton085f3782014-04-01 16:18:17 +0100440
441 :type: :class:`~cryptography.hazmat.primitives.interfaces.EllipticCurve`
442
443 The elliptic curve for this key.
444
Alex Stapleton085f3782014-04-01 16:18:17 +0100445 .. 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 Stapleton20c99032014-05-03 21:06:46 +0100454 .. versionadded:: 0.5
Alex Stapleton085f3782014-04-01 16:18:17 +0100455
456 An elliptic curve public key.
457
Alex Stapletone47bafb2014-05-17 13:19:15 +0100458 .. classmethod:: verifier(signature, signature_algorithm)
Alex Stapletona1853f92014-04-18 11:38:28 +0100459 Verify data was signed by the private key associated with this public
460 key.
461
Alex Stapleton80228a12014-04-20 16:44:26 +0100462 :param bytes signature: The signature to verify.
463
Alex Stapletona1853f92014-04-18 11:38:28 +0100464 :param signature_algorithm: An instance of a
465 :class:`~cryptography.hazmat.primitives.interfaces.EllipticCurveSignatureAlgorithm`
466 provider.
467
Alex Stapletona1853f92014-04-18 11:38:28 +0100468 :returns:
469 :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricSignatureContext`
470
Alex Stapleton085f3782014-04-01 16:18:17 +0100471 .. attribute:: curve
472
473 :type: :class:`~cryptography.hazmat.primitives.interfaces.EllipticCurve`
474
475 The elliptic curve for this key.
476
Alex Stapleton085f3782014-04-01 16:18:17 +0100477
Paul Kehrereda558c2014-02-17 21:18:13 -0600478.. class:: AsymmetricSignatureContext
Paul Kehrere0f0f342014-02-17 19:20:51 -0600479
480 .. versionadded:: 0.2
481
482 .. method:: update(data)
483
Paul Kehrereda558c2014-02-17 21:18:13 -0600484 :param bytes data: The data you want to sign.
Paul Kehrere0f0f342014-02-17 19:20:51 -0600485
486 .. method:: finalize()
487
488 :return bytes signature: The signature.
489
490
Paul Kehrer430202d2014-02-18 13:36:53 -0600491.. class:: AsymmetricVerificationContext
Paul Kehrere0f0f342014-02-17 19:20:51 -0600492
493 .. versionadded:: 0.2
494
495 .. method:: update(data)
496
Paul Kehrereda558c2014-02-17 21:18:13 -0600497 :param bytes data: The data you wish to verify using the signature.
Paul Kehrere0f0f342014-02-17 19:20:51 -0600498
Paul Kehrerdd3780a2014-02-18 13:17:53 -0600499 .. method:: verify()
Paul Kehrere0f0f342014-02-17 19:20:51 -0600500
Paul Kehrerfef1fbd2014-02-26 23:39:37 -0400501 :raises cryptography.exceptions.InvalidSignature: If the signature does
502 not validate.
Paul Kehrere0f0f342014-02-17 19:20:51 -0600503
504
505.. class:: AsymmetricPadding
506
Paul Kehrer19f32d52014-02-17 19:23:06 -0600507 .. versionadded:: 0.2
Paul Kehrere0f0f342014-02-17 19:20:51 -0600508
509 .. attribute:: name
510
David Reid3e0c21e2014-05-13 14:30:45 -0700511
Alex Stapletonc5fffd32014-03-18 15:29:00 +0000512Hash algorithms
Paul Kehrere51a2db2014-01-29 11:49:35 -0600513~~~~~~~~~~~~~~~
514
515.. class:: HashAlgorithm
516
Paul Kehrere51a2db2014-01-29 11:49:35 -0600517 .. attribute:: name
518
519 :type: str
520
Paul Kehrer4c75a8c2014-01-29 12:20:37 -0600521 The standard name for the hash algorithm, for example: ``"sha256"`` or
522 ``"whirlpool"``.
Paul Kehrere51a2db2014-01-29 11:49:35 -0600523
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
Ayrxa0f98502014-04-15 19:17:03 +0800537.. 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 Stapletonc5fffd32014-03-18 15:29:00 +0000558Key derivation functions
Alex Gaynorb2774f52014-01-27 11:05:29 -0800559~~~~~~~~~~~~~~~~~~~~~~~~
560
561.. class:: KeyDerivationFunction
562
Alex Gaynor8454c512014-01-28 07:01:54 -0800563 .. versionadded:: 0.2
564
Alex Gaynorb2774f52014-01-27 11:05:29 -0800565 .. method:: derive(key_material)
566
Alex Gaynor5484f722014-01-28 05:46:15 -0800567 :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 Gaynorb2774f52014-01-27 11:05:29 -0800570 supplied password.
Alex Gaynor5484f722014-01-28 05:46:15 -0800571 :return: The new key.
Alex Gaynore19e89f2014-01-28 06:58:43 -0800572 :raises cryptography.exceptions.AlreadyFinalized: This is raised when
573 :meth:`derive` or
574 :meth:`verify` is
575 called more than
576 once.
Alex Gaynorb2774f52014-01-27 11:05:29 -0800577
Alex Gaynor5484f722014-01-28 05:46:15 -0800578 This generates and returns a new key from the supplied key material.
Alex Gaynorb2774f52014-01-27 11:05:29 -0800579
580 .. method:: verify(key_material, expected_key)
581
Alex Gaynor5484f722014-01-28 05:46:15 -0800582 :param key_material bytes: The input key material. This is the same as
Alex Gaynorb2774f52014-01-27 11:05:29 -0800583 ``key_material`` in :meth:`derive`.
Alex Gaynor5484f722014-01-28 05:46:15 -0800584 :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 Gaynorb2774f52014-01-27 11:05:29 -0800587 :raises cryptography.exceptions.InvalidKey: This is raised when the
588 derived key does not match
589 the expected key.
Alex Gaynore19e89f2014-01-28 06:58:43 -0800590 :raises cryptography.exceptions.AlreadyFinalized: This is raised when
591 :meth:`derive` or
592 :meth:`verify` is
593 called more than
594 once.
Alex Gaynorb2774f52014-01-27 11:05:29 -0800595
Alex Gaynor5484f722014-01-28 05:46:15 -0800596 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 Gaynorb2774f52014-01-27 11:05:29 -0800601
Ayrxc8121702014-04-15 19:02:05 +0800602
Ayrx83cd3f82014-04-15 21:56:32 +0800603`CMAC`_
604~~~~~~~
Ayrxc8121702014-04-15 19:02:05 +0800605
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
Ayrx7964c172014-04-15 21:50:58 +0800616 :return: The message authentication code.
Ayrxc8121702014-04-15 19:02:05 +0800617
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 Kehrer8e9c9842014-02-13 12:23:27 -0600624.. _`RSA`: https://en.wikipedia.org/wiki/RSA_(cryptosystem)
625.. _`Chinese remainder theorem`: https://en.wikipedia.org/wiki/Chinese_remainder_theorem
Mohammed Attia604c78f2014-03-04 03:56:08 +0200626.. _`DSA`: https://en.wikipedia.org/wiki/Digital_Signature_Algorithm
Ayrx83cd3f82014-04-15 21:56:32 +0800627.. _`CMAC`: https://en.wikipedia.org/wiki/CMAC
Alex Stapleton085f3782014-04-01 16:18:17 +0100628.. _`ECDSA`: http://en.wikipedia.org/wiki/ECDSA
629.. _`EdDSA`: http://en.wikipedia.org/wiki/EdDSA