author | Claus Gittinger <cg@exept.de> |
Thu, 17 Jan 2013 23:41:35 +0100 | |
changeset 14668 | dae8d0efb155 |
parent 14667 | f6a830b971f3 |
child 14716 | 19f1a850f981 |
child 18011 | deb0c3355881 |
permissions | -rw-r--r-- |
6864 | 1 |
" |
2 |
COPYRIGHT (c) 1999 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 |
" |
|
7041 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
6864 | 14 |
HashStream subclass:#MD5Stream |
15 |
instanceVariableNames:'hashContext' |
|
16 |
classVariableNames:'HashSize ContextSize' |
|
17 |
poolDictionaries:'' |
|
12419 | 18 |
category:'System-Crypt-Hashing' |
6864 | 19 |
! |
20 |
||
21 |
!MD5Stream primitiveDefinitions! |
|
22 |
%{ |
|
23 |
||
24 |
/* |
|
25 |
* includes, defines, structure definitions |
|
26 |
* and typedefs come here. |
|
27 |
*/ |
|
28 |
||
29 |
#include "md5.h" |
|
30 |
||
31 |
%} |
|
32 |
! ! |
|
33 |
||
34 |
!MD5Stream class methodsFor:'documentation'! |
|
35 |
||
36 |
copyright |
|
37 |
" |
|
38 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
39 |
All Rights Reserved |
|
40 |
||
41 |
This software is furnished under a license and may be used |
|
42 |
only in accordance with the terms of that license and with the |
|
43 |
inclusion of the above copyright notice. This software may not |
|
44 |
be provided or otherwise made available to, or used by, any |
|
45 |
other person. No title to or ownership of the software is |
|
46 |
hereby transferred. |
|
47 |
" |
|
48 |
||
49 |
||
50 |
! |
|
51 |
||
52 |
documentation |
|
53 |
" |
|
54 |
Generate a MD5 hash value as defined in RFC 1321. |
|
12756 | 55 |
This may be used as checksum or for generating cryptographic signatures. |
56 |
||
57 |
Note: |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
58 |
in August 2004, some researchers have found a way to generate full collisions for MD5. |
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
59 |
Therefore, for new applications, it may be wise to choose another hash function for security stuff. |
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
60 |
See a hash-collision example in the examples method. |
6864 | 61 |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
62 |
So, the MD5 algorithm has severe weaknesses, for example it is easy to compute two messages yielding |
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
63 |
the same hash (collision attack). |
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
64 |
The use of this algorithm is only justified for non-cryptographic application. |
13932 | 65 |
|
66 |
||
12265 | 67 |
performance: roughly |
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
68 |
80000 Kb/s on a 2Ghz Duo |
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
69 |
27200 Kb/s on a 1.2Ghz Athlon |
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
70 |
12600 Kb/s on a 400Mhz PIII |
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
71 |
9150 Kb/s on a 300Mhz Sparc. |
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
72 |
performance is almost completely limited by the speed of the md5-routine, which is the reference |
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
73 |
implementation in C from md5lib. |
12756 | 74 |
|
6864 | 75 |
[author:] |
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
76 |
Stefan Vogel |
6864 | 77 |
|
78 |
[see also:] |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
79 |
SHA1Stream |
6864 | 80 |
|
81 |
[class variables:] |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
82 |
HashSize size of returned hash value |
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
83 |
ContextSize (implementation) size of hash context |
6864 | 84 |
|
85 |
[instance variables:] |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
86 |
hashContext (implementation) |
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
87 |
internal buffer for computation of the hash value |
6864 | 88 |
" |
89 |
! |
|
90 |
||
91 |
examples |
|
92 |
" |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
93 |
[exBegin] |
10782 | 94 |
Test Vectors (from FIPS PUB 180-1); results are: |
7041 | 95 |
|
10782 | 96 |
'abc' |
97 |
-> #[90 1 50 98 3C D2 4F B0 D6 96 3F 7D 28 E1 7F 72] |
|
6864 | 98 |
|
10782 | 99 |
'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq' |
100 |
-> #[82 15 EF 7 96 A2 B CA AA E1 16 D3 87 6C 66 4A] |
|
7041 | 101 |
|
10782 | 102 |
A million repetitions of 'a' |
103 |
-> #[77 7 D6 AE 4E 2 7C 70 EE A2 A9 35 C2 29 6F 21] |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
104 |
[exEnd] |
6864 | 105 |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
106 |
[exBegin] |
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
107 |
Transcript showCR:(MD5Stream hashValueOf:'abc') hexPrintString |
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
108 |
[exEnd] |
13001 | 109 |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
110 |
[exBegin] |
12265 | 111 |
(MD5Stream hashValueOf:'abc') |
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
112 |
printOn:Transcript base:16. |
10782 | 113 |
Transcript cr. |
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
114 |
[exEnd] |
6864 | 115 |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
116 |
[exBegin] |
12265 | 117 |
(MD5Stream hashValueOfStream:('abc' readStream)) |
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
118 |
printOn:Transcript base:16. |
10782 | 119 |
Transcript cr. |
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
120 |
[exEnd] |
6864 | 121 |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
122 |
[exBegin] |
6864 | 123 |
|hashStream| |
124 |
||
125 |
hashStream := MD5Stream new. |
|
126 |
hashStream nextPut:'abc'. |
|
127 |
hashStream hashValue printOn:Transcript base:16. Transcript cr. |
|
128 |
hashStream nextPut:'dbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'. |
|
129 |
hashStream hashValue printOn:Transcript base:16. Transcript cr. |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
130 |
[exEnd] |
6864 | 131 |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
132 |
[exBegin] |
6864 | 133 |
|hashStream| |
134 |
||
135 |
hashStream := MD5Stream new. |
|
7041 | 136 |
hashStream nextPut:'a' asByteArray. |
137 |
hashStream nextPut:'bc' asByteArray. |
|
6864 | 138 |
hashStream hashValue printOn:Transcript base:16. Transcript cr. |
139 |
hashStream nextPut:'dbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq' asByteArray. |
|
140 |
hashStream hashValue printOn:Transcript base:16. Transcript cr. |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
141 |
[exEnd] |
6864 | 142 |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
143 |
[exBegin] |
6864 | 144 |
|hashStream| |
145 |
||
146 |
hashStream := MD5Stream new. |
|
147 |
1000000 timesRepeat:[ hashStream nextPut:$a ]. |
|
148 |
hashStream hashValue printOn:Transcript base:16. Transcript cr. |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
149 |
[exEnd] |
6864 | 150 |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
151 |
[exBegin] |
6864 | 152 |
|hashStream| |
153 |
||
154 |
hashStream := MD5Stream new. |
|
155 |
hashStream nextPut:'a'. |
|
156 |
hashStream hashValue printOn:Transcript base:16. Transcript cr. |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
157 |
[exEnd] |
6864 | 158 |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
159 |
[exBegin] |
6864 | 160 |
|hashStream| |
161 |
||
162 |
hashStream := MD5Stream new. |
|
163 |
hashStream nextPut:$a. |
|
164 |
hashStream hashValue printOn:Transcript base:16. Transcript cr. |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
165 |
[exEnd] |
6864 | 166 |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
167 |
[exBegin] |
6864 | 168 |
|hashStream| |
169 |
||
170 |
hashStream := MD5Stream new. |
|
171 |
hashStream nextPut:'abc'. |
|
172 |
hashStream hashValue printOn:Transcript base:16. Transcript cr. |
|
173 |
hashStream reset. |
|
174 |
hashStream nextPut:'abc'. |
|
175 |
hashStream hashValue printOn:Transcript base:16. Transcript cr. |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
176 |
[exEnd] |
6864 | 177 |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
178 |
a collision: |
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
179 |
[exBegin] |
13896 | 180 |
|hashStream| |
181 |
||
182 |
hashStream := MD5Stream new. |
|
183 |
hashStream nextPut:(ByteArray fromHexStringWithSeparators:' |
|
184 |
d131dd02c5e6eec4693d9a0698aff95c 2fcab58712467eab4004583eb8fb7f89 |
|
185 |
55ad340609f4b30283e488832571415a 085125e8f7cdc99fd91dbdf280373c5b |
|
186 |
d8823e3156348f5bae6dacd436c919c6 dd53e2b487da03fd02396306d248cda0 |
|
187 |
e99f33420f577ee8ce54b67080a80d1e c69821bcb6a8839396f9652b6ff72a70'). |
|
188 |
hashStream hashValue printOn:Transcript base:16. Transcript cr. |
|
189 |
hashStream reset. |
|
190 |
||
191 |
hashStream nextPut:(ByteArray fromHexStringWithSeparators:' |
|
192 |
d131dd02c5e6eec4693d9a0698aff95c 2fcab50712467eab4004583eb8fb7f89 |
|
193 |
55ad340609f4b30283e4888325f1415a 085125e8f7cdc99fd91dbd7280373c5b |
|
194 |
d8823e3156348f5bae6dacd436c919c6 dd53e23487da03fd02396306d248cda0 |
|
195 |
e99f33420f577ee8ce54b67080280d1e c69821bcb6a8839396f965ab6ff72a70'). |
|
196 |
hashStream hashValue printOn:Transcript base:16. Transcript cr. |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
197 |
[exEnd] |
13896 | 198 |
|
6864 | 199 |
timing throughput: |
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
200 |
[exBegin] |
6864 | 201 |
|hashStream n t| |
202 |
||
203 |
hashStream := MD5Stream new. |
|
204 |
n := 1000000. |
|
205 |
t := Time millisecondsToRun:[ |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
206 |
n timesRepeat:[ |
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
207 |
hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'. |
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
208 |
]. |
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
209 |
]. |
6864 | 210 |
t := (t / 1000) asFloat. |
211 |
Transcript show:t; show:' seconds for '; show:(50*n/1024) asFloat; showCR:' Kb'. |
|
212 |
Transcript show:(n*50/1024 / t); showCR:' Kb/s' |
|
14667
f6a830b971f3
care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents:
13932
diff
changeset
|
213 |
[exEnd] |
7041 | 214 |
" |
6864 | 215 |
! ! |
216 |
||
217 |
!MD5Stream class methodsFor:'initialization'! |
|
218 |
||
219 |
initialize |
|
220 |
|ctxSize| |
|
221 |
||
222 |
%{ |
|
8913 | 223 |
ctxSize = __mkSmallInteger(sizeof(MD5_CTX)); |
6864 | 224 |
%}. |
225 |
ContextSize := ctxSize. |
|
226 |
HashSize := 16. |
|
227 |
||
228 |
" |
|
229 |
self initialize |
|
230 |
" |
|
231 |
||
232 |
||
233 |
||
234 |
! ! |
|
235 |
||
236 |
!MD5Stream class methodsFor:'queries'! |
|
237 |
||
238 |
blockSize |
|
239 |
"return the block size used internally by the compression function" |
|
240 |
||
241 |
^ 64 |
|
242 |
||
243 |
"Created: / 18.3.1999 / 08:36:44 / stefan" |
|
244 |
! |
|
245 |
||
246 |
hashSize |
|
247 |
"return the size of the hashvalue returned by instances of this class" |
|
248 |
||
249 |
^ HashSize |
|
250 |
||
251 |
"Created: / 18.3.1999 / 08:02:16 / stefan" |
|
252 |
! ! |
|
253 |
||
254 |
!MD5Stream methodsFor:'initialization'! |
|
255 |
||
256 |
initialize |
|
257 |
||
258 |
hashContext := ByteArray new:ContextSize. |
|
259 |
self reset. |
|
260 |
||
261 |
"Modified: / 18.3.1999 / 08:03:42 / stefan" |
|
262 |
! ! |
|
263 |
||
264 |
!MD5Stream methodsFor:'positioning'! |
|
265 |
||
266 |
reset |
|
267 |
"reset the stream in order to compute a new hash value" |
|
268 |
||
269 |
%{ |
|
270 |
if (__isNonNilObject(__INST(hashContext)) && |
|
271 |
__qClass(__INST(hashContext)) == @global(ByteArray) && |
|
272 |
__byteArraySize(__INST(hashContext)) == sizeof(MD5_CTX) |
|
273 |
) { |
|
12265 | 274 |
MD5_CTX *ctx = |
6864 | 275 |
(MD5_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element; |
276 |
||
277 |
MD5Init(ctx); |
|
278 |
RETURN(self); |
|
279 |
} |
|
280 |
%}. |
|
281 |
^ self primitiveFailed |
|
282 |
||
283 |
||
284 |
||
285 |
! ! |
|
286 |
||
287 |
!MD5Stream methodsFor:'queries'! |
|
288 |
||
289 |
hashValue |
|
290 |
"Get the value hashed so far. |
|
291 |
The context is kept, so that more objects may be hashed after |
|
292 |
retrieving a hash value" |
|
293 |
||
294 |
||
295 |
|digest| |
|
296 |
||
297 |
digest := ByteArray new:HashSize. |
|
298 |
||
299 |
%{ |
|
300 |
if (__isNonNilObject(__INST(hashContext)) && |
|
301 |
__qClass(__INST(hashContext)) == @global(ByteArray) && |
|
302 |
__byteArraySize(__INST(hashContext)) == sizeof(MD5_CTX) && |
|
303 |
__isNonNilObject(digest) && |
|
304 |
__qClass(digest) == @global(ByteArray) && |
|
305 |
__byteArraySize(digest) == 16 |
|
306 |
) { |
|
12265 | 307 |
MD5_CTX *ctx = |
6864 | 308 |
(MD5_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element; |
309 |
MD5_CTX copyContext; |
|
310 |
||
311 |
memcpy(©Context, ctx, sizeof(copyContext)); |
|
312 |
MD5Final(__ByteArrayInstPtr(digest)->ba_element, ©Context); |
|
313 |
RETURN(digest); |
|
314 |
} |
|
315 |
%}. |
|
316 |
||
12265 | 317 |
^ self primitiveFailed |
6864 | 318 |
! ! |
319 |
||
320 |
!MD5Stream methodsFor:'writing'! |
|
321 |
||
7042 | 322 |
nextPutBytes:count from:anObject startingAt:start |
323 |
"update the hash value with count bytes from an object starting at index start. |
|
12265 | 324 |
The object must have non-pointer indexed instvars |
7042 | 325 |
(i.e. be a ByteArray, String, Float- or DoubleArray), |
326 |
or an externalBytes object (with known size)" |
|
327 |
||
328 |
%{ |
|
329 |
int len, offs; |
|
330 |
int objSize, nInstVars, nInstBytes; |
|
331 |
char *extPtr; |
|
332 |
||
7197
a68adb223592
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7042
diff
changeset
|
333 |
if (__isNonNilObject(__INST(hashContext)) |
7042 | 334 |
&&__qClass(__INST(hashContext)) == @global(ByteArray) |
335 |
&&__byteArraySize(__INST(hashContext)) == sizeof(MD5_CTX) |
|
336 |
&& __bothSmallInteger(count, start) |
|
7197
a68adb223592
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7042
diff
changeset
|
337 |
) { |
12265 | 338 |
MD5_CTX *ctx = |
339 |
(MD5_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element; |
|
7042 | 340 |
|
12265 | 341 |
len = __intVal(count); |
342 |
offs = __intVal(start) - 1; |
|
7042 | 343 |
|
12265 | 344 |
if (__isExternalBytesLike(anObject)) { |
345 |
OBJ sz; |
|
7042 | 346 |
|
12265 | 347 |
nInstBytes = 0; |
348 |
extPtr = (char *)__externalBytesAddress(anObject); |
|
14668 | 349 |
if (extPtr == (char *)0) goto bad; |
12265 | 350 |
sz = __externalBytesSize(anObject); |
351 |
if (__isSmallInteger(sz)) { |
|
352 |
objSize = __intVal(sz); |
|
353 |
} else { |
|
354 |
objSize = 0; /* unknown */ |
|
355 |
} |
|
356 |
} else { |
|
357 |
OBJ oClass; |
|
7197
a68adb223592
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7042
diff
changeset
|
358 |
|
12265 | 359 |
oClass = __Class(anObject); |
360 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
361 |
case BYTEARRAY: |
|
362 |
case WORDARRAY: |
|
363 |
case LONGARRAY: |
|
364 |
case SWORDARRAY: |
|
365 |
case SLONGARRAY: |
|
366 |
case FLOATARRAY: |
|
367 |
case DOUBLEARRAY: |
|
368 |
break; |
|
369 |
default: |
|
370 |
goto bad; |
|
371 |
} |
|
372 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
373 |
nInstBytes = __OBJS2BYTES__(nInstVars); |
|
374 |
// nInstBytes is the number of bytes occupied by pointer instance variables |
|
375 |
// subtract from size and add to byte-pointer |
|
376 |
objSize = __Size(anObject) - OHDR_SIZE - nInstBytes; |
|
377 |
extPtr = (char *)__byteArrayVal(anObject)+nInstBytes; |
|
378 |
} |
|
379 |
if ((offs >= 0) && (len >= 0) && (objSize >= (len + offs))) { |
|
380 |
MD5Update(ctx, extPtr+offs, len); |
|
381 |
RETURN (count); |
|
382 |
} |
|
7042 | 383 |
} |
384 |
bad: ; |
|
385 |
%}. |
|
386 |
||
387 |
^ self primitiveFailed |
|
6864 | 388 |
! ! |
389 |
||
390 |
!MD5Stream class methodsFor:'documentation'! |
|
391 |
||
392 |
version |
|
14668 | 393 |
^ '$Header: /cvs/stx/stx/libbasic/MD5Stream.st,v 1.22 2013-01-17 22:41:35 cg Exp $' |
12204 | 394 |
! |
395 |
||
396 |
version_CVS |
|
14668 | 397 |
^ '$Header: /cvs/stx/stx/libbasic/MD5Stream.st,v 1.22 2013-01-17 22:41:35 cg Exp $' |
6864 | 398 |
! ! |
399 |
||
400 |
MD5Stream initialize! |