eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'MD5Stream':

Home

everywhere
www.exept.de
for:
[back]

Class: MD5Stream


Inheritance:

   Object
   |
   +--Stream
      |
      +--HashStream
         |
         +--MD5Stream

Package:
stx:libbasic
Category:
System-Crypt-Hashing
Version:
rev: 1.13 date: 2010/03/04 20:55:03
user: cg
file: MD5Stream.st directory: libbasic
module: stx stc-classLibrary: libbasic
Author:
Stefan Vogel

Description:


Generate a MD5 hash value as defined in RFC 1321.
This may be used as checksum or for generating cryptographic signatures.

Note:
    in August 2004, some researchers have found a way to generate full collisions for MD5. 
    Therefore, for new applications, it may be wise to choose another hash function for security stuff. 

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 is almost completely limited by the speed of the md5-routine, which is the reference
    implementation in C from md5lib.



[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


Related information:

    SHA1Stream

Class protocol:

initialization
o  initialize

queries
o  blockSize
return the block size used internally by the compression function

o  hashSize
return the size of the hashvalue returned by instances of this class

testing
o  testVector


Instance protocol:

initialization
o  initialize

positioning
o  reset
reset the stream in order to compute a new hash value

queries
o  hashValue
Get the value hashed so far.
The context is kept, so that more objects may be hashed after
retrieving a hash value

writing
o  nextPut: anObject
update our hash value for anObject.
anObject may be a String, a Character, a Smallinteger or an Array of primitive
types like ByteArray

o  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)


Examples:



    Test Vectors (from FIPS PUB 180-1); results are:

    'abc'
    -> #[90 1 50 98 3C D2 4F B0 D6 96 3F 7D 28 E1 7F 72]

    'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
    -> #[82 15 EF 7 96 A2 B CA AA E1 16 D3 87 6C 66 4A]

    A million repetitions of 'a'
    -> #[77 7 D6 AE 4E 2 7C 70 EE A2 A9 35 C2 29 6F 21]


     (MD5Stream hashValueOf:'abc')
        printOn:Transcript base:16.
     Transcript cr.


     (MD5Stream hashValueOfStream:('abc' readStream))
            printOn:Transcript base:16.
     Transcript cr.


    |hashStream|

    hashStream := MD5Stream new.
    hashStream nextPut:'abc'.
    hashStream hashValue printOn:Transcript base:16. Transcript cr.
    hashStream nextPut:'dbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'.
    hashStream hashValue printOn:Transcript base:16. Transcript cr.


    |hashStream|

    hashStream := MD5Stream new.
    hashStream nextPut:'a' asByteArray.
    hashStream nextPut:'bc' asByteArray.
    hashStream hashValue printOn:Transcript base:16. Transcript cr.
    hashStream nextPut:'dbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq' asByteArray.
    hashStream hashValue printOn:Transcript base:16. Transcript cr.


    |hashStream|

    hashStream := MD5Stream new.
    1000000 timesRepeat:[ hashStream nextPut:$a ].
    hashStream hashValue printOn:Transcript base:16. Transcript cr.


    |hashStream|

    hashStream := MD5Stream new.
    hashStream nextPut:'a'.
    hashStream hashValue printOn:Transcript base:16. Transcript cr.


    |hashStream|

    hashStream := MD5Stream new.
    hashStream nextPut:$a.
    hashStream hashValue printOn:Transcript base:16. Transcript cr.


    |hashStream|

    hashStream := MD5Stream new.
    hashStream nextPut:'abc'.
    hashStream hashValue printOn:Transcript base:16. Transcript cr.
    hashStream reset.
    hashStream nextPut:'abc'.
    hashStream hashValue printOn:Transcript base:16. Transcript cr.
timing throughput:


    |hashStream n t|

    hashStream := MD5Stream 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'


ST/X 6.1.1; WebServer 1.620 at exept:8081; Wed, 23 May 2012 19:56:02 GMT