18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/**
38c2ecf20Sopenharmony_ci * eCryptfs: Linux filesystem encryption layer
48c2ecf20Sopenharmony_ci * Kernel declarations.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 1997-2003 Erez Zadok
78c2ecf20Sopenharmony_ci * Copyright (C) 2001-2003 Stony Brook University
88c2ecf20Sopenharmony_ci * Copyright (C) 2004-2008 International Business Machines Corp.
98c2ecf20Sopenharmony_ci *   Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
108c2ecf20Sopenharmony_ci *              Trevor S. Highland <trevor.highland@gmail.com>
118c2ecf20Sopenharmony_ci *              Tyler Hicks <code@tyhicks.com>
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#ifndef ECRYPTFS_KERNEL_H
158c2ecf20Sopenharmony_ci#define ECRYPTFS_KERNEL_H
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <crypto/skcipher.h>
188c2ecf20Sopenharmony_ci#include <keys/user-type.h>
198c2ecf20Sopenharmony_ci#include <keys/encrypted-type.h>
208c2ecf20Sopenharmony_ci#include <linux/kernel.h>
218c2ecf20Sopenharmony_ci#include <linux/fs.h>
228c2ecf20Sopenharmony_ci#include <linux/fs_stack.h>
238c2ecf20Sopenharmony_ci#include <linux/namei.h>
248c2ecf20Sopenharmony_ci#include <linux/scatterlist.h>
258c2ecf20Sopenharmony_ci#include <linux/hash.h>
268c2ecf20Sopenharmony_ci#include <linux/nsproxy.h>
278c2ecf20Sopenharmony_ci#include <linux/backing-dev.h>
288c2ecf20Sopenharmony_ci#include <linux/ecryptfs.h>
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define ECRYPTFS_DEFAULT_IV_BYTES 16
318c2ecf20Sopenharmony_ci#define ECRYPTFS_DEFAULT_EXTENT_SIZE 4096
328c2ecf20Sopenharmony_ci#define ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE 8192
338c2ecf20Sopenharmony_ci#define ECRYPTFS_DEFAULT_MSG_CTX_ELEMS 32
348c2ecf20Sopenharmony_ci#define ECRYPTFS_DEFAULT_SEND_TIMEOUT HZ
358c2ecf20Sopenharmony_ci#define ECRYPTFS_MAX_MSG_CTX_TTL (HZ*3)
368c2ecf20Sopenharmony_ci#define ECRYPTFS_DEFAULT_NUM_USERS 4
378c2ecf20Sopenharmony_ci#define ECRYPTFS_MAX_NUM_USERS 32768
388c2ecf20Sopenharmony_ci#define ECRYPTFS_XATTR_NAME "user.ecryptfs"
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_civoid ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok);
418c2ecf20Sopenharmony_cistatic inline void
428c2ecf20Sopenharmony_ciecryptfs_to_hex(char *dst, char *src, size_t src_size)
438c2ecf20Sopenharmony_ci{
448c2ecf20Sopenharmony_ci	char *end = bin2hex(dst, src, src_size);
458c2ecf20Sopenharmony_ci	*end = '\0';
468c2ecf20Sopenharmony_ci}
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ciextern void ecryptfs_from_hex(char *dst, char *src, int dst_size);
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistruct ecryptfs_key_record {
518c2ecf20Sopenharmony_ci	unsigned char type;
528c2ecf20Sopenharmony_ci	size_t enc_key_size;
538c2ecf20Sopenharmony_ci	unsigned char sig[ECRYPTFS_SIG_SIZE];
548c2ecf20Sopenharmony_ci	unsigned char enc_key[ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES];
558c2ecf20Sopenharmony_ci};
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cistruct ecryptfs_auth_tok_list {
588c2ecf20Sopenharmony_ci	struct ecryptfs_auth_tok *auth_tok;
598c2ecf20Sopenharmony_ci	struct list_head list;
608c2ecf20Sopenharmony_ci};
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistruct ecryptfs_crypt_stat;
638c2ecf20Sopenharmony_cistruct ecryptfs_mount_crypt_stat;
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_cistruct ecryptfs_page_crypt_context {
668c2ecf20Sopenharmony_ci	struct page *page;
678c2ecf20Sopenharmony_ci#define ECRYPTFS_PREPARE_COMMIT_MODE 0
688c2ecf20Sopenharmony_ci#define ECRYPTFS_WRITEPAGE_MODE      1
698c2ecf20Sopenharmony_ci	unsigned int mode;
708c2ecf20Sopenharmony_ci	union {
718c2ecf20Sopenharmony_ci		struct file *lower_file;
728c2ecf20Sopenharmony_ci		struct writeback_control *wbc;
738c2ecf20Sopenharmony_ci	} param;
748c2ecf20Sopenharmony_ci};
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci#if defined(CONFIG_ENCRYPTED_KEYS) || defined(CONFIG_ENCRYPTED_KEYS_MODULE)
778c2ecf20Sopenharmony_cistatic inline struct ecryptfs_auth_tok *
788c2ecf20Sopenharmony_ciecryptfs_get_encrypted_key_payload_data(struct key *key)
798c2ecf20Sopenharmony_ci{
808c2ecf20Sopenharmony_ci	struct encrypted_key_payload *payload;
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	if (key->type != &key_type_encrypted)
838c2ecf20Sopenharmony_ci		return NULL;
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci	payload = key->payload.data[0];
868c2ecf20Sopenharmony_ci	if (!payload)
878c2ecf20Sopenharmony_ci		return ERR_PTR(-EKEYREVOKED);
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci	return (struct ecryptfs_auth_tok *)payload->payload_data;
908c2ecf20Sopenharmony_ci}
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_cistatic inline struct key *ecryptfs_get_encrypted_key(char *sig)
938c2ecf20Sopenharmony_ci{
948c2ecf20Sopenharmony_ci	return request_key(&key_type_encrypted, sig, NULL);
958c2ecf20Sopenharmony_ci}
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci#else
988c2ecf20Sopenharmony_cistatic inline struct ecryptfs_auth_tok *
998c2ecf20Sopenharmony_ciecryptfs_get_encrypted_key_payload_data(struct key *key)
1008c2ecf20Sopenharmony_ci{
1018c2ecf20Sopenharmony_ci	return NULL;
1028c2ecf20Sopenharmony_ci}
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistatic inline struct key *ecryptfs_get_encrypted_key(char *sig)
1058c2ecf20Sopenharmony_ci{
1068c2ecf20Sopenharmony_ci	return ERR_PTR(-ENOKEY);
1078c2ecf20Sopenharmony_ci}
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci#endif /* CONFIG_ENCRYPTED_KEYS */
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistatic inline struct ecryptfs_auth_tok *
1128c2ecf20Sopenharmony_ciecryptfs_get_key_payload_data(struct key *key)
1138c2ecf20Sopenharmony_ci{
1148c2ecf20Sopenharmony_ci	struct ecryptfs_auth_tok *auth_tok;
1158c2ecf20Sopenharmony_ci	struct user_key_payload *ukp;
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci	auth_tok = ecryptfs_get_encrypted_key_payload_data(key);
1188c2ecf20Sopenharmony_ci	if (auth_tok)
1198c2ecf20Sopenharmony_ci		return auth_tok;
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci	ukp = user_key_payload_locked(key);
1228c2ecf20Sopenharmony_ci	if (!ukp)
1238c2ecf20Sopenharmony_ci		return ERR_PTR(-EKEYREVOKED);
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci	return (struct ecryptfs_auth_tok *)ukp->data;
1268c2ecf20Sopenharmony_ci}
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#define ECRYPTFS_MAX_KEYSET_SIZE 1024
1298c2ecf20Sopenharmony_ci#define ECRYPTFS_MAX_CIPHER_NAME_SIZE 31
1308c2ecf20Sopenharmony_ci#define ECRYPTFS_MAX_NUM_ENC_KEYS 64
1318c2ecf20Sopenharmony_ci#define ECRYPTFS_MAX_IV_BYTES 16	/* 128 bits */
1328c2ecf20Sopenharmony_ci#define ECRYPTFS_SALT_BYTES 2
1338c2ecf20Sopenharmony_ci#define MAGIC_ECRYPTFS_MARKER 0x3c81b7f5
1348c2ecf20Sopenharmony_ci#define MAGIC_ECRYPTFS_MARKER_SIZE_BYTES 8	/* 4*2 */
1358c2ecf20Sopenharmony_ci#define ECRYPTFS_FILE_SIZE_BYTES (sizeof(u64))
1368c2ecf20Sopenharmony_ci#define ECRYPTFS_SIZE_AND_MARKER_BYTES (ECRYPTFS_FILE_SIZE_BYTES \
1378c2ecf20Sopenharmony_ci					+ MAGIC_ECRYPTFS_MARKER_SIZE_BYTES)
1388c2ecf20Sopenharmony_ci#define ECRYPTFS_DEFAULT_CIPHER "aes"
1398c2ecf20Sopenharmony_ci#define ECRYPTFS_DEFAULT_KEY_BYTES 16
1408c2ecf20Sopenharmony_ci#define ECRYPTFS_DEFAULT_HASH "md5"
1418c2ecf20Sopenharmony_ci#define ECRYPTFS_TAG_70_DIGEST ECRYPTFS_DEFAULT_HASH
1428c2ecf20Sopenharmony_ci#define ECRYPTFS_TAG_1_PACKET_TYPE 0x01
1438c2ecf20Sopenharmony_ci#define ECRYPTFS_TAG_3_PACKET_TYPE 0x8C
1448c2ecf20Sopenharmony_ci#define ECRYPTFS_TAG_11_PACKET_TYPE 0xED
1458c2ecf20Sopenharmony_ci#define ECRYPTFS_TAG_64_PACKET_TYPE 0x40
1468c2ecf20Sopenharmony_ci#define ECRYPTFS_TAG_65_PACKET_TYPE 0x41
1478c2ecf20Sopenharmony_ci#define ECRYPTFS_TAG_66_PACKET_TYPE 0x42
1488c2ecf20Sopenharmony_ci#define ECRYPTFS_TAG_67_PACKET_TYPE 0x43
1498c2ecf20Sopenharmony_ci#define ECRYPTFS_TAG_70_PACKET_TYPE 0x46 /* FNEK-encrypted filename
1508c2ecf20Sopenharmony_ci					  * as dentry name */
1518c2ecf20Sopenharmony_ci#define ECRYPTFS_TAG_71_PACKET_TYPE 0x47 /* FNEK-encrypted filename in
1528c2ecf20Sopenharmony_ci					  * metadata */
1538c2ecf20Sopenharmony_ci#define ECRYPTFS_TAG_72_PACKET_TYPE 0x48 /* FEK-encrypted filename as
1548c2ecf20Sopenharmony_ci					  * dentry name */
1558c2ecf20Sopenharmony_ci#define ECRYPTFS_TAG_73_PACKET_TYPE 0x49 /* FEK-encrypted filename as
1568c2ecf20Sopenharmony_ci					  * metadata */
1578c2ecf20Sopenharmony_ci#define ECRYPTFS_MIN_PKT_LEN_SIZE 1 /* Min size to specify packet length */
1588c2ecf20Sopenharmony_ci#define ECRYPTFS_MAX_PKT_LEN_SIZE 2 /* Pass at least this many bytes to
1598c2ecf20Sopenharmony_ci				     * ecryptfs_parse_packet_length() and
1608c2ecf20Sopenharmony_ci				     * ecryptfs_write_packet_length()
1618c2ecf20Sopenharmony_ci				     */
1628c2ecf20Sopenharmony_ci/* Constraint: ECRYPTFS_FILENAME_MIN_RANDOM_PREPEND_BYTES >=
1638c2ecf20Sopenharmony_ci * ECRYPTFS_MAX_IV_BYTES */
1648c2ecf20Sopenharmony_ci#define ECRYPTFS_FILENAME_MIN_RANDOM_PREPEND_BYTES 16
1658c2ecf20Sopenharmony_ci#define ECRYPTFS_NON_NULL 0x42 /* A reasonable substitute for NULL */
1668c2ecf20Sopenharmony_ci#define MD5_DIGEST_SIZE 16
1678c2ecf20Sopenharmony_ci#define ECRYPTFS_TAG_70_DIGEST_SIZE MD5_DIGEST_SIZE
1688c2ecf20Sopenharmony_ci#define ECRYPTFS_TAG_70_MIN_METADATA_SIZE (1 + ECRYPTFS_MIN_PKT_LEN_SIZE \
1698c2ecf20Sopenharmony_ci					   + ECRYPTFS_SIG_SIZE + 1 + 1)
1708c2ecf20Sopenharmony_ci#define ECRYPTFS_TAG_70_MAX_METADATA_SIZE (1 + ECRYPTFS_MAX_PKT_LEN_SIZE \
1718c2ecf20Sopenharmony_ci					   + ECRYPTFS_SIG_SIZE + 1 + 1)
1728c2ecf20Sopenharmony_ci#define ECRYPTFS_FEK_ENCRYPTED_FILENAME_PREFIX "ECRYPTFS_FEK_ENCRYPTED."
1738c2ecf20Sopenharmony_ci#define ECRYPTFS_FEK_ENCRYPTED_FILENAME_PREFIX_SIZE 23
1748c2ecf20Sopenharmony_ci#define ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX "ECRYPTFS_FNEK_ENCRYPTED."
1758c2ecf20Sopenharmony_ci#define ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX_SIZE 24
1768c2ecf20Sopenharmony_ci#define ECRYPTFS_ENCRYPTED_DENTRY_NAME_LEN (18 + 1 + 4 + 1 + 32)
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci#ifdef CONFIG_ECRYPT_FS_MESSAGING
1798c2ecf20Sopenharmony_ci# define ECRYPTFS_VERSIONING_MASK_MESSAGING (ECRYPTFS_VERSIONING_DEVMISC \
1808c2ecf20Sopenharmony_ci					     | ECRYPTFS_VERSIONING_PUBKEY)
1818c2ecf20Sopenharmony_ci#else
1828c2ecf20Sopenharmony_ci# define ECRYPTFS_VERSIONING_MASK_MESSAGING 0
1838c2ecf20Sopenharmony_ci#endif
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci#define ECRYPTFS_VERSIONING_MASK (ECRYPTFS_VERSIONING_PASSPHRASE \
1868c2ecf20Sopenharmony_ci				  | ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH \
1878c2ecf20Sopenharmony_ci				  | ECRYPTFS_VERSIONING_XATTR \
1888c2ecf20Sopenharmony_ci				  | ECRYPTFS_VERSIONING_MULTKEY \
1898c2ecf20Sopenharmony_ci				  | ECRYPTFS_VERSIONING_MASK_MESSAGING \
1908c2ecf20Sopenharmony_ci				  | ECRYPTFS_VERSIONING_FILENAME_ENCRYPTION)
1918c2ecf20Sopenharmony_cistruct ecryptfs_key_sig {
1928c2ecf20Sopenharmony_ci	struct list_head crypt_stat_list;
1938c2ecf20Sopenharmony_ci	char keysig[ECRYPTFS_SIG_SIZE_HEX + 1];
1948c2ecf20Sopenharmony_ci};
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_cistruct ecryptfs_filename {
1978c2ecf20Sopenharmony_ci	struct list_head crypt_stat_list;
1988c2ecf20Sopenharmony_ci#define ECRYPTFS_FILENAME_CONTAINS_DECRYPTED 0x00000001
1998c2ecf20Sopenharmony_ci	u32 flags;
2008c2ecf20Sopenharmony_ci	u32 seq_no;
2018c2ecf20Sopenharmony_ci	char *filename;
2028c2ecf20Sopenharmony_ci	char *encrypted_filename;
2038c2ecf20Sopenharmony_ci	size_t filename_size;
2048c2ecf20Sopenharmony_ci	size_t encrypted_filename_size;
2058c2ecf20Sopenharmony_ci	char fnek_sig[ECRYPTFS_SIG_SIZE_HEX];
2068c2ecf20Sopenharmony_ci	char dentry_name[ECRYPTFS_ENCRYPTED_DENTRY_NAME_LEN + 1];
2078c2ecf20Sopenharmony_ci};
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci/**
2108c2ecf20Sopenharmony_ci * This is the primary struct associated with each encrypted file.
2118c2ecf20Sopenharmony_ci *
2128c2ecf20Sopenharmony_ci * TODO: cache align/pack?
2138c2ecf20Sopenharmony_ci */
2148c2ecf20Sopenharmony_cistruct ecryptfs_crypt_stat {
2158c2ecf20Sopenharmony_ci#define ECRYPTFS_STRUCT_INITIALIZED   0x00000001
2168c2ecf20Sopenharmony_ci#define ECRYPTFS_POLICY_APPLIED       0x00000002
2178c2ecf20Sopenharmony_ci#define ECRYPTFS_ENCRYPTED            0x00000004
2188c2ecf20Sopenharmony_ci#define ECRYPTFS_SECURITY_WARNING     0x00000008
2198c2ecf20Sopenharmony_ci#define ECRYPTFS_ENABLE_HMAC          0x00000010
2208c2ecf20Sopenharmony_ci#define ECRYPTFS_ENCRYPT_IV_PAGES     0x00000020
2218c2ecf20Sopenharmony_ci#define ECRYPTFS_KEY_VALID            0x00000040
2228c2ecf20Sopenharmony_ci#define ECRYPTFS_METADATA_IN_XATTR    0x00000080
2238c2ecf20Sopenharmony_ci#define ECRYPTFS_VIEW_AS_ENCRYPTED    0x00000100
2248c2ecf20Sopenharmony_ci#define ECRYPTFS_KEY_SET              0x00000200
2258c2ecf20Sopenharmony_ci#define ECRYPTFS_ENCRYPT_FILENAMES    0x00000400
2268c2ecf20Sopenharmony_ci#define ECRYPTFS_ENCFN_USE_MOUNT_FNEK 0x00000800
2278c2ecf20Sopenharmony_ci#define ECRYPTFS_ENCFN_USE_FEK        0x00001000
2288c2ecf20Sopenharmony_ci#define ECRYPTFS_UNLINK_SIGS          0x00002000
2298c2ecf20Sopenharmony_ci#define ECRYPTFS_I_SIZE_INITIALIZED   0x00004000
2308c2ecf20Sopenharmony_ci	u32 flags;
2318c2ecf20Sopenharmony_ci	unsigned int file_version;
2328c2ecf20Sopenharmony_ci	size_t iv_bytes;
2338c2ecf20Sopenharmony_ci	size_t metadata_size;
2348c2ecf20Sopenharmony_ci	size_t extent_size; /* Data extent size; default is 4096 */
2358c2ecf20Sopenharmony_ci	size_t key_size;
2368c2ecf20Sopenharmony_ci	size_t extent_shift;
2378c2ecf20Sopenharmony_ci	unsigned int extent_mask;
2388c2ecf20Sopenharmony_ci	struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
2398c2ecf20Sopenharmony_ci	struct crypto_skcipher *tfm;
2408c2ecf20Sopenharmony_ci	struct crypto_shash *hash_tfm; /* Crypto context for generating
2418c2ecf20Sopenharmony_ci					* the initialization vectors */
2428c2ecf20Sopenharmony_ci	unsigned char cipher[ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1];
2438c2ecf20Sopenharmony_ci	unsigned char key[ECRYPTFS_MAX_KEY_BYTES];
2448c2ecf20Sopenharmony_ci	unsigned char root_iv[ECRYPTFS_MAX_IV_BYTES];
2458c2ecf20Sopenharmony_ci	struct list_head keysig_list;
2468c2ecf20Sopenharmony_ci	struct mutex keysig_list_mutex;
2478c2ecf20Sopenharmony_ci	struct mutex cs_tfm_mutex;
2488c2ecf20Sopenharmony_ci	struct mutex cs_mutex;
2498c2ecf20Sopenharmony_ci};
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci/* inode private data. */
2528c2ecf20Sopenharmony_cistruct ecryptfs_inode_info {
2538c2ecf20Sopenharmony_ci	struct inode vfs_inode;
2548c2ecf20Sopenharmony_ci	struct inode *wii_inode;
2558c2ecf20Sopenharmony_ci	struct mutex lower_file_mutex;
2568c2ecf20Sopenharmony_ci	atomic_t lower_file_count;
2578c2ecf20Sopenharmony_ci	struct file *lower_file;
2588c2ecf20Sopenharmony_ci	struct ecryptfs_crypt_stat crypt_stat;
2598c2ecf20Sopenharmony_ci};
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci/* dentry private data. Each dentry must keep track of a lower
2628c2ecf20Sopenharmony_ci * vfsmount too. */
2638c2ecf20Sopenharmony_cistruct ecryptfs_dentry_info {
2648c2ecf20Sopenharmony_ci	struct path lower_path;
2658c2ecf20Sopenharmony_ci	union {
2668c2ecf20Sopenharmony_ci		struct ecryptfs_crypt_stat *crypt_stat;
2678c2ecf20Sopenharmony_ci		struct rcu_head rcu;
2688c2ecf20Sopenharmony_ci	};
2698c2ecf20Sopenharmony_ci};
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci/**
2728c2ecf20Sopenharmony_ci * ecryptfs_global_auth_tok - A key used to encrypt all new files under the mountpoint
2738c2ecf20Sopenharmony_ci * @flags: Status flags
2748c2ecf20Sopenharmony_ci * @mount_crypt_stat_list: These auth_toks hang off the mount-wide
2758c2ecf20Sopenharmony_ci *                         cryptographic context. Every time a new
2768c2ecf20Sopenharmony_ci *                         inode comes into existence, eCryptfs copies
2778c2ecf20Sopenharmony_ci *                         the auth_toks on that list to the set of
2788c2ecf20Sopenharmony_ci *                         auth_toks on the inode's crypt_stat
2798c2ecf20Sopenharmony_ci * @global_auth_tok_key: The key from the user's keyring for the sig
2808c2ecf20Sopenharmony_ci * @global_auth_tok: The key contents
2818c2ecf20Sopenharmony_ci * @sig: The key identifier
2828c2ecf20Sopenharmony_ci *
2838c2ecf20Sopenharmony_ci * ecryptfs_global_auth_tok structs refer to authentication token keys
2848c2ecf20Sopenharmony_ci * in the user keyring that apply to newly created files. A list of
2858c2ecf20Sopenharmony_ci * these objects hangs off of the mount_crypt_stat struct for any
2868c2ecf20Sopenharmony_ci * given eCryptfs mount. This struct maintains a reference to both the
2878c2ecf20Sopenharmony_ci * key contents and the key itself so that the key can be put on
2888c2ecf20Sopenharmony_ci * unmount.
2898c2ecf20Sopenharmony_ci */
2908c2ecf20Sopenharmony_cistruct ecryptfs_global_auth_tok {
2918c2ecf20Sopenharmony_ci#define ECRYPTFS_AUTH_TOK_INVALID 0x00000001
2928c2ecf20Sopenharmony_ci#define ECRYPTFS_AUTH_TOK_FNEK    0x00000002
2938c2ecf20Sopenharmony_ci	u32 flags;
2948c2ecf20Sopenharmony_ci	struct list_head mount_crypt_stat_list;
2958c2ecf20Sopenharmony_ci	struct key *global_auth_tok_key;
2968c2ecf20Sopenharmony_ci	unsigned char sig[ECRYPTFS_SIG_SIZE_HEX + 1];
2978c2ecf20Sopenharmony_ci};
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci/**
3008c2ecf20Sopenharmony_ci * ecryptfs_key_tfm - Persistent key tfm
3018c2ecf20Sopenharmony_ci * @key_tfm: crypto API handle to the key
3028c2ecf20Sopenharmony_ci * @key_size: Key size in bytes
3038c2ecf20Sopenharmony_ci * @key_tfm_mutex: Mutex to ensure only one operation in eCryptfs is
3048c2ecf20Sopenharmony_ci *                 using the persistent TFM at any point in time
3058c2ecf20Sopenharmony_ci * @key_tfm_list: Handle to hang this off the module-wide TFM list
3068c2ecf20Sopenharmony_ci * @cipher_name: String name for the cipher for this TFM
3078c2ecf20Sopenharmony_ci *
3088c2ecf20Sopenharmony_ci * Typically, eCryptfs will use the same ciphers repeatedly throughout
3098c2ecf20Sopenharmony_ci * the course of its operations. In order to avoid unnecessarily
3108c2ecf20Sopenharmony_ci * destroying and initializing the same cipher repeatedly, eCryptfs
3118c2ecf20Sopenharmony_ci * keeps a list of crypto API contexts around to use when needed.
3128c2ecf20Sopenharmony_ci */
3138c2ecf20Sopenharmony_cistruct ecryptfs_key_tfm {
3148c2ecf20Sopenharmony_ci	struct crypto_skcipher *key_tfm;
3158c2ecf20Sopenharmony_ci	size_t key_size;
3168c2ecf20Sopenharmony_ci	struct mutex key_tfm_mutex;
3178c2ecf20Sopenharmony_ci	struct list_head key_tfm_list;
3188c2ecf20Sopenharmony_ci	unsigned char cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1];
3198c2ecf20Sopenharmony_ci};
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ciextern struct mutex key_tfm_list_mutex;
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci/**
3248c2ecf20Sopenharmony_ci * This struct is to enable a mount-wide passphrase/salt combo. This
3258c2ecf20Sopenharmony_ci * is more or less a stopgap to provide similar functionality to other
3268c2ecf20Sopenharmony_ci * crypto filesystems like EncFS or CFS until full policy support is
3278c2ecf20Sopenharmony_ci * implemented in eCryptfs.
3288c2ecf20Sopenharmony_ci */
3298c2ecf20Sopenharmony_cistruct ecryptfs_mount_crypt_stat {
3308c2ecf20Sopenharmony_ci	/* Pointers to memory we do not own, do not free these */
3318c2ecf20Sopenharmony_ci#define ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED 0x00000001
3328c2ecf20Sopenharmony_ci#define ECRYPTFS_XATTR_METADATA_ENABLED        0x00000002
3338c2ecf20Sopenharmony_ci#define ECRYPTFS_ENCRYPTED_VIEW_ENABLED        0x00000004
3348c2ecf20Sopenharmony_ci#define ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED  0x00000008
3358c2ecf20Sopenharmony_ci#define ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES      0x00000010
3368c2ecf20Sopenharmony_ci#define ECRYPTFS_GLOBAL_ENCFN_USE_MOUNT_FNEK   0x00000020
3378c2ecf20Sopenharmony_ci#define ECRYPTFS_GLOBAL_ENCFN_USE_FEK          0x00000040
3388c2ecf20Sopenharmony_ci#define ECRYPTFS_GLOBAL_MOUNT_AUTH_TOK_ONLY    0x00000080
3398c2ecf20Sopenharmony_ci	u32 flags;
3408c2ecf20Sopenharmony_ci	struct list_head global_auth_tok_list;
3418c2ecf20Sopenharmony_ci	struct mutex global_auth_tok_list_mutex;
3428c2ecf20Sopenharmony_ci	size_t global_default_cipher_key_size;
3438c2ecf20Sopenharmony_ci	size_t global_default_fn_cipher_key_bytes;
3448c2ecf20Sopenharmony_ci	unsigned char global_default_cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE
3458c2ecf20Sopenharmony_ci						 + 1];
3468c2ecf20Sopenharmony_ci	unsigned char global_default_fn_cipher_name[
3478c2ecf20Sopenharmony_ci		ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1];
3488c2ecf20Sopenharmony_ci	char global_default_fnek_sig[ECRYPTFS_SIG_SIZE_HEX + 1];
3498c2ecf20Sopenharmony_ci};
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci/* superblock private data. */
3528c2ecf20Sopenharmony_cistruct ecryptfs_sb_info {
3538c2ecf20Sopenharmony_ci	struct super_block *wsi_sb;
3548c2ecf20Sopenharmony_ci	struct ecryptfs_mount_crypt_stat mount_crypt_stat;
3558c2ecf20Sopenharmony_ci};
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci/* file private data. */
3588c2ecf20Sopenharmony_cistruct ecryptfs_file_info {
3598c2ecf20Sopenharmony_ci	struct file *wfi_file;
3608c2ecf20Sopenharmony_ci	struct ecryptfs_crypt_stat *crypt_stat;
3618c2ecf20Sopenharmony_ci};
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci/* auth_tok <=> encrypted_session_key mappings */
3648c2ecf20Sopenharmony_cistruct ecryptfs_auth_tok_list_item {
3658c2ecf20Sopenharmony_ci	unsigned char encrypted_session_key[ECRYPTFS_MAX_KEY_BYTES];
3668c2ecf20Sopenharmony_ci	struct list_head list;
3678c2ecf20Sopenharmony_ci	struct ecryptfs_auth_tok auth_tok;
3688c2ecf20Sopenharmony_ci};
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_cistruct ecryptfs_message {
3718c2ecf20Sopenharmony_ci	/* Can never be greater than ecryptfs_message_buf_len */
3728c2ecf20Sopenharmony_ci	/* Used to find the parent msg_ctx */
3738c2ecf20Sopenharmony_ci	/* Inherits from msg_ctx->index */
3748c2ecf20Sopenharmony_ci	u32 index;
3758c2ecf20Sopenharmony_ci	u32 data_len;
3768c2ecf20Sopenharmony_ci	u8 data[];
3778c2ecf20Sopenharmony_ci};
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_cistruct ecryptfs_msg_ctx {
3808c2ecf20Sopenharmony_ci#define ECRYPTFS_MSG_CTX_STATE_FREE     0x01
3818c2ecf20Sopenharmony_ci#define ECRYPTFS_MSG_CTX_STATE_PENDING  0x02
3828c2ecf20Sopenharmony_ci#define ECRYPTFS_MSG_CTX_STATE_DONE     0x03
3838c2ecf20Sopenharmony_ci#define ECRYPTFS_MSG_CTX_STATE_NO_REPLY 0x04
3848c2ecf20Sopenharmony_ci	u8 state;
3858c2ecf20Sopenharmony_ci#define ECRYPTFS_MSG_HELO 100
3868c2ecf20Sopenharmony_ci#define ECRYPTFS_MSG_QUIT 101
3878c2ecf20Sopenharmony_ci#define ECRYPTFS_MSG_REQUEST 102
3888c2ecf20Sopenharmony_ci#define ECRYPTFS_MSG_RESPONSE 103
3898c2ecf20Sopenharmony_ci	u8 type;
3908c2ecf20Sopenharmony_ci	u32 index;
3918c2ecf20Sopenharmony_ci	/* Counter converts to a sequence number. Each message sent
3928c2ecf20Sopenharmony_ci	 * out for which we expect a response has an associated
3938c2ecf20Sopenharmony_ci	 * sequence number. The response must have the same sequence
3948c2ecf20Sopenharmony_ci	 * number as the counter for the msg_stc for the message to be
3958c2ecf20Sopenharmony_ci	 * valid. */
3968c2ecf20Sopenharmony_ci	u32 counter;
3978c2ecf20Sopenharmony_ci	size_t msg_size;
3988c2ecf20Sopenharmony_ci	struct ecryptfs_message *msg;
3998c2ecf20Sopenharmony_ci	struct task_struct *task;
4008c2ecf20Sopenharmony_ci	struct list_head node;
4018c2ecf20Sopenharmony_ci	struct list_head daemon_out_list;
4028c2ecf20Sopenharmony_ci	struct mutex mux;
4038c2ecf20Sopenharmony_ci};
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_cistruct ecryptfs_daemon {
4068c2ecf20Sopenharmony_ci#define ECRYPTFS_DAEMON_IN_READ      0x00000001
4078c2ecf20Sopenharmony_ci#define ECRYPTFS_DAEMON_IN_POLL      0x00000002
4088c2ecf20Sopenharmony_ci#define ECRYPTFS_DAEMON_ZOMBIE       0x00000004
4098c2ecf20Sopenharmony_ci#define ECRYPTFS_DAEMON_MISCDEV_OPEN 0x00000008
4108c2ecf20Sopenharmony_ci	u32 flags;
4118c2ecf20Sopenharmony_ci	u32 num_queued_msg_ctx;
4128c2ecf20Sopenharmony_ci	struct file *file;
4138c2ecf20Sopenharmony_ci	struct mutex mux;
4148c2ecf20Sopenharmony_ci	struct list_head msg_ctx_out_queue;
4158c2ecf20Sopenharmony_ci	wait_queue_head_t wait;
4168c2ecf20Sopenharmony_ci	struct hlist_node euid_chain;
4178c2ecf20Sopenharmony_ci};
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci#ifdef CONFIG_ECRYPT_FS_MESSAGING
4208c2ecf20Sopenharmony_ciextern struct mutex ecryptfs_daemon_hash_mux;
4218c2ecf20Sopenharmony_ci#endif
4228c2ecf20Sopenharmony_ci
4238c2ecf20Sopenharmony_cistatic inline size_t
4248c2ecf20Sopenharmony_ciecryptfs_lower_header_size(struct ecryptfs_crypt_stat *crypt_stat)
4258c2ecf20Sopenharmony_ci{
4268c2ecf20Sopenharmony_ci	if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
4278c2ecf20Sopenharmony_ci		return 0;
4288c2ecf20Sopenharmony_ci	return crypt_stat->metadata_size;
4298c2ecf20Sopenharmony_ci}
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_cistatic inline struct ecryptfs_file_info *
4328c2ecf20Sopenharmony_ciecryptfs_file_to_private(struct file *file)
4338c2ecf20Sopenharmony_ci{
4348c2ecf20Sopenharmony_ci	return file->private_data;
4358c2ecf20Sopenharmony_ci}
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_cistatic inline void
4388c2ecf20Sopenharmony_ciecryptfs_set_file_private(struct file *file,
4398c2ecf20Sopenharmony_ci			  struct ecryptfs_file_info *file_info)
4408c2ecf20Sopenharmony_ci{
4418c2ecf20Sopenharmony_ci	file->private_data = file_info;
4428c2ecf20Sopenharmony_ci}
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_cistatic inline struct file *ecryptfs_file_to_lower(struct file *file)
4458c2ecf20Sopenharmony_ci{
4468c2ecf20Sopenharmony_ci	return ((struct ecryptfs_file_info *)file->private_data)->wfi_file;
4478c2ecf20Sopenharmony_ci}
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_cistatic inline void
4508c2ecf20Sopenharmony_ciecryptfs_set_file_lower(struct file *file, struct file *lower_file)
4518c2ecf20Sopenharmony_ci{
4528c2ecf20Sopenharmony_ci	((struct ecryptfs_file_info *)file->private_data)->wfi_file =
4538c2ecf20Sopenharmony_ci		lower_file;
4548c2ecf20Sopenharmony_ci}
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_cistatic inline struct ecryptfs_inode_info *
4578c2ecf20Sopenharmony_ciecryptfs_inode_to_private(struct inode *inode)
4588c2ecf20Sopenharmony_ci{
4598c2ecf20Sopenharmony_ci	return container_of(inode, struct ecryptfs_inode_info, vfs_inode);
4608c2ecf20Sopenharmony_ci}
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_cistatic inline struct inode *ecryptfs_inode_to_lower(struct inode *inode)
4638c2ecf20Sopenharmony_ci{
4648c2ecf20Sopenharmony_ci	return ecryptfs_inode_to_private(inode)->wii_inode;
4658c2ecf20Sopenharmony_ci}
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_cistatic inline void
4688c2ecf20Sopenharmony_ciecryptfs_set_inode_lower(struct inode *inode, struct inode *lower_inode)
4698c2ecf20Sopenharmony_ci{
4708c2ecf20Sopenharmony_ci	ecryptfs_inode_to_private(inode)->wii_inode = lower_inode;
4718c2ecf20Sopenharmony_ci}
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_cistatic inline struct ecryptfs_sb_info *
4748c2ecf20Sopenharmony_ciecryptfs_superblock_to_private(struct super_block *sb)
4758c2ecf20Sopenharmony_ci{
4768c2ecf20Sopenharmony_ci	return (struct ecryptfs_sb_info *)sb->s_fs_info;
4778c2ecf20Sopenharmony_ci}
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_cistatic inline void
4808c2ecf20Sopenharmony_ciecryptfs_set_superblock_private(struct super_block *sb,
4818c2ecf20Sopenharmony_ci				struct ecryptfs_sb_info *sb_info)
4828c2ecf20Sopenharmony_ci{
4838c2ecf20Sopenharmony_ci	sb->s_fs_info = sb_info;
4848c2ecf20Sopenharmony_ci}
4858c2ecf20Sopenharmony_ci
4868c2ecf20Sopenharmony_cistatic inline struct super_block *
4878c2ecf20Sopenharmony_ciecryptfs_superblock_to_lower(struct super_block *sb)
4888c2ecf20Sopenharmony_ci{
4898c2ecf20Sopenharmony_ci	return ((struct ecryptfs_sb_info *)sb->s_fs_info)->wsi_sb;
4908c2ecf20Sopenharmony_ci}
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_cistatic inline void
4938c2ecf20Sopenharmony_ciecryptfs_set_superblock_lower(struct super_block *sb,
4948c2ecf20Sopenharmony_ci			      struct super_block *lower_sb)
4958c2ecf20Sopenharmony_ci{
4968c2ecf20Sopenharmony_ci	((struct ecryptfs_sb_info *)sb->s_fs_info)->wsi_sb = lower_sb;
4978c2ecf20Sopenharmony_ci}
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_cistatic inline struct ecryptfs_dentry_info *
5008c2ecf20Sopenharmony_ciecryptfs_dentry_to_private(struct dentry *dentry)
5018c2ecf20Sopenharmony_ci{
5028c2ecf20Sopenharmony_ci	return (struct ecryptfs_dentry_info *)dentry->d_fsdata;
5038c2ecf20Sopenharmony_ci}
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_cistatic inline void
5068c2ecf20Sopenharmony_ciecryptfs_set_dentry_private(struct dentry *dentry,
5078c2ecf20Sopenharmony_ci			    struct ecryptfs_dentry_info *dentry_info)
5088c2ecf20Sopenharmony_ci{
5098c2ecf20Sopenharmony_ci	dentry->d_fsdata = dentry_info;
5108c2ecf20Sopenharmony_ci}
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_cistatic inline struct dentry *
5138c2ecf20Sopenharmony_ciecryptfs_dentry_to_lower(struct dentry *dentry)
5148c2ecf20Sopenharmony_ci{
5158c2ecf20Sopenharmony_ci	return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.dentry;
5168c2ecf20Sopenharmony_ci}
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_cistatic inline struct vfsmount *
5198c2ecf20Sopenharmony_ciecryptfs_dentry_to_lower_mnt(struct dentry *dentry)
5208c2ecf20Sopenharmony_ci{
5218c2ecf20Sopenharmony_ci	return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.mnt;
5228c2ecf20Sopenharmony_ci}
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_cistatic inline struct path *
5258c2ecf20Sopenharmony_ciecryptfs_dentry_to_lower_path(struct dentry *dentry)
5268c2ecf20Sopenharmony_ci{
5278c2ecf20Sopenharmony_ci	return &((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path;
5288c2ecf20Sopenharmony_ci}
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_ci#define ecryptfs_printk(type, fmt, arg...) \
5318c2ecf20Sopenharmony_ci        __ecryptfs_printk(type "%s: " fmt, __func__, ## arg);
5328c2ecf20Sopenharmony_ci__printf(1, 2)
5338c2ecf20Sopenharmony_civoid __ecryptfs_printk(const char *fmt, ...);
5348c2ecf20Sopenharmony_ci
5358c2ecf20Sopenharmony_ciextern const struct file_operations ecryptfs_main_fops;
5368c2ecf20Sopenharmony_ciextern const struct file_operations ecryptfs_dir_fops;
5378c2ecf20Sopenharmony_ciextern const struct inode_operations ecryptfs_main_iops;
5388c2ecf20Sopenharmony_ciextern const struct inode_operations ecryptfs_dir_iops;
5398c2ecf20Sopenharmony_ciextern const struct inode_operations ecryptfs_symlink_iops;
5408c2ecf20Sopenharmony_ciextern const struct super_operations ecryptfs_sops;
5418c2ecf20Sopenharmony_ciextern const struct dentry_operations ecryptfs_dops;
5428c2ecf20Sopenharmony_ciextern const struct address_space_operations ecryptfs_aops;
5438c2ecf20Sopenharmony_ciextern int ecryptfs_verbosity;
5448c2ecf20Sopenharmony_ciextern unsigned int ecryptfs_message_buf_len;
5458c2ecf20Sopenharmony_ciextern signed long ecryptfs_message_wait_timeout;
5468c2ecf20Sopenharmony_ciextern unsigned int ecryptfs_number_of_users;
5478c2ecf20Sopenharmony_ci
5488c2ecf20Sopenharmony_ciextern struct kmem_cache *ecryptfs_auth_tok_list_item_cache;
5498c2ecf20Sopenharmony_ciextern struct kmem_cache *ecryptfs_file_info_cache;
5508c2ecf20Sopenharmony_ciextern struct kmem_cache *ecryptfs_dentry_info_cache;
5518c2ecf20Sopenharmony_ciextern struct kmem_cache *ecryptfs_inode_info_cache;
5528c2ecf20Sopenharmony_ciextern struct kmem_cache *ecryptfs_sb_info_cache;
5538c2ecf20Sopenharmony_ciextern struct kmem_cache *ecryptfs_header_cache;
5548c2ecf20Sopenharmony_ciextern struct kmem_cache *ecryptfs_xattr_cache;
5558c2ecf20Sopenharmony_ciextern struct kmem_cache *ecryptfs_key_record_cache;
5568c2ecf20Sopenharmony_ciextern struct kmem_cache *ecryptfs_key_sig_cache;
5578c2ecf20Sopenharmony_ciextern struct kmem_cache *ecryptfs_global_auth_tok_cache;
5588c2ecf20Sopenharmony_ciextern struct kmem_cache *ecryptfs_key_tfm_cache;
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_cistruct inode *ecryptfs_get_inode(struct inode *lower_inode,
5618c2ecf20Sopenharmony_ci				 struct super_block *sb);
5628c2ecf20Sopenharmony_civoid ecryptfs_i_size_init(const char *page_virt, struct inode *inode);
5638c2ecf20Sopenharmony_ciint ecryptfs_initialize_file(struct dentry *ecryptfs_dentry,
5648c2ecf20Sopenharmony_ci			     struct inode *ecryptfs_inode);
5658c2ecf20Sopenharmony_ciint ecryptfs_decode_and_decrypt_filename(char **decrypted_name,
5668c2ecf20Sopenharmony_ci					 size_t *decrypted_name_size,
5678c2ecf20Sopenharmony_ci					 struct super_block *sb,
5688c2ecf20Sopenharmony_ci					 const char *name, size_t name_size);
5698c2ecf20Sopenharmony_ciint ecryptfs_fill_zeros(struct file *file, loff_t new_length);
5708c2ecf20Sopenharmony_ciint ecryptfs_encrypt_and_encode_filename(
5718c2ecf20Sopenharmony_ci	char **encoded_name,
5728c2ecf20Sopenharmony_ci	size_t *encoded_name_size,
5738c2ecf20Sopenharmony_ci	struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
5748c2ecf20Sopenharmony_ci	const char *name, size_t name_size);
5758c2ecf20Sopenharmony_cistruct dentry *ecryptfs_lower_dentry(struct dentry *this_dentry);
5768c2ecf20Sopenharmony_civoid ecryptfs_dump_hex(char *data, int bytes);
5778c2ecf20Sopenharmony_ciint virt_to_scatterlist(const void *addr, int size, struct scatterlist *sg,
5788c2ecf20Sopenharmony_ci			int sg_size);
5798c2ecf20Sopenharmony_ciint ecryptfs_compute_root_iv(struct ecryptfs_crypt_stat *crypt_stat);
5808c2ecf20Sopenharmony_civoid ecryptfs_rotate_iv(unsigned char *iv);
5818c2ecf20Sopenharmony_ciint ecryptfs_init_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat);
5828c2ecf20Sopenharmony_civoid ecryptfs_destroy_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat);
5838c2ecf20Sopenharmony_civoid ecryptfs_destroy_mount_crypt_stat(
5848c2ecf20Sopenharmony_ci	struct ecryptfs_mount_crypt_stat *mount_crypt_stat);
5858c2ecf20Sopenharmony_ciint ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat);
5868c2ecf20Sopenharmony_ciint ecryptfs_write_inode_size_to_metadata(struct inode *ecryptfs_inode);
5878c2ecf20Sopenharmony_ciint ecryptfs_encrypt_page(struct page *page);
5888c2ecf20Sopenharmony_ciint ecryptfs_decrypt_page(struct page *page);
5898c2ecf20Sopenharmony_ciint ecryptfs_write_metadata(struct dentry *ecryptfs_dentry,
5908c2ecf20Sopenharmony_ci			    struct inode *ecryptfs_inode);
5918c2ecf20Sopenharmony_ciint ecryptfs_read_metadata(struct dentry *ecryptfs_dentry);
5928c2ecf20Sopenharmony_ciint ecryptfs_new_file_context(struct inode *ecryptfs_inode);
5938c2ecf20Sopenharmony_civoid ecryptfs_write_crypt_stat_flags(char *page_virt,
5948c2ecf20Sopenharmony_ci				     struct ecryptfs_crypt_stat *crypt_stat,
5958c2ecf20Sopenharmony_ci				     size_t *written);
5968c2ecf20Sopenharmony_ciint ecryptfs_read_and_validate_header_region(struct inode *inode);
5978c2ecf20Sopenharmony_ciint ecryptfs_read_and_validate_xattr_region(struct dentry *dentry,
5988c2ecf20Sopenharmony_ci					    struct inode *inode);
5998c2ecf20Sopenharmony_ciu8 ecryptfs_code_for_cipher_string(char *cipher_name, size_t key_bytes);
6008c2ecf20Sopenharmony_ciint ecryptfs_cipher_code_to_string(char *str, u8 cipher_code);
6018c2ecf20Sopenharmony_civoid ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat);
6028c2ecf20Sopenharmony_ciint ecryptfs_generate_key_packet_set(char *dest_base,
6038c2ecf20Sopenharmony_ci				     struct ecryptfs_crypt_stat *crypt_stat,
6048c2ecf20Sopenharmony_ci				     struct dentry *ecryptfs_dentry,
6058c2ecf20Sopenharmony_ci				     size_t *len, size_t max);
6068c2ecf20Sopenharmony_ciint
6078c2ecf20Sopenharmony_ciecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
6088c2ecf20Sopenharmony_ci			  unsigned char *src, struct dentry *ecryptfs_dentry);
6098c2ecf20Sopenharmony_ciint ecryptfs_truncate(struct dentry *dentry, loff_t new_length);
6108c2ecf20Sopenharmony_cissize_t
6118c2ecf20Sopenharmony_ciecryptfs_getxattr_lower(struct dentry *lower_dentry, struct inode *lower_inode,
6128c2ecf20Sopenharmony_ci			const char *name, void *value, size_t size);
6138c2ecf20Sopenharmony_ciint
6148c2ecf20Sopenharmony_ciecryptfs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
6158c2ecf20Sopenharmony_ci		  const void *value, size_t size, int flags);
6168c2ecf20Sopenharmony_ciint ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode);
6178c2ecf20Sopenharmony_ci#ifdef CONFIG_ECRYPT_FS_MESSAGING
6188c2ecf20Sopenharmony_ciint ecryptfs_process_response(struct ecryptfs_daemon *daemon,
6198c2ecf20Sopenharmony_ci			      struct ecryptfs_message *msg, u32 seq);
6208c2ecf20Sopenharmony_ciint ecryptfs_send_message(char *data, int data_len,
6218c2ecf20Sopenharmony_ci			  struct ecryptfs_msg_ctx **msg_ctx);
6228c2ecf20Sopenharmony_ciint ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx,
6238c2ecf20Sopenharmony_ci			       struct ecryptfs_message **emsg);
6248c2ecf20Sopenharmony_ciint ecryptfs_init_messaging(void);
6258c2ecf20Sopenharmony_civoid ecryptfs_release_messaging(void);
6268c2ecf20Sopenharmony_ci#else
6278c2ecf20Sopenharmony_cistatic inline int ecryptfs_init_messaging(void)
6288c2ecf20Sopenharmony_ci{
6298c2ecf20Sopenharmony_ci	return 0;
6308c2ecf20Sopenharmony_ci}
6318c2ecf20Sopenharmony_cistatic inline void ecryptfs_release_messaging(void)
6328c2ecf20Sopenharmony_ci{ }
6338c2ecf20Sopenharmony_cistatic inline int ecryptfs_send_message(char *data, int data_len,
6348c2ecf20Sopenharmony_ci					struct ecryptfs_msg_ctx **msg_ctx)
6358c2ecf20Sopenharmony_ci{
6368c2ecf20Sopenharmony_ci	return -ENOTCONN;
6378c2ecf20Sopenharmony_ci}
6388c2ecf20Sopenharmony_cistatic inline int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx,
6398c2ecf20Sopenharmony_ci					     struct ecryptfs_message **emsg)
6408c2ecf20Sopenharmony_ci{
6418c2ecf20Sopenharmony_ci	return -ENOMSG;
6428c2ecf20Sopenharmony_ci}
6438c2ecf20Sopenharmony_ci#endif
6448c2ecf20Sopenharmony_ci
6458c2ecf20Sopenharmony_civoid
6468c2ecf20Sopenharmony_ciecryptfs_write_header_metadata(char *virt,
6478c2ecf20Sopenharmony_ci			       struct ecryptfs_crypt_stat *crypt_stat,
6488c2ecf20Sopenharmony_ci			       size_t *written);
6498c2ecf20Sopenharmony_ciint ecryptfs_add_keysig(struct ecryptfs_crypt_stat *crypt_stat, char *sig);
6508c2ecf20Sopenharmony_ciint
6518c2ecf20Sopenharmony_ciecryptfs_add_global_auth_tok(struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
6528c2ecf20Sopenharmony_ci			   char *sig, u32 global_auth_tok_flags);
6538c2ecf20Sopenharmony_ciint ecryptfs_get_global_auth_tok_for_sig(
6548c2ecf20Sopenharmony_ci	struct ecryptfs_global_auth_tok **global_auth_tok,
6558c2ecf20Sopenharmony_ci	struct ecryptfs_mount_crypt_stat *mount_crypt_stat, char *sig);
6568c2ecf20Sopenharmony_ciint
6578c2ecf20Sopenharmony_ciecryptfs_add_new_key_tfm(struct ecryptfs_key_tfm **key_tfm, char *cipher_name,
6588c2ecf20Sopenharmony_ci			 size_t key_size);
6598c2ecf20Sopenharmony_ciint ecryptfs_init_crypto(void);
6608c2ecf20Sopenharmony_ciint ecryptfs_destroy_crypto(void);
6618c2ecf20Sopenharmony_ciint ecryptfs_tfm_exists(char *cipher_name, struct ecryptfs_key_tfm **key_tfm);
6628c2ecf20Sopenharmony_ciint ecryptfs_get_tfm_and_mutex_for_cipher_name(struct crypto_skcipher **tfm,
6638c2ecf20Sopenharmony_ci					       struct mutex **tfm_mutex,
6648c2ecf20Sopenharmony_ci					       char *cipher_name);
6658c2ecf20Sopenharmony_ciint ecryptfs_keyring_auth_tok_for_sig(struct key **auth_tok_key,
6668c2ecf20Sopenharmony_ci				      struct ecryptfs_auth_tok **auth_tok,
6678c2ecf20Sopenharmony_ci				      char *sig);
6688c2ecf20Sopenharmony_ciint ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
6698c2ecf20Sopenharmony_ci			 loff_t offset, size_t size);
6708c2ecf20Sopenharmony_ciint ecryptfs_write_lower_page_segment(struct inode *ecryptfs_inode,
6718c2ecf20Sopenharmony_ci				      struct page *page_for_lower,
6728c2ecf20Sopenharmony_ci				      size_t offset_in_page, size_t size);
6738c2ecf20Sopenharmony_ciint ecryptfs_write(struct inode *inode, char *data, loff_t offset, size_t size);
6748c2ecf20Sopenharmony_ciint ecryptfs_read_lower(char *data, loff_t offset, size_t size,
6758c2ecf20Sopenharmony_ci			struct inode *ecryptfs_inode);
6768c2ecf20Sopenharmony_ciint ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs,
6778c2ecf20Sopenharmony_ci				     pgoff_t page_index,
6788c2ecf20Sopenharmony_ci				     size_t offset_in_page, size_t size,
6798c2ecf20Sopenharmony_ci				     struct inode *ecryptfs_inode);
6808c2ecf20Sopenharmony_cistruct page *ecryptfs_get_locked_page(struct inode *inode, loff_t index);
6818c2ecf20Sopenharmony_ciint ecryptfs_parse_packet_length(unsigned char *data, size_t *size,
6828c2ecf20Sopenharmony_ci				 size_t *length_size);
6838c2ecf20Sopenharmony_ciint ecryptfs_write_packet_length(char *dest, size_t size,
6848c2ecf20Sopenharmony_ci				 size_t *packet_size_length);
6858c2ecf20Sopenharmony_ci#ifdef CONFIG_ECRYPT_FS_MESSAGING
6868c2ecf20Sopenharmony_ciint ecryptfs_init_ecryptfs_miscdev(void);
6878c2ecf20Sopenharmony_civoid ecryptfs_destroy_ecryptfs_miscdev(void);
6888c2ecf20Sopenharmony_ciint ecryptfs_send_miscdev(char *data, size_t data_size,
6898c2ecf20Sopenharmony_ci			  struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type,
6908c2ecf20Sopenharmony_ci			  u16 msg_flags, struct ecryptfs_daemon *daemon);
6918c2ecf20Sopenharmony_civoid ecryptfs_msg_ctx_alloc_to_free(struct ecryptfs_msg_ctx *msg_ctx);
6928c2ecf20Sopenharmony_ciint
6938c2ecf20Sopenharmony_ciecryptfs_spawn_daemon(struct ecryptfs_daemon **daemon, struct file *file);
6948c2ecf20Sopenharmony_ciint ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon);
6958c2ecf20Sopenharmony_ciint ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon);
6968c2ecf20Sopenharmony_ci#endif
6978c2ecf20Sopenharmony_ciint ecryptfs_init_kthread(void);
6988c2ecf20Sopenharmony_civoid ecryptfs_destroy_kthread(void);
6998c2ecf20Sopenharmony_ciint ecryptfs_privileged_open(struct file **lower_file,
7008c2ecf20Sopenharmony_ci			     struct dentry *lower_dentry,
7018c2ecf20Sopenharmony_ci			     struct vfsmount *lower_mnt,
7028c2ecf20Sopenharmony_ci			     const struct cred *cred);
7038c2ecf20Sopenharmony_ciint ecryptfs_get_lower_file(struct dentry *dentry, struct inode *inode);
7048c2ecf20Sopenharmony_civoid ecryptfs_put_lower_file(struct inode *inode);
7058c2ecf20Sopenharmony_ciint
7068c2ecf20Sopenharmony_ciecryptfs_write_tag_70_packet(char *dest, size_t *remaining_bytes,
7078c2ecf20Sopenharmony_ci			     size_t *packet_size,
7088c2ecf20Sopenharmony_ci			     struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
7098c2ecf20Sopenharmony_ci			     char *filename, size_t filename_size);
7108c2ecf20Sopenharmony_ciint
7118c2ecf20Sopenharmony_ciecryptfs_parse_tag_70_packet(char **filename, size_t *filename_size,
7128c2ecf20Sopenharmony_ci			     size_t *packet_size,
7138c2ecf20Sopenharmony_ci			     struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
7148c2ecf20Sopenharmony_ci			     char *data, size_t max_packet_size);
7158c2ecf20Sopenharmony_ciint ecryptfs_set_f_namelen(long *namelen, long lower_namelen,
7168c2ecf20Sopenharmony_ci			   struct ecryptfs_mount_crypt_stat *mount_crypt_stat);
7178c2ecf20Sopenharmony_ciint ecryptfs_derive_iv(char *iv, struct ecryptfs_crypt_stat *crypt_stat,
7188c2ecf20Sopenharmony_ci		       loff_t offset);
7198c2ecf20Sopenharmony_ci
7208c2ecf20Sopenharmony_ciextern const struct xattr_handler *ecryptfs_xattr_handlers[];
7218c2ecf20Sopenharmony_ci
7228c2ecf20Sopenharmony_ci#endif /* #ifndef ECRYPTFS_KERNEL_H */
723