diff options
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ecryptfs/crypto.c | 69 |
1 files changed, 18 insertions, 51 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index fb54a0182f2e..609efc01d5c2 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
@@ -40,14 +40,9 @@ | |||
40 | #define DECRYPT 0 | 40 | #define DECRYPT 0 |
41 | #define ENCRYPT 1 | 41 | #define ENCRYPT 1 |
42 | 42 | ||
43 | static int | 43 | static int crypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat, |
44 | ecryptfs_decrypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat, | ||
45 | struct page *dst_page, struct page *src_page, | ||
46 | int offset, int size, unsigned char *iv); | ||
47 | static int | ||
48 | ecryptfs_encrypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat, | ||
49 | struct page *dst_page, struct page *src_page, | 44 | struct page *dst_page, struct page *src_page, |
50 | int offset, int size, unsigned char *iv); | 45 | int offset, int size, unsigned char *iv, int op); |
51 | 46 | ||
52 | /** | 47 | /** |
53 | * ecryptfs_to_hex | 48 | * ecryptfs_to_hex |
@@ -452,9 +447,9 @@ static int ecryptfs_encrypt_extent(struct page *enc_extent_page, | |||
452 | (unsigned long long)(extent_base + extent_offset), rc); | 447 | (unsigned long long)(extent_base + extent_offset), rc); |
453 | goto out; | 448 | goto out; |
454 | } | 449 | } |
455 | rc = ecryptfs_encrypt_page_offset(crypt_stat, enc_extent_page, page, | 450 | rc = crypt_page_offset(crypt_stat, enc_extent_page, page, |
456 | extent_offset * crypt_stat->extent_size, | 451 | (extent_offset * crypt_stat->extent_size), |
457 | crypt_stat->extent_size, extent_iv); | 452 | crypt_stat->extent_size, extent_iv, ENCRYPT); |
458 | if (rc < 0) { | 453 | if (rc < 0) { |
459 | printk(KERN_ERR "%s: Error attempting to encrypt page with " | 454 | printk(KERN_ERR "%s: Error attempting to encrypt page with " |
460 | "page->index = [%ld], extent_offset = [%ld]; " | 455 | "page->index = [%ld], extent_offset = [%ld]; " |
@@ -555,9 +550,9 @@ static int ecryptfs_decrypt_extent(struct page *page, | |||
555 | (unsigned long long)(extent_base + extent_offset), rc); | 550 | (unsigned long long)(extent_base + extent_offset), rc); |
556 | goto out; | 551 | goto out; |
557 | } | 552 | } |
558 | rc = ecryptfs_decrypt_page_offset(crypt_stat, page, enc_extent_page, | 553 | rc = crypt_page_offset(crypt_stat, page, enc_extent_page, |
559 | extent_offset * crypt_stat->extent_size, | 554 | (extent_offset * crypt_stat->extent_size), |
560 | crypt_stat->extent_size, extent_iv); | 555 | crypt_stat->extent_size, extent_iv, DECRYPT); |
561 | if (rc < 0) { | 556 | if (rc < 0) { |
562 | printk(KERN_ERR "%s: Error attempting to decrypt to page with " | 557 | printk(KERN_ERR "%s: Error attempting to decrypt to page with " |
563 | "page->index = [%ld], extent_offset = [%ld]; " | 558 | "page->index = [%ld], extent_offset = [%ld]; " |
@@ -628,20 +623,20 @@ out: | |||
628 | } | 623 | } |
629 | 624 | ||
630 | /** | 625 | /** |
631 | * ecryptfs_encrypt_page_offset | 626 | * crypt_page_offset |
632 | * @crypt_stat: The cryptographic context | 627 | * @crypt_stat: The cryptographic context |
633 | * @dst_page: The page to encrypt into | 628 | * @dst_page: The page to write the result into |
634 | * @src_page: The page to encrypt from | 629 | * @src_page: The page to read from |
635 | * @offset: The byte offset into the dst_page and src_page | 630 | * @offset: The byte offset into the dst_page and src_page |
636 | * @size: The number of bytes to encrypt | 631 | * @size: The number of bytes of data |
637 | * @iv: The initialization vector to use for the encryption | 632 | * @iv: The initialization vector to use for the crypto operation |
633 | * @op: ENCRYPT or DECRYPT to indicate the desired operation | ||
638 | * | 634 | * |
639 | * Returns the number of bytes encrypted | 635 | * Returns the number of bytes encrypted or decrypted |
640 | */ | 636 | */ |
641 | static int | 637 | static int crypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat, |
642 | ecryptfs_encrypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat, | ||
643 | struct page *dst_page, struct page *src_page, | 638 | struct page *dst_page, struct page *src_page, |
644 | int offset, int size, unsigned char *iv) | 639 | int offset, int size, unsigned char *iv, int op) |
645 | { | 640 | { |
646 | struct scatterlist src_sg, dst_sg; | 641 | struct scatterlist src_sg, dst_sg; |
647 | 642 | ||
@@ -650,36 +645,8 @@ ecryptfs_encrypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat, | |||
650 | 645 | ||
651 | sg_set_page(&src_sg, src_page, size, offset); | 646 | sg_set_page(&src_sg, src_page, size, offset); |
652 | sg_set_page(&dst_sg, dst_page, size, offset); | 647 | sg_set_page(&dst_sg, dst_page, size, offset); |
653 | return crypt_scatterlist(crypt_stat, &dst_sg, &src_sg, | ||
654 | size, iv, ENCRYPT); | ||
655 | } | ||
656 | |||
657 | /** | ||
658 | * ecryptfs_decrypt_page_offset | ||
659 | * @crypt_stat: The cryptographic context | ||
660 | * @dst_page: The page to decrypt into | ||
661 | * @src_page: The page to decrypt from | ||
662 | * @offset: The byte offset into the dst_page and src_page | ||
663 | * @size: The number of bytes to decrypt | ||
664 | * @iv: The initialization vector to use for the decryption | ||
665 | * | ||
666 | * Returns the number of bytes decrypted | ||
667 | */ | ||
668 | static int | ||
669 | ecryptfs_decrypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat, | ||
670 | struct page *dst_page, struct page *src_page, | ||
671 | int offset, int size, unsigned char *iv) | ||
672 | { | ||
673 | struct scatterlist src_sg, dst_sg; | ||
674 | |||
675 | sg_init_table(&src_sg, 1); | ||
676 | sg_set_page(&src_sg, src_page, size, offset); | ||
677 | |||
678 | sg_init_table(&dst_sg, 1); | ||
679 | sg_set_page(&dst_sg, dst_page, size, offset); | ||
680 | 648 | ||
681 | return crypt_scatterlist(crypt_stat, &dst_sg, &src_sg, | 649 | return crypt_scatterlist(crypt_stat, &dst_sg, &src_sg, size, iv, op); |
682 | size, iv, DECRYPT); | ||
683 | } | 650 | } |
684 | 651 | ||
685 | #define ECRYPTFS_MAX_SCATTERLIST_LEN 4 | 652 | #define ECRYPTFS_MAX_SCATTERLIST_LEN 4 |