aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2018-04-30 18:51:46 -0400
committerTheodore Ts'o <tytso@mit.edu>2018-05-20 16:21:04 -0400
commit11b8818ec09d577567f59fc1b32cfa56c756fe89 (patch)
tree297fcf6b65f411969f3546bcd3ed310096dab5c5
parent1086c80c4d9144ff32741ddbca2fbb268a5de5f5 (diff)
fscrypt: remove internal key size constants
With one exception, the internal key size constants such as FS_AES_256_XTS_KEY_SIZE are only used for the 'available_modes' array, where they really only serve to obfuscate what the values are. Also some of the constants are unused, and the key sizes tend to be in the names of the algorithms anyway. In the past these values were also misused, e.g. we used to have FS_AES_256_XTS_KEY_SIZE in places that technically should have been FS_MAX_KEY_SIZE. The exception is that FS_AES_128_ECB_KEY_SIZE is used for key derivation. But it's more appropriate to use FS_KEY_DERIVATION_NONCE_SIZE for that instead. Thus, just put the sizes directly in the 'available_modes' array. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--fs/crypto/fscrypt_private.h10
-rw-r--r--fs/crypto/keyinfo.c17
2 files changed, 7 insertions, 20 deletions
diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h
index fb96e493167b..8358610d6558 100644
--- a/fs/crypto/fscrypt_private.h
+++ b/fs/crypto/fscrypt_private.h
@@ -18,15 +18,7 @@
18 18
19/* Encryption parameters */ 19/* Encryption parameters */
20#define FS_IV_SIZE 16 20#define FS_IV_SIZE 16
21#define FS_AES_128_ECB_KEY_SIZE 16 21#define FS_KEY_DERIVATION_NONCE_SIZE 16
22#define FS_AES_128_CBC_KEY_SIZE 16
23#define FS_AES_128_CTS_KEY_SIZE 16
24#define FS_AES_256_GCM_KEY_SIZE 32
25#define FS_AES_256_CBC_KEY_SIZE 32
26#define FS_AES_256_CTS_KEY_SIZE 32
27#define FS_AES_256_XTS_KEY_SIZE 64
28
29#define FS_KEY_DERIVATION_NONCE_SIZE 16
30 22
31/** 23/**
32 * Encryption context for inode 24 * Encryption context for inode
diff --git a/fs/crypto/keyinfo.c b/fs/crypto/keyinfo.c
index 0b48aa469453..f6d6acd37b97 100644
--- a/fs/crypto/keyinfo.c
+++ b/fs/crypto/keyinfo.c
@@ -27,7 +27,7 @@ static struct crypto_shash *essiv_hash_tfm;
27 * 27 *
28 * Return: Zero on success; non-zero otherwise. 28 * Return: Zero on success; non-zero otherwise.
29 */ 29 */
30static int derive_key_aes(u8 deriving_key[FS_AES_128_ECB_KEY_SIZE], 30static int derive_key_aes(u8 deriving_key[FS_KEY_DERIVATION_NONCE_SIZE],
31 const struct fscrypt_key *source_key, 31 const struct fscrypt_key *source_key,
32 u8 derived_raw_key[FS_MAX_KEY_SIZE]) 32 u8 derived_raw_key[FS_MAX_KEY_SIZE])
33{ 33{
@@ -52,7 +52,7 @@ static int derive_key_aes(u8 deriving_key[FS_AES_128_ECB_KEY_SIZE],
52 CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, 52 CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
53 crypto_req_done, &wait); 53 crypto_req_done, &wait);
54 res = crypto_skcipher_setkey(tfm, deriving_key, 54 res = crypto_skcipher_setkey(tfm, deriving_key,
55 FS_AES_128_ECB_KEY_SIZE); 55 FS_KEY_DERIVATION_NONCE_SIZE);
56 if (res < 0) 56 if (res < 0)
57 goto out; 57 goto out;
58 58
@@ -100,7 +100,6 @@ static int validate_user_key(struct fscrypt_info *crypt_info,
100 goto out; 100 goto out;
101 } 101 }
102 master_key = (struct fscrypt_key *)ukp->data; 102 master_key = (struct fscrypt_key *)ukp->data;
103 BUILD_BUG_ON(FS_AES_128_ECB_KEY_SIZE != FS_KEY_DERIVATION_NONCE_SIZE);
104 103
105 if (master_key->size < min_keysize || master_key->size > FS_MAX_KEY_SIZE 104 if (master_key->size < min_keysize || master_key->size > FS_MAX_KEY_SIZE
106 || master_key->size % AES_BLOCK_SIZE != 0) { 105 || master_key->size % AES_BLOCK_SIZE != 0) {
@@ -121,14 +120,10 @@ static const struct {
121 const char *cipher_str; 120 const char *cipher_str;
122 int keysize; 121 int keysize;
123} available_modes[] = { 122} available_modes[] = {
124 [FS_ENCRYPTION_MODE_AES_256_XTS] = { "xts(aes)", 123 [FS_ENCRYPTION_MODE_AES_256_XTS] = { "xts(aes)", 64 },
125 FS_AES_256_XTS_KEY_SIZE }, 124 [FS_ENCRYPTION_MODE_AES_256_CTS] = { "cts(cbc(aes))", 32 },
126 [FS_ENCRYPTION_MODE_AES_256_CTS] = { "cts(cbc(aes))", 125 [FS_ENCRYPTION_MODE_AES_128_CBC] = { "cbc(aes)", 16 },
127 FS_AES_256_CTS_KEY_SIZE }, 126 [FS_ENCRYPTION_MODE_AES_128_CTS] = { "cts(cbc(aes))", 16 },
128 [FS_ENCRYPTION_MODE_AES_128_CBC] = { "cbc(aes)",
129 FS_AES_128_CBC_KEY_SIZE },
130 [FS_ENCRYPTION_MODE_AES_128_CTS] = { "cts(cbc(aes))",
131 FS_AES_128_CTS_KEY_SIZE },
132}; 127};
133 128
134static int determine_cipher_type(struct fscrypt_info *ci, struct inode *inode, 129static int determine_cipher_type(struct fscrypt_info *ci, struct inode *inode,