mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 19:01:57 -04:00
Uses -1 as initial value for the CRC computation.
This commit is contained in:
parent
053bdd9952
commit
5136eb3719
4 changed files with 14 additions and 7 deletions
|
|
@ -236,6 +236,7 @@ struct crc_test_vector {
|
|||
* Test vectors for CRC32C (Castagnoli)
|
||||
*/
|
||||
static struct crc_test_vector TEST_CRC32C[] = {
|
||||
{ "", 0, 0 },
|
||||
{ "\x61", 1, 0xc1d04330 },
|
||||
{ "\x66\x6f\x6f", 3, 0xcfc4ae1d },
|
||||
{ "\x68\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64", 11, 0xc99465aa },
|
||||
|
|
@ -261,7 +262,7 @@ static void crc32ctest(void)
|
|||
|
||||
for(i=0;TEST_CRC32C[i].data;++i) {
|
||||
uint32_t digest;
|
||||
digest = 0xffffffffU ^ crc32c(0xffffffffU, (const unsigned char*)TEST_CRC32C[i].data, TEST_CRC32C[i].len);
|
||||
digest = CRC_IV ^ crc32c(CRC_IV, (const unsigned char*)TEST_CRC32C[i].data, TEST_CRC32C[i].len);
|
||||
if (digest != TEST_CRC32C[i].digest) {
|
||||
fprintf(stderr, "Failed CRC32C test vector %u\n", i);
|
||||
exit(EXIT_FAILURE);
|
||||
|
|
|
|||
2
state.c
2
state.c
|
|
@ -2103,7 +2103,7 @@ static void decoding_error(const char* path, STREAM* f)
|
|||
crc_computed = scrc(f);
|
||||
|
||||
/* adjust the stored crc to include itself */
|
||||
crc_stored = crc32c(crc_stored, buf, 4);
|
||||
crc_stored = crc32c(crc_stored ^ CRC_IV, buf, 4) ^ CRC_IV;
|
||||
|
||||
if (crc_computed != crc_stored) {
|
||||
fprintf(stderr, "Mismatching CRC in '%s'\n", path);
|
||||
|
|
|
|||
10
util.c
10
util.c
|
|
@ -84,8 +84,8 @@ STREAM* sopen_read(const char* file)
|
|||
s->state_index = 0;
|
||||
s->offset = 0;
|
||||
s->offset_uncached = 0;
|
||||
s->crc = 0;
|
||||
s->crc_uncached = 0;
|
||||
s->crc = CRC_IV;
|
||||
s->crc_uncached = CRC_IV;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
@ -109,8 +109,8 @@ STREAM* sopen_multi_write(unsigned count)
|
|||
s->state_index = 0;
|
||||
s->offset = 0;
|
||||
s->offset_uncached = 0;
|
||||
s->crc = 0;
|
||||
s->crc_uncached = 0;
|
||||
s->crc = CRC_IV;
|
||||
s->crc_uncached = CRC_IV;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
@ -251,7 +251,7 @@ int64_t stell(STREAM* s)
|
|||
|
||||
uint32_t scrc(STREAM*s)
|
||||
{
|
||||
return crc32c(s->crc_uncached, s->buffer, s->pos - s->buffer);
|
||||
return crc32c(s->crc_uncached, s->buffer, s->pos - s->buffer) ^ CRC_IV;
|
||||
}
|
||||
|
||||
int sgettok(STREAM* f, char* str, int size)
|
||||
|
|
|
|||
6
util.h
6
util.h
|
|
@ -496,6 +496,12 @@ void randomize(void* ptr, unsigned size);
|
|||
/****************************************************************************/
|
||||
/* crc */
|
||||
|
||||
/**
|
||||
* CRC initial value.
|
||||
* Using a not zero value allows to detect trailing zeros at the end.
|
||||
*/
|
||||
#define CRC_IV 0xffffffffU
|
||||
|
||||
/**
|
||||
* Computes the CRC-32 (Castagnoli)
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue