Commit 565d9724 authored by Michael Halcrow's avatar Michael Halcrow Committed by Linus Torvalds

[PATCH] eCryptfs: Hash code to new crypto API

Update eCryptfs hash code to the new kernel crypto API.
Signed-off-by: default avatarMichael Halcrow <mhalcrow@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent e5d9cbde
...@@ -94,25 +94,31 @@ static int ecryptfs_calculate_md5(char *dst, ...@@ -94,25 +94,31 @@ static int ecryptfs_calculate_md5(char *dst,
struct ecryptfs_crypt_stat *crypt_stat, struct ecryptfs_crypt_stat *crypt_stat,
char *src, int len) char *src, int len)
{ {
int rc = 0;
struct scatterlist sg; 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_md5_tfm_mutex); mutex_lock(&crypt_stat->cs_hash_tfm_mutex);
sg_init_one(&sg, (u8 *)src, len); sg_init_one(&sg, (u8 *)src, len);
if (!crypt_stat->md5_tfm) { if (!desc.tfm) {
crypt_stat->md5_tfm = desc.tfm = crypto_alloc_hash(ECRYPTFS_DEFAULT_HASH, 0,
crypto_alloc_tfm("md5", CRYPTO_TFM_REQ_MAY_SLEEP); CRYPTO_ALG_ASYNC);
if (!crypt_stat->md5_tfm) { if (IS_ERR(desc.tfm)) {
rc = -ENOMEM; rc = PTR_ERR(desc.tfm);
ecryptfs_printk(KERN_ERR, "Error attempting to " ecryptfs_printk(KERN_ERR, "Error attempting to "
"allocate crypto context\n"); "allocate crypto context; rc = [%d]\n",
rc);
goto out; goto out;
} }
crypt_stat->hash_tfm = desc.tfm;
} }
crypto_digest_init(crypt_stat->md5_tfm); crypto_hash_init(&desc);
crypto_digest_update(crypt_stat->md5_tfm, &sg, 1); crypto_hash_update(&desc, &sg, len);
crypto_digest_final(crypt_stat->md5_tfm, dst); crypto_hash_final(&desc, dst);
mutex_unlock(&crypt_stat->cs_md5_tfm_mutex); mutex_unlock(&crypt_stat->cs_hash_tfm_mutex);
out: out:
return rc; return rc;
} }
...@@ -178,7 +184,7 @@ ecryptfs_init_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat) ...@@ -178,7 +184,7 @@ ecryptfs_init_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat)
memset((void *)crypt_stat, 0, sizeof(struct ecryptfs_crypt_stat)); memset((void *)crypt_stat, 0, sizeof(struct ecryptfs_crypt_stat));
mutex_init(&crypt_stat->cs_mutex); mutex_init(&crypt_stat->cs_mutex);
mutex_init(&crypt_stat->cs_tfm_mutex); mutex_init(&crypt_stat->cs_tfm_mutex);
mutex_init(&crypt_stat->cs_md5_tfm_mutex); mutex_init(&crypt_stat->cs_hash_tfm_mutex);
ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_STRUCT_INITIALIZED); ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_STRUCT_INITIALIZED);
} }
...@@ -192,8 +198,8 @@ void ecryptfs_destruct_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat) ...@@ -192,8 +198,8 @@ void ecryptfs_destruct_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat)
{ {
if (crypt_stat->tfm) if (crypt_stat->tfm)
crypto_free_tfm(crypt_stat->tfm); crypto_free_tfm(crypt_stat->tfm);
if (crypt_stat->md5_tfm) if (crypt_stat->hash_tfm)
crypto_free_tfm(crypt_stat->md5_tfm); crypto_free_hash(crypt_stat->hash_tfm);
memset(crypt_stat, 0, sizeof(struct ecryptfs_crypt_stat)); memset(crypt_stat, 0, sizeof(struct ecryptfs_crypt_stat));
} }
......
...@@ -175,6 +175,7 @@ ecryptfs_get_key_payload_data(struct key *key) ...@@ -175,6 +175,7 @@ ecryptfs_get_key_payload_data(struct key *key)
#define ECRYPTFS_DEFAULT_CIPHER "aes" #define ECRYPTFS_DEFAULT_CIPHER "aes"
#define ECRYPTFS_DEFAULT_KEY_BYTES 16 #define ECRYPTFS_DEFAULT_KEY_BYTES 16
#define ECRYPTFS_DEFAULT_CHAINING_MODE CRYPTO_TFM_MODE_CBC #define ECRYPTFS_DEFAULT_CHAINING_MODE CRYPTO_TFM_MODE_CBC
#define ECRYPTFS_DEFAULT_HASH "md5"
#define ECRYPTFS_TAG_3_PACKET_TYPE 0x8C #define ECRYPTFS_TAG_3_PACKET_TYPE 0x8C
#define ECRYPTFS_TAG_11_PACKET_TYPE 0xED #define ECRYPTFS_TAG_11_PACKET_TYPE 0xED
#define MD5_DIGEST_SIZE 16 #define MD5_DIGEST_SIZE 16
...@@ -205,14 +206,14 @@ struct ecryptfs_crypt_stat { ...@@ -205,14 +206,14 @@ struct ecryptfs_crypt_stat {
unsigned int extent_mask; unsigned int extent_mask;
struct ecryptfs_mount_crypt_stat *mount_crypt_stat; struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
struct crypto_tfm *tfm; struct crypto_tfm *tfm;
struct crypto_tfm *md5_tfm; /* Crypto context for generating struct crypto_hash *hash_tfm; /* Crypto context for generating
* the initialization vectors */ * the initialization vectors */
unsigned char cipher[ECRYPTFS_MAX_CIPHER_NAME_SIZE]; unsigned char cipher[ECRYPTFS_MAX_CIPHER_NAME_SIZE];
unsigned char key[ECRYPTFS_MAX_KEY_BYTES]; unsigned char key[ECRYPTFS_MAX_KEY_BYTES];
unsigned char root_iv[ECRYPTFS_MAX_IV_BYTES]; unsigned char root_iv[ECRYPTFS_MAX_IV_BYTES];
unsigned char keysigs[ECRYPTFS_MAX_NUM_KEYSIGS][ECRYPTFS_SIG_SIZE_HEX]; unsigned char keysigs[ECRYPTFS_MAX_NUM_KEYSIGS][ECRYPTFS_SIG_SIZE_HEX];
struct mutex cs_tfm_mutex; struct mutex cs_tfm_mutex;
struct mutex cs_md5_tfm_mutex; struct mutex cs_hash_tfm_mutex;
struct mutex cs_mutex; struct mutex cs_mutex;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment