History

fscrypt: use FSCRYPT_ prefix for uapi constants

Prefix all filesystem encryption UAPI constants except the ioctl numbers with "FSCRYPT_" rather than with "FS_". This namespaces the constants more appropriately and makes it clear that they are related specifically to the filesystem encryption feature, and to the 'fscrypt_*' structures. With some of the old names like "FS_POLICY_FLAGS_VALID", it was not immediately clear that the constant had anything to do with encryption. This is also useful because we'll be adding more encryption-related constants, e.g. for the policy version, and we'd otherwise have to choose whether to use unclear names like FS_POLICY_V1 or inconsistent names like FS_ENCRYPTION_POLICY_V1. For source compatibility with existing userspace programs, keep the old names defined as aliases to the new names. Finally, as long as new names are being defined anyway, I skipped defining new names for the fscrypt mode numbers that aren't actually used: INVALID (0), AES_256_GCM (2), AES_256_CBC (3), SPECK128_256_XTS (7), and SPECK128_256_CTS (8).

Eric Biggers committed 7 years ago

Commit 2336d0d1 parent 7af0ab02 files · +62 −43Browse files

Unified · Split

2 files
  1. Documentation/filesystems/fscrypt.rst +20 −20
  2. include/uapi/linux/fscrypt.h +42 −23
Documentation/filesystems/fscrypt.rst+20−20
@@ -225,9 +225,10 @@ a little endian number, except that: · 224 unmodified lines
225225 is encrypted with AES-256 where the AES-256 key is the SHA-256 hash
226226 of the file's data encryption key.
227227
228−- In the "direct key" configuration (FS_POLICY_FLAG_DIRECT_KEY set in
229− the fscrypt_policy), the file's nonce is also appended to the IV.
230− Currently this is only allowed with the Adiantum encryption mode.
228+- In the "direct key" configuration (FSCRYPT_POLICY_FLAG_DIRECT_KEY
229+ set in the fscrypt_policy), the file's nonce is also appended to the
230+ IV. Currently this is only allowed with the Adiantum encryption
231+ mode.
231232
232233 Filenames encryption
233234 --------------------
@@ -274,14 +275,14 @@ empty directory or verifies that a directory or regular file already · 40 unmodified lines
274275 has the specified encryption policy. It takes in a pointer to a
275276 :c:type:`struct fscrypt_policy`, defined as follows::
276277
277− #define FS_KEY_DESCRIPTOR_SIZE 8
278+ #define FSCRYPT_KEY_DESCRIPTOR_SIZE 8
278279
279280 struct fscrypt_policy {
280281 __u8 version;
281282 __u8 contents_encryption_mode;
282283 __u8 filenames_encryption_mode;
283284 __u8 flags;
284− __u8 master_key_descriptor[FS_KEY_DESCRIPTOR_SIZE];
285+ __u8 master_key_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE];
285286 };
286287
287288 This structure must be initialized as follows:
@@ -289,19 +290,18 @@ This structure must be initialized as follows: · 1 unmodified line
289290 - ``version`` must be 0.
290291
291292 - ``contents_encryption_mode`` and ``filenames_encryption_mode`` must
292− be set to constants from ``<linux/fs.h>`` which identify the
293− encryption modes to use. If unsure, use
294− FS_ENCRYPTION_MODE_AES_256_XTS (1) for ``contents_encryption_mode``
295− and FS_ENCRYPTION_MODE_AES_256_CTS (4) for
296− ``filenames_encryption_mode``.
293+ be set to constants from ``<linux/fscrypt.h>`` which identify the
294+ encryption modes to use. If unsure, use FSCRYPT_MODE_AES_256_XTS
295+ (1) for ``contents_encryption_mode`` and FSCRYPT_MODE_AES_256_CTS
296+ (4) for ``filenames_encryption_mode``.
297297
298−- ``flags`` must contain a value from ``<linux/fs.h>`` which
298+- ``flags`` must contain a value from ``<linux/fscrypt.h>`` which
299299 identifies the amount of NUL-padding to use when encrypting
300− filenames. If unsure, use FS_POLICY_FLAGS_PAD_32 (0x3).
301− In addition, if the chosen encryption modes are both
302− FS_ENCRYPTION_MODE_ADIANTUM, this can contain
303− FS_POLICY_FLAG_DIRECT_KEY to specify that the master key should be
304− used directly, without key derivation.
300+ filenames. If unsure, use FSCRYPT_POLICY_FLAGS_PAD_32 (0x3). In
301+ addition, if the chosen encryption modes are both
302+ FSCRYPT_MODE_ADIANTUM, this can contain
303+ FSCRYPT_POLICY_FLAG_DIRECT_KEY to specify that the master key should
304+ be used directly, without key derivation.
305305
306306 - ``master_key_descriptor`` specifies how to find the master key in
307307 the keyring; see `Adding keys`_. It is up to userspace to choose a
@@ -401,11 +401,11 @@ followed by the 16-character lower case hex representation of the · 93 unmodified lines
401401 ``master_key_descriptor`` that was set in the encryption policy. The
402402 key payload must conform to the following structure::
403403
404− #define FS_MAX_KEY_SIZE 64
404+ #define FSCRYPT_MAX_KEY_SIZE 64
405405
406406 struct fscrypt_key {
407407 u32 mode;
408− u8 raw[FS_MAX_KEY_SIZE];
408+ u8 raw[FSCRYPT_MAX_KEY_SIZE];
409409 u32 size;
410410 };
411411
@@ -574,7 +574,7 @@ much confusion if an encryption policy were to be added to or removed · 162 unmodified lines
574574 from anything other than an empty directory.) The struct is defined
575575 as follows::
576576
577− #define FS_KEY_DESCRIPTOR_SIZE 8
577+ #define FSCRYPT_KEY_DESCRIPTOR_SIZE 8
578578 #define FS_KEY_DERIVATION_NONCE_SIZE 16
579579
580580 struct fscrypt_context {
@@ -582,7 +582,7 @@ as follows:: · 1 unmodified line
582582 u8 contents_encryption_mode;
583583 u8 filenames_encryption_mode;
584584 u8 flags;
585− u8 master_key_descriptor[FS_KEY_DESCRIPTOR_SIZE];
585+ u8 master_key_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE];
586586 u8 nonce[FS_KEY_DERIVATION_NONCE_SIZE];
587587 };
588588
include/uapi/linux/fscrypt.h+42−23
@@ -10,35 +10,30 @@ · 9 unmodified lines
1010
1111 #include <linux/types.h>
1212
13−#define FS_KEY_DESCRIPTOR_SIZE 8
13+#define FSCRYPT_KEY_DESCRIPTOR_SIZE 8
1414
1515 /* Encryption policy flags */
16−#define FS_POLICY_FLAGS_PAD_4 0x00
17−#define FS_POLICY_FLAGS_PAD_8 0x01
18−#define FS_POLICY_FLAGS_PAD_16 0x02
19−#define FS_POLICY_FLAGS_PAD_32 0x03
20−#define FS_POLICY_FLAGS_PAD_MASK 0x03
21−#define FS_POLICY_FLAG_DIRECT_KEY 0x04 /* use master key directly */
22−#define FS_POLICY_FLAGS_VALID 0x07
16+#define FSCRYPT_POLICY_FLAGS_PAD_4 0x00
17+#define FSCRYPT_POLICY_FLAGS_PAD_8 0x01
18+#define FSCRYPT_POLICY_FLAGS_PAD_16 0x02
19+#define FSCRYPT_POLICY_FLAGS_PAD_32 0x03
20+#define FSCRYPT_POLICY_FLAGS_PAD_MASK 0x03
21+#define FSCRYPT_POLICY_FLAG_DIRECT_KEY 0x04 /* use master key directly */
22+#define FSCRYPT_POLICY_FLAGS_VALID 0x07
2323
2424 /* Encryption algorithms */
25−#define FS_ENCRYPTION_MODE_INVALID 0
26−#define FS_ENCRYPTION_MODE_AES_256_XTS 1
27−#define FS_ENCRYPTION_MODE_AES_256_GCM 2
28−#define FS_ENCRYPTION_MODE_AES_256_CBC 3
29−#define FS_ENCRYPTION_MODE_AES_256_CTS 4
30−#define FS_ENCRYPTION_MODE_AES_128_CBC 5
31−#define FS_ENCRYPTION_MODE_AES_128_CTS 6
32−#define FS_ENCRYPTION_MODE_SPECK128_256_XTS 7 /* Removed, do not use. */
33−#define FS_ENCRYPTION_MODE_SPECK128_256_CTS 8 /* Removed, do not use. */
34−#define FS_ENCRYPTION_MODE_ADIANTUM 9
25+#define FSCRYPT_MODE_AES_256_XTS 1
26+#define FSCRYPT_MODE_AES_256_CTS 4
27+#define FSCRYPT_MODE_AES_128_CBC 5
28+#define FSCRYPT_MODE_AES_128_CTS 6
29+#define FSCRYPT_MODE_ADIANTUM 9
3530
3631 struct fscrypt_policy {
3732 __u8 version;
3833 __u8 contents_encryption_mode;
3934 __u8 filenames_encryption_mode;
4035 __u8 flags;
41− __u8 master_key_descriptor[FS_KEY_DESCRIPTOR_SIZE];
36+ __u8 master_key_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE];
4237 };
4338
4439 #define FS_IOC_SET_ENCRYPTION_POLICY _IOR('f', 19, struct fscrypt_policy)
@@ -46,16 +41,40 @@ struct fscrypt_policy { · 1 unmodified line
4641 #define FS_IOC_GET_ENCRYPTION_POLICY _IOW('f', 21, struct fscrypt_policy)
4742
4843 /* Parameters for passing an encryption key into the kernel keyring */
49−#define FS_KEY_DESC_PREFIX "fscrypt:"
50−#define FS_KEY_DESC_PREFIX_SIZE 8
44+#define FSCRYPT_KEY_DESC_PREFIX "fscrypt:"
45+#define FSCRYPT_KEY_DESC_PREFIX_SIZE 8
5146
5247 /* Structure that userspace passes to the kernel keyring */
53−#define FS_MAX_KEY_SIZE 64
48+#define FSCRYPT_MAX_KEY_SIZE 64
5449
5550 struct fscrypt_key {
5651 __u32 mode;
57− __u8 raw[FS_MAX_KEY_SIZE];
52+ __u8 raw[FSCRYPT_MAX_KEY_SIZE];
5853 __u32 size;
5954 };
55+/**********************************************************************/
56+
57+/* old names; don't add anything new here! */
58+#define FS_KEY_DESCRIPTOR_SIZE FSCRYPT_KEY_DESCRIPTOR_SIZE
59+#define FS_POLICY_FLAGS_PAD_4 FSCRYPT_POLICY_FLAGS_PAD_4
60+#define FS_POLICY_FLAGS_PAD_8 FSCRYPT_POLICY_FLAGS_PAD_8
61+#define FS_POLICY_FLAGS_PAD_16 FSCRYPT_POLICY_FLAGS_PAD_16
62+#define FS_POLICY_FLAGS_PAD_32 FSCRYPT_POLICY_FLAGS_PAD_32
63+#define FS_POLICY_FLAGS_PAD_MASK FSCRYPT_POLICY_FLAGS_PAD_MASK
64+#define FS_POLICY_FLAG_DIRECT_KEY FSCRYPT_POLICY_FLAG_DIRECT_KEY
65+#define FS_POLICY_FLAGS_VALID FSCRYPT_POLICY_FLAGS_VALID
66+#define FS_ENCRYPTION_MODE_INVALID 0 /* never used */
67+#define FS_ENCRYPTION_MODE_AES_256_XTS FSCRYPT_MODE_AES_256_XTS
68+#define FS_ENCRYPTION_MODE_AES_256_GCM 2 /* never used */
69+#define FS_ENCRYPTION_MODE_AES_256_CBC 3 /* never used */
70+#define FS_ENCRYPTION_MODE_AES_256_CTS FSCRYPT_MODE_AES_256_CTS
71+#define FS_ENCRYPTION_MODE_AES_128_CBC FSCRYPT_MODE_AES_128_CBC
72+#define FS_ENCRYPTION_MODE_AES_128_CTS FSCRYPT_MODE_AES_128_CTS
73+#define FS_ENCRYPTION_MODE_SPECK128_256_XTS 7 /* removed */
74+#define FS_ENCRYPTION_MODE_SPECK128_256_CTS 8 /* removed */
75+#define FS_ENCRYPTION_MODE_ADIANTUM FSCRYPT_MODE_ADIANTUM
76+#define FS_KEY_DESC_PREFIX FSCRYPT_KEY_DESC_PREFIX
77+#define FS_KEY_DESC_PREFIX_SIZE FSCRYPT_KEY_DESC_PREFIX_SIZE
78+#define FS_MAX_KEY_SIZE FSCRYPT_MAX_KEY_SIZE
6079
6180 #endif /* _UAPI_LINUX_FSCRYPT_H */