|
Class: HashStream
Object
|
+--Stream
|
+--HashStream
|
+--CRCStream
|
+--MD5Stream
|
+--SHA1Stream
- Package:
- stx:libbasic
- Category:
- System-Crypt-Hashing
- Version:
- rev:
1.50
date: 2024/01/30 09:35:57
- user: cg
- file: HashStream.st directory: libbasic
- module: stx stc-classLibrary: libbasic
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).
copyrightCOPYRIGHT (c) 1999 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.
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 (in bytes) 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 must be redefined in concrete classes (subclassResponsibility) **
-
hashSize
-
return the size of the hashvalue returned by instances of this class (in bytes)
** This method must be redefined in concrete classes (subclassResponsibility) **
-
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 must be redefined in concrete classes (subclassResponsibility) **
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'
MD5Stream hashValueHexString:'Hello World'
MD5Stream hashValueOf:'Hello World'
-
hashValueOf: aStringOrByteArrayOrStream
-
MD5Stream hashValueOf:'BlaBlaBla'
MD5Stream hashValueOf:('makefile' asFilename readStream)
MD5Stream hashValueOf:('BlaBlaBla' readStream)
-
hashValueOfFile: aFilename
-
generate a hashValue for the whole contents of a file
Usage example(s):
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 must be redefined in concrete classes (subclassResponsibility) **
queries
-
atEnd
-
return true if the end of the stream has been reached;
this is never reached
-
blockSize
-
the class knows about the basic block size (in bytes)
-
canStream
-
-
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 must be redefined in concrete classes (subclassResponsibility) **
-
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
writing
-
nextPut: anObject
-
add the hash of anObject to the computed hash so far.
anObject can be a Character, SmallInteger ByteArray or String.
Answer the argument
-
nextPutAll: aCollection
-
Hash streams handle Strings and ByteArrays in #nextPutBytes:
Answer the receiver
-
nextPutAll: count from: aCollection startingAt: initialIndex
-
Hash streams handle Strings and ByteArrays in #nextPutBytes:
Answer the number of elements written
-
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 must be redefined in concrete classes (subclassResponsibility) **
hashFunction mode:
MD5Stream hashValueOf:'hello world'
MD4Stream hashValueOf:'hello world'
|
hashStream mode:
|md5|
md5 := MD5Stream new.
md5 nextPutAll:'hello world'.
md5 hashValue
|
|