Commit 5cbeb9fd authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Fix handling of 16-byte quantities in endianness adjusted check-summing.

parent c7b07c41
......@@ -112,16 +112,17 @@ memcrc_r(uint32_t *state, const unsigned char *block, size_t block_len)
*state = s;
}
#define SWAP_CSUM(BITWIDTH,BYTEWIDTH) \
#define SWAP_CSUM(BITWIDTH,BYTEWIDTH,NACC) \
do { \
register const uint##BITWIDTH##_t *b = (uint##BITWIDTH##_t *)elems; \
for (size_t i = 0; i < num_elems; ++i) { \
uint##BITWIDTH##_t accum = b[i]; \
for (size_t j = 0; j < BYTEWIDTH; ++j) \
{ \
uint32_t c = (uint32_t)(accum & UCHAR_MAX); \
s = (s << 8) ^ crctab[(s >> 24) ^ c]; \
accum >>= 8; \
for(size_t aofs = NACC; aofs > 0; --aofs) { \
uint##BITWIDTH##_t accum = b[i + aofs - 1]; \
for (size_t j = 0; j < BYTEWIDTH; ++j) { \
uint32_t c = (uint32_t)(accum & UCHAR_MAX); \
s = (s << 8) ^ crctab[(s >> 24) ^ c]; \
accum >>= 8; \
} \
} \
} \
} while (0)
......@@ -148,16 +149,16 @@ memcrc_r_eswap(uint32_t *state, const unsigned char *elems, size_t num_elems,
memcrc_r(state, elems, num_elems * elem_size);
return;
case 2:
SWAP_CSUM(16,2);
SWAP_CSUM(16,2,1);
break;
case 4:
SWAP_CSUM(32,4);
SWAP_CSUM(32,4,1);
break;
case 8:
SWAP_CSUM(64,8);
SWAP_CSUM(64,8,1);
break;
case 16:
SWAP_CSUM(64,8);
SWAP_CSUM(64,8,2);
break;
}
*state = s;
......@@ -182,3 +183,13 @@ memcrc_finish(uint32_t *state, off_t total_size)
return ~s;
}
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment