Skip to content
Snippets Groups Projects
Commit a6a3a742 authored by rswindell's avatar rswindell
Browse files

Moved crc32 function here from misc.c.

parent 6ee7eb44
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,9 @@
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#include <string.h> /* strlen */
#include "crc32.h"
long crc32tbl[]={ /* CRC polynomial 0xedb88320 */
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
......@@ -70,5 +73,21 @@ long crc32tbl[]={ /* CRC polynomial 0xedb88320 */
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
/****************************************************************************/
/* Returns CRC-32 of sequence of bytes (binary or ASCIIZ) */
/* Pass len of 0 to auto-determine ASCIIZ string length */
/* or non-zero for arbitrary binary data */
/****************************************************************************/
unsigned long crc32(char *buf, unsigned long len)
{
unsigned long l,crc=0xffffffff;
if(len==0)
len=strlen(buf);
for(l=0;l<len;l++)
crc=ucrc32(buf[l],crc);
return(~crc);
}
......@@ -35,8 +35,13 @@
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#ifndef _CRC32_H_
#define _CRC32_H_
extern long crc32tbl[];
#define ucrc32(ch,crc) (crc32tbl[(crc^ch)&0xff]^(crc>>8))
unsigned long crc32(char *buf, unsigned long len);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment