From: Eric Sandeen <sandeen@redhat.com> Date: Tue, 18 Dec 2007 12:15:13 -0600 Subject: [fs] ecryptfs: backport to crypto hash api Message-id: 47680E31.5040003@redhat.com O-Subject: [RHEL 5.2 PATCH] 11/15: eCryptfs: backport to RHEL5 crypto hash APII Bugzilla: 228341 Backport ecryptfs to use the RHEL5 crypto hash API crypto.c | 41 +++++++++-------------------------------- ecryptfs_kernel.h | 4 ++-- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 2b656d0..2a4a317 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c @@ -95,47 +95,24 @@ static int ecryptfs_calculate_md5(char *dst, char *src, int len) { struct scatterlist sg; - struct hash_desc desc = { - .tfm = crypt_stat->hash_tfm, - .flags = CRYPTO_TFM_REQ_MAY_SLEEP - }; int rc = 0; mutex_lock(&crypt_stat->cs_hash_tfm_mutex); sg_init_one(&sg, (u8 *)src, len); - if (!desc.tfm) { - desc.tfm = crypto_alloc_hash(ECRYPTFS_DEFAULT_HASH, 0, - CRYPTO_ALG_ASYNC); - if (IS_ERR(desc.tfm)) { - rc = PTR_ERR(desc.tfm); + if (!crypt_stat->hash_tfm) { + crypt_stat->hash_tfm = + crypto_alloc_tfm("md5", CRYPTO_TFM_REQ_MAY_SLEEP); + if (!crypt_stat->hash_tfm) { + rc = -ENOMEM; ecryptfs_printk(KERN_ERR, "Error attempting to " "allocate crypto context; rc = [%d]\n", rc); goto out; } - crypt_stat->hash_tfm = desc.tfm; - } - rc = crypto_hash_init(&desc); - if (rc) { - printk(KERN_ERR - "%s: Error initializing crypto hash; rc = [%d]\n", - __FUNCTION__, rc); - goto out; - } - rc = crypto_hash_update(&desc, &sg, len); - if (rc) { - printk(KERN_ERR - "%s: Error updating crypto hash; rc = [%d]\n", - __FUNCTION__, rc); - goto out; - } - rc = crypto_hash_final(&desc, dst); - if (rc) { - printk(KERN_ERR - "%s: Error finalizing crypto hash; rc = [%d]\n", - __FUNCTION__, rc); - goto out; } + crypto_digest_init(crypt_stat->hash_tfm); + crypto_digest_update(crypt_stat->hash_tfm, &sg, 1); + crypto_digest_final(crypt_stat->hash_tfm, dst); out: mutex_unlock(&crypt_stat->cs_hash_tfm_mutex); return rc; @@ -221,7 +198,7 @@ void ecryptfs_destroy_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat) if (crypt_stat->tfm) crypto_free_tfm(crypt_stat->tfm); if (crypt_stat->hash_tfm) - crypto_free_hash(crypt_stat->hash_tfm); + crypto_free_tfm(crypt_stat->hash_tfm); mutex_lock(&crypt_stat->keysig_list_mutex); list_for_each_entry_safe(key_sig, key_sig_tmp, &crypt_stat->keysig_list, crypt_stat_list) { diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h index 55b4f9a..e2aca2b 100644 --- a/fs/ecryptfs/ecryptfs_kernel.h +++ b/fs/ecryptfs/ecryptfs_kernel.h @@ -202,7 +202,7 @@ ecryptfs_get_key_payload_data(struct key *key) #define ECRYPTFS_FILE_SIZE_BYTES (sizeof(u64)) #define ECRYPTFS_DEFAULT_CIPHER "aes" #define ECRYPTFS_DEFAULT_KEY_BYTES 16 -#define ECRYPTFS_DEFAULT_HASH "md5" +#define ECRYPTFS_DEFAULT_CHAINING_MODE CRYPTO_TFM_MODE_CBC #define ECRYPTFS_TAG_1_PACKET_TYPE 0x01 #define ECRYPTFS_TAG_3_PACKET_TYPE 0x8C #define ECRYPTFS_TAG_11_PACKET_TYPE 0xED @@ -243,7 +243,7 @@ struct ecryptfs_crypt_stat { unsigned int extent_mask; struct ecryptfs_mount_crypt_stat *mount_crypt_stat; struct crypto_tfm *tfm; - struct crypto_hash *hash_tfm; /* Crypto context for generating + struct crypto_tfm *hash_tfm; /* Crypto context for generating * the initialization vectors */ unsigned char cipher[ECRYPTFS_MAX_CIPHER_NAME_SIZE]; unsigned char key[ECRYPTFS_MAX_KEY_BYTES];