--- a/MD5Stream.st Tue Oct 13 18:54:04 2009 +0200
+++ b/MD5Stream.st Wed Oct 14 07:17:40 2009 +0200
@@ -55,30 +55,30 @@
This may be used as checksum
or for generating cryptographic signatures.
- performance: roughly
- 80000 Kb/s on a 2Ghz Duo
- 27200 Kb/s on a 1.2Ghz Athlon
- 12600 Kb/s on a 400Mhz PIII
- 9150 Kb/s on a 300Mhz Sparc.
+ performance: roughly
+ 80000 Kb/s on a 2Ghz Duo
+ 27200 Kb/s on a 1.2Ghz Athlon
+ 12600 Kb/s on a 400Mhz PIII
+ 9150 Kb/s on a 300Mhz Sparc.
[author:]
- Stefan Vogel
+ Stefan Vogel
[see also:]
- SHA1Stream
+ SHA1Stream
[class variables:]
- HashSize size of returned hash value
- ContextSize (implementation) size of hash context
+ HashSize size of returned hash value
+ ContextSize (implementation) size of hash context
[instance variables:]
- hashContext (implementation)
- internal buffer for computation of the hash value
+ hashContext (implementation)
+ internal buffer for computation of the hash value
"
!
examples
"
- [exBegin]
+ [exBegin]
Test Vectors (from FIPS PUB 180-1); results are:
'abc'
@@ -89,22 +89,22 @@
A million repetitions of 'a'
-> #[77 7 D6 AE 4E 2 7C 70 EE A2 A9 35 C2 29 6F 21]
- [exEnd]
+ [exEnd]
- [exBegin]
- (MD5Stream hashValueOf:'abc')
- printOn:Transcript base:16.
+ [exBegin]
+ (MD5Stream hashValueOf:'abc')
+ printOn:Transcript base:16.
Transcript cr.
- [exEnd]
+ [exEnd]
- [exBegin]
- (MD5Stream hashValueOfStream:('abc' readStream))
- printOn:Transcript base:16.
+ [exBegin]
+ (MD5Stream hashValueOfStream:('abc' readStream))
+ printOn:Transcript base:16.
Transcript cr.
- [exEnd]
+ [exEnd]
- [exBegin]
+ [exBegin]
|hashStream|
hashStream := MD5Stream new.
@@ -112,9 +112,9 @@
hashStream hashValue printOn:Transcript base:16. Transcript cr.
hashStream nextPut:'dbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'.
hashStream hashValue printOn:Transcript base:16. Transcript cr.
- [exEnd]
+ [exEnd]
- [exBegin]
+ [exBegin]
|hashStream|
hashStream := MD5Stream new.
@@ -123,33 +123,33 @@
hashStream hashValue printOn:Transcript base:16. Transcript cr.
hashStream nextPut:'dbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq' asByteArray.
hashStream hashValue printOn:Transcript base:16. Transcript cr.
- [exEnd]
+ [exEnd]
- [exBegin]
+ [exBegin]
|hashStream|
hashStream := MD5Stream new.
1000000 timesRepeat:[ hashStream nextPut:$a ].
hashStream hashValue printOn:Transcript base:16. Transcript cr.
- [exEnd]
+ [exEnd]
- [exBegin]
+ [exBegin]
|hashStream|
hashStream := MD5Stream new.
hashStream nextPut:'a'.
hashStream hashValue printOn:Transcript base:16. Transcript cr.
- [exEnd]
+ [exEnd]
- [exBegin]
+ [exBegin]
|hashStream|
hashStream := MD5Stream new.
hashStream nextPut:$a.
hashStream hashValue printOn:Transcript base:16. Transcript cr.
- [exEnd]
+ [exEnd]
- [exBegin]
+ [exBegin]
|hashStream|
hashStream := MD5Stream new.
@@ -158,23 +158,23 @@
hashStream reset.
hashStream nextPut:'abc'.
hashStream hashValue printOn:Transcript base:16. Transcript cr.
- [exEnd]
+ [exEnd]
timing throughput:
- [exBegin]
+ [exBegin]
|hashStream n t|
hashStream := MD5Stream new.
n := 1000000.
t := Time millisecondsToRun:[
- n timesRepeat:[
- hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
- ].
- ].
+ n timesRepeat:[
+ hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
+ ].
+ ].
t := (t / 1000) asFloat.
Transcript show:t; show:' seconds for '; show:(50*n/1024) asFloat; showCR:' Kb'.
Transcript show:(n*50/1024 / t); showCR:' Kb/s'
- [exEnd]
+ [exEnd]
"
! !
@@ -219,15 +219,15 @@
testVector
- ^ #(
- ('abc'
- #[16r90 16r01 16r50 16r98 16r3C 16rD2 16r4F 16rB0 16rD6 16r96 16r3F 16r7D 16r28 16rE1 16r7F 16r72])
+ ^ #(
+ ('abc'
+ #[16r90 16r01 16r50 16r98 16r3C 16rD2 16r4F 16rB0 16rD6 16r96 16r3F 16r7D 16r28 16rE1 16r7F 16r72])
- ('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
- #[16r82 16r15 16rEF 16r07 16r96 16rA2 16r0B 16rCA 16rAA 16rE1 16r16 16rD3 16r87 16r6C 16r66 16r4A])
- ) copyWith:
- (Array with:(String new:1000000 withAll:$a)
- with:#[16r77 16r07 16rD6 16rAE 16r4E 16r02 16r7C 16r70 16rEE 16rA2 16rA9 16r35 16rC2 16r29 16r6F 16r21])
+ ('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
+ #[16r82 16r15 16rEF 16r07 16r96 16rA2 16r0B 16rCA 16rAA 16rE1 16r16 16rD3 16r87 16r6C 16r66 16r4A])
+ ) copyWith:
+ (Array with:(String new:1000000 withAll:$a)
+ with:#[16r77 16r07 16rD6 16rAE 16r4E 16r02 16r7C 16r70 16rEE 16rA2 16rA9 16r35 16rC2 16r29 16r6F 16r21])
"
@@ -255,7 +255,7 @@
__qClass(__INST(hashContext)) == @global(ByteArray) &&
__byteArraySize(__INST(hashContext)) == sizeof(MD5_CTX)
) {
- MD5_CTX *ctx =
+ MD5_CTX *ctx =
(MD5_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
MD5Init(ctx);
@@ -288,7 +288,7 @@
__qClass(digest) == @global(ByteArray) &&
__byteArraySize(digest) == 16
) {
- MD5_CTX *ctx =
+ MD5_CTX *ctx =
(MD5_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
MD5_CTX copyContext;
@@ -298,7 +298,7 @@
}
%}.
- ^ self primitiveFailed
+ ^ self primitiveFailed
! !
!MD5Stream methodsFor:'writing'!
@@ -315,70 +315,70 @@
__qClass(__INST(hashContext)) == @global(ByteArray) &&
__byteArraySize(__INST(hashContext)) == sizeof(MD5_CTX)
) {
- MD5_CTX *ctx =
- (MD5_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
+ MD5_CTX *ctx =
+ (MD5_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
- if (__isNonNilObject(anObject)) {
- OBJ cls =__qClass(anObject);
- INT mask = (INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK);
+ if (__isNonNilObject(anObject)) {
+ OBJ cls =__qClass(anObject);
+ INT mask = (INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK);
- if (cls == @global(String) || cls == @global(Symbol)) {
- /* String: omit leading '\0' */
+ if (cls == @global(String) || cls == @global(Symbol)) {
+ /* String: omit leading '\0' */
- MD5Update(ctx, __StringInstPtr(anObject)->s_element, __stringSize(anObject));
- } else if (mask != __MASKSMALLINT(POINTERARRAY) &&
- mask != __MASKSMALLINT(WKPOINTERARRAY) &&
- mask != __MASKSMALLINT(0)
- ) {
- /* Byte|Integer|.... Array */
+ MD5Update(ctx, __StringInstPtr(anObject)->s_element, __stringSize(anObject));
+ } else if (mask != __MASKSMALLINT(POINTERARRAY) &&
+ mask != __MASKSMALLINT(WKPOINTERARRAY) &&
+ mask != __MASKSMALLINT(0)
+ ) {
+ /* Byte|Integer|.... Array */
- register int n;
- char *pFirst;
+ register int n;
+ char *pFirst;
- n /* nInstVars */ = __intVal(__ClassInstPtr(cls)->c_ninstvars);
- n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* nInstVars */);
- pFirst = (char *)(__InstPtr(anObject)) + n /* nInstBytes */;
- n /* nbytes */ = __qSize(anObject) - n /* nInstBytes */;
- MD5Update(ctx, pFirst, n);
- } else if (cls == @global(Character)) {
- /* Character */
-
- INT val = __intVal(_characterVal(anObject));
- if (val > 255) {
- /* Two byte character */
- short s = val;
- MD5Update(ctx, &s, 2);
- } else {
- char c = val;
- MD5Update(ctx, &c, 1);
- }
- } else {
- ret = false;
- }
- } else {
- if (anObject == nil) {
- ret = false;
- } else {
- /* SmallInteger */
-
- INT i = __intVal(anObject);
- MD5Update(ctx, &i, sizeof(INT));
- }
- }
+ n /* nInstVars */ = __intVal(__ClassInstPtr(cls)->c_ninstvars);
+ n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* nInstVars */);
+ pFirst = (char *)(__InstPtr(anObject)) + n /* nInstBytes */;
+ n /* nbytes */ = __qSize(anObject) - n /* nInstBytes */;
+ MD5Update(ctx, pFirst, n);
+ } else if (cls == @global(Character)) {
+ /* Character */
+
+ INT val = __intVal(_characterVal(anObject));
+ if (val > 255) {
+ /* Two byte character */
+ short s = val;
+ MD5Update(ctx, &s, 2);
+ } else {
+ char c = val;
+ MD5Update(ctx, &c, 1);
+ }
+ } else {
+ ret = false;
+ }
+ } else {
+ if (anObject == nil) {
+ ret = false;
+ } else {
+ /* SmallInteger */
+
+ INT i = __intVal(anObject);
+ MD5Update(ctx, &i, sizeof(INT));
+ }
+ }
}
%}.
ret notNil ifTrue:[
- ^ self primitiveFailed
+ ^ self primitiveFailed
].
-
+
"Created: 22.10.1996 / 21:53:24 / stefan"
!
nextPutBytes:count from:anObject startingAt:start
"update the hash value with count bytes from an object starting at index start.
- The object must have non-pointer indexed instvars
+ The object must have non-pointer indexed instvars
(i.e. be a ByteArray, String, Float- or DoubleArray),
or an externalBytes object (with known size)"
@@ -392,50 +392,50 @@
&&__byteArraySize(__INST(hashContext)) == sizeof(MD5_CTX)
&& __bothSmallInteger(count, start)
) {
- MD5_CTX *ctx =
- (MD5_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
+ MD5_CTX *ctx =
+ (MD5_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
- len = __intVal(count);
- offs = __intVal(start) - 1;
+ len = __intVal(count);
+ offs = __intVal(start) - 1;
- if (__isExternalBytesLike(anObject)) {
- OBJ sz;
+ if (__isExternalBytesLike(anObject)) {
+ OBJ sz;
- nInstBytes = 0;
- extPtr = (char *)__externalBytesAddress(anObject);
- sz = __externalBytesSize(anObject);
- if (__isSmallInteger(sz)) {
- objSize = __intVal(sz);
- } else {
- objSize = 0; /* unknown */
- }
- } else {
- OBJ oClass;
+ nInstBytes = 0;
+ extPtr = (char *)__externalBytesAddress(anObject);
+ sz = __externalBytesSize(anObject);
+ if (__isSmallInteger(sz)) {
+ objSize = __intVal(sz);
+ } else {
+ objSize = 0; /* unknown */
+ }
+ } else {
+ OBJ oClass;
- oClass = __Class(anObject);
- switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
- case BYTEARRAY:
- case WORDARRAY:
- case LONGARRAY:
- case SWORDARRAY:
- case SLONGARRAY:
- case FLOATARRAY:
- case DOUBLEARRAY:
- break;
- default:
- goto bad;
- }
- nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
- nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
- // nInstBytes is the number of bytes occupied by pointer instance variables
- // subtract from size and add to byte-pointer
- objSize = __Size(anObject) - nInstBytes;
- extPtr = (char *)__byteArrayVal(anObject)+nInstBytes;
- }
- if ((offs >= 0) && (len >= 0) && (objSize >= (len + offs))) {
- MD5Update(ctx, extPtr+offs, len);
- RETURN (count);
- }
+ oClass = __Class(anObject);
+ switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
+ case BYTEARRAY:
+ case WORDARRAY:
+ case LONGARRAY:
+ case SWORDARRAY:
+ case SLONGARRAY:
+ case FLOATARRAY:
+ case DOUBLEARRAY:
+ break;
+ default:
+ goto bad;
+ }
+ nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
+ nInstBytes = __OBJS2BYTES__(nInstVars);
+ // nInstBytes is the number of bytes occupied by pointer instance variables
+ // subtract from size and add to byte-pointer
+ objSize = __Size(anObject) - OHDR_SIZE - nInstBytes;
+ extPtr = (char *)__byteArrayVal(anObject)+nInstBytes;
+ }
+ if ((offs >= 0) && (len >= 0) && (objSize >= (len + offs))) {
+ MD5Update(ctx, extPtr+offs, len);
+ RETURN (count);
+ }
}
bad: ;
%}.
@@ -446,11 +446,11 @@
!MD5Stream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/MD5Stream.st,v 1.9 2009-10-13 14:33:33 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/MD5Stream.st,v 1.10 2009-10-14 05:17:40 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/MD5Stream.st,v 1.9 2009-10-13 14:33:33 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/MD5Stream.st,v 1.10 2009-10-14 05:17:40 cg Exp $'
! !
MD5Stream initialize!
--- a/SHA1Stream.st Tue Oct 13 18:54:04 2009 +0200
+++ b/SHA1Stream.st Wed Oct 14 07:17:40 2009 +0200
@@ -308,24 +308,24 @@
This may be used as checksum
or for generating cryptographic signatures.
- performance: roughly
- 47400 Kb/s on a 2Ghz Duo
- 9580 Kb/s on a 400Mhz PIII
- 3970 Kb/s on a 300Mhz Sparc
+ performance: roughly
+ 47400 Kb/s on a 2Ghz Duo
+ 9580 Kb/s on a 400Mhz PIII
+ 3970 Kb/s on a 300Mhz Sparc
[author:]
- Stefan Vogel
+ Stefan Vogel
[see also:]
- MD5Stream
+ MD5Stream
[class variables:]
- HashSize size of returned hash value
- ContextSize (implementation) size of hash context
+ HashSize size of returned hash value
+ ContextSize (implementation) size of hash context
[instance variables:]
- hashContext (implementation)
- internal buffer for computation of the hash value
+ hashContext (implementation)
+ internal buffer for computation of the hash value
"
!
@@ -342,7 +342,7 @@
A million repetitions of 'a'
-> 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
- [exBegin]
+ [exBegin]
|hashStream|
hashStream := SHA1Stream new.
@@ -350,16 +350,16 @@
hashStream hashValue printOn:Transcript base:16. Transcript cr.
hashStream nextPut:'dbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'.
hashStream hashValue printOn:Transcript base:16. Transcript cr.
- [exEnd]
+ [exEnd]
- [exBegin]
+ [exBegin]
|hashValue|
hahValue := SHA1Stream hashValueOf:'abc'.
hashValue printOn:Transcript base:16. Transcript cr.
- [exEnd]
+ [exEnd]
- [exBegin]
+ [exBegin]
|hashStream|
hashStream := SHA1Stream new.
@@ -368,47 +368,47 @@
hashStream nextPut:'dbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq' asByteArray.
hashStream hashValue printOn:Transcript base:16. Transcript cr.
- [exEnd]
+ [exEnd]
- [exBegin]
+ [exBegin]
|hashStream|
hashStream := SHA1Stream new.
1000000 timesRepeat:[ hashStream nextPut:$a ].
hashStream hashValue printOn:Transcript base:16. Transcript cr.
- [exEnd]
+ [exEnd]
- [exBegin]
+ [exBegin]
|hashStream|
hashStream := SHA1Stream new.
hashStream nextPut:'a'.
hashStream hashValue printOn:Transcript base:16. Transcript cr.
- [exEnd]
+ [exEnd]
- [exBegin]
+ [exBegin]
|hashStream|
hashStream := SHA1Stream new.
hashStream nextPut:$a.
hashStream hashValue printOn:Transcript base:16. Transcript cr.
- [exEnd]
+ [exEnd]
timing throughput:
- [exBegin]
+ [exBegin]
|hashStream n t|
hashStream := SHA1Stream new.
n := 1000000.
t := Time millisecondsToRun:[
- n timesRepeat:[
- hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
- ].
- ].
+ n timesRepeat:[
+ hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
+ ].
+ ].
t := (t / 1000) asFloat.
Transcript show:t; show:' seconds for '; show:(50*n/1024) asFloat; showCR:' Kb'.
Transcript show:(n*50/1024 / t); showCR:' Kb/s'
- [exEnd]
+ [exEnd]
"
! !
@@ -630,48 +630,48 @@
&& __byteArraySize(__INST(hashContext)) == sizeof(SHA1_CTX)
&& __bothSmallInteger(count, start)
) {
- SHA1_CTX *ctx =
- (SHA1_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
+ SHA1_CTX *ctx =
+ (SHA1_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
- len = __intVal(count);
- offs = __intVal(start) - 1;
+ len = __intVal(count);
+ offs = __intVal(start) - 1;
- oClass = __Class(anObject);
- if (oClass == ExternalBytes) {
- OBJ sz;
+ oClass = __Class(anObject);
+ if (oClass == ExternalBytes) {
+ OBJ sz;
- nInstBytes = 0;
- extPtr = (char *)__externalBytesAddress(anObject);
- sz = __externalBytesSize(anObject);
- if (__isSmallInteger(sz)) {
- objSize = __intVal(sz);
- } else {
- objSize = 0; /* unknown */
- }
- } else {
- switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
- case BYTEARRAY:
- case WORDARRAY:
- case LONGARRAY:
- case SWORDARRAY:
- case SLONGARRAY:
- case FLOATARRAY:
- case DOUBLEARRAY:
- break;
- default:
- goto bad;
- }
- nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
- nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
- // nInstBytes is the number of bytes occupied by pointer instance variables
- // subtract from size and add to byte-pointer
- objSize = __Size(anObject) - nInstBytes;
- extPtr = (char *)__byteArrayVal(anObject)+nInstBytes;
- }
- if ((offs >= 0) && (len >= 0) && (objSize >= (len + offs))) {
- SHA1Update(ctx, extPtr+offs, len);
- RETURN (count);
- }
+ nInstBytes = 0;
+ extPtr = (char *)__externalBytesAddress(anObject);
+ sz = __externalBytesSize(anObject);
+ if (__isSmallInteger(sz)) {
+ objSize = __intVal(sz);
+ } else {
+ objSize = 0; /* unknown */
+ }
+ } else {
+ switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
+ case BYTEARRAY:
+ case WORDARRAY:
+ case LONGARRAY:
+ case SWORDARRAY:
+ case SLONGARRAY:
+ case FLOATARRAY:
+ case DOUBLEARRAY:
+ break;
+ default:
+ goto bad;
+ }
+ nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
+ nInstBytes = __OBJS2BYTES__(nInstVars);
+ // nInstBytes is the number of bytes occupied by pointer instance variables
+ // subtract from size and add to byte-pointer
+ objSize = __Size(anObject) - OHDR_SIZE - nInstBytes;
+ extPtr = (char *)__byteArrayVal(anObject)+nInstBytes;
+ }
+ if ((offs >= 0) && (len >= 0) && (objSize >= (len + offs))) {
+ SHA1Update(ctx, extPtr+offs, len);
+ RETURN (count);
+ }
}
bad: ;
%}.
@@ -682,11 +682,11 @@
!SHA1Stream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.15 2009-10-13 14:34:09 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.16 2009-10-14 05:17:40 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.15 2009-10-13 14:34:09 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.16 2009-10-14 05:17:40 cg Exp $'
! !
SHA1Stream initialize!