Add proper per-file copyright notices/licenses and top-level license.
[bluesky.git] / bluesky / crc32c.c
index 8e11bbf..40ce983 100644 (file)
 #include <stdint.h>
 #include "bluesky-private.h"
 
+/* Generator polynomial is 0x1edc6f41; input and output are reflected.  The
+ * recommended starting value for the accumulator is ~0, and the bits of the
+ * CRC are inverted at the end as well. */
+
 static const uint32_t crc32c_table[256] = {
     0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L,
     0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL,
@@ -101,5 +105,5 @@ uint32_t crc32c(uint32_t crc, const char *buf, unsigned int length)
 
 uint32_t crc32c_finalize(uint32_t crc)
 {
-    return GUINT32_TO_LE(crc);
+    return ~GUINT32_TO_LE(crc);
 }