aboutsummaryrefslogtreecommitdiffstats
path: root/doc/manual/keywrap.rst
blob: ae1172701fd8aa6b03320c3f496ed2312ba8536d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
AES Key Wrapping
=================================

NIST specifies two mechanisms for wrapping (encrypting) symmetric keys using
another key. The first (and older, more widely supported) methd requres the
input be a multiple of 8 bytes long. The other allows any length input, though
only up to 2**32 bytes.

These algorithms are described in NIST SP 800-38F, and RFCs 3394 and 5694.

This API, defined in ``nist_keywrap.h``, first became available in version 2.4.0

These functions take an arbitrary 128-bit block cipher object, which must
already have been keyed with the key encryption key. NIST only allows these
functions with AES, but any 128-bit cipher will do and some other implementations
(such as in OpenSSL) do also allow other ciphers.  Use AES for best interop.

.. cpp:function:: std::vector<uint8_t> nist_key_wrap(const uint8_t input[], \
                  size_t input_len, const BlockCipher& bc)

   This performs KW (key wrap) mode. The input must be a multiple of 8 bytes long.

.. cpp:function:: secure_vector<uint8_t> nist_key_unwrap(const uint8_t input[], \
                  size_t input_len,  const BlockCipher& bc)

   This unwraps the result of nist_key_wrap, or throw Integrity_Failure on error.

.. cpp:function:: std::vector<uint8_t> nist_key_wrap_padded(const uint8_t input[], \
                  size_t input_len, const BlockCipher& bc)

   This performs KWP (key wrap with padding) mode. The input can be any length.

.. cpp:function:: secure_vector<uint8_t> nist_key_unwrap_padded(const uint8_t input[], \
                  size_t input_len, const BlockCipher& bc)

   This unwraps the result of nist_key_wrap_padded, or throws Integrity_Failure
   on error.

RFC 3394 Interface
-----------------------------

This is an older interface that was first available (with slight changes) in
1.10, and available in its current form since 2.0 release. It uses a 128-bit,
192-bit, or 256-bit key to encrypt an input key. AES is always used. The input
must be a multiple of 8 bytes; if not an exception is thrown.

This interface is defined in ``rfc3394.h``.

.. cpp:function:: secure_vector<uint8_t> rfc3394_keywrap(const secure_vector<uint8_t>& key, \
                                                         const SymmetricKey& kek)

  Wrap the input key using kek (the key encryption key), and return the result. It will
  be 8 bytes longer than the input key.

.. cpp:function:: secure_vector<uint8_t> rfc3394_keyunwrap(const secure_vector<uint8_t>& key, \
                                                           const SymmetricKey& kek)

  Unwrap a key wrapped wtih rfc3394_keywrap.