summaryrefslogtreecommitdiffstats
path: root/Documentation
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2019-01-06 08:36:21 -0500
committerTheodore Ts'o <tytso@mit.edu>2019-01-06 08:36:21 -0500
commit8094c3ceb21ad93896fd4d238e8ba41911932eaf (patch)
tree8dcc0b7473ad0996841ce20dc84febfe45b7e591 /Documentation
parent7beb01f74415c56f5992922b5b902b45d365e694 (diff)
fscrypt: add Adiantum support
Add support for the Adiantum encryption mode to fscrypt. Adiantum is a tweakable, length-preserving encryption mode with security provably reducible to that of XChaCha12 and AES-256, subject to a security bound. It's also a true wide-block mode, unlike XTS. See the paper "Adiantum: length-preserving encryption for entry-level processors" (https://eprint.iacr.org/2018/720.pdf) for more details. Also see commit 059c2a4d8e16 ("crypto: adiantum - add Adiantum support"). On sufficiently long messages, Adiantum's bottlenecks are XChaCha12 and the NH hash function. These algorithms are fast even on processors without dedicated crypto instructions. Adiantum makes it feasible to enable storage encryption on low-end mobile devices that lack AES instructions; currently such devices are unencrypted. On ARM Cortex-A7, on 4096-byte messages Adiantum encryption is about 4 times faster than AES-256-XTS encryption; decryption is about 5 times faster. In fscrypt, Adiantum is suitable for encrypting both file contents and names. With filenames, it fixes a known weakness: when two filenames in a directory share a common prefix of >= 16 bytes, with CTS-CBC their encrypted filenames share a common prefix too, leaking information. Adiantum does not have this problem. Since Adiantum also accepts long tweaks (IVs), it's also safe to use the master key directly for Adiantum encryption rather than deriving per-file keys, provided that the per-file nonce is included in the IVs and the master key isn't used for any other encryption mode. This configuration saves memory and improves performance. A new fscrypt policy flag is added to allow users to opt-in to this configuration. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/filesystems/fscrypt.rst179
1 files changed, 102 insertions, 77 deletions
diff --git a/Documentation/filesystems/fscrypt.rst b/Documentation/filesystems/fscrypt.rst
index cfbc18f0d9c9..3a7b60521b94 100644
--- a/Documentation/filesystems/fscrypt.rst
+++ b/Documentation/filesystems/fscrypt.rst
@@ -132,47 +132,28 @@ designed for this purpose be used, such as scrypt, PBKDF2, or Argon2.
132Per-file keys 132Per-file keys
133------------- 133-------------
134 134
135Master keys are not used to encrypt file contents or names directly. 135Since each master key can protect many files, it is necessary to
136Instead, a unique key is derived for each encrypted file, including 136"tweak" the encryption of each file so that the same plaintext in two
137each regular file, directory, and symbolic link. This has several 137files doesn't map to the same ciphertext, or vice versa. In most
138advantages: 138cases, fscrypt does this by deriving per-file keys. When a new
139 139encrypted inode (regular file, directory, or symlink) is created,
140- In cryptosystems, the same key material should never be used for 140fscrypt randomly generates a 16-byte nonce and stores it in the
141 different purposes. Using the master key as both an XTS key for 141inode's encryption xattr. Then, it uses a KDF (Key Derivation
142 contents encryption and as a CTS-CBC key for filenames encryption 142Function) to derive the file's key from the master key and nonce.
143 would violate this rule. 143
144- Per-file keys simplify the choice of IVs (Initialization Vectors) 144The Adiantum encryption mode (see `Encryption modes and usage`_) is
145 for contents encryption. Without per-file keys, to ensure IV 145special, since it accepts longer IVs and is suitable for both contents
146 uniqueness both the inode and logical block number would need to be 146and filenames encryption. For it, a "direct key" option is offered
147 encoded in the IVs. This would make it impossible to renumber 147where the file's nonce is included in the IVs and the master key is
148 inodes, which e.g. ``resize2fs`` can do when resizing an ext4 148used for encryption directly. This improves performance; however,
149 filesystem. With per-file keys, it is sufficient to encode just the 149users must not use the same master key for any other encryption mode.
150 logical block number in the IVs. 150
151- Per-file keys strengthen the encryption of filenames, where IVs are 151Below, the KDF and design considerations are described in more detail.
152 reused out of necessity. With a unique key per directory, IV reuse 152
153 is limited to within a single directory. 153The current KDF works by encrypting the master key with AES-128-ECB,
154- Per-file keys allow individual files to be securely erased simply by 154using the file's nonce as the AES key. The output is used as the
155 securely erasing their keys. (Not yet implemented.) 155derived key. If the output is longer than needed, then it is
156 156truncated to the needed length.
157A KDF (Key Derivation Function) is used to derive per-file keys from
158the master key. This is done instead of wrapping a randomly-generated
159key for each file because it reduces the size of the encryption xattr,
160which for some filesystems makes the xattr more likely to fit in-line
161in the filesystem's inode table. With a KDF, only a 16-byte nonce is
162required --- long enough to make key reuse extremely unlikely. A
163wrapped key, on the other hand, would need to be up to 64 bytes ---
164the length of an AES-256-XTS key. Furthermore, currently there is no
165requirement to support unlocking a file with multiple alternative
166master keys or to support rotating master keys. Instead, the master
167keys may be wrapped in userspace, e.g. as done by the `fscrypt
168<https://github.com/google/fscrypt>`_ tool.
169
170The current KDF encrypts the master key using the 16-byte nonce as an
171AES-128-ECB key. The output is used as the derived key. If the
172output is longer than needed, then it is truncated to the needed
173length. Truncation is the norm for directories and symlinks, since
174those use the CTS-CBC encryption mode which requires a key half as
175long as that required by the XTS encryption mode.
176 157
177Note: this KDF meets the primary security requirement, which is to 158Note: this KDF meets the primary security requirement, which is to
178produce unique derived keys that preserve the entropy of the master 159produce unique derived keys that preserve the entropy of the master
@@ -181,6 +162,20 @@ However, it is nonstandard and has some problems such as being
181reversible, so it is generally considered to be a mistake! It may be 162reversible, so it is generally considered to be a mistake! It may be
182replaced with HKDF or another more standard KDF in the future. 163replaced with HKDF or another more standard KDF in the future.
183 164
165Key derivation was chosen over key wrapping because wrapped keys would
166require larger xattrs which would be less likely to fit in-line in the
167filesystem's inode table, and there didn't appear to be any
168significant advantages to key wrapping. In particular, currently
169there is no requirement to support unlocking a file with multiple
170alternative master keys or to support rotating master keys. Instead,
171the master keys may be wrapped in userspace, e.g. as is done by the
172`fscrypt <https://github.com/google/fscrypt>`_ tool.
173
174Including the inode number in the IVs was considered. However, it was
175rejected as it would have prevented ext4 filesystems from being
176resized, and by itself still wouldn't have been sufficient to prevent
177the same key from being directly reused for both XTS and CTS-CBC.
178
184Encryption modes and usage 179Encryption modes and usage
185========================== 180==========================
186 181
@@ -191,54 +186,80 @@ Currently, the following pairs of encryption modes are supported:
191 186
192- AES-256-XTS for contents and AES-256-CTS-CBC for filenames 187- AES-256-XTS for contents and AES-256-CTS-CBC for filenames
193- AES-128-CBC for contents and AES-128-CTS-CBC for filenames 188- AES-128-CBC for contents and AES-128-CTS-CBC for filenames
189- Adiantum for both contents and filenames
190
191If unsure, you should use the (AES-256-XTS, AES-256-CTS-CBC) pair.
194 192
195It is strongly recommended to use AES-256-XTS for contents encryption.
196AES-128-CBC was added only for low-powered embedded devices with 193AES-128-CBC was added only for low-powered embedded devices with
197crypto accelerators such as CAAM or CESA that do not support XTS. 194crypto accelerators such as CAAM or CESA that do not support XTS.
198 195
196Adiantum is a (primarily) stream cipher-based mode that is fast even
197on CPUs without dedicated crypto instructions. It's also a true
198wide-block mode, unlike XTS. It can also eliminate the need to derive
199per-file keys. However, it depends on the security of two primitives,
200XChaCha12 and AES-256, rather than just one. See the paper
201"Adiantum: length-preserving encryption for entry-level processors"
202(https://eprint.iacr.org/2018/720.pdf) for more details. To use
203Adiantum, CONFIG_CRYPTO_ADIANTUM must be enabled. Also, fast
204implementations of ChaCha and NHPoly1305 should be enabled, e.g.
205CONFIG_CRYPTO_CHACHA20_NEON and CONFIG_CRYPTO_NHPOLY1305_NEON for ARM.
206
199New encryption modes can be added relatively easily, without changes 207New encryption modes can be added relatively easily, without changes
200to individual filesystems. However, authenticated encryption (AE) 208to individual filesystems. However, authenticated encryption (AE)
201modes are not currently supported because of the difficulty of dealing 209modes are not currently supported because of the difficulty of dealing
202with ciphertext expansion. 210with ciphertext expansion.
203 211
212Contents encryption
213-------------------
214
204For file contents, each filesystem block is encrypted independently. 215For file contents, each filesystem block is encrypted independently.
205Currently, only the case where the filesystem block size is equal to 216Currently, only the case where the filesystem block size is equal to
206the system's page size (usually 4096 bytes) is supported. With the 217the system's page size (usually 4096 bytes) is supported.
207XTS mode of operation (recommended), the logical block number within 218
208the file is used as the IV. With the CBC mode of operation (not 219Each block's IV is set to the logical block number within the file as
209recommended), ESSIV is used; specifically, the IV for CBC is the 220a little endian number, except that:
210logical block number encrypted with AES-256, where the AES-256 key is 221
211the SHA-256 hash of the inode's data encryption key. 222- With CBC mode encryption, ESSIV is also used. Specifically, each IV
212 223 is encrypted with AES-256 where the AES-256 key is the SHA-256 hash
213For filenames, the full filename is encrypted at once. Because of the 224 of the file's data encryption key.
214requirements to retain support for efficient directory lookups and 225
215filenames of up to 255 bytes, a constant initialization vector (IV) is 226- In the "direct key" configuration (FS_POLICY_FLAG_DIRECT_KEY set in
216used. However, each encrypted directory uses a unique key, which 227 the fscrypt_policy), the file's nonce is also appended to the IV.
217limits IV reuse to within a single directory. Note that IV reuse in 228 Currently this is only allowed with the Adiantum encryption mode.
218the context of CTS-CBC encryption means that when the original 229
219filenames share a common prefix at least as long as the cipher block 230Filenames encryption
220size (16 bytes for AES), the corresponding encrypted filenames will 231--------------------
221also share a common prefix. This is undesirable; it may be fixed in 232
222the future by switching to an encryption mode that is a strong 233For filenames, each full filename is encrypted at once. Because of
223pseudorandom permutation on arbitrary-length messages, e.g. the HEH 234the requirements to retain support for efficient directory lookups and
224(Hash-Encrypt-Hash) mode. 235filenames of up to 255 bytes, the same IV is used for every filename
225 236in a directory.
226Since filenames are encrypted with the CTS-CBC mode of operation, the 237
227plaintext and ciphertext filenames need not be multiples of the AES 238However, each encrypted directory still uses a unique key; or
228block size, i.e. 16 bytes. However, the minimum size that can be 239alternatively (for the "direct key" configuration) has the file's
229encrypted is 16 bytes, so shorter filenames are NUL-padded to 16 bytes 240nonce included in the IVs. Thus, IV reuse is limited to within a
230before being encrypted. In addition, to reduce leakage of filename 241single directory.
231lengths via their ciphertexts, all filenames are NUL-padded to the 242
232next 4, 8, 16, or 32-byte boundary (configurable). 32 is recommended 243With CTS-CBC, the IV reuse means that when the plaintext filenames
233since this provides the best confidentiality, at the cost of making 244share a common prefix at least as long as the cipher block size (16
234directory entries consume slightly more space. Note that since NUL 245bytes for AES), the corresponding encrypted filenames will also share
235(``\0``) is not otherwise a valid character in filenames, the padding 246a common prefix. This is undesirable. Adiantum does not have this
236will never produce duplicate plaintexts. 247weakness, as it is a wide-block encryption mode.
248
249All supported filenames encryption modes accept any plaintext length
250>= 16 bytes; cipher block alignment is not required. However,
251filenames shorter than 16 bytes are NUL-padded to 16 bytes before
252being encrypted. In addition, to reduce leakage of filename lengths
253via their ciphertexts, all filenames are NUL-padded to the next 4, 8,
25416, or 32-byte boundary (configurable). 32 is recommended since this
255provides the best confidentiality, at the cost of making directory
256entries consume slightly more space. Note that since NUL (``\0``) is
257not otherwise a valid character in filenames, the padding will never
258produce duplicate plaintexts.
237 259
238Symbolic link targets are considered a type of filename and are 260Symbolic link targets are considered a type of filename and are
239encrypted in the same way as filenames in directory entries. Each 261encrypted in the same way as filenames in directory entries, except
240symlink also uses a unique key; hence, the hardcoded IV is not a 262that IV reuse is not a problem as each symlink has its own inode.
241problem for symlinks.
242 263
243User API 264User API
244======== 265========
@@ -272,9 +293,13 @@ This structure must be initialized as follows:
272 and FS_ENCRYPTION_MODE_AES_256_CTS (4) for 293 and FS_ENCRYPTION_MODE_AES_256_CTS (4) for
273 ``filenames_encryption_mode``. 294 ``filenames_encryption_mode``.
274 295
275- ``flags`` must be set to a value from ``<linux/fs.h>`` which 296- ``flags`` must contain a value from ``<linux/fs.h>`` which
276 identifies the amount of NUL-padding to use when encrypting 297 identifies the amount of NUL-padding to use when encrypting
277 filenames. If unsure, use FS_POLICY_FLAGS_PAD_32 (0x3). 298 filenames. If unsure, use FS_POLICY_FLAGS_PAD_32 (0x3).
299 In addition, if the chosen encryption modes are both
300 FS_ENCRYPTION_MODE_ADIANTUM, this can contain
301 FS_POLICY_FLAG_DIRECT_KEY to specify that the master key should be
302 used directly, without key derivation.
278 303
279- ``master_key_descriptor`` specifies how to find the master key in 304- ``master_key_descriptor`` specifies how to find the master key in
280 the keyring; see `Adding keys`_. It is up to userspace to choose a 305 the keyring; see `Adding keys`_. It is up to userspace to choose a