Skip to content

Commit

Permalink
dm crypt: introduce new format of cipher with "capi:" prefix
Browse files Browse the repository at this point in the history
For the new authenticated encryption we have to support generic composed
modes (combination of encryption algorithm and authenticator) because
this is how the kernel crypto API accesses such algorithms.

To simplify the interface, we accept an algorithm directly in crypto API
format.  The new format is recognised by the "capi:" prefix.  The
dmcrypt internal IV specification is the same as for the old format.

The crypto API cipher specifications format is:
     capi:cipher_api_spec-ivmode[:ivopts]
Examples:
     capi:cbc(aes)-essiv:sha256 (equivalent to old aes-cbc-essiv:sha256)
     capi:xts(aes)-plain64      (equivalent to old aes-xts-plain64)
Examples of authenticated modes:
     capi:gcm(aes)-random
     capi:authenc(hmac(sha256),xts(aes))-random
     capi:rfc7539(chacha20,poly1305)-random

Authenticated modes can only be configured using the new cipher format.
Note that this format allows user to specify arbitrary combinations that
can be insecure. (Policy decision is done in cryptsetup userspace.)

Authenticated encryption algorithms can be of two types, either native
modes (like GCM) that performs both encryption and authentication
internally, or composed modes where user can compose AEAD with separate
specification of encryption algorithm and authenticator.

For composed mode with HMAC (length-preserving encryption mode like an
XTS and HMAC as an authenticator) we have to calculate HMAC digest size
(the separate authentication key is the same size as the HMAC digest).
Introduce crypt_ctr_auth_cipher() to parse the crypto API string to get
HMAC algorithm and retrieve digest size from it.

Also, for HMAC composed mode we need to parse the crypto API string to
get the cipher mode nested in the specification.  For native AEAD mode
(like GCM), we can use crypto_tfm_alg_name() API to get the cipher
specification.

Because the HMAC composed mode is not processed the same as the native
AEAD mode, the CRYPT_MODE_INTEGRITY_HMAC flag is no longer needed and
"hmac" specification for the table integrity argument is removed.

Signed-off-by: Milan Broz <gmazyland@gmail.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
  • Loading branch information
Milan Broz authored and Mike Snitzer committed Mar 24, 2017
1 parent e889f97 commit 33d2f09
Show file tree
Hide file tree
Showing 2 changed files with 223 additions and 99 deletions.
47 changes: 30 additions & 17 deletions Documentation/device-mapper/dm-crypt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,31 @@ Parameters: <cipher> <key> <iv_offset> <device path> \
<offset> [<#opt_params> <opt_params>]

<cipher>
Encryption cipher and an optional IV generation mode.
(In format cipher[:keycount]-chainmode-ivmode[:ivopts]).
Encryption cipher, encryption mode and Initial Vector (IV) generator.

The cipher specifications format is:
cipher[:keycount]-chainmode-ivmode[:ivopts]
Examples:
des
aes-cbc-essiv:sha256
twofish-ecb
aes-xts-plain64
serpent-xts-plain64

Cipher format also supports direct specification with kernel crypt API
format (selected by capi: prefix). The IV specification is the same
as for the first format type.
This format is mainly used for specification of authenticated modes.

/proc/crypto contains supported crypto modes
The crypto API cipher specifications format is:
capi:cipher_api_spec-ivmode[:ivopts]
Examples:
capi:cbc(aes)-essiv:sha256
capi:xts(aes)-plain64
Examples of authenticated modes:
capi:gcm(aes)-random
capi:authenc(hmac(sha256),xts(aes))-random
capi:rfc7539(chacha20,poly1305)-random

The /proc/crypto contains a list of curently loaded crypto modes.

<key>
Key used for encryption. It is encoded either as a hexadecimal number
Expand Down Expand Up @@ -94,20 +111,16 @@ submit_from_crypt_cpus
same context.

integrity:<bytes>:<type>
Calculates and verifies integrity for the encrypted device (uses
authenticated encryption). This mode requires metadata stored in per-bio
integrity structure of <bytes> in size.

This option requires that the underlying device is created by dm-integrity
target and provides exactly <bytes> of per-sector metadata.
The device requires additional <bytes> metadata per-sector stored
in per-bio integrity structure. This metadata must by provided
by underlying dm-integrity target.

There can by two options for <type>. The first one is used when encryption
mode is Authenticated mode (AEAD mode), then type must be just "aead".
The second option is integrity calculated by keyed hash (HMAC), then
<type> is for example "hmac(sha256)".
The <type> can be "none" if metadata is used only for persistent IV.

If random IV is used (persistently stored IV in metadata per-sector),
then <bytes> includes both space for random IV and authentication tag.
For Authenticated Encryption with Additional Data (AEAD)
the <type> is "aead". An AEAD mode additionally calculates and verifies
integrity for the encrypted device. The additional space is then
used for storing authentication tag (and persistent IV if needed).

Example scripts
===============
Expand Down
Loading

0 comments on commit 33d2f09

Please sign in to comment.