summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>1998-10-06 21:43:58 +0000
committerLuke Leighton <lkcl@samba.org>1998-10-06 21:43:58 +0000
commitb960514077419ddd13dcd8824f40ad1b0e3555d1 (patch)
tree095369d8ffff9fea0c0ca9241a61d6b34d2230d4
parentf8a3e2df1186de898866087536e56892b8e10ba7 (diff)
downloadsamba-b960514077419ddd13dcd8824f40ad1b0e3555d1.tar.gz
samba-b960514077419ddd13dcd8824f40ad1b0e3555d1.tar.bz2
samba-b960514077419ddd13dcd8824f40ad1b0e3555d1.zip
crc32 algorithm. obtained from dr dobb's journal
http://www.ddj.com/ftp/1992/1992.05/crcman.zip. copyright 1992 mark r nelson. (This used to be commit 73667141af2f707fe306a0fda4853d160e55bd97)
-rw-r--r--source3/lib/crc32.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/source3/lib/crc32.c b/source3/lib/crc32.c
new file mode 100644
index 0000000000..ef9cefea18
--- /dev/null
+++ b/source3/lib/crc32.c
@@ -0,0 +1,70 @@
+/*
+ * Dr Dobb's Journal: http://www.ddj.com/ftp/1992/1992.05/crcman.zip
+ *
+ * Copyright Mark R. Nelson 1992
+ *
+ */
+
+#include "includes.h"
+
+#define CRC32_POLYNOMIAL 0xEDB88320L
+
+/*****************************************************************
+ Instead of performing a straightforward calculation of the 32 bit
+ CRC using a series of logical operations, this program uses the
+ faster table lookup method. This routine is called once when the
+ program starts up to build the table which will be used later
+ when calculating the CRC values.
+ *****************************************************************/
+
+static uint32 CRCTable[256];
+
+void crc32_build_table(void)
+{
+ int i;
+ int j;
+ uint32 crc;
+
+ for ( i = 0; i <= 255 ; i++ )
+ {
+ crc = i;
+ for ( j = 8 ; j > 0; j-- )
+ {
+ if ( crc & 1 )
+ {
+ crc = ( crc >> 1 ) ^ CRC32_POLYNOMIAL;
+ }
+ else
+ {
+ crc >>= 1;
+ }
+ }
+ CRCTable[ i ] = crc;
+ }
+}
+
+/*****************************************************************
+ This routine calculates the CRC for a block of data using the
+ table lookup method.
+ *****************************************************************/
+
+uint32 crc32_calc_buffer( uint32 count, uchar *buffer)
+{
+ uchar *p;
+ uint32 crc;
+
+ p = buffer;
+ crc = 0xffffffff;
+
+ while ( count-- != 0 )
+ {
+ uint32 temp1;
+ uint32 temp2;
+
+ temp1 = ( crc >> 8 ) & 0x00FFFFFFL;
+ temp2 = CRCTable[ ( (int) crc ^ *p++ ) & 0xff ];
+ crc = temp1 ^ temp2;
+ }
+ return crc;
+}
+