eCryptfs: Combine page_offset crypto functions
Combine ecryptfs_encrypt_page_offset() and ecryptfs_decrypt_page_offset(). These two functions are functionally identical so they can be safely merged if the caller can indicate whether an encryption or decryption operation should occur. Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
This commit is contained in:
parent
00a699400a
commit
a8ca90e207
|
@ -40,14 +40,9 @@
|
||||||
#define DECRYPT 0
|
#define DECRYPT 0
|
||||||
#define ENCRYPT 1
|
#define ENCRYPT 1
|
||||||
|
|
||||||
static int
|
static int crypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat,
|
||||||
ecryptfs_decrypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat,
|
|
||||||
struct page *dst_page, struct page *src_page,
|
struct page *dst_page, struct page *src_page,
|
||||||
int offset, int size, unsigned char *iv);
|
int offset, int size, unsigned char *iv, int op);
|
||||||
static int
|
|
||||||
ecryptfs_encrypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat,
|
|
||||||
struct page *dst_page, struct page *src_page,
|
|
||||||
int offset, int size, unsigned char *iv);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ecryptfs_to_hex
|
* ecryptfs_to_hex
|
||||||
|
@ -452,9 +447,9 @@ static int ecryptfs_encrypt_extent(struct page *enc_extent_page,
|
||||||
(unsigned long long)(extent_base + extent_offset), rc);
|
(unsigned long long)(extent_base + extent_offset), rc);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
rc = ecryptfs_encrypt_page_offset(crypt_stat, enc_extent_page, page,
|
rc = crypt_page_offset(crypt_stat, enc_extent_page, page,
|
||||||
extent_offset * crypt_stat->extent_size,
|
(extent_offset * crypt_stat->extent_size),
|
||||||
crypt_stat->extent_size, extent_iv);
|
crypt_stat->extent_size, extent_iv, ENCRYPT);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
printk(KERN_ERR "%s: Error attempting to encrypt page with "
|
printk(KERN_ERR "%s: Error attempting to encrypt page with "
|
||||||
"page->index = [%ld], extent_offset = [%ld]; "
|
"page->index = [%ld], extent_offset = [%ld]; "
|
||||||
|
@ -555,9 +550,9 @@ static int ecryptfs_decrypt_extent(struct page *page,
|
||||||
(unsigned long long)(extent_base + extent_offset), rc);
|
(unsigned long long)(extent_base + extent_offset), rc);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
rc = ecryptfs_decrypt_page_offset(crypt_stat, page, enc_extent_page,
|
rc = crypt_page_offset(crypt_stat, page, enc_extent_page,
|
||||||
extent_offset * crypt_stat->extent_size,
|
(extent_offset * crypt_stat->extent_size),
|
||||||
crypt_stat->extent_size, extent_iv);
|
crypt_stat->extent_size, extent_iv, DECRYPT);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
printk(KERN_ERR "%s: Error attempting to decrypt to page with "
|
printk(KERN_ERR "%s: Error attempting to decrypt to page with "
|
||||||
"page->index = [%ld], extent_offset = [%ld]; "
|
"page->index = [%ld], extent_offset = [%ld]; "
|
||||||
|
@ -628,20 +623,20 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ecryptfs_encrypt_page_offset
|
* crypt_page_offset
|
||||||
* @crypt_stat: The cryptographic context
|
* @crypt_stat: The cryptographic context
|
||||||
* @dst_page: The page to encrypt into
|
* @dst_page: The page to write the result into
|
||||||
* @src_page: The page to encrypt from
|
* @src_page: The page to read from
|
||||||
* @offset: The byte offset into the dst_page and src_page
|
* @offset: The byte offset into the dst_page and src_page
|
||||||
* @size: The number of bytes to encrypt
|
* @size: The number of bytes of data
|
||||||
* @iv: The initialization vector to use for the encryption
|
* @iv: The initialization vector to use for the crypto operation
|
||||||
|
* @op: ENCRYPT or DECRYPT to indicate the desired operation
|
||||||
*
|
*
|
||||||
* Returns the number of bytes encrypted
|
* Returns the number of bytes encrypted or decrypted
|
||||||
*/
|
*/
|
||||||
static int
|
static int crypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat,
|
||||||
ecryptfs_encrypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat,
|
|
||||||
struct page *dst_page, struct page *src_page,
|
struct page *dst_page, struct page *src_page,
|
||||||
int offset, int size, unsigned char *iv)
|
int offset, int size, unsigned char *iv, int op)
|
||||||
{
|
{
|
||||||
struct scatterlist src_sg, dst_sg;
|
struct scatterlist src_sg, dst_sg;
|
||||||
|
|
||||||
|
@ -650,36 +645,8 @@ ecryptfs_encrypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat,
|
||||||
|
|
||||||
sg_set_page(&src_sg, src_page, size, offset);
|
sg_set_page(&src_sg, src_page, size, offset);
|
||||||
sg_set_page(&dst_sg, dst_page, size, offset);
|
sg_set_page(&dst_sg, dst_page, size, offset);
|
||||||
return crypt_scatterlist(crypt_stat, &dst_sg, &src_sg,
|
|
||||||
size, iv, ENCRYPT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return crypt_scatterlist(crypt_stat, &dst_sg, &src_sg, size, iv, op);
|
||||||
* ecryptfs_decrypt_page_offset
|
|
||||||
* @crypt_stat: The cryptographic context
|
|
||||||
* @dst_page: The page to decrypt into
|
|
||||||
* @src_page: The page to decrypt from
|
|
||||||
* @offset: The byte offset into the dst_page and src_page
|
|
||||||
* @size: The number of bytes to decrypt
|
|
||||||
* @iv: The initialization vector to use for the decryption
|
|
||||||
*
|
|
||||||
* Returns the number of bytes decrypted
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
ecryptfs_decrypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat,
|
|
||||||
struct page *dst_page, struct page *src_page,
|
|
||||||
int offset, int size, unsigned char *iv)
|
|
||||||
{
|
|
||||||
struct scatterlist src_sg, dst_sg;
|
|
||||||
|
|
||||||
sg_init_table(&src_sg, 1);
|
|
||||||
sg_set_page(&src_sg, src_page, size, offset);
|
|
||||||
|
|
||||||
sg_init_table(&dst_sg, 1);
|
|
||||||
sg_set_page(&dst_sg, dst_page, size, offset);
|
|
||||||
|
|
||||||
return crypt_scatterlist(crypt_stat, &dst_sg, &src_sg,
|
|
||||||
size, iv, DECRYPT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ECRYPTFS_MAX_SCATTERLIST_LEN 4
|
#define ECRYPTFS_MAX_SCATTERLIST_LEN 4
|
||||||
|
|
Loading…
Reference in New Issue