|
Class: HashStream
Object
|
+--Stream
|
+--HashStream
|
+--CRCStream
|
+--MD5Stream
|
+--SHA1Stream
- Package:
- stx:libbasic
- Category:
- System-Crypt-Hashing
- Version:
- rev:
1.40
date: 2019/06/06 21:19:34
- user: cg
- file: HashStream.st directory: libbasic
- module: stx stc-classLibrary: libbasic
- Author:
- Stefan Vogel
Abstract class.
Subclasses generate hash values used as checksums
or for generating cryptographic signatures.
Notice: due to historic reasons and compatibility with Squeak,
there are two modes of operation:
1) hashFunction mode, in which the hash of a single block of bytes is computed
2) hashStream mode, in which instances behave like a writeStream, computing and
updating the hash, as data is sent to it.
hashFunction mode is called using: #hashValueOf:aStringOrByteArray
Warning: Not all subclasses support the stream mode
(especially those which were ported from squeak do not).
SHA1Stream
MD5Stream
Compatibility-Squeak
-
hashMessage: aStringOrByteArrayOrStream
-
SQUEAK compatibility
- but this is a bad choice - squeak uses #digestMessage: at the instance side
instance creation
-
new
-
have to re-allow new - it was disabled in Stream
-
random
-
create a random number generator using myself
usage example(s):
queries
-
blockSize
-
return the block size when the hash is used by encryption/decryption.
(see OfbCipherMode and CtrCipherMode)
-
canStream
-
simple hash functions (squeak-ported) cannot stream.
Use hashFunction: there
-
hashBlockSize
-
return the block size used internally by the compression function
** This method raises an error - it must be redefined in concrete classes **
-
hashSize
-
return the size of the hashvalue returned by instances of this class (in bytes)
** This method raises an error - it must be redefined in concrete classes **
-
isAbstract
-
Return if this class is an abstract class.
True is returned here for myself only; false for subclasses.
Abstract subclasses must redefine this again.
self tests
-
test
-
test against testVector
usage example(s):
MD5Stream test.
SHA1Stream test.
RipeMD160Stream test.
|
-
testVector
-
obsolete - moved to TestHashAlgorithms unit test.
** This method raises an error - it must be redefined in concrete classes **
utilities
-
cryptBlock: aStringOrByteArray from: srcIdx to: srcEndOrNil into: resultOrNil startingAt: dstIdx encrypt: encryptMode
-
one-way encryption of aStringOrByteArray.
Used when a HashStream is used as the block cipher with OFB or CTR mode.
encryptMode is ignored here.
-
digestMessage: aStringOrByteArrayOrStream
-
-
hashValueHexString: aString
-
MD5Stream hashValueHexString:'abc'
-
hashValueOf: aStringOrByteArrayOrStream
-
MD5Stream hashValueOf:'BlaBlaBla'
MD5Stream hashValueOf:('makefile' asFilename readStream)
MD5Stream hashValueOf:('BlaBlaBla' readStream)
-
hashValueOfFile: aFilename
-
MD5Stream hashValueOfFile:'makefile'
Compatibility-Squeak
-
digestMessage: bytes
-
SQUEAK: answer the digest of bytes
-
hashMessage: bytes
-
SQUEAK: answer the digest of bytes
accessing
-
contents
-
return the entire contents of the stream
- this is our hashValue.
not implemented
-
next
-
I can only write
operations
-
hashValueOf: bytes
-
answer the digest of bytes
usage example(s):
SHA1Stream new
hashValueOf:'123456789abcdefg';
hashValueOf:'123456789abcdefg'
(SHA1Stream new hmac key:'123456')
hashValueOf:'123456789abcdefg';
hashValueOf:'123456789abcdefg'
(SHA1Stream new hmac key:'123456')
nextPutAll:'123456789abcdefg';
contents
|
-
reset
-
initialize to a clean state
** This method raises an error - it must be redefined in concrete classes **
queries
-
blockSize
-
the class knows about the basic block size
-
hashBlockSize
-
the class knows about the basic block size
-
hashSize
-
return the size of the returned hashvalue (in bytes)
-
hashValue
-
return the value of the computed hash
** This method raises an error - it must be redefined in concrete classes **
-
isReadable
-
return true, if reading is supported by the receiver.
Always return false here
-
isWritable
-
return true, if writing is supported by the receiver.
Always return true here
testing
-
atEnd
-
return true if the end of the stream has been reached;
this is never reached
writing
-
nextPut: anObject
-
add the hash of anObject to the computed hash so far.
anObject can be a Character, SmallInteger ByteArray or String
-
nextPutAll: aCollection
-
Hash streams handle Strings and ByteArrays in #nextPutBytes:
-
nextPutByte: aByte
-
add the hash of anObject to the computed hash so far.
aByte can be a SmallInteger <= 255
-
nextPutBytes: count from: anObject startingAt: start
-
write count bytes from an object starting at index start.
Return the number of bytes written.
The object must have non-pointer indexed instvars
(i.e. be a ByteArray, String, Float- or DoubleArray).
** This method raises an error - it must be redefined in concrete classes **
hashFunction mode:
MD5Stream hashValueOf:'hello world'
MD4Stream hashValueOf:'hello world'
|
hashStream mode:
|md5|
md5 := MD5Stream new.
md5 nextPutAll:'hello world'.
md5 hashValue
|
|