blob: e4f9ffeb51fb64099960d9c0ff925a7ead3e619a [file] [log] [blame]
Paul Kehrerca8e1612015-03-16 20:57:09 -05001.. hazmat::
2
3.. module:: cryptography.hazmat.primitives.keywrap
4
5Key wrapping
6============
7
8Key wrapping is a cryptographic construct that uses symmetric encryption to
Paul Kehrer42e029b2015-10-17 09:52:04 -05009encapsulate key material. Key wrapping algorithms are occasionally utilized
10to protect keys at rest or transmit them over insecure networks. Many of the
11protections offered by key wrapping are also offered by using authenticated
12:doc:`symmetric encryption </hazmat/primitives/symmetric-encryption>`.
Paul Kehrerca8e1612015-03-16 20:57:09 -050013
14.. function:: aes_key_wrap(wrapping_key, key_to_wrap, backend)
15
Paul Kehrer6f6cf002015-06-17 19:58:10 -060016 .. versionadded:: 1.1
17
Paul Kehrer974e8752015-10-22 11:21:55 -050018 This function performs AES key wrap (without padding) as specified in
19 :rfc:`3394`.
20
Paul Kehrerca8e1612015-03-16 20:57:09 -050021 :param bytes wrapping_key: The wrapping key.
22
23 :param bytes key_to_wrap: The key to wrap.
24
25 :param backend: A
26 :class:`~cryptography.hazmat.backends.interfaces.CipherBackend`
27 provider that supports
28 :class:`~cryptography.hazmat.primitives.ciphers.algorithms.AES`.
29
30 :return bytes: The wrapped key as bytes.
31
32.. function:: aes_key_unwrap(wrapping_key, wrapped_key, backend)
33
Paul Kehrer6f6cf002015-06-17 19:58:10 -060034 .. versionadded:: 1.1
35
Paul Kehrer974e8752015-10-22 11:21:55 -050036 This function performs AES key unwrap (without padding) as specified in
37 :rfc:`3394`.
38
Paul Kehrerca8e1612015-03-16 20:57:09 -050039 :param bytes wrapping_key: The wrapping key.
40
41 :param bytes wrapped_key: The wrapped key.
42
43 :param backend: A
44 :class:`~cryptography.hazmat.backends.interfaces.CipherBackend`
45 provider that supports
46 :class:`~cryptography.hazmat.primitives.ciphers.algorithms.AES`.
47
48 :return bytes: The unwrapped key as bytes.
49
Paul Kehrer6f6cf002015-06-17 19:58:10 -060050 :raises cryptography.hazmat.primitives.keywrap.InvalidUnwrap: This is
51 raised if the key is not successfully unwrapped.
52
Paul Kehrerca8e1612015-03-16 20:57:09 -050053Exceptions
54~~~~~~~~~~
55
56.. class:: InvalidUnwrap
57
58 This is raised when a wrapped key fails to unwrap. It can be caused by a
59 corrupted or invalid wrapped key or an invalid wrapping key.