|
Class: CRC32Stream
Object
|
+--Stream
|
+--HashStream
|
+--CRC32Stream
- Package:
- stx:libbasic2
- Category:
- System-Crypt-Hashing
- Version:
- rev:
1.28
date: 2016/12/20 21:39:17
- user: cg
- file: CRC32Stream.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
- Author:
- Stefan Vogel (stefan@zwerg)
Standard CRC method as defined by ISO 3309 [ISO-3309] or ITU-T V.42 [ITU-T-V42].
The default CRC polynomial employed is
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 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
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
directly affects png image processing.
throughput:
220 Mb/s on MacBook Pro (2.6Ghz I7)
157000 Kb/s on a 2.5Ghz 64X2 Athlon 4800+ (64bit)
150000 Kb/s on 2Ghz Duo
[instance variables:]
[class variables:]
SHA1Stream
MD5Stream
initialization
-
crcTableFor: generatorPolynomInteger
-
-
initialize
-
instance creation
-
generatorPolynom: anInteger
-
self assert:((self generatorPolynom:16r82F63B78)
nextPut:'123456789';
hashValue) = 16rE3069283
-
newCrc32c
-
return an instance of the Castagnoli CRC-32
x32 + x28 + x27 + x26 + x25 + x23 + x22 + x20 + x19 + x18 + x14 + x13 + x11 + x10 + x9 + x8 + x6 + 1
(used in iSCSI & SCTP, G.hn payload, SSE4.2)
usage example(s):
Castagnoli crc:
self assert:((self newCrc32c)
nextPut:'123456789';
hashValue) = 3808858755. '16rE3069283'
default crc:
self assert:((self new)
nextPut:'123456789';
hashValue) = 3421780262. '16rCBF43926'
|
accessing
-
generatorPolynom
-
answer the generator polynom
-
generatorPolynom: anInteger
-
set the generator polynom for this instance.
Note: you have to set the bit-reversed value, so the LSB must be first
-
reset
-
reset the current crc value
initialization
-
initialize
-
initialize the CRC to CRC-32 ITU-T:
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
queries
-
hashValue
-
return the computed CRC
writing
-
nextPutBytes: count from: anObject startingAt: start
-
add the hash of anObject to the computed hash so far.
expect 60C1D0A0
self information:(CRC32Stream hashValueOf:'resume') hexPrintString
|
expect 16r60C1D0A0
self information:(CRC32Stream new
nextPut:$r;
nextPut:$e;
nextPut:$s;
nextPut:$u;
nextPut:$m;
nextPut:$e;
hashValue) hexPrintString
|
expect 16r70E46888:
self information:(CRC32Stream hashValueOf:#[1 2 3 4 5 6 7]) hexPrintString
|
expect 16r8CD04C73:
self information:((CRC32Stream hashValueOf:#[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]) hexPrintString)
|
expect 16r86D7D79A:
timing throughput:
|hashStream n t|
hashStream := CRC32Stream new.
n := 1000000.
t := Time millisecondsToRun:[
n timesRepeat:[
hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
].
].
t := (t / 1000) asFloat.
Transcript show:'crc32:'; showCR: hashStream hashValue hexPrintString.
Transcript show:t; show:' seconds for '; show:(50*n/1024) asFloat; showCR:' Kb'.
Transcript show:(n*50/1024 / t); showCR:' Kb/s'
|
|