diff options
author | Tyler Hicks <tyhicks@canonical.com> | 2013-04-15 20:49:31 -0400 |
---|---|---|
committer | Tyler Hicks <tyhicks@canonical.com> | 2013-06-07 20:28:28 -0400 |
commit | 406c93df09ae7a345b510cf6619f881b42a3d553 (patch) | |
tree | 88457521ce43574bc6d71296b8ac8bcd79d5b8c4 /fs/ecryptfs/crypto.c | |
parent | d78de618962d1e9d28c602e3c75991fe9c94e961 (diff) |
eCryptfs: Collapse crypt_page_offset() into crypt_extent()
crypt_page_offset() simply initialized the two scatterlists and called
crypt_scatterlist() so it is simple enough to move into the only
function that calls it.
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Diffstat (limited to 'fs/ecryptfs/crypto.c')
-rw-r--r-- | fs/ecryptfs/crypto.c | 50 |
1 files changed, 14 insertions, 36 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 9845d2fd2506..9947388ccd8d 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
@@ -40,10 +40,6 @@ | |||
40 | #define DECRYPT 0 | 40 | #define DECRYPT 0 |
41 | #define ENCRYPT 1 | 41 | #define ENCRYPT 1 |
42 | 42 | ||
43 | static int crypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat, | ||
44 | struct page *dst_page, struct page *src_page, | ||
45 | int offset, int size, unsigned char *iv, int op); | ||
46 | |||
47 | /** | 43 | /** |
48 | * ecryptfs_to_hex | 44 | * ecryptfs_to_hex |
49 | * @dst: Buffer to take hex character representation of contents of | 45 | * @dst: Buffer to take hex character representation of contents of |
@@ -436,10 +432,11 @@ static int crypt_extent(struct page *dst_page, | |||
436 | pgoff_t page_index = op == ENCRYPT ? src_page->index : dst_page->index; | 432 | pgoff_t page_index = op == ENCRYPT ? src_page->index : dst_page->index; |
437 | loff_t extent_base; | 433 | loff_t extent_base; |
438 | char extent_iv[ECRYPTFS_MAX_IV_BYTES]; | 434 | char extent_iv[ECRYPTFS_MAX_IV_BYTES]; |
435 | struct scatterlist src_sg, dst_sg; | ||
436 | size_t extent_size = crypt_stat->extent_size; | ||
439 | int rc; | 437 | int rc; |
440 | 438 | ||
441 | extent_base = (((loff_t)page_index) | 439 | extent_base = (((loff_t)page_index) * (PAGE_CACHE_SIZE / extent_size)); |
442 | * (PAGE_CACHE_SIZE / crypt_stat->extent_size)); | ||
443 | rc = ecryptfs_derive_iv(extent_iv, crypt_stat, | 440 | rc = ecryptfs_derive_iv(extent_iv, crypt_stat, |
444 | (extent_base + extent_offset)); | 441 | (extent_base + extent_offset)); |
445 | if (rc) { | 442 | if (rc) { |
@@ -448,9 +445,17 @@ static int crypt_extent(struct page *dst_page, | |||
448 | (unsigned long long)(extent_base + extent_offset), rc); | 445 | (unsigned long long)(extent_base + extent_offset), rc); |
449 | goto out; | 446 | goto out; |
450 | } | 447 | } |
451 | rc = crypt_page_offset(crypt_stat, dst_page, src_page, | 448 | |
452 | (extent_offset * crypt_stat->extent_size), | 449 | sg_init_table(&src_sg, 1); |
453 | crypt_stat->extent_size, extent_iv, op); | 450 | sg_init_table(&dst_sg, 1); |
451 | |||
452 | sg_set_page(&src_sg, src_page, extent_size, | ||
453 | extent_offset * extent_size); | ||
454 | sg_set_page(&dst_sg, dst_page, extent_size, | ||
455 | extent_offset * extent_size); | ||
456 | |||
457 | rc = crypt_scatterlist(crypt_stat, &dst_sg, &src_sg, extent_size, | ||
458 | extent_iv, op); | ||
454 | if (rc < 0) { | 459 | if (rc < 0) { |
455 | printk(KERN_ERR "%s: Error attempting to crypt page with " | 460 | printk(KERN_ERR "%s: Error attempting to crypt page with " |
456 | "page_index = [%ld], extent_offset = [%ld]; " | 461 | "page_index = [%ld], extent_offset = [%ld]; " |
@@ -588,33 +593,6 @@ out: | |||
588 | return rc; | 593 | return rc; |
589 | } | 594 | } |
590 | 595 | ||
591 | /** | ||
592 | * crypt_page_offset | ||
593 | * @crypt_stat: The cryptographic context | ||
594 | * @dst_page: The page to write the result into | ||
595 | * @src_page: The page to read from | ||
596 | * @offset: The byte offset into the dst_page and src_page | ||
597 | * @size: The number of bytes of data | ||
598 | * @iv: The initialization vector to use for the crypto operation | ||
599 | * @op: ENCRYPT or DECRYPT to indicate the desired operation | ||
600 | * | ||
601 | * Returns the number of bytes encrypted or decrypted | ||
602 | */ | ||
603 | static int crypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat, | ||
604 | struct page *dst_page, struct page *src_page, | ||
605 | int offset, int size, unsigned char *iv, int op) | ||
606 | { | ||
607 | struct scatterlist src_sg, dst_sg; | ||
608 | |||
609 | sg_init_table(&src_sg, 1); | ||
610 | sg_init_table(&dst_sg, 1); | ||
611 | |||
612 | sg_set_page(&src_sg, src_page, size, offset); | ||
613 | sg_set_page(&dst_sg, dst_page, size, offset); | ||
614 | |||
615 | return crypt_scatterlist(crypt_stat, &dst_sg, &src_sg, size, iv, op); | ||
616 | } | ||
617 | |||
618 | #define ECRYPTFS_MAX_SCATTERLIST_LEN 4 | 596 | #define ECRYPTFS_MAX_SCATTERLIST_LEN 4 |
619 | 597 | ||
620 | /** | 598 | /** |