8
8
*
9
9
******************************************************************************/
10
10
11
- #include <crypto/hash .h>
11
+ #include <linux/crc32c .h>
12
12
#include <linux/string.h>
13
13
#include <linux/kthread.h>
14
14
#include <linux/completion.h>
@@ -490,8 +490,8 @@ void iscsit_aborted_task(struct iscsit_conn *conn, struct iscsit_cmd *cmd)
490
490
}
491
491
EXPORT_SYMBOL (iscsit_aborted_task );
492
492
493
- static void iscsit_do_crypto_hash_buf ( struct ahash_request * , const void * ,
494
- u32 , u32 , const void * , void * );
493
+ static u32 iscsit_crc_buf ( const void * buf , u32 payload_length ,
494
+ u32 padding , const void * pad_bytes );
495
495
static void iscsit_tx_thread_wait_for_tcp (struct iscsit_conn * );
496
496
497
497
static int
@@ -510,9 +510,7 @@ iscsit_xmit_nondatain_pdu(struct iscsit_conn *conn, struct iscsit_cmd *cmd,
510
510
if (conn -> conn_ops -> HeaderDigest ) {
511
511
u32 * header_digest = (u32 * )& cmd -> pdu [ISCSI_HDR_LEN ];
512
512
513
- iscsit_do_crypto_hash_buf (conn -> conn_tx_hash , hdr ,
514
- ISCSI_HDR_LEN , 0 , NULL ,
515
- header_digest );
513
+ * header_digest = iscsit_crc_buf (hdr , ISCSI_HDR_LEN , 0 , NULL );
516
514
517
515
iov [0 ].iov_len += ISCSI_CRC_LEN ;
518
516
tx_size += ISCSI_CRC_LEN ;
@@ -537,11 +535,9 @@ iscsit_xmit_nondatain_pdu(struct iscsit_conn *conn, struct iscsit_cmd *cmd,
537
535
}
538
536
539
537
if (conn -> conn_ops -> DataDigest ) {
540
- iscsit_do_crypto_hash_buf (conn -> conn_tx_hash ,
541
- data_buf , data_buf_len ,
542
- padding , & cmd -> pad_bytes ,
543
- & cmd -> data_crc );
544
-
538
+ cmd -> data_crc = iscsit_crc_buf (data_buf , data_buf_len ,
539
+ padding ,
540
+ & cmd -> pad_bytes );
545
541
iov [niov ].iov_base = & cmd -> data_crc ;
546
542
iov [niov ++ ].iov_len = ISCSI_CRC_LEN ;
547
543
tx_size += ISCSI_CRC_LEN ;
@@ -566,8 +562,8 @@ iscsit_xmit_nondatain_pdu(struct iscsit_conn *conn, struct iscsit_cmd *cmd,
566
562
static int iscsit_map_iovec (struct iscsit_cmd * cmd , struct kvec * iov , int nvec ,
567
563
u32 data_offset , u32 data_length );
568
564
static void iscsit_unmap_iovec (struct iscsit_cmd * );
569
- static u32 iscsit_do_crypto_hash_sg ( struct ahash_request * , struct iscsit_cmd * ,
570
- u32 , u32 , u32 , u8 * );
565
+ static u32 iscsit_crc_sglist ( const struct iscsit_cmd * cmd , u32 data_length ,
566
+ u32 padding , const u8 * pad_bytes );
571
567
static int
572
568
iscsit_xmit_datain_pdu (struct iscsit_conn * conn , struct iscsit_cmd * cmd ,
573
569
const struct iscsi_datain * datain )
@@ -584,10 +580,8 @@ iscsit_xmit_datain_pdu(struct iscsit_conn *conn, struct iscsit_cmd *cmd,
584
580
if (conn -> conn_ops -> HeaderDigest ) {
585
581
u32 * header_digest = (u32 * )& cmd -> pdu [ISCSI_HDR_LEN ];
586
582
587
- iscsit_do_crypto_hash_buf (conn -> conn_tx_hash , cmd -> pdu ,
588
- ISCSI_HDR_LEN , 0 , NULL ,
589
- header_digest );
590
-
583
+ * header_digest = iscsit_crc_buf (cmd -> pdu , ISCSI_HDR_LEN , 0 ,
584
+ NULL );
591
585
iov [0 ].iov_len += ISCSI_CRC_LEN ;
592
586
tx_size += ISCSI_CRC_LEN ;
593
587
@@ -614,12 +608,8 @@ iscsit_xmit_datain_pdu(struct iscsit_conn *conn, struct iscsit_cmd *cmd,
614
608
}
615
609
616
610
if (conn -> conn_ops -> DataDigest ) {
617
- cmd -> data_crc = iscsit_do_crypto_hash_sg (conn -> conn_tx_hash ,
618
- cmd , datain -> offset ,
619
- datain -> length ,
620
- cmd -> padding ,
621
- cmd -> pad_bytes );
622
-
611
+ cmd -> data_crc = iscsit_crc_sglist (cmd , datain -> length ,
612
+ cmd -> padding , cmd -> pad_bytes );
623
613
iov [iov_count ].iov_base = & cmd -> data_crc ;
624
614
iov [iov_count ++ ].iov_len = ISCSI_CRC_LEN ;
625
615
tx_size += ISCSI_CRC_LEN ;
@@ -1404,77 +1394,45 @@ iscsit_handle_scsi_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd,
1404
1394
return iscsit_get_immediate_data (cmd , hdr , dump_payload );
1405
1395
}
1406
1396
1407
- static u32 iscsit_do_crypto_hash_sg (
1408
- struct ahash_request * hash ,
1409
- struct iscsit_cmd * cmd ,
1410
- u32 data_offset ,
1411
- u32 data_length ,
1412
- u32 padding ,
1413
- u8 * pad_bytes )
1397
+ static u32 iscsit_crc_sglist (const struct iscsit_cmd * cmd , u32 data_length ,
1398
+ u32 padding , const u8 * pad_bytes )
1414
1399
{
1415
- u32 data_crc ;
1416
- struct scatterlist * sg ;
1417
- unsigned int page_off ;
1418
-
1419
- crypto_ahash_init (hash );
1420
-
1421
- sg = cmd -> first_data_sg ;
1422
- page_off = cmd -> first_data_sg_off ;
1423
-
1424
- if (data_length && page_off ) {
1425
- struct scatterlist first_sg ;
1426
- u32 len = min_t (u32 , data_length , sg -> length - page_off );
1427
-
1428
- sg_init_table (& first_sg , 1 );
1429
- sg_set_page (& first_sg , sg_page (sg ), len , sg -> offset + page_off );
1430
-
1431
- ahash_request_set_crypt (hash , & first_sg , NULL , len );
1432
- crypto_ahash_update (hash );
1433
-
1434
- data_length -= len ;
1435
- sg = sg_next (sg );
1436
- }
1400
+ struct scatterlist * sg = cmd -> first_data_sg ;
1401
+ unsigned int page_off = cmd -> first_data_sg_off ;
1402
+ u32 crc = ~0 ;
1437
1403
1438
1404
while (data_length ) {
1439
- u32 cur_len = min_t (u32 , data_length , sg -> length );
1405
+ u32 cur_len = min_t (u32 , data_length , sg -> length - page_off );
1406
+ const void * virt ;
1440
1407
1441
- ahash_request_set_crypt (hash , sg , NULL , cur_len );
1442
- crypto_ahash_update (hash );
1408
+ virt = kmap_local_page (sg_page (sg )) + sg -> offset + page_off ;
1409
+ crc = crc32c (crc , virt , cur_len );
1410
+ kunmap_local (virt );
1443
1411
1444
- data_length -= cur_len ;
1445
1412
/* iscsit_map_iovec has already checked for invalid sg pointers */
1446
1413
sg = sg_next (sg );
1447
- }
1448
1414
1449
- if (padding ) {
1450
- struct scatterlist pad_sg ;
1451
-
1452
- sg_init_one (& pad_sg , pad_bytes , padding );
1453
- ahash_request_set_crypt (hash , & pad_sg , (u8 * )& data_crc ,
1454
- padding );
1455
- crypto_ahash_finup (hash );
1456
- } else {
1457
- ahash_request_set_crypt (hash , NULL , (u8 * )& data_crc , 0 );
1458
- crypto_ahash_final (hash );
1415
+ page_off = 0 ;
1416
+ data_length -= cur_len ;
1459
1417
}
1460
1418
1461
- return data_crc ;
1419
+ if (padding )
1420
+ crc = crc32c (crc , pad_bytes , padding );
1421
+
1422
+ return ~crc ;
1462
1423
}
1463
1424
1464
- static void iscsit_do_crypto_hash_buf (struct ahash_request * hash ,
1465
- const void * buf , u32 payload_length , u32 padding ,
1466
- const void * pad_bytes , void * data_crc )
1425
+ static u32 iscsit_crc_buf (const void * buf , u32 payload_length ,
1426
+ u32 padding , const void * pad_bytes )
1467
1427
{
1468
- struct scatterlist sg [ 2 ] ;
1428
+ u32 crc = ~ 0 ;
1469
1429
1470
- sg_init_table (sg , ARRAY_SIZE (sg ));
1471
- sg_set_buf (sg , buf , payload_length );
1472
- if (padding )
1473
- sg_set_buf (sg + 1 , pad_bytes , padding );
1430
+ crc = crc32c (crc , buf , payload_length );
1474
1431
1475
- ahash_request_set_crypt (hash , sg , data_crc , payload_length + padding );
1432
+ if (padding )
1433
+ crc = crc32c (crc , pad_bytes , padding );
1476
1434
1477
- crypto_ahash_digest ( hash ) ;
1435
+ return ~ crc ;
1478
1436
}
1479
1437
1480
1438
int
@@ -1662,11 +1620,8 @@ iscsit_get_dataout(struct iscsit_conn *conn, struct iscsit_cmd *cmd,
1662
1620
if (conn -> conn_ops -> DataDigest ) {
1663
1621
u32 data_crc ;
1664
1622
1665
- data_crc = iscsit_do_crypto_hash_sg (conn -> conn_rx_hash , cmd ,
1666
- be32_to_cpu (hdr -> offset ),
1667
- payload_length , padding ,
1668
- cmd -> pad_bytes );
1669
-
1623
+ data_crc = iscsit_crc_sglist (cmd , payload_length , padding ,
1624
+ cmd -> pad_bytes );
1670
1625
if (checksum != data_crc ) {
1671
1626
pr_err ("ITT: 0x%08x, Offset: %u, Length: %u,"
1672
1627
" DataSN: 0x%08x, CRC32C DataDigest 0x%08x"
@@ -1925,10 +1880,8 @@ static int iscsit_handle_nop_out(struct iscsit_conn *conn, struct iscsit_cmd *cm
1925
1880
}
1926
1881
1927
1882
if (conn -> conn_ops -> DataDigest ) {
1928
- iscsit_do_crypto_hash_buf (conn -> conn_rx_hash , ping_data ,
1929
- payload_length , padding ,
1930
- cmd -> pad_bytes , & data_crc );
1931
-
1883
+ data_crc = iscsit_crc_buf (ping_data , payload_length ,
1884
+ padding , cmd -> pad_bytes );
1932
1885
if (checksum != data_crc ) {
1933
1886
pr_err ("Ping data CRC32C DataDigest"
1934
1887
" 0x%08x does not match computed 0x%08x\n" ,
@@ -2328,10 +2281,7 @@ iscsit_handle_text_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd,
2328
2281
goto reject ;
2329
2282
2330
2283
if (conn -> conn_ops -> DataDigest ) {
2331
- iscsit_do_crypto_hash_buf (conn -> conn_rx_hash ,
2332
- text_in , rx_size , 0 , NULL ,
2333
- & data_crc );
2334
-
2284
+ data_crc = iscsit_crc_buf (text_in , rx_size , 0 , NULL );
2335
2285
if (checksum != data_crc ) {
2336
2286
pr_err ("Text data CRC32C DataDigest"
2337
2287
" 0x%08x does not match computed"
@@ -2688,10 +2638,8 @@ static int iscsit_handle_immediate_data(
2688
2638
if (conn -> conn_ops -> DataDigest ) {
2689
2639
u32 data_crc ;
2690
2640
2691
- data_crc = iscsit_do_crypto_hash_sg (conn -> conn_rx_hash , cmd ,
2692
- cmd -> write_data_done , length , padding ,
2693
- cmd -> pad_bytes );
2694
-
2641
+ data_crc = iscsit_crc_sglist (cmd , length , padding ,
2642
+ cmd -> pad_bytes );
2695
2643
if (checksum != data_crc ) {
2696
2644
pr_err ("ImmediateData CRC32C DataDigest 0x%08x"
2697
2645
" does not match computed 0x%08x\n" , checksum ,
@@ -4116,10 +4064,8 @@ static void iscsit_get_rx_pdu(struct iscsit_conn *conn)
4116
4064
break ;
4117
4065
}
4118
4066
4119
- iscsit_do_crypto_hash_buf (conn -> conn_rx_hash , buffer ,
4120
- ISCSI_HDR_LEN , 0 , NULL ,
4121
- & checksum );
4122
-
4067
+ checksum = iscsit_crc_buf (buffer , ISCSI_HDR_LEN , 0 ,
4068
+ NULL );
4123
4069
if (digest != checksum ) {
4124
4070
pr_err ("HeaderDigest CRC32C failed,"
4125
4071
" received 0x%08x, computed 0x%08x\n" ,
@@ -4406,15 +4352,6 @@ int iscsit_close_connection(
4406
4352
*/
4407
4353
iscsit_check_conn_usage_count (conn );
4408
4354
4409
- ahash_request_free (conn -> conn_tx_hash );
4410
- if (conn -> conn_rx_hash ) {
4411
- struct crypto_ahash * tfm ;
4412
-
4413
- tfm = crypto_ahash_reqtfm (conn -> conn_rx_hash );
4414
- ahash_request_free (conn -> conn_rx_hash );
4415
- crypto_free_ahash (tfm );
4416
- }
4417
-
4418
4355
if (conn -> sock )
4419
4356
sock_release (conn -> sock );
4420
4357
0 commit comments