CRC32Stream.st
changeset 2746 d9d60eda74b3
parent 2705 47bcf29473ad
child 2747 c6e4b8d6d9e7
--- a/CRC32Stream.st	Tue May 08 16:15:57 2012 +0200
+++ b/CRC32Stream.st	Thu May 17 12:34:17 2012 +0200
@@ -42,14 +42,14 @@
         x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1
         (or 16r04C11DB7)
 
-    You can also create an instace perforing the Castagnioli CRC-32C 
+    You can also create an instace performing the Castagnioli CRC-32C 
     (used in iSCSI & SCTP, G.hn payload, SSE4.2):
 
         self newCrc32c
 
         x32 + x28 + x27 + x26 + x25 + x23 + x22 + x20 + x19 + x18 + x14 + x13 + x11 + x10 + x9 + x8 + x6 + 1 
 
-    Use CRC to protect against communication errors;
+    Only use CRC to protect against communication errors;
     do NOT use CRC for cryptography - use SHA1Stream or MD5Stream instead.
 
     Notice that this CRC is also used with PNG images - therefore, its performance 
@@ -290,6 +290,27 @@
 
                 _crcTable = __integerArrayVal( __INST(crcTable) );
 
+#ifdef __LSBFIRST__
+                if (((unsigned)cp & 3) == 0) {
+                    // word aligned
+                    while (n >= 4) {
+                        unsigned word;
+                        unsigned _idx;
+
+                        word = ((unsigned int *)cp)[0];
+                        _idx = (_crc ^ word) & 0xFF;
+                        _crc = _crcTable[_idx] ^ (_crc >> 8);
+                        _idx = (_crc ^ (word>>8)) & 0xFF;
+                        _crc = _crcTable[_idx] ^ (_crc >> 8);
+                        _idx = (_crc ^ (word>>16)) & 0xFF;
+                        _crc = _crcTable[_idx] ^ (_crc >> 8);
+                        _idx = (_crc ^ (word>>24)) & 0xFF;
+                        _crc = _crcTable[_idx] ^ (_crc >> 8);
+                        cp += 4;
+                        n -= 4;
+                    }
+                }
+#endif
                 while (n > 3) {
                     unsigned _idx;
 
@@ -327,11 +348,11 @@
 !CRC32Stream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/CRC32Stream.st,v 1.21 2012-01-12 11:25:06 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/CRC32Stream.st,v 1.22 2012-05-17 10:34:17 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic2/CRC32Stream.st,v 1.21 2012-01-12 11:25:06 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/CRC32Stream.st,v 1.22 2012-05-17 10:34:17 cg Exp $'
 ! !
 
 CRC32Stream initialize!