Commit 33d2f09f authored by Milan Broz's avatar Milan Broz Committed by Mike Snitzer

dm crypt: introduce new format of cipher with "capi:" prefix

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: default avatarMilan Broz <gmazyland@gmail.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent e889f97a
...@@ -11,14 +11,31 @@ Parameters: <cipher> <key> <iv_offset> <device path> \ ...@@ -11,14 +11,31 @@ Parameters: <cipher> <key> <iv_offset> <device path> \
<offset> [<#opt_params> <opt_params>] <offset> [<#opt_params> <opt_params>]
<cipher> <cipher>
Encryption cipher and an optional IV generation mode. Encryption cipher, encryption mode and Initial Vector (IV) generator.
(In format cipher[:keycount]-chainmode-ivmode[:ivopts]).
The cipher specifications format is:
cipher[:keycount]-chainmode-ivmode[:ivopts]
Examples: Examples:
des
aes-cbc-essiv:sha256 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>
Key used for encryption. It is encoded either as a hexadecimal number Key used for encryption. It is encoded either as a hexadecimal number
...@@ -94,20 +111,16 @@ submit_from_crypt_cpus ...@@ -94,20 +111,16 @@ submit_from_crypt_cpus
same context. same context.
integrity:<bytes>:<type> integrity:<bytes>:<type>
Calculates and verifies integrity for the encrypted device (uses The device requires additional <bytes> metadata per-sector stored
authenticated encryption). This mode requires metadata stored in per-bio in per-bio integrity structure. This metadata must by provided
integrity structure of <bytes> in size. by underlying dm-integrity target.
This option requires that the underlying device is created by dm-integrity
target and provides exactly <bytes> of per-sector metadata.
There can by two options for <type>. The first one is used when encryption The <type> can be "none" if metadata is used only for persistent IV.
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)".
If random IV is used (persistently stored IV in metadata per-sector), For Authenticated Encryption with Additional Data (AEAD)
then <bytes> includes both space for random IV and authentication tag. 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 Example scripts
=============== ===============
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment