eCryptfs: Add mount option for cipher mode
RFC 1/2 eCryptfs: Add mount option for cipher mode
This patch removes the hardcoding of CBC mode in eCryptfs and adds a mount option allowing one to specify the desired mode of operation. Currently this defaults to CBC, but should work with any plain block cipher mode supported by the kernel.
Signed-off-by Alvin Tran <[email protected]>
Signed-off-by Michael Chang <[email protected]>
Signed-off-by William Morrison <[email protected]>
Signed-off-by Zameer Manji <[email protected]>
--- fs/ecryptfs/crypto.c | 16 ++++++++++++--- fs/ecryptfs/ecryptfs_kernel.h | 5 +++++ fs/ecryptfs/main.c | 44 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 3 deletions(-)
fs/ecryptfs/crypto.c +13 -3
@@ -624,7 +624,8 @@ int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat) }mutex_lock (&crypt_stat->cs_tfm_mutex); rc =ecryptfs_crypto_api_algify_cipher_name (&full_alg_name, - crypt_stat->cipher,"cbc" ); + crypt_stat->cipher, + crypt_stat->cipher_mode);if (rc) goto out_unlock; crypt_stat->tfm =crypto_alloc_ablkcipher (full_alg_name,0 ,0 );
@@ -633,8 +634,9 @@ int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat) rc =PTR_ERR (crypt_stat->tfm); crypt_stat->tfm =NULL ;ecryptfs_printk (KERN_ERR ,"cryptfs: init_crypt_ctx(): " -"Error initializing cipher [%s]\n" , - crypt_stat->cipher); +"Error initializing cipher [%s] and mode [%s]\n" , + crypt_stat->cipher, + crypt_stat->cipher_mode); goto out_unlock; }crypto_ablkcipher_set_flags (crypt_stat->tfm,CRYPTO_TFM_REQ_WEAK_KEY );
@@ -796,6 +798,7 @@ static void ecryptfs_set_default_crypt_stat_vals( mount_crypt_stat);ecryptfs_set_default_sizes (crypt_stat);strcpy (crypt_stat->cipher,ECRYPTFS_DEFAULT_CIPHER ); +strcpy (crypt_stat->cipher_mode,ECRYPTFS_DEFAULT_CIPHER_MODE ); crypt_stat->key_size =ECRYPTFS_DEFAULT_KEY_BYTES ; crypt_stat->flags &= ~(ECRYPTFS_KEY_VALID ); crypt_stat->file_version =ECRYPTFS_FILE_VERSION ;
@@ -829,6 +832,7 @@ int ecryptfs_new_file_context(struct inode *ecryptfs_inode) &ecryptfs_superblock_to_private ( ecryptfs_inode->i_sb)->mount_crypt_stat;int cipher_name_len; +int cipher_mode_name_len;int rc =0 ;ecryptfs_set_default_crypt_stat_vals (crypt_stat, mount_crypt_stat);
@@ -848,6 +852,12 @@ int ecryptfs_new_file_context(struct inode *ecryptfs_inode) mount_crypt_stat->global_default_cipher_name, cipher_name_len); crypt_stat->cipher[cipher_name_len] ='\0' ; + cipher_mode_name_len = +strlen (mount_crypt_stat->global_default_cipher_mode_name); +memcpy (crypt_stat->cipher_mode, + mount_crypt_stat->global_default_cipher_mode_name, + cipher_mode_name_len); + crypt_stat->cipher_mode[cipher_mode_name_len] ='\0' ; crypt_stat->key_size = mount_crypt_stat->global_default_cipher_key_size;ecryptfs_generate_new_key (crypt_stat);
fs/ecryptfs/ecryptfs_kernel.h +5 -0
@@ -125,6 +125,7 @@ ecryptfs_get_key_payload_data(struct key *key)#define ECRYPTFS_MAX_KEYSET_SIZE 1024#define ECRYPTFS_MAX_CIPHER_NAME_SIZE 32 +#define ECRYPTFS_MAX_CIPHER_MODE_NAME_SIZE 32#define ECRYPTFS_MAX_NUM_ENC_KEYS 64#define ECRYPTFS_MAX_IV_BYTES 16/* 128 bits */ #define ECRYPTFS_SALT_BYTES 2
@@ -134,6 +135,7 @@ ecryptfs_get_key_payload_data(struct key *key)#define ECRYPTFS_SIZE_AND_MARKER_BYTES (ECRYPTFS_FILE_SIZE_BYTES \ + MAGIC_ECRYPTFS_MARKER_SIZE_BYTES)#define ECRYPTFS_DEFAULT_CIPHER "aes" +#define ECRYPTFS_DEFAULT_CIPHER_MODE "cbc"#define ECRYPTFS_DEFAULT_KEY_BYTES 16#define ECRYPTFS_DEFAULT_HASH "md5"#define ECRYPTFS_TAG_70_DIGEST ECRYPTFS_DEFAULT_HASH
@@ -238,6 +240,7 @@ struct ecryptfs_crypt_stat {struct crypto_hash *hash_tfm;/* Crypto context for generating * the initialization vectors */ unsigned char cipher[ECRYPTFS_MAX_CIPHER_NAME_SIZE ]; +unsigned char cipher_mode[ECRYPTFS_MAX_CIPHER_MODE_NAME_SIZE ];unsigned char key[ECRYPTFS_MAX_KEY_BYTES ];unsigned char root_iv[ECRYPTFS_MAX_IV_BYTES ];struct list_head keysig_list;
@@ -339,6 +342,8 @@ struct ecryptfs_mount_crypt_stat {size_t global_default_fn_cipher_key_bytes;unsigned char global_default_cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE +1 ]; +unsigned char global_default_cipher_mode_name[ +ECRYPTFS_MAX_CIPHER_MODE_NAME_SIZE +1 ];unsigned char global_default_fn_cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE +1 ];char global_default_fnek_sig[ECRYPTFS_SIG_SIZE_HEX +1 ];
fs/ecryptfs/main.c +43 -0
89 lines not on this page · raw message
Signature · 1 line
1.7.10.4