Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
libcdi
Commits
5cbeb9fd
Commit
5cbeb9fd
authored
Apr 17, 2014
by
Thomas Jahns
🤸
Browse files
Fix handling of 16-byte quantities in endianness adjusted check-summing.
parent
c7b07c41
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/cksum.c
View file @
5cbeb9fd
...
...
@@ -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:
*/
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment