Skip to content

Commit cc0a38d

Browse files
committed
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
2 parents 6016fc9 + 324718d commit cc0a38d

File tree

1 file changed

+119
-45
lines changed

1 file changed

+119
-45
lines changed

Documentation/filesystems/fscrypt.rst

Lines changed: 119 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -332,54 +332,121 @@ Encryption modes and usage
332332
fscrypt allows one encryption mode to be specified for file contents
333333
and one encryption mode to be specified for filenames. Different
334334
directory trees are permitted to use different encryption modes.
335+
336+
Supported modes
337+
---------------
338+
335339
Currently, the following pairs of encryption modes are supported:
336340

337341
- AES-256-XTS for contents and AES-256-CTS-CBC for filenames
338-
- AES-128-CBC for contents and AES-128-CTS-CBC for filenames
342+
- AES-256-XTS for contents and AES-256-HCTR2 for filenames
339343
- Adiantum for both contents and filenames
340-
- AES-256-XTS for contents and AES-256-HCTR2 for filenames (v2 policies only)
341-
- SM4-XTS for contents and SM4-CTS-CBC for filenames (v2 policies only)
342-
343-
If unsure, you should use the (AES-256-XTS, AES-256-CTS-CBC) pair.
344-
345-
AES-128-CBC was added only for low-powered embedded devices with
346-
crypto accelerators such as CAAM or CESA that do not support XTS. To
347-
use AES-128-CBC, CONFIG_CRYPTO_ESSIV and CONFIG_CRYPTO_SHA256 (or
348-
another SHA-256 implementation) must be enabled so that ESSIV can be
349-
used.
350-
351-
Adiantum is a (primarily) stream cipher-based mode that is fast even
352-
on CPUs without dedicated crypto instructions. It's also a true
353-
wide-block mode, unlike XTS. It can also eliminate the need to derive
354-
per-file encryption keys. However, it depends on the security of two
355-
primitives, XChaCha12 and AES-256, rather than just one. See the
356-
paper "Adiantum: length-preserving encryption for entry-level
357-
processors" (https://eprint.iacr.org/2018/720.pdf) for more details.
358-
To use Adiantum, CONFIG_CRYPTO_ADIANTUM must be enabled. Also, fast
359-
implementations of ChaCha and NHPoly1305 should be enabled, e.g.
360-
CONFIG_CRYPTO_CHACHA20_NEON and CONFIG_CRYPTO_NHPOLY1305_NEON for ARM.
361-
362-
AES-256-HCTR2 is another true wide-block encryption mode that is intended for
363-
use on CPUs with dedicated crypto instructions. AES-256-HCTR2 has the property
364-
that a bitflip in the plaintext changes the entire ciphertext. This property
365-
makes it desirable for filename encryption since initialization vectors are
366-
reused within a directory. For more details on AES-256-HCTR2, see the paper
367-
"Length-preserving encryption with HCTR2"
368-
(https://eprint.iacr.org/2021/1441.pdf). To use AES-256-HCTR2,
369-
CONFIG_CRYPTO_HCTR2 must be enabled. Also, fast implementations of XCTR and
370-
POLYVAL should be enabled, e.g. CRYPTO_POLYVAL_ARM64_CE and
371-
CRYPTO_AES_ARM64_CE_BLK for ARM64.
372-
373-
SM4 is a Chinese block cipher that is an alternative to AES. It has
374-
not seen as much security review as AES, and it only has a 128-bit key
375-
size. It may be useful in cases where its use is mandated.
376-
Otherwise, it should not be used. For SM4 support to be available, it
377-
also needs to be enabled in the kernel crypto API.
378-
379-
New encryption modes can be added relatively easily, without changes
380-
to individual filesystems. However, authenticated encryption (AE)
381-
modes are not currently supported because of the difficulty of dealing
382-
with ciphertext expansion.
344+
- AES-128-CBC-ESSIV for contents and AES-128-CTS-CBC for filenames
345+
- SM4-XTS for contents and SM4-CTS-CBC for filenames
346+
347+
Authenticated encryption modes are not currently supported because of
348+
the difficulty of dealing with ciphertext expansion. Therefore,
349+
contents encryption uses a block cipher in `XTS mode
350+
<https://en.wikipedia.org/wiki/Disk_encryption_theory#XTS>`_ or
351+
`CBC-ESSIV mode
352+
<https://en.wikipedia.org/wiki/Disk_encryption_theory#Encrypted_salt-sector_initialization_vector_(ESSIV)>`_,
353+
or a wide-block cipher. Filenames encryption uses a
354+
block cipher in `CTS-CBC mode
355+
<https://en.wikipedia.org/wiki/Ciphertext_stealing>`_ or a wide-block
356+
cipher.
357+
358+
The (AES-256-XTS, AES-256-CTS-CBC) pair is the recommended default.
359+
It is also the only option that is *guaranteed* to always be supported
360+
if the kernel supports fscrypt at all; see `Kernel config options`_.
361+
362+
The (AES-256-XTS, AES-256-HCTR2) pair is also a good choice that
363+
upgrades the filenames encryption to use a wide-block cipher. (A
364+
*wide-block cipher*, also called a tweakable super-pseudorandom
365+
permutation, has the property that changing one bit scrambles the
366+
entire result.) As described in `Filenames encryption`_, a wide-block
367+
cipher is the ideal mode for the problem domain, though CTS-CBC is the
368+
"least bad" choice among the alternatives. For more information about
369+
HCTR2, see `the HCTR2 paper <https://eprint.iacr.org/2021/1441.pdf>`_.
370+
371+
Adiantum is recommended on systems where AES is too slow due to lack
372+
of hardware acceleration for AES. Adiantum is a wide-block cipher
373+
that uses XChaCha12 and AES-256 as its underlying components. Most of
374+
the work is done by XChaCha12, which is much faster than AES when AES
375+
acceleration is unavailable. For more information about Adiantum, see
376+
`the Adiantum paper <https://eprint.iacr.org/2018/720.pdf>`_.
377+
378+
The (AES-128-CBC-ESSIV, AES-128-CTS-CBC) pair exists only to support
379+
systems whose only form of AES acceleration is an off-CPU crypto
380+
accelerator such as CAAM or CESA that does not support XTS.
381+
382+
The remaining mode pairs are the "national pride ciphers":
383+
384+
- (SM4-XTS, SM4-CTS-CBC)
385+
386+
Generally speaking, these ciphers aren't "bad" per se, but they
387+
receive limited security review compared to the usual choices such as
388+
AES and ChaCha. They also don't bring much new to the table. It is
389+
suggested to only use these ciphers where their use is mandated.
390+
391+
Kernel config options
392+
---------------------
393+
394+
Enabling fscrypt support (CONFIG_FS_ENCRYPTION) automatically pulls in
395+
only the basic support from the crypto API needed to use AES-256-XTS
396+
and AES-256-CTS-CBC encryption. For optimal performance, it is
397+
strongly recommended to also enable any available platform-specific
398+
kconfig options that provide acceleration for the algorithm(s) you
399+
wish to use. Support for any "non-default" encryption modes typically
400+
requires extra kconfig options as well.
401+
402+
Below, some relevant options are listed by encryption mode. Note,
403+
acceleration options not listed below may be available for your
404+
platform; refer to the kconfig menus. File contents encryption can
405+
also be configured to use inline encryption hardware instead of the
406+
kernel crypto API (see `Inline encryption support`_); in that case,
407+
the file contents mode doesn't need to supported in the kernel crypto
408+
API, but the filenames mode still does.
409+
410+
- AES-256-XTS and AES-256-CTS-CBC
411+
- Recommended:
412+
- arm64: CONFIG_CRYPTO_AES_ARM64_CE_BLK
413+
- x86: CONFIG_CRYPTO_AES_NI_INTEL
414+
415+
- AES-256-HCTR2
416+
- Mandatory:
417+
- CONFIG_CRYPTO_HCTR2
418+
- Recommended:
419+
- arm64: CONFIG_CRYPTO_AES_ARM64_CE_BLK
420+
- arm64: CONFIG_CRYPTO_POLYVAL_ARM64_CE
421+
- x86: CONFIG_CRYPTO_AES_NI_INTEL
422+
- x86: CONFIG_CRYPTO_POLYVAL_CLMUL_NI
423+
424+
- Adiantum
425+
- Mandatory:
426+
- CONFIG_CRYPTO_ADIANTUM
427+
- Recommended:
428+
- arm32: CONFIG_CRYPTO_CHACHA20_NEON
429+
- arm32: CONFIG_CRYPTO_NHPOLY1305_NEON
430+
- arm64: CONFIG_CRYPTO_CHACHA20_NEON
431+
- arm64: CONFIG_CRYPTO_NHPOLY1305_NEON
432+
- x86: CONFIG_CRYPTO_CHACHA20_X86_64
433+
- x86: CONFIG_CRYPTO_NHPOLY1305_SSE2
434+
- x86: CONFIG_CRYPTO_NHPOLY1305_AVX2
435+
436+
- AES-128-CBC-ESSIV and AES-128-CTS-CBC:
437+
- Mandatory:
438+
- CONFIG_CRYPTO_ESSIV
439+
- CONFIG_CRYPTO_SHA256 or another SHA-256 implementation
440+
- Recommended:
441+
- AES-CBC acceleration
442+
443+
fscrypt also uses HMAC-SHA512 for key derivation, so enabling SHA-512
444+
acceleration is recommended:
445+
446+
- SHA-512
447+
- Recommended:
448+
- arm64: CONFIG_CRYPTO_SHA512_ARM64_CE
449+
- x86: CONFIG_CRYPTO_SHA512_SSSE3
383450

384451
Contents encryption
385452
-------------------
@@ -493,7 +560,14 @@ This structure must be initialized as follows:
493560
be set to constants from ``<linux/fscrypt.h>`` which identify the
494561
encryption modes to use. If unsure, use FSCRYPT_MODE_AES_256_XTS
495562
(1) for ``contents_encryption_mode`` and FSCRYPT_MODE_AES_256_CTS
496-
(4) for ``filenames_encryption_mode``.
563+
(4) for ``filenames_encryption_mode``. For details, see `Encryption
564+
modes and usage`_.
565+
566+
v1 encryption policies only support three combinations of modes:
567+
(FSCRYPT_MODE_AES_256_XTS, FSCRYPT_MODE_AES_256_CTS),
568+
(FSCRYPT_MODE_AES_128_CBC, FSCRYPT_MODE_AES_128_CTS), and
569+
(FSCRYPT_MODE_ADIANTUM, FSCRYPT_MODE_ADIANTUM). v2 policies support
570+
all combinations documented in `Supported modes`_.
497571

498572
- ``flags`` contains optional flags from ``<linux/fscrypt.h>``:
499573

0 commit comments

Comments
 (0)