aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/crypto/crypto.c2
-rw-r--r--fs/crypto/fscrypt_private.h71
-rw-r--r--fs/crypto/policy.c2
-rw-r--r--include/linux/fscrypto.h68
4 files changed, 76 insertions, 67 deletions
diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c
index 56f98f45cece..4d9d221b1d60 100644
--- a/fs/crypto/crypto.c
+++ b/fs/crypto/crypto.c
@@ -27,7 +27,7 @@
27#include <linux/bio.h> 27#include <linux/bio.h>
28#include <linux/dcache.h> 28#include <linux/dcache.h>
29#include <linux/namei.h> 29#include <linux/namei.h>
30#include <linux/fscrypto.h> 30#include "fscrypt_private.h"
31 31
32static unsigned int num_prealloc_crypto_pages = 32; 32static unsigned int num_prealloc_crypto_pages = 32;
33static unsigned int num_prealloc_crypto_ctxs = 128; 33static unsigned int num_prealloc_crypto_ctxs = 128;
diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h
index bb92f0c0961b..c98b2a7fb6d3 100644
--- a/fs/crypto/fscrypt_private.h
+++ b/fs/crypto/fscrypt_private.h
@@ -13,6 +13,77 @@
13 13
14#include <linux/fscrypto.h> 14#include <linux/fscrypto.h>
15 15
16#define FS_FNAME_CRYPTO_DIGEST_SIZE 32
17
18/* Encryption parameters */
19#define FS_XTS_TWEAK_SIZE 16
20#define FS_AES_128_ECB_KEY_SIZE 16
21#define FS_AES_256_GCM_KEY_SIZE 32
22#define FS_AES_256_CBC_KEY_SIZE 32
23#define FS_AES_256_CTS_KEY_SIZE 32
24#define FS_AES_256_XTS_KEY_SIZE 64
25#define FS_MAX_KEY_SIZE 64
26
27#define FS_KEY_DESC_PREFIX "fscrypt:"
28#define FS_KEY_DESC_PREFIX_SIZE 8
29
30#define FS_KEY_DERIVATION_NONCE_SIZE 16
31
32/**
33 * Encryption context for inode
34 *
35 * Protector format:
36 * 1 byte: Protector format (1 = this version)
37 * 1 byte: File contents encryption mode
38 * 1 byte: File names encryption mode
39 * 1 byte: Flags
40 * 8 bytes: Master Key descriptor
41 * 16 bytes: Encryption Key derivation nonce
42 */
43struct fscrypt_context {
44 u8 format;
45 u8 contents_encryption_mode;
46 u8 filenames_encryption_mode;
47 u8 flags;
48 u8 master_key_descriptor[FS_KEY_DESCRIPTOR_SIZE];
49 u8 nonce[FS_KEY_DERIVATION_NONCE_SIZE];
50} __packed;
51
52#define FS_ENCRYPTION_CONTEXT_FORMAT_V1 1
53
54/* This is passed in from userspace into the kernel keyring */
55struct fscrypt_key {
56 u32 mode;
57 u8 raw[FS_MAX_KEY_SIZE];
58 u32 size;
59} __packed;
60
61/*
62 * A pointer to this structure is stored in the file system's in-core
63 * representation of an inode.
64 */
65struct fscrypt_info {
66 u8 ci_data_mode;
67 u8 ci_filename_mode;
68 u8 ci_flags;
69 struct crypto_skcipher *ci_ctfm;
70 struct key *ci_keyring_key;
71 u8 ci_master_key[FS_KEY_DESCRIPTOR_SIZE];
72};
73
74#define FS_CTX_REQUIRES_FREE_ENCRYPT_FL 0x00000001
75#define FS_WRITE_PATH_FL 0x00000002
76
77struct fscrypt_completion_result {
78 struct completion completion;
79 int res;
80};
81
82#define DECLARE_FS_COMPLETION_RESULT(ecr) \
83 struct fscrypt_completion_result ecr = { \
84 COMPLETION_INITIALIZER((ecr).completion), 0 }
85
86
16/* crypto.c */ 87/* crypto.c */
17int fscrypt_initialize(void); 88int fscrypt_initialize(void);
18 89
diff --git a/fs/crypto/policy.c b/fs/crypto/policy.c
index b96a10e3cf78..6ed7c2eebeec 100644
--- a/fs/crypto/policy.c
+++ b/fs/crypto/policy.c
@@ -10,8 +10,8 @@
10 10
11#include <linux/random.h> 11#include <linux/random.h>
12#include <linux/string.h> 12#include <linux/string.h>
13#include <linux/fscrypto.h>
14#include <linux/mount.h> 13#include <linux/mount.h>
14#include "fscrypt_private.h"
15 15
16static int inode_has_encryption_context(struct inode *inode) 16static int inode_has_encryption_context(struct inode *inode)
17{ 17{
diff --git a/include/linux/fscrypto.h b/include/linux/fscrypto.h
index ce2ebdee6a89..71e8a20711ec 100644
--- a/include/linux/fscrypto.h
+++ b/include/linux/fscrypto.h
@@ -18,9 +18,6 @@
18#include <crypto/skcipher.h> 18#include <crypto/skcipher.h>
19#include <uapi/linux/fs.h> 19#include <uapi/linux/fs.h>
20 20
21#define FS_KEY_DERIVATION_NONCE_SIZE 16
22#define FS_ENCRYPTION_CONTEXT_FORMAT_V1 1
23
24#define FS_POLICY_FLAGS_PAD_4 0x00 21#define FS_POLICY_FLAGS_PAD_4 0x00
25#define FS_POLICY_FLAGS_PAD_8 0x01 22#define FS_POLICY_FLAGS_PAD_8 0x01
26#define FS_POLICY_FLAGS_PAD_16 0x02 23#define FS_POLICY_FLAGS_PAD_16 0x02
@@ -35,56 +32,10 @@
35#define FS_ENCRYPTION_MODE_AES_256_CBC 3 32#define FS_ENCRYPTION_MODE_AES_256_CBC 3
36#define FS_ENCRYPTION_MODE_AES_256_CTS 4 33#define FS_ENCRYPTION_MODE_AES_256_CTS 4
37 34
38/** 35#define FS_CRYPTO_BLOCK_SIZE 16
39 * Encryption context for inode
40 *
41 * Protector format:
42 * 1 byte: Protector format (1 = this version)
43 * 1 byte: File contents encryption mode
44 * 1 byte: File names encryption mode
45 * 1 byte: Flags
46 * 8 bytes: Master Key descriptor
47 * 16 bytes: Encryption Key derivation nonce
48 */
49struct fscrypt_context {
50 u8 format;
51 u8 contents_encryption_mode;
52 u8 filenames_encryption_mode;
53 u8 flags;
54 u8 master_key_descriptor[FS_KEY_DESCRIPTOR_SIZE];
55 u8 nonce[FS_KEY_DERIVATION_NONCE_SIZE];
56} __packed;
57
58/* Encryption parameters */
59#define FS_XTS_TWEAK_SIZE 16
60#define FS_AES_128_ECB_KEY_SIZE 16
61#define FS_AES_256_GCM_KEY_SIZE 32
62#define FS_AES_256_CBC_KEY_SIZE 32
63#define FS_AES_256_CTS_KEY_SIZE 32
64#define FS_AES_256_XTS_KEY_SIZE 64
65#define FS_MAX_KEY_SIZE 64
66
67#define FS_KEY_DESC_PREFIX "fscrypt:"
68#define FS_KEY_DESC_PREFIX_SIZE 8
69
70/* This is passed in from userspace into the kernel keyring */
71struct fscrypt_key {
72 u32 mode;
73 u8 raw[FS_MAX_KEY_SIZE];
74 u32 size;
75} __packed;
76
77struct fscrypt_info {
78 u8 ci_data_mode;
79 u8 ci_filename_mode;
80 u8 ci_flags;
81 struct crypto_skcipher *ci_ctfm;
82 struct key *ci_keyring_key;
83 u8 ci_master_key[FS_KEY_DESCRIPTOR_SIZE];
84};
85 36
86#define FS_CTX_REQUIRES_FREE_ENCRYPT_FL 0x00000001 37struct fscrypt_info;
87#define FS_WRITE_PATH_FL 0x00000002 38struct fscrypt_ctx;
88 39
89struct fscrypt_ctx { 40struct fscrypt_ctx {
90 union { 41 union {
@@ -102,19 +53,6 @@ struct fscrypt_ctx {
102 u8 mode; /* Encryption mode for tfm */ 53 u8 mode; /* Encryption mode for tfm */
103}; 54};
104 55
105struct fscrypt_completion_result {
106 struct completion completion;
107 int res;
108};
109
110#define DECLARE_FS_COMPLETION_RESULT(ecr) \
111 struct fscrypt_completion_result ecr = { \
112 COMPLETION_INITIALIZER((ecr).completion), 0 }
113
114#define FS_FNAME_NUM_SCATTER_ENTRIES 4
115#define FS_CRYPTO_BLOCK_SIZE 16
116#define FS_FNAME_CRYPTO_DIGEST_SIZE 32
117
118/** 56/**
119 * For encrypted symlinks, the ciphertext length is stored at the beginning 57 * For encrypted symlinks, the ciphertext length is stored at the beginning
120 * of the string in little-endian format. 58 * of the string in little-endian format.