1 /* SPDX-License-Identifier: GPL-2.0 */
3 * fscrypt_common.h: common declarations for per-file encryption
5 * Copyright (C) 2015, Google, Inc.
7 * Written by Michael Halcrow, 2015.
8 * Modified by Jaegeuk Kim, 2015.
11 #ifndef _LINUX_FSCRYPT_COMMON_H
12 #define _LINUX_FSCRYPT_COMMON_H
14 #include <linux/key.h>
17 #include <linux/bio.h>
18 #include <linux/dcache.h>
19 #include <crypto/skcipher.h>
20 #include <uapi/linux/fs.h>
22 #define FS_CRYPTO_BLOCK_SIZE 16
29 struct page *bounce_page; /* Ciphertext page */
30 struct page *control_page; /* Original page */
34 struct work_struct work;
36 struct list_head free_list; /* Free list */
42 * For encrypted symlinks, the ciphertext length is stored at the beginning
43 * of the string in little-endian format.
45 struct fscrypt_symlink_data {
47 char encrypted_path[1];
56 const struct qstr *usr_fname;
57 struct fscrypt_str disk_name;
60 struct fscrypt_str crypto_buf;
63 #define FSTR_INIT(n, l) { .name = n, .len = l }
64 #define FSTR_TO_QSTR(f) QSTR_INIT((f)->name, (f)->len)
65 #define fname_name(p) ((p)->disk_name.name)
66 #define fname_len(p) ((p)->disk_name.len)
69 * fscrypt superblock flags
71 #define FS_CFLG_OWN_PAGES (1U << 1)
74 * crypto opertions for filesystems
76 struct fscrypt_operations {
78 const char *key_prefix;
79 int (*get_context)(struct inode *, void *, size_t);
80 int (*set_context)(struct inode *, const void *, size_t, void *);
81 bool (*dummy_context)(struct inode *);
82 bool (*is_encrypted)(struct inode *);
83 bool (*empty_dir)(struct inode *);
84 unsigned (*max_namelen)(struct inode *);
87 /* Maximum value for the third parameter of fscrypt_operations.set_context(). */
88 #define FSCRYPT_SET_CONTEXT_MAX_SIZE 28
90 static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
92 if (inode->i_sb->s_cop->dummy_context &&
93 inode->i_sb->s_cop->dummy_context(inode))
98 static inline bool fscrypt_valid_enc_modes(u32 contents_mode,
101 if (contents_mode == FS_ENCRYPTION_MODE_AES_128_CBC &&
102 filenames_mode == FS_ENCRYPTION_MODE_AES_128_CTS)
105 if (contents_mode == FS_ENCRYPTION_MODE_AES_256_XTS &&
106 filenames_mode == FS_ENCRYPTION_MODE_AES_256_CTS)
112 static inline bool fscrypt_is_dot_dotdot(const struct qstr *str)
114 if (str->len == 1 && str->name[0] == '.')
117 if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.')
123 static inline struct page *fscrypt_control_page(struct page *page)
125 #if IS_ENABLED(CONFIG_FS_ENCRYPTION)
126 return ((struct fscrypt_ctx *)page_private(page))->w.control_page;
129 return ERR_PTR(-EINVAL);
133 static inline int fscrypt_has_encryption_key(const struct inode *inode)
135 #if IS_ENABLED(CONFIG_FS_ENCRYPTION)
136 return (inode->i_crypt_info != NULL);
142 #endif /* _LINUX_FSCRYPT_COMMON_H */