Commit cc0a38d0 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'fscrypt-for-linus' of git://git.kernel.org/pub/scm/fs/fscrypt/linux

Pull fscrypt update from Eric Biggers:
 "Just a small documentation improvement"

* tag 'fscrypt-for-linus' of git://git.kernel.org/pub/scm/fs/fscrypt/linux:
  fscrypt: improve the "Encryption modes and usage" section
parents 6016fc91 324718dd
...@@ -332,54 +332,121 @@ Encryption modes and usage ...@@ -332,54 +332,121 @@ Encryption modes and usage
fscrypt allows one encryption mode to be specified for file contents fscrypt allows one encryption mode to be specified for file contents
and one encryption mode to be specified for filenames. Different and one encryption mode to be specified for filenames. Different
directory trees are permitted to use different encryption modes. directory trees are permitted to use different encryption modes.
Supported modes
---------------
Currently, the following pairs of encryption modes are supported: Currently, the following pairs of encryption modes are supported:
- AES-256-XTS for contents and AES-256-CTS-CBC for filenames - AES-256-XTS for contents and AES-256-CTS-CBC for filenames
- AES-128-CBC for contents and AES-128-CTS-CBC for filenames - AES-256-XTS for contents and AES-256-HCTR2 for filenames
- Adiantum for both contents and filenames - Adiantum for both contents and filenames
- AES-256-XTS for contents and AES-256-HCTR2 for filenames (v2 policies only) - AES-128-CBC-ESSIV for contents and AES-128-CTS-CBC for filenames
- SM4-XTS for contents and SM4-CTS-CBC for filenames (v2 policies only) - SM4-XTS for contents and SM4-CTS-CBC for filenames
If unsure, you should use the (AES-256-XTS, AES-256-CTS-CBC) pair. Authenticated encryption modes are not currently supported because of
the difficulty of dealing with ciphertext expansion. Therefore,
AES-128-CBC was added only for low-powered embedded devices with contents encryption uses a block cipher in `XTS mode
crypto accelerators such as CAAM or CESA that do not support XTS. To <https://en.wikipedia.org/wiki/Disk_encryption_theory#XTS>`_ or
use AES-128-CBC, CONFIG_CRYPTO_ESSIV and CONFIG_CRYPTO_SHA256 (or `CBC-ESSIV mode
another SHA-256 implementation) must be enabled so that ESSIV can be <https://en.wikipedia.org/wiki/Disk_encryption_theory#Encrypted_salt-sector_initialization_vector_(ESSIV)>`_,
used. or a wide-block cipher. Filenames encryption uses a
block cipher in `CTS-CBC mode
Adiantum is a (primarily) stream cipher-based mode that is fast even <https://en.wikipedia.org/wiki/Ciphertext_stealing>`_ or a wide-block
on CPUs without dedicated crypto instructions. It's also a true cipher.
wide-block mode, unlike XTS. It can also eliminate the need to derive
per-file encryption keys. However, it depends on the security of two The (AES-256-XTS, AES-256-CTS-CBC) pair is the recommended default.
primitives, XChaCha12 and AES-256, rather than just one. See the It is also the only option that is *guaranteed* to always be supported
paper "Adiantum: length-preserving encryption for entry-level if the kernel supports fscrypt at all; see `Kernel config options`_.
processors" (https://eprint.iacr.org/2018/720.pdf) for more details.
To use Adiantum, CONFIG_CRYPTO_ADIANTUM must be enabled. Also, fast The (AES-256-XTS, AES-256-HCTR2) pair is also a good choice that
implementations of ChaCha and NHPoly1305 should be enabled, e.g. upgrades the filenames encryption to use a wide-block cipher. (A
CONFIG_CRYPTO_CHACHA20_NEON and CONFIG_CRYPTO_NHPOLY1305_NEON for ARM. *wide-block cipher*, also called a tweakable super-pseudorandom
permutation, has the property that changing one bit scrambles the
AES-256-HCTR2 is another true wide-block encryption mode that is intended for entire result.) As described in `Filenames encryption`_, a wide-block
use on CPUs with dedicated crypto instructions. AES-256-HCTR2 has the property cipher is the ideal mode for the problem domain, though CTS-CBC is the
that a bitflip in the plaintext changes the entire ciphertext. This property "least bad" choice among the alternatives. For more information about
makes it desirable for filename encryption since initialization vectors are HCTR2, see `the HCTR2 paper <https://eprint.iacr.org/2021/1441.pdf>`_.
reused within a directory. For more details on AES-256-HCTR2, see the paper
"Length-preserving encryption with HCTR2" Adiantum is recommended on systems where AES is too slow due to lack
(https://eprint.iacr.org/2021/1441.pdf). To use AES-256-HCTR2, of hardware acceleration for AES. Adiantum is a wide-block cipher
CONFIG_CRYPTO_HCTR2 must be enabled. Also, fast implementations of XCTR and that uses XChaCha12 and AES-256 as its underlying components. Most of
POLYVAL should be enabled, e.g. CRYPTO_POLYVAL_ARM64_CE and the work is done by XChaCha12, which is much faster than AES when AES
CRYPTO_AES_ARM64_CE_BLK for ARM64. acceleration is unavailable. For more information about Adiantum, see
`the Adiantum paper <https://eprint.iacr.org/2018/720.pdf>`_.
SM4 is a Chinese block cipher that is an alternative to AES. It has
not seen as much security review as AES, and it only has a 128-bit key The (AES-128-CBC-ESSIV, AES-128-CTS-CBC) pair exists only to support
size. It may be useful in cases where its use is mandated. systems whose only form of AES acceleration is an off-CPU crypto
Otherwise, it should not be used. For SM4 support to be available, it accelerator such as CAAM or CESA that does not support XTS.
also needs to be enabled in the kernel crypto API.
The remaining mode pairs are the "national pride ciphers":
New encryption modes can be added relatively easily, without changes
to individual filesystems. However, authenticated encryption (AE) - (SM4-XTS, SM4-CTS-CBC)
modes are not currently supported because of the difficulty of dealing
with ciphertext expansion. Generally speaking, these ciphers aren't "bad" per se, but they
receive limited security review compared to the usual choices such as
AES and ChaCha. They also don't bring much new to the table. It is
suggested to only use these ciphers where their use is mandated.
Kernel config options
---------------------
Enabling fscrypt support (CONFIG_FS_ENCRYPTION) automatically pulls in
only the basic support from the crypto API needed to use AES-256-XTS
and AES-256-CTS-CBC encryption. For optimal performance, it is
strongly recommended to also enable any available platform-specific
kconfig options that provide acceleration for the algorithm(s) you
wish to use. Support for any "non-default" encryption modes typically
requires extra kconfig options as well.
Below, some relevant options are listed by encryption mode. Note,
acceleration options not listed below may be available for your
platform; refer to the kconfig menus. File contents encryption can
also be configured to use inline encryption hardware instead of the
kernel crypto API (see `Inline encryption support`_); in that case,
the file contents mode doesn't need to supported in the kernel crypto
API, but the filenames mode still does.
- AES-256-XTS and AES-256-CTS-CBC
- Recommended:
- arm64: CONFIG_CRYPTO_AES_ARM64_CE_BLK
- x86: CONFIG_CRYPTO_AES_NI_INTEL
- AES-256-HCTR2
- Mandatory:
- CONFIG_CRYPTO_HCTR2
- Recommended:
- arm64: CONFIG_CRYPTO_AES_ARM64_CE_BLK
- arm64: CONFIG_CRYPTO_POLYVAL_ARM64_CE
- x86: CONFIG_CRYPTO_AES_NI_INTEL
- x86: CONFIG_CRYPTO_POLYVAL_CLMUL_NI
- Adiantum
- Mandatory:
- CONFIG_CRYPTO_ADIANTUM
- Recommended:
- arm32: CONFIG_CRYPTO_CHACHA20_NEON
- arm32: CONFIG_CRYPTO_NHPOLY1305_NEON
- arm64: CONFIG_CRYPTO_CHACHA20_NEON
- arm64: CONFIG_CRYPTO_NHPOLY1305_NEON
- x86: CONFIG_CRYPTO_CHACHA20_X86_64
- x86: CONFIG_CRYPTO_NHPOLY1305_SSE2
- x86: CONFIG_CRYPTO_NHPOLY1305_AVX2
- AES-128-CBC-ESSIV and AES-128-CTS-CBC:
- Mandatory:
- CONFIG_CRYPTO_ESSIV
- CONFIG_CRYPTO_SHA256 or another SHA-256 implementation
- Recommended:
- AES-CBC acceleration
fscrypt also uses HMAC-SHA512 for key derivation, so enabling SHA-512
acceleration is recommended:
- SHA-512
- Recommended:
- arm64: CONFIG_CRYPTO_SHA512_ARM64_CE
- x86: CONFIG_CRYPTO_SHA512_SSSE3
Contents encryption Contents encryption
------------------- -------------------
...@@ -493,7 +560,14 @@ This structure must be initialized as follows: ...@@ -493,7 +560,14 @@ This structure must be initialized as follows:
be set to constants from ``<linux/fscrypt.h>`` which identify the be set to constants from ``<linux/fscrypt.h>`` which identify the
encryption modes to use. If unsure, use FSCRYPT_MODE_AES_256_XTS encryption modes to use. If unsure, use FSCRYPT_MODE_AES_256_XTS
(1) for ``contents_encryption_mode`` and FSCRYPT_MODE_AES_256_CTS (1) for ``contents_encryption_mode`` and FSCRYPT_MODE_AES_256_CTS
(4) for ``filenames_encryption_mode``. (4) for ``filenames_encryption_mode``. For details, see `Encryption
modes and usage`_.
v1 encryption policies only support three combinations of modes:
(FSCRYPT_MODE_AES_256_XTS, FSCRYPT_MODE_AES_256_CTS),
(FSCRYPT_MODE_AES_128_CBC, FSCRYPT_MODE_AES_128_CTS), and
(FSCRYPT_MODE_ADIANTUM, FSCRYPT_MODE_ADIANTUM). v2 policies support
all combinations documented in `Supported modes`_.
- ``flags`` contains optional flags from ``<linux/fscrypt.h>``: - ``flags`` contains optional flags from ``<linux/fscrypt.h>``:
......
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