From 745f4540091a14c1b4df602f3734a69d968957e6 Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Fri, 3 Nov 2017 10:10:18 +0800 Subject: [PATCH] crc32c 1.2 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 --- _crc32c.c | 2 ++ setup.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/_crc32c.c b/_crc32c.c index 9d0b55c..ae3e67b 100644 --- a/_crc32c.c +++ b/_crc32c.c @@ -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); diff --git a/setup.py b/setup.py index 1e5e379..7ebce3e 100644 --- a/setup.py +++ b/setup.py @@ -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,