ocfs2: fix locking for res->tracking and dlm->tracking_list
[linux/fpc-iii.git] / fs / f2fs / f2fs_crypto.h
blobf113f1a1e8c1047dfdf0b80aa20e7781617fe633
1 /*
2 * linux/fs/f2fs/f2fs_crypto.h
4 * Copied from linux/fs/ext4/ext4_crypto.h
6 * Copyright (C) 2015, Google, Inc.
8 * This contains encryption header content for f2fs
10 * Written by Michael Halcrow, 2015.
11 * Modified by Jaegeuk Kim, 2015.
13 #ifndef _F2FS_CRYPTO_H
14 #define _F2FS_CRYPTO_H
16 #include <linux/fs.h>
18 #define F2FS_KEY_DESCRIPTOR_SIZE 8
20 /* Policy provided via an ioctl on the topmost directory */
21 struct f2fs_encryption_policy {
22 char version;
23 char contents_encryption_mode;
24 char filenames_encryption_mode;
25 char flags;
26 char master_key_descriptor[F2FS_KEY_DESCRIPTOR_SIZE];
27 } __attribute__((__packed__));
29 #define F2FS_ENCRYPTION_CONTEXT_FORMAT_V1 1
30 #define F2FS_KEY_DERIVATION_NONCE_SIZE 16
32 #define F2FS_POLICY_FLAGS_PAD_4 0x00
33 #define F2FS_POLICY_FLAGS_PAD_8 0x01
34 #define F2FS_POLICY_FLAGS_PAD_16 0x02
35 #define F2FS_POLICY_FLAGS_PAD_32 0x03
36 #define F2FS_POLICY_FLAGS_PAD_MASK 0x03
37 #define F2FS_POLICY_FLAGS_VALID 0x03
39 /**
40 * Encryption context for inode
42 * Protector format:
43 * 1 byte: Protector format (1 = this version)
44 * 1 byte: File contents encryption mode
45 * 1 byte: File names encryption mode
46 * 1 byte: Flags
47 * 8 bytes: Master Key descriptor
48 * 16 bytes: Encryption Key derivation nonce
50 struct f2fs_encryption_context {
51 char format;
52 char contents_encryption_mode;
53 char filenames_encryption_mode;
54 char flags;
55 char master_key_descriptor[F2FS_KEY_DESCRIPTOR_SIZE];
56 char nonce[F2FS_KEY_DERIVATION_NONCE_SIZE];
57 } __attribute__((__packed__));
59 /* Encryption parameters */
60 #define F2FS_XTS_TWEAK_SIZE 16
61 #define F2FS_AES_128_ECB_KEY_SIZE 16
62 #define F2FS_AES_256_GCM_KEY_SIZE 32
63 #define F2FS_AES_256_CBC_KEY_SIZE 32
64 #define F2FS_AES_256_CTS_KEY_SIZE 32
65 #define F2FS_AES_256_XTS_KEY_SIZE 64
66 #define F2FS_MAX_KEY_SIZE 64
68 #define F2FS_KEY_DESC_PREFIX "f2fs:"
69 #define F2FS_KEY_DESC_PREFIX_SIZE 5
71 struct f2fs_encryption_key {
72 __u32 mode;
73 char raw[F2FS_MAX_KEY_SIZE];
74 __u32 size;
75 } __attribute__((__packed__));
77 struct f2fs_crypt_info {
78 char ci_data_mode;
79 char ci_filename_mode;
80 char ci_flags;
81 struct crypto_ablkcipher *ci_ctfm;
82 char ci_master_key[F2FS_KEY_DESCRIPTOR_SIZE];
85 #define F2FS_CTX_REQUIRES_FREE_ENCRYPT_FL 0x00000001
86 #define F2FS_WRITE_PATH_FL 0x00000002
88 struct f2fs_crypto_ctx {
89 union {
90 struct {
91 struct page *bounce_page; /* Ciphertext page */
92 struct page *control_page; /* Original page */
93 } w;
94 struct {
95 struct bio *bio;
96 struct work_struct work;
97 } r;
98 struct list_head free_list; /* Free list */
100 char flags; /* Flags */
103 struct f2fs_completion_result {
104 struct completion completion;
105 int res;
108 #define DECLARE_F2FS_COMPLETION_RESULT(ecr) \
109 struct f2fs_completion_result ecr = { \
110 COMPLETION_INITIALIZER((ecr).completion), 0 }
112 static inline int f2fs_encryption_key_size(int mode)
114 switch (mode) {
115 case F2FS_ENCRYPTION_MODE_AES_256_XTS:
116 return F2FS_AES_256_XTS_KEY_SIZE;
117 case F2FS_ENCRYPTION_MODE_AES_256_GCM:
118 return F2FS_AES_256_GCM_KEY_SIZE;
119 case F2FS_ENCRYPTION_MODE_AES_256_CBC:
120 return F2FS_AES_256_CBC_KEY_SIZE;
121 case F2FS_ENCRYPTION_MODE_AES_256_CTS:
122 return F2FS_AES_256_CTS_KEY_SIZE;
123 default:
124 BUG();
126 return 0;
129 #define F2FS_FNAME_NUM_SCATTER_ENTRIES 4
130 #define F2FS_CRYPTO_BLOCK_SIZE 16
131 #define F2FS_FNAME_CRYPTO_DIGEST_SIZE 32
134 * For encrypted symlinks, the ciphertext length is stored at the beginning
135 * of the string in little-endian format.
137 struct f2fs_encrypted_symlink_data {
138 __le16 len;
139 char encrypted_path[1];
140 } __attribute__((__packed__));
143 * This function is used to calculate the disk space required to
144 * store a filename of length l in encrypted symlink format.
146 static inline u32 encrypted_symlink_data_len(u32 l)
148 return (l + sizeof(struct f2fs_encrypted_symlink_data) - 1);
150 #endif /* _F2FS_CRYPTO_H */