17
17
#include <linux/bio.h>
18
18
#include <linux/blkdev.h>
19
19
#include <linux/blk-integrity.h>
20
+ #include <linux/crc32.h>
20
21
#include <linux/mempool.h>
21
22
#include <linux/slab.h>
22
23
#include <linux/crypto.h>
@@ -125,7 +126,6 @@ struct iv_lmk_private {
125
126
126
127
#define TCW_WHITENING_SIZE 16
127
128
struct iv_tcw_private {
128
- struct crypto_shash * crc32_tfm ;
129
129
u8 * iv_seed ;
130
130
u8 * whitening ;
131
131
};
@@ -607,10 +607,6 @@ static void crypt_iv_tcw_dtr(struct crypt_config *cc)
607
607
tcw -> iv_seed = NULL ;
608
608
kfree_sensitive (tcw -> whitening );
609
609
tcw -> whitening = NULL ;
610
-
611
- if (tcw -> crc32_tfm && !IS_ERR (tcw -> crc32_tfm ))
612
- crypto_free_shash (tcw -> crc32_tfm );
613
- tcw -> crc32_tfm = NULL ;
614
610
}
615
611
616
612
static int crypt_iv_tcw_ctr (struct crypt_config * cc , struct dm_target * ti ,
@@ -628,13 +624,6 @@ static int crypt_iv_tcw_ctr(struct crypt_config *cc, struct dm_target *ti,
628
624
return - EINVAL ;
629
625
}
630
626
631
- tcw -> crc32_tfm = crypto_alloc_shash ("crc32" , 0 ,
632
- CRYPTO_ALG_ALLOCATES_MEMORY );
633
- if (IS_ERR (tcw -> crc32_tfm )) {
634
- ti -> error = "Error initializing CRC32 in TCW" ;
635
- return PTR_ERR (tcw -> crc32_tfm );
636
- }
637
-
638
627
tcw -> iv_seed = kzalloc (cc -> iv_size , GFP_KERNEL );
639
628
tcw -> whitening = kzalloc (TCW_WHITENING_SIZE , GFP_KERNEL );
640
629
if (!tcw -> iv_seed || !tcw -> whitening ) {
@@ -668,36 +657,28 @@ static int crypt_iv_tcw_wipe(struct crypt_config *cc)
668
657
return 0 ;
669
658
}
670
659
671
- static int crypt_iv_tcw_whitening (struct crypt_config * cc ,
672
- struct dm_crypt_request * dmreq ,
673
- u8 * data )
660
+ static void crypt_iv_tcw_whitening (struct crypt_config * cc ,
661
+ struct dm_crypt_request * dmreq , u8 * data )
674
662
{
675
663
struct iv_tcw_private * tcw = & cc -> iv_gen_private .tcw ;
676
664
__le64 sector = cpu_to_le64 (dmreq -> iv_sector );
677
665
u8 buf [TCW_WHITENING_SIZE ];
678
- SHASH_DESC_ON_STACK (desc , tcw -> crc32_tfm );
679
- int i , r ;
666
+ int i ;
680
667
681
668
/* xor whitening with sector number */
682
669
crypto_xor_cpy (buf , tcw -> whitening , (u8 * )& sector , 8 );
683
670
crypto_xor_cpy (& buf [8 ], tcw -> whitening + 8 , (u8 * )& sector , 8 );
684
671
685
672
/* calculate crc32 for every 32bit part and xor it */
686
- desc -> tfm = tcw -> crc32_tfm ;
687
- for (i = 0 ; i < 4 ; i ++ ) {
688
- r = crypto_shash_digest (desc , & buf [i * 4 ], 4 , & buf [i * 4 ]);
689
- if (r )
690
- goto out ;
691
- }
673
+ for (i = 0 ; i < 4 ; i ++ )
674
+ put_unaligned_le32 (crc32 (0 , & buf [i * 4 ], 4 ), & buf [i * 4 ]);
692
675
crypto_xor (& buf [0 ], & buf [12 ], 4 );
693
676
crypto_xor (& buf [4 ], & buf [8 ], 4 );
694
677
695
678
/* apply whitening (8 bytes) to whole sector */
696
679
for (i = 0 ; i < ((1 << SECTOR_SHIFT ) / 8 ); i ++ )
697
680
crypto_xor (data + i * 8 , buf , 8 );
698
- out :
699
681
memzero_explicit (buf , sizeof (buf ));
700
- return r ;
701
682
}
702
683
703
684
static int crypt_iv_tcw_gen (struct crypt_config * cc , u8 * iv ,
@@ -707,13 +688,12 @@ static int crypt_iv_tcw_gen(struct crypt_config *cc, u8 *iv,
707
688
struct iv_tcw_private * tcw = & cc -> iv_gen_private .tcw ;
708
689
__le64 sector = cpu_to_le64 (dmreq -> iv_sector );
709
690
u8 * src ;
710
- int r = 0 ;
711
691
712
692
/* Remove whitening from ciphertext */
713
693
if (bio_data_dir (dmreq -> ctx -> bio_in ) != WRITE ) {
714
694
sg = crypt_get_sg_data (cc , dmreq -> sg_in );
715
695
src = kmap_local_page (sg_page (sg ));
716
- r = crypt_iv_tcw_whitening (cc , dmreq , src + sg -> offset );
696
+ crypt_iv_tcw_whitening (cc , dmreq , src + sg -> offset );
717
697
kunmap_local (src );
718
698
}
719
699
@@ -723,26 +703,25 @@ static int crypt_iv_tcw_gen(struct crypt_config *cc, u8 *iv,
723
703
crypto_xor_cpy (& iv [8 ], tcw -> iv_seed + 8 , (u8 * )& sector ,
724
704
cc -> iv_size - 8 );
725
705
726
- return r ;
706
+ return 0 ;
727
707
}
728
708
729
709
static int crypt_iv_tcw_post (struct crypt_config * cc , u8 * iv ,
730
710
struct dm_crypt_request * dmreq )
731
711
{
732
712
struct scatterlist * sg ;
733
713
u8 * dst ;
734
- int r ;
735
714
736
715
if (bio_data_dir (dmreq -> ctx -> bio_in ) != WRITE )
737
716
return 0 ;
738
717
739
718
/* Apply whitening on ciphertext */
740
719
sg = crypt_get_sg_data (cc , dmreq -> sg_out );
741
720
dst = kmap_local_page (sg_page (sg ));
742
- r = crypt_iv_tcw_whitening (cc , dmreq , dst + sg -> offset );
721
+ crypt_iv_tcw_whitening (cc , dmreq , dst + sg -> offset );
743
722
kunmap_local (dst );
744
723
745
- return r ;
724
+ return 0 ;
746
725
}
747
726
748
727
static int crypt_iv_random_gen (struct crypt_config * cc , u8 * iv ,
0 commit comments