|
Class: SHA1Stream
Object
|
+--Stream
|
+--HashStream
|
+--SHA1Stream
- Package:
- stx:libbasic
- Category:
- System-Crypt-Hashing
- Version:
- rev:
1.60
date: 2021/01/20 10:25:57
- user: cg
- file: SHA1Stream.st directory: libbasic
- module: stx stc-classLibrary: libbasic
Generate a SHA-1 hash value as defined in
NIST, FIPS PUB 180-1: Secure Hash Standard, April 1995.
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.
performance: roughly
200 Mb/s on a 2012 MAC Powerbook (2.6Ghz I7)
150 Mb/s on a 2007 MAC Powerbook (2.6Ghz Duo)
120 Mb/s on a 2.5Ghz 64X2 Athlon 4800+ (64bit)
47400 Kb/s on a 2Ghz Duo (old measure)
9580 Kb/s on a 400Mhz PIII
3970 Kb/s on a 300Mhz Sparc
[class variables:]
HashSize size of returned hash value
ContextSize (implementation) size of hash context
[instance variables:]
hashContext (implementation)
internal buffer for computation of the hash value
copyrightCOPYRIGHT (c) 1999-2013 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
performanceCPU cc algo mb/sec
MAC (2010 macbook; 2.7Ghz Duo) clang -O2 slow 128.5
132
MAC (2012 macbook; 2.6Ghz I7) clang -O2 190
chunk size 10: 86.70 Mb/s 90.83
chunk size 50: 227.07 Mb/s 238.42
chunk size 1000: 405.82 Mb/s 414.64
chunk size 50000: 421.98 Mb/s 447.73
timing throughput:
[exBegin]
|hashStream n t|
hashStream := SHA1Stream new.
n := 1000000.
t := Time millisecondsToRun:[
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]
initialization
-
initialize
-
self initialize
queries
-
hashBlockSize
-
return the block size used internally by the compression function
-
hashSize
-
return the size of the hashvalue returned by instances of this class
initialization
-
initialize
-
(comment from inherited method)
just to ignore initialize to objects which do not need it
positioning
-
reset
-
reset the stream in order to compute a new hash value
-
seedWith: fiveWordVector
-
seed the stream with 5*16 (for testing)
queries
-
hashValue
-
Get the value hashed so far.
The context is kept, so that more objects may be hashed after
retrieving a hash value
writing
-
nextPutByte: anInteger
-
update the hash value with anInteger <= 255.
-
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
(i.e. be a ByteArray, String, Float- or DoubleArray),
or an externalBytes object (with known size)
Test Vectors (from FIPS PUB 180-1); results are:
|hashStream|
hashStream := SHA1Stream new.
hashStream nextPut:'abc'.
hashStream hashValue printOn:Transcript base:16. Transcript cr.
hashStream nextPut:'dbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'.
hashStream hashValue printOn:Transcript base:16. Transcript cr.
|
|hashValue|
hashValue := SHA1Stream hashValueOf:'hello world'.
self assert:(hashValue hexPrintString = '2AAE6C35C94FCFB415DBE95F408B9CE91EE846ED')
|
|hashValue|
hashValue := SHA1Stream hashValueOf:'abc'.
hashValue printOn:Transcript base:16. Transcript cr.
|
|hashStream|
hashStream := SHA1Stream new.
hashStream nextPut:'abc' asByteArray.
hashStream hashValue printOn:Transcript base:16. Transcript cr.
hashStream nextPut:'dbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq' asByteArray.
hashStream hashValue printOn:Transcript base:16. Transcript cr.
|
|hashStream|
hashStream := SHA1Stream new.
1000000 timesRepeat:[ hashStream nextPut:$a ].
hashStream hashValue printOn:Transcript base:16. Transcript cr.
|
|hashStream|
hashStream := SHA1Stream new.
hashStream nextPut:'a'.
hashStream hashValue printOn:Transcript base:16. Transcript cr.
|
|hashStream|
hashStream := SHA1Stream new.
hashStream nextPut:$a.
hashStream hashValue printOn:Transcript base:16. Transcript cr.
|
timing throughput:
|hashStream n t|
hashStream := SHA1Stream new.
n := 1000000.
t := Time millisecondsToRun:[
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'
|
|