Created
November 14, 2012 18:29
-
-
Save fakessh/4073870 to your computer and use it in GitHub Desktop.
compute hash from crc32 algorythmes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************************** | |
* * | |
* Fichier : crc32.c * | |
* Fonctions pour calculer le hash CRC32 * | |
* * | |
**************************************************************/ | |
/* Table of CRCs of all 8-bit messages. */ | |
unsigned long crc32_table[256]; | |
/* Flag: has the table been computed? Initially false. */ | |
int crc32_table_computed = 0; | |
/* Make the table for a fast CRC. */ | |
void make_crc32_table(void) | |
{ | |
unsigned long c; | |
int n, k; | |
for (n = 0; n < 256; n++) { | |
c = (unsigned long) n; | |
for (k = 0; k < 8; k++) { | |
if (c & 1) { | |
c = 0xedb88320L ^ (c >> 1); | |
} else { | |
c = c >> 1; | |
} | |
} | |
crc32_table[n] = c; | |
} | |
crc32_table_computed = 1; | |
} | |
unsigned long Update_CRC32(unsigned long crc, unsigned char *buf, int len) | |
{ | |
unsigned long c = crc ^ 0xffffffffL; | |
int n; | |
if (!crc32_table_computed) | |
make_crc32_table(); | |
for (n = 0; n < len; n++) { | |
c = crc32_table[(c ^ buf[n]) & 0xff] ^ (c >> 8); | |
} | |
return c ^ 0xffffffffL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment