Skip to content

Commit

Permalink
crc32c 1.2
Browse files Browse the repository at this point in the history
This version changes the behavior of the crc32 method, making it easier
for users to start using it (they don't need to specify an initial value
of 0xffffffff) and to get the final checksum value (they don't need to
XOR the value with 0xffffffff after the final call).

This is achieved by the same trick used by other crc32 methods:
 * The default value for the crc parameter is 0
 * The crc value is XORed with 0xffffffff, thus yielding 0xffffffff for
   the initial register value.
 * The final register value is XORed with 0xffffffff, taking this
   responsibility away from the user.
 * If the method is called in a loop with adjacent chunks of a message
   (e.g., crc32('def', crc32('abc')) for message 'abcdef'), the crc
   from the first call will effectively pass through two XORs with
   0xffffffff, and thus the internal checksum loop will proceed with the
   correct value.

Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
  • Loading branch information
rtobar committed Nov 3, 2017
1 parent da4ddf6 commit 745f454
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions _crc32c.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ PyObject* crc32c_crc32(PyObject *self, PyObject *args) {
return NULL;

bin_data = pbin.buf;
crc ^= 0xffffffff;
uint32_t result = _crc32c_intel(crc, bin_data, pbin.len);
result ^= 0xffffffff;

PyBuffer_Release(&pbin);
return PyInt_FromLong(result);
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
author='The ICRAR DIA Team',
url='https://github.com/ICRAR/crc32c',
author_email='rtobar@icrar.org',
version='1.1',
version='1.2',
license="LGPLv2.1+",
description='A python package exposing the Intel SSE4.2 CRC32C instruction',
classifiers=classifiers,
Expand Down

0 comments on commit 745f454

Please sign in to comment.