--- a/SHA1Stream.st Thu Dec 20 11:48:59 2012 +0000
+++ b/SHA1Stream.st Sat Jan 19 01:30:00 2013 +0000
@@ -308,27 +308,27 @@
This may be used as checksum or for generating cryptographic signatures.
Notice (2005):
- Be aware that SHA-1 is considered broken and may not be appropriate in some applications.
- Especially it should no longer be used for security stuff.
+ Be aware that SHA-1 is considered broken and may not be appropriate in some applications.
+ Especially it should no longer be used for security stuff.
performance: roughly
- 47400 Kb/s on a 2Ghz Duo
- 9580 Kb/s on a 400Mhz PIII
- 3970 Kb/s on a 300Mhz Sparc
+ 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 SHA256Stream SHA512Stream
+ MD5Stream SHA256Stream SHA512Stream
[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
"
!
@@ -336,7 +336,7 @@
"
Test Vectors (from FIPS PUB 180-1); results are:
- [exBegin]
+ [exBegin]
|hashStream|
hashStream := SHA1Stream new.
@@ -344,16 +344,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.
@@ -362,47 +362,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]
"
! !
@@ -457,14 +457,13 @@
"reset the stream in order to compute a new hash value"
%{
- if (__isNonNilObject(__INST(hashContext)) &&
- __qClass(__INST(hashContext)) == @global(ByteArray) &&
+ if (__isByteArray(__INST(hashContext)) &&
__byteArraySize(__INST(hashContext)) == sizeof(SHA1_CTX)
) {
- SHA1_CTX *ctx = (SHA1_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
+ SHA1_CTX *ctx = (SHA1_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
- SHA1Init(ctx);
- RETURN(self);
+ SHA1Init(ctx);
+ RETURN(self);
}
%}.
^ self primitiveFailed
@@ -486,15 +485,12 @@
digest := ByteArray new:HashSize.
%{
- if (__isNonNilObject(__INST(hashContext)) &&
- __qClass(__INST(hashContext)) == @global(ByteArray) &&
+ if (__isByteArray(__INST(hashContext)) &&
__byteArraySize(__INST(hashContext)) == sizeof(SHA1_CTX) &&
- __isNonNilObject(digest) &&
- __qClass(digest) == @global(ByteArray) &&
+ __isByteArray(digest) &&
__byteArraySize(digest) == 20
) {
- SHA1_CTX *ctx =
- (SHA1_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
+ SHA1_CTX *ctx = (SHA1_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
SHA1_CTX copyContext;
memcpy(©Context, ctx, sizeof(copyContext));
@@ -518,18 +514,17 @@
or an externalBytes object (with known size)"
%{
- int len, offs;
- int objSize, nInstVars, nInstBytes;
+ INT len, offs;
+ INT objSize;
+ int nInstVars, nInstBytes;
char *extPtr;
OBJ oClass;
- if (__isNonNilObject(__INST(hashContext))
- &&__qClass(__INST(hashContext)) == @global(ByteArray)
+ if (__isByteArray(__INST(hashContext))
&& __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;
@@ -540,6 +535,7 @@
nInstBytes = 0;
extPtr = (char *)__externalBytesAddress(anObject);
+ if (extPtr == NULL) goto bad;
sz = __externalBytesSize(anObject);
if (__isSmallInteger(sz)) {
objSize = __intVal(sz);
@@ -580,19 +576,11 @@
!SHA1Stream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.28 2012/01/12 16:38:42 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.30 2013-01-17 23:54:04 cg Exp $'
!
version_CVS
- ^ 'Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.28 2012/01/12 16:38:42 cg Exp '
-!
-
-version_SVN
- ^ '$Id: SHA1Stream.st 10761 2012-01-19 11:46:00Z vranyj1 $'
+ ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.30 2013-01-17 23:54:04 cg Exp $'
! !
SHA1Stream initialize!
-
-
-
-