aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ecryptfs/crypto.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ecryptfs/crypto.c')
-rw-r--r--fs/ecryptfs/crypto.c36
1 files changed, 21 insertions, 15 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