4919
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
4906
|
3 |
"
|
|
4 |
COPYRIGHT (c) 2019 by eXept Software AG
|
|
5 |
All Rights Reserved
|
|
6 |
|
|
7 |
This software is furnished under a license and may be used
|
|
8 |
only in accordance with the terms of that license and with the
|
|
9 |
inclusion of the above copyright notice. This software may not
|
|
10 |
be provided or otherwise made available to, or used by, any
|
|
11 |
other person. No title to or ownership of the software is
|
|
12 |
hereby transferred.
|
|
13 |
"
|
|
14 |
"{ Package: 'stx:libbasic2' }"
|
|
15 |
|
|
16 |
"{ NameSpace: Smalltalk }"
|
|
17 |
|
|
18 |
CRCStream subclass:#CRC8Stream
|
|
19 |
instanceVariableNames:''
|
|
20 |
classVariableNames:''
|
|
21 |
poolDictionaries:''
|
|
22 |
category:'System-Crypt-Hashing'
|
|
23 |
!
|
|
24 |
|
|
25 |
!CRC8Stream class methodsFor:'documentation'!
|
|
26 |
|
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 2019 by eXept Software AG
|
|
30 |
All Rights Reserved
|
|
31 |
|
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
|
39 |
!
|
|
40 |
|
|
41 |
documentation
|
|
42 |
"
|
|
43 |
ATTENTION: CRC8Stream is currently BROKEN (in development)
|
|
44 |
|
|
45 |
newSAE_J1850:
|
|
46 |
Standard CRC method as defined by SAE J1850 (used in AUTOSAR)
|
|
47 |
The polynomial is 0x1D; initial value 0xFF; xorOut is 0xFF
|
|
48 |
|
|
49 |
[author:]
|
|
50 |
Claus Gittinger
|
|
51 |
|
|
52 |
[instance variables:]
|
|
53 |
|
|
54 |
[class variables:]
|
|
55 |
|
|
56 |
[see also:]
|
|
57 |
SHA1Stream
|
|
58 |
MD5Stream
|
|
59 |
|
|
60 |
"
|
|
61 |
!
|
|
62 |
|
|
63 |
examples
|
|
64 |
"
|
|
65 |
expect xxx:
|
|
66 |
[exBegin]
|
|
67 |
self information:(CRC8Stream new hashValueOf:'resume') hexPrintString
|
|
68 |
[exEnd]
|
|
69 |
|
|
70 |
expect xxx:
|
|
71 |
[exBegin]
|
|
72 |
self information:(CRC16Stream new
|
|
73 |
nextPut:$r;
|
|
74 |
nextPut:$e;
|
|
75 |
nextPut:$s;
|
|
76 |
nextPut:$u;
|
|
77 |
nextPut:$m;
|
|
78 |
nextPut:$e;
|
|
79 |
hashValue) hexPrintString
|
|
80 |
[exEnd]
|
|
81 |
|
|
82 |
expect xxx:
|
|
83 |
[exBegin]
|
|
84 |
self information:(CRC16Stream hashValueOf:#[1 2 3 4 5 6 7]) hexPrintString
|
|
85 |
[exEnd]
|
|
86 |
|
|
87 |
expect xxx:
|
|
88 |
[exBegin]
|
|
89 |
self information:((CRC16Stream hashValueOf:#[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
|
|
90 |
16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
|
|
91 |
16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
|
|
92 |
16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]) hexPrintString)
|
|
93 |
[exEnd]
|
|
94 |
|
|
95 |
expect xxx:
|
|
96 |
timing throughput:
|
|
97 |
[exBegin]
|
|
98 |
|hashStream n t|
|
|
99 |
|
|
100 |
hashStream := CRC16Stream new.
|
|
101 |
n := 1000000.
|
|
102 |
t := Time millisecondsToRun:[
|
|
103 |
n timesRepeat:[
|
|
104 |
hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
|
|
105 |
].
|
|
106 |
].
|
|
107 |
t := (t / 1000) asFloat.
|
|
108 |
Transcript show:'crc16:'; showCR: hashStream hashValue hexPrintString.
|
|
109 |
Transcript show:t; show:' seconds for '; show:(50*n/1024) asFloat; showCR:' Kb'.
|
|
110 |
Transcript show:(n*50/1024 / t); showCR:' Kb/s'
|
|
111 |
[exEnd]
|
|
112 |
|
|
113 |
"
|
|
114 |
! !
|
|
115 |
|
|
116 |
!CRC8Stream class methodsFor:'instance creation'!
|
|
117 |
|
|
118 |
generatorPolynomMSB:anInteger
|
|
119 |
"notice, in literature, the generator polynom is usually specified as an MSB number"
|
|
120 |
|
|
121 |
^ self generatorPolynom:(anInteger bitReversed8)
|
|
122 |
|
|
123 |
"Created: / 16-03-2019 / 20:58:49 / Claus Gittinger"
|
|
124 |
"Modified: / 24-03-2019 / 12:15:05 / Claus Gittinger"
|
|
125 |
!
|
|
126 |
|
|
127 |
generatorPolynomMSB:anInteger initValue:initValue
|
|
128 |
"notice, in literature, the generator polynom is usually specified as an MSB number"
|
|
129 |
|
|
130 |
^ self generatorPolynom:(anInteger bitReversed8) initValue:initValue
|
|
131 |
|
|
132 |
"Created: / 16-03-2019 / 21:12:24 / Claus Gittinger"
|
|
133 |
"Modified: / 24-03-2019 / 12:15:09 / Claus Gittinger"
|
|
134 |
!
|
|
135 |
|
|
136 |
generatorPolynomMSB:anInteger initValue:initValueArg xorOut:xorOut
|
|
137 |
"notice, in literature, the generator polynom is usually specified as an MSB number"
|
|
138 |
|
|
139 |
^ self generatorPolynom:(anInteger bitReversed8) initValue:initValueArg xorOut:xorOut
|
|
140 |
|
|
141 |
"Created: / 16-03-2019 / 21:29:04 / Claus Gittinger"
|
|
142 |
"Modified: / 24-03-2019 / 12:15:13 / Claus Gittinger"
|
|
143 |
!
|
|
144 |
|
|
145 |
newSAE_J1850
|
|
146 |
"return an instance of the SAE_J1850 CRC8 (used in AUTOSAR)"
|
|
147 |
|
4919
|
148 |
self error:'currently broken'.
|
4906
|
149 |
^ self generatorPolynomMSB:16r1D initValue:16rFF xorOut:16rFF
|
|
150 |
|
|
151 |
"Created: / 24-03-2019 / 11:34:16 / Claus Gittinger"
|
4919
|
152 |
"Modified: / 25-03-2019 / 14:27:48 / Claus Gittinger"
|
|
153 |
!
|
|
154 |
|
|
155 |
new_2F
|
|
156 |
"return an instance of the CRC8-2F (used in AUTOSAR).
|
|
157 |
Currently broken."
|
|
158 |
|
|
159 |
self error:'currently broken'.
|
|
160 |
^ self generatorPolynom:16r2F initValue:16rFF xorOut:16rFF
|
|
161 |
|
|
162 |
"Created: / 25-03-2019 / 14:25:16 / Claus Gittinger"
|
4906
|
163 |
! !
|
|
164 |
|
|
165 |
!CRC8Stream class methodsFor:'queries'!
|
|
166 |
|
|
167 |
hashSize
|
|
168 |
"return the size of the hashvalue returned by instances of this class (in bytes)"
|
|
169 |
|
|
170 |
^ 1
|
|
171 |
|
|
172 |
"Created: / 24-03-2019 / 12:52:58 / Claus Gittinger"
|
|
173 |
! !
|
|
174 |
|
|
175 |
!CRC8Stream methodsFor:'initialization'!
|
|
176 |
|
|
177 |
generatorPolynom:anLSBInteger
|
|
178 |
"set the generator polynom for this instance,
|
|
179 |
set start and xorOut to 16rFF.
|
|
180 |
Note: you have to set the bit-reversed value, so the LSB must be first"
|
|
181 |
|
|
182 |
self generatorPolynom:anLSBInteger
|
|
183 |
initValue:16rFF xorOut:16rFF.
|
|
184 |
|
|
185 |
"Modified: / 24-03-2019 / 11:30:56 / Claus Gittinger"
|
|
186 |
!
|
|
187 |
|
|
188 |
generatorPolynom:anLSBInteger initValue:initValueArg
|
|
189 |
"set the generator polynom for this instance.
|
|
190 |
set start to initValueArg and xorOut to 16rFF.
|
|
191 |
Note: you have to set the bit-reversed value, so the LSB must be first"
|
|
192 |
|
|
193 |
self generatorPolynom:anLSBInteger
|
|
194 |
initValue:initValueArg xorOut:16rFF
|
|
195 |
|
|
196 |
"Created: / 16-03-2019 / 21:24:03 / Claus Gittinger"
|
|
197 |
"Modified: / 24-03-2019 / 11:31:06 / Claus Gittinger"
|
|
198 |
! !
|
|
199 |
|
|
200 |
!CRC8Stream methodsFor:'queries'!
|
|
201 |
|
|
202 |
hashValue
|
|
203 |
"return the computed CRC"
|
|
204 |
|
|
205 |
^ super hashValue bitAnd:16rFF
|
|
206 |
|
|
207 |
"Created: / 24-03-2019 / 12:08:33 / Claus Gittinger"
|
|
208 |
! !
|
|
209 |
|
|
210 |
!CRC8Stream class methodsFor:'documentation'!
|
|
211 |
|
|
212 |
version_CVS
|
|
213 |
^ '$Header$'
|
|
214 |
! !
|
|
215 |
|