Browse Source Download (without any required ccan dependencies)
crc
routines for crc of bytes
Rusty Russell <[email protected]>
Gary S. Brown, Clay Haapala
Cyclic Redundancy Check routines. These are reasonably fast checksum routines, but not suitable for cryptographic use.
They are useful for simple error detection, eg. a 32-bit CRC will detect a single error burst of up to 32 bits.
#include <ccan/crc/crc.h>
#include <stdio.h>
#include <stdlib.h>
// Given "IHATEMATH" outputs 0x35c6ad5a
int main(int argc, char *argv[])
{
if (argc != 2) {
fprintf(stderr, "Usage: %s <string>\n"
"Prints 32 bit CRC of the string\n", argv[0]);
exit(1);
}
printf("0x%08x\n", crc32_ieee(0, argv[1], strlen(argv[1])));
exit(0);
}
GPL (v2 or any later version)