aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/ecryptfs/crypto.c36
-rw-r--r--fs/ecryptfs/ecryptfs_kernel.h7
2 files changed, 25 insertions, 18 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index 82e7d02cefae..f14c5a38215e 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -94,25 +94,31 @@ static int ecryptfs_calculate_md5(char *dst,
94 struct ecryptfs_crypt_stat *crypt_stat, 94 struct ecryptfs_crypt_stat *crypt_stat,
95 char *src, int len) 95 char *src, int len)
96{ 96{
97 int rc = 0;
98 struct scatterlist sg; 97 struct scatterlist sg;
98 struct hash_desc desc = {
99 .tfm = crypt_stat->hash_tfm,
100 .flags = CRYPTO_TFM_REQ_MAY_SLEEP
101 };
102 int rc = 0;
99 103
100 mutex_lock(&crypt_stat->cs_md5_tfm_mutex); 104 mutex_lock(&crypt_stat->cs_hash_tfm_mutex);
101 sg_init_one(&sg, (u8 *)src, len); 105 sg_init_one(&sg, (u8 *)src, len);
102 if (!crypt_stat->md5_tfm) { 106 if (!desc.tfm) {
103 crypt_stat->md5_tfm = 107 desc.tfm = crypto_alloc_hash(ECRYPTFS_DEFAULT_HASH, 0,
104 crypto_alloc_tfm("md5", CRYPTO_TFM_REQ_MAY_SLEEP); 108 CRYPTO_ALG_ASYNC);
105 if (!crypt_stat->md5_tfm) { 109 if (IS_ERR(desc.tfm)) {
106 rc = -ENOMEM; 110 rc = PTR_ERR(desc.tfm);
107 ecryptfs_printk(KERN_ERR, "Error attempting to " 111 ecryptfs_printk(KERN_ERR, "Error attempting to "
108 "allocate crypto context\n"); 112 "allocate crypto context; rc = [%d]\n",
113 rc);
109 goto out; 114 goto out;
110 } 115 }
116 crypt_stat->hash_tfm = desc.tfm;
111 } 117 }
112 crypto_digest_init(crypt_stat->md5_tfm); 118 crypto_hash_init(&desc);
113 crypto_digest_update(crypt_stat->md5_tfm, &sg, 1); 119 crypto_hash_update(&desc, &sg, len);
114 crypto_digest_final(crypt_stat->md5_tfm, dst); 120 crypto_hash_final(&desc, dst);
115 mutex_unlock(&crypt_stat->cs_md5_tfm_mutex); 121 mutex_unlock(&crypt_stat->cs_hash_tfm_mutex);
116out: 122out:
117 return rc; 123 return rc;
118} 124}
@@ -178,7 +184,7 @@ ecryptfs_init_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat)
178 memset((void *)crypt_stat, 0, sizeof(struct ecryptfs_crypt_stat)); 184 memset((void *)crypt_stat, 0, sizeof(struct ecryptfs_crypt_stat));
179 mutex_init(&crypt_stat->cs_mutex); 185 mutex_init(&crypt_stat->cs_mutex);
180 mutex_init(&crypt_stat->cs_tfm_mutex); 186 mutex_init(&crypt_stat->cs_tfm_mutex);
181 mutex_init(&crypt_stat->cs_md5_tfm_mutex); 187 mutex_init(&crypt_stat->cs_hash_tfm_mutex);
182 ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_STRUCT_INITIALIZED); 188 ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_STRUCT_INITIALIZED);
183} 189}
184 190
@@ -192,8 +198,8 @@ void ecryptfs_destruct_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat)
192{ 198{
193 if (crypt_stat->tfm) 199 if (crypt_stat->tfm)
194 crypto_free_tfm(crypt_stat->tfm); 200 crypto_free_tfm(crypt_stat->tfm);
195 if (crypt_stat->md5_tfm) 201 if (crypt_stat->hash_tfm)
196 crypto_free_tfm(crypt_stat->md5_tfm); 202 crypto_free_hash(crypt_stat->hash_tfm);
197 memset(crypt_stat, 0, sizeof(struct ecryptfs_crypt_stat)); 203 memset(crypt_stat, 0, sizeof(struct ecryptfs_crypt_stat));
198} 204}
199 205
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h
index 4112df9dec50..840aa010e0d3 100644
--- a/fs/ecryptfs/ecryptfs_kernel.h
+++ b/fs/ecryptfs/ecryptfs_kernel.h
@@ -175,6 +175,7 @@ ecryptfs_get_key_payload_data(struct key *key)
175#define ECRYPTFS_DEFAULT_CIPHER "aes" 175#define ECRYPTFS_DEFAULT_CIPHER "aes"
176#define ECRYPTFS_DEFAULT_KEY_BYTES 16 176#define ECRYPTFS_DEFAULT_KEY_BYTES 16
177#define ECRYPTFS_DEFAULT_CHAINING_MODE CRYPTO_TFM_MODE_CBC 177#define ECRYPTFS_DEFAULT_CHAINING_MODE CRYPTO_TFM_MODE_CBC
178#define ECRYPTFS_DEFAULT_HASH "md5"
178#define ECRYPTFS_TAG_3_PACKET_TYPE 0x8C 179#define ECRYPTFS_TAG_3_PACKET_TYPE 0x8C
179#define ECRYPTFS_TAG_11_PACKET_TYPE 0xED 180#define ECRYPTFS_TAG_11_PACKET_TYPE 0xED
180#define MD5_DIGEST_SIZE 16 181#define MD5_DIGEST_SIZE 16
@@ -205,14 +206,14 @@ struct ecryptfs_crypt_stat {
205 unsigned int extent_mask; 206 unsigned int extent_mask;
206 struct ecryptfs_mount_crypt_stat *mount_crypt_stat; 207 struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
207 struct crypto_tfm *tfm; 208 struct crypto_tfm *tfm;
208 struct crypto_tfm *md5_tfm; /* Crypto context for generating 209 struct crypto_hash *hash_tfm; /* Crypto context for generating
209 * the initialization vectors */ 210 * the initialization vectors */
210 unsigned char cipher[ECRYPTFS_MAX_CIPHER_NAME_SIZE]; 211 unsigned char cipher[ECRYPTFS_MAX_CIPHER_NAME_SIZE];
211 unsigned char key[ECRYPTFS_MAX_KEY_BYTES]; 212 unsigned char key[ECRYPTFS_MAX_KEY_BYTES];
212 unsigned char root_iv[ECRYPTFS_MAX_IV_BYTES]; 213 unsigned char root_iv[ECRYPTFS_MAX_IV_BYTES];
213 unsigned char keysigs[ECRYPTFS_MAX_NUM_KEYSIGS][ECRYPTFS_SIG_SIZE_HEX]; 214 unsigned char keysigs[ECRYPTFS_MAX_NUM_KEYSIGS][ECRYPTFS_SIG_SIZE_HEX];
214 struct mutex cs_tfm_mutex; 215 struct mutex cs_tfm_mutex;
215 struct mutex cs_md5_tfm_mutex; 216 struct mutex cs_hash_tfm_mutex;
216 struct mutex cs_mutex; 217 struct mutex cs_mutex;
217}; 218};
218 219