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