9 other person. No title to or ownership of the software is |
9 other person. No title to or ownership of the software is |
10 hereby transferred. |
10 hereby transferred. |
11 " |
11 " |
12 "{ Package: 'stx:libbasic2' }" |
12 "{ Package: 'stx:libbasic2' }" |
13 |
13 |
|
14 "{ NameSpace: Smalltalk }" |
|
15 |
14 HashStream subclass:#CRC32Stream |
16 HashStream subclass:#CRC32Stream |
15 instanceVariableNames:'crc generatorPolynom crcTable' |
17 instanceVariableNames:'crc generatorPolynom crcTable' |
16 classVariableNames:'CrcTables' |
18 classVariableNames:'CrcTables' |
17 poolDictionaries:'' |
19 poolDictionaries:'' |
18 category:'System-Crypt-Hashing' |
20 category:'System-Crypt-Hashing' |
37 documentation |
39 documentation |
38 " |
40 " |
39 Standard CRC method as defined by ISO 3309 [ISO-3309] or ITU-T V.42 [ITU-T-V42]. |
41 Standard CRC method as defined by ISO 3309 [ISO-3309] or ITU-T V.42 [ITU-T-V42]. |
40 The default CRC polynomial employed is |
42 The default CRC polynomial employed is |
41 |
43 |
42 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 |
44 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 |
43 (or 16r04C11DB7) |
45 (or 16r04C11DB7) |
44 |
46 |
45 You can also create an instace performing the Castagnioli CRC-32C |
47 You can also create an instace performing the Castagnioli CRC-32C |
46 (used in iSCSI & SCTP, G.hn payload, SSE4.2): |
48 (used in iSCSI & SCTP, G.hn payload, SSE4.2): |
47 |
49 |
48 self newCrc32c |
50 self newCrc32c |
49 |
51 |
50 x32 + x28 + x27 + x26 + x25 + x23 + x22 + x20 + x19 + x18 + x14 + x13 + x11 + x10 + x9 + x8 + x6 + 1 |
52 x32 + x28 + x27 + x26 + x25 + x23 + x22 + x20 + x19 + x18 + x14 + x13 + x11 + x10 + x9 + x8 + x6 + 1 |
51 |
53 |
52 Only use CRC to protect against communication errors; |
54 Only use CRC to protect against communication errors; |
53 do NOT use CRC for cryptography - use SHA1Stream or MD5Stream instead. |
55 do NOT use CRC for cryptography - use SHA1Stream or MD5Stream instead. |
54 |
56 |
55 Notice that this CRC is also used with PNG images - therefore, its performance |
57 Notice that this CRC is also used with PNG images - therefore, its performance |
56 directly affects png image processing. |
58 directly affects png image processing. |
57 |
59 |
58 throughput: |
60 throughput: |
59 157000 Kb/s on a 2.5Ghz 64X2 Athlon 4800+ (64bit) |
61 220 Mb/s on MacBook Pro (2.6Ghz I7) |
60 150000 Kb/s on 2Ghz Duo |
62 157000 Kb/s on a 2.5Ghz 64X2 Athlon 4800+ (64bit) |
|
63 150000 Kb/s on 2Ghz Duo |
61 |
64 |
62 [author:] |
65 [author:] |
63 Stefan Vogel (stefan@zwerg) |
66 Stefan Vogel (stefan@zwerg) |
64 |
67 |
65 [instance variables:] |
68 [instance variables:] |
66 |
69 |
67 [class variables:] |
70 [class variables:] |
68 |
71 |
69 [see also:] |
72 [see also:] |
70 SHA1Stream |
73 SHA1Stream |
71 MD5Stream |
74 MD5Stream |
72 |
75 |
73 " |
76 " |
74 ! |
77 ! |
75 |
78 |
76 examples |
79 examples |
77 " |
80 " |
78 |
81 |
79 expect 60C1D0A0 |
82 expect 60C1D0A0 |
80 [exBegin] |
83 [exBegin] |
81 self information:(CRC32Stream hashValueOf:'resume') hexPrintString |
84 self information:(CRC32Stream hashValueOf:'resume') hexPrintString |
82 [exEnd] |
85 [exEnd] |
83 |
86 |
84 expect 16r60C1D0A0 |
87 expect 16r60C1D0A0 |
85 [exBegin] |
88 [exBegin] |
86 self information:(CRC32Stream new |
89 self information:(CRC32Stream new |
87 nextPut:$r; |
90 nextPut:$r; |
88 nextPut:$e; |
91 nextPut:$e; |
89 nextPut:$s; |
92 nextPut:$s; |
90 nextPut:$u; |
93 nextPut:$u; |
91 nextPut:$m; |
94 nextPut:$m; |
92 nextPut:$e; |
95 nextPut:$e; |
93 hashValue) hexPrintString |
96 hashValue) hexPrintString |
94 [exEnd] |
97 [exEnd] |
95 |
98 |
96 expect 16r70E46888: |
99 expect 16r70E46888: |
97 [exBegin] |
100 [exBegin] |
98 self information:(CRC32Stream hashValueOf:#[1 2 3 4 5 6 7]) hexPrintString |
101 self information:(CRC32Stream hashValueOf:#[1 2 3 4 5 6 7]) hexPrintString |
99 [exEnd] |
102 [exEnd] |
100 |
103 |
101 expect 16r8CD04C73: |
104 expect 16r8CD04C73: |
102 [exBegin] |
105 [exBegin] |
103 self information:((CRC32Stream hashValueOf:#[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF |
106 self information:((CRC32Stream hashValueOf:#[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF |
104 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF |
107 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF |
105 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF |
108 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF |
106 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]) hexPrintString) |
109 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]) hexPrintString) |
107 [exEnd] |
110 [exEnd] |
108 |
111 |
109 expect 16r86D7D79A: |
112 expect 16r86D7D79A: |
110 timing throughput: |
113 timing throughput: |
111 [exBegin] |
114 [exBegin] |
112 |hashStream n t| |
115 |hashStream n t| |
113 |
116 |
114 hashStream := CRC32Stream new. |
117 hashStream := CRC32Stream new. |
115 n := 1000000. |
118 n := 1000000. |
116 t := Time millisecondsToRun:[ |
119 t := Time millisecondsToRun:[ |
117 n timesRepeat:[ |
120 n timesRepeat:[ |
118 hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'. |
121 hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'. |
119 ]. |
122 ]. |
120 ]. |
123 ]. |
121 t := (t / 1000) asFloat. |
124 t := (t / 1000) asFloat. |
122 Transcript show:'crc32:'; showCR: hashStream hashValue hexPrintString. |
125 Transcript show:'crc32:'; showCR: hashStream hashValue hexPrintString. |
123 Transcript show:t; show:' seconds for '; show:(50*n/1024) asFloat; showCR:' Kb'. |
126 Transcript show:t; show:' seconds for '; show:(50*n/1024) asFloat; showCR:' Kb'. |
124 Transcript show:(n*50/1024 / t); showCR:' Kb/s' |
127 Transcript show:(n*50/1024 / t); showCR:' Kb/s' |
125 [exEnd] |
128 [exEnd] |
126 |
129 |
127 " |
130 " |
128 ! ! |
131 ! ! |
129 |
132 |
130 !CRC32Stream class methodsFor:'initialization'! |
133 !CRC32Stream class methodsFor:'initialization'! |