Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CRC32 C or C++ implementation [closed]

Tags:

c++

c

crc32

I'm looking for an implementation of CRC32 in C or C++ that is explicitly licensed as being no cost or public domain. The implementation here seems nice, but the only thing it says about the license is "source code", which isn't good enough. I'd prefer non LGPL so I don't have to fool around with a DLL (my app is closed source). I saw the adler32 implementation in zlib, but I'm checking small chunks of data, which adler is not good for.

like image 577
twk Avatar asked Nov 19 '08 18:11

twk


People also ask

Can a CRC32 be reversed?

A CRC32 is only reversible if the original string is 4 bytes or less.

What does CRC32 mean?

CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.

How do you calculate CRC?

The theory of a CRC calculation is straight forward. The data is treated by the CRC algorithm as a binary num- ber. This number is divided by another binary number called the polynomial. The rest of the division is the CRC checksum, which is appended to the transmitted message.


2 Answers

I am the author of the source code at the specified link. While the intention of the source code license is not clear (it will be later today), the code is in fact open and free for use in your free or commercial applications with no strings attached.

like image 22
NTDLS Avatar answered Oct 20 '22 01:10

NTDLS


The SNIPPETS C Source Code Archive has a CRC32 implementation that is freely usable:

/* Copyright (C) 1986 Gary S. Brown.  You may use this program, or    code or tables extracted from it, as desired without restriction.*/ 

(Unfortunately, c.snippets.org seems to have died. Fortunately, the Wayback Machine has it archived.)

In order to be able to compile the code, you'll need to add typedefs for BYTE as an unsigned 8-bit integer and DWORD as an unsigned 32-bit integer, along with the header files crc.h & sniptype.h.

The only critical item in the header is this macro (which could just as easily go in CRC_32.c itself:

#define UPDC32(octet, crc) (crc_32_tab[((crc) ^ (octet)) & 0xff] ^ ((crc) >> 8)) 
like image 66
cjm Avatar answered Oct 20 '22 01:10

cjm