From 443b104833718d130f94a0fa3e2cc8bdd6d02984 Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Thu, 5 Jan 2017 14:39:15 +0100 Subject: [PATCH] crc32c: use uint_t types Signed-off-by: Peter Lieven --- include/iscsi-private.h | 2 +- lib/crc32c.c | 6 +++--- lib/socket.c | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/iscsi-private.h b/include/iscsi-private.h index 60d216e..b9f38f7 100644 --- a/include/iscsi-private.h +++ b/include/iscsi-private.h @@ -355,7 +355,7 @@ void* iscsi_smalloc(struct iscsi_context *iscsi, size_t size); void* iscsi_szmalloc(struct iscsi_context *iscsi, size_t size); void iscsi_sfree(struct iscsi_context *iscsi, void* ptr); -unsigned long crc32c(char *buf, int len); +uint32_t crc32c(uint8_t *buf, int len); struct scsi_task *iscsi_scsi_get_task_from_pdu(struct iscsi_pdu *pdu); diff --git a/lib/crc32c.c b/lib/crc32c.c index 0ae2cda..4455171 100644 --- a/lib/crc32c.c +++ b/lib/crc32c.c @@ -43,7 +43,7 @@ /* */ /*****************************************************************/ -static unsigned long crctable[256] = { +uint32_t crctable[256] = { 0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L, 0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL, 0x8AD958CFL, 0x78B2DBCCL, 0x6BE22838L, 0x9989AB3BL, @@ -110,9 +110,9 @@ static unsigned long crctable[256] = { 0xBE2DA0A5L, 0x4C4623A6L, 0x5F16D052L, 0xAD7D5351L }; -unsigned long crc32c(char *buf, int len) +uint32_t crc32c(uint8_t *buf, int len) { - unsigned long crc = 0xffffffff; + uint32_t crc = 0xffffffff; while (len-- > 0) { crc = (crc>>8) ^ crctable[(crc ^ (*buf++)) & 0xFF]; } diff --git a/lib/socket.c b/lib/socket.c index caf51a5..3b32ba2 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -677,7 +677,7 @@ iscsi_read_from_socket(struct iscsi_context *iscsi) static int iscsi_pdu_update_headerdigest(struct iscsi_context *iscsi, struct iscsi_pdu *pdu) { - unsigned long crc; + uint32_t crc; if (pdu->outdata.size < ISCSI_RAW_HEADER_SIZE + ISCSI_DIGEST_SIZE) { iscsi_set_error(iscsi, "PDU too small (%u) to contain header digest", @@ -685,12 +685,12 @@ static int iscsi_pdu_update_headerdigest(struct iscsi_context *iscsi, struct isc return -1; } - crc = crc32c((char *)pdu->outdata.data, ISCSI_RAW_HEADER_SIZE); + crc = crc32c(pdu->outdata.data, ISCSI_RAW_HEADER_SIZE); - pdu->outdata.data[ISCSI_RAW_HEADER_SIZE+3] = (crc >> 24)&0xff; - pdu->outdata.data[ISCSI_RAW_HEADER_SIZE+2] = (crc >> 16)&0xff; - pdu->outdata.data[ISCSI_RAW_HEADER_SIZE+1] = (crc >> 8)&0xff; - pdu->outdata.data[ISCSI_RAW_HEADER_SIZE+0] = (crc) &0xff; + pdu->outdata.data[ISCSI_RAW_HEADER_SIZE+3] = (crc >> 24); + pdu->outdata.data[ISCSI_RAW_HEADER_SIZE+2] = (crc >> 16); + pdu->outdata.data[ISCSI_RAW_HEADER_SIZE+1] = (crc >> 8); + pdu->outdata.data[ISCSI_RAW_HEADER_SIZE+0] = (crc); return 0; }