+
+// From http://www.cl.cam.ac.uk/research/srg/bluebook/21/crc/node6.html
+#define QUOTIENT 0x04c11db7
+void Link_InitCRC(void)
+{
+ int i, j;
+ Uint32 crc;
+
+ for (i = 0; i < 256; i++)
+ {
+ crc = i << 24;
+ for (j = 0; j < 8; j++)
+ {
+ if (crc & 0x80000000)
+ crc = (crc << 1) ^ QUOTIENT;
+ else
+ crc = crc << 1;
+ }
+ gaiLink_CRCTable[i] = crc;
+ }
+
+ gbLink_CRCTableGenerated = 1;
+}
+
+Uint32 Link_CalculateCRC(void *Data, int Length)
+{
+ // x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1
+ Uint32 result;
+ int i;
+ Uint32 *data = Data;
+
+ if(Length < 4) return 0;
+
+ result = *data++ << 24;
+ result |= *data++ << 16;
+ result |= *data++ << 8;
+ result |= *data++;
+ result = ~ result;
+ Length -= 4;
+
+ for( i = 0; i < Length; i++ )
+ {
+ result = (result << 8 | *data++) ^ gaiLink_CRCTable[result >> 24];
+ }
+
+ return ~result;
+}