Oberon || Library || Module Index || Search Engine || Definition || Module

Ulm's Oberon Library:


OneWayHashes - general abstraction for one-way hash functions


TYPE HashRec = RECORD (Services.ObjectRec) END;
TYPE Value = POINTER TO ValueRec;
TYPE ValueRec = RECORD (PersistentDisciplines.ObjectRec) END;
TYPE GenerateProc = PROCEDURE (hash: Hash; message: Streams.Stream;
			       VAR value: Value);
TYPE BitlengthProc = PROCEDURE (hash: Hash): LONGINT;
TYPE Interface = POINTER TO InterfaceRec;
TYPE InterfaceRec =
      generate:  GenerateProc;
      bitlength: BitlengthProc;
TYPE GeneratorProc = PROCEDURE (value: Value): Hash;
TYPE EqualProc = PROCEDURE (value1, value2: Value): BOOLEAN;
TYPE CreateStreamProc = PROCEDURE (value: Value; VAR stream: Streams.Stream);
TYPE ValueInterface = POINTER TO ValueInterfaceRec;
TYPE ValueInterfaceRec =
      generator:    GeneratorProc;
      equal:	    EqualProc;
      createStream: CreateStreamProc;

PROCEDURE Init(hash: Hash; if: Interface); PROCEDURE InitValue(value: Value; if: ValueInterface); PROCEDURE Generate(hash: Hash; message: Streams.Stream; VAR value: Value); PROCEDURE Bitlength(hash: Hash): LONGINT; PROCEDURE Generator(value: Value): Hash; PROCEDURE Equal(value1, value2: Value): BOOLEAN; PROCEDURE CreateStream(value: Value; VAR stream: Streams.Stream);


OneWayHashes provides a general interface for one-way hash functions. One-way hash functions operate on arbitrary-length messages and return fixed-length hash values. Such functions have the following characteristics:

The interface procedures of hashes should meet the specifications following:

generate: PROCEDURE(hash: Hash; message: Streams.Stream; VAR value: Value);
generate a hash value out of given message by using the one-way hash function specified in hash and store the computed hash value in value. message is a stream that will be read sequentially until end of file.

bitlength: PROCEDURE(hash: Hash) : LONGINT;
return the fixed bit length of a hash value generated by the one-way hash function specified in hash.

Moreover, interface procedures of hash values are specified as follows:

generator: PROCEDURE(value: Value) : Hash;
return the hash that generated value.

equal: PROCEDURE(value1, value2: Value) : BOOLEAN;
test whether two values generated by same hash are equal. This function is not supposed to be called with values generated by different hashes.

createStream: PROCEDURE(value: Value; VAR s: Streams.Stream);
open the memory area allocated by value as stream, for reading.

Init is to be called by implementations of OneWayHashes and connects the interface if to hash. Note that Services.Init must of course be called as well.

InitValue connects values with their OneWayHashes interface. Note that PersistentObjects.Init is supposed to have been called before.

Generate uses the one-way hash function specified by hash to compute a hash value out of given message and stores the result in value. Bitlength returns the fixed bit length of hash values created by the one-way hash function specified by hash.

Generator returns the hash that created a given value. Equal returns TRUE if two values generated by the same hash are equal. By definition, this is a strong hint that the original messages were equal as well. Note that comparing values of different hash functions does not make sense and is in fact illegal.

CreateStream opens the memory area of a hash value as a stream for reading.


Frank B.J. Fischer

revised by Martin Hasch


stream operations
implementation of the MD5 one-way hash function

Edited by: martin, last change: 1998/04/04, revision: 1.6, converted to HTML: 1998/04/04

Oberon || Library || Module Index || Search Engine || Definition || Module