Bifroest Mr. Tines MacCTC CTCjava Manual Pages
Bifroest Mr. Tines CTC Home CTClib MacCTC CTCjava Manual


Message Digests

File hash.c is the control module for running message digests. It calls out to specific symmetric encryption routines for the specific algorithms supported.

Constants

The following constant is defined (in abstract.h)

Data Types

md_context

The Message Digest context structure is private; and its contents are dependent on the algorithm employed.

Public Methods

All functions within this module are public
md_context hashInit(byte md_algor);
The chosen message digest algorithm is instantiated; the return value is a handle on this instance.
void hashUpdate(md_context contextArg, byte *buf, uint32_t count);
A byte array buf containing count bytes is added to the (possibly null) set of bytes already digested in the given md_context..
void hashFinal(md_context *contextArg, byte *digest);
The md_context is destroyed, yielding the result of all data submitted.
int hashDigest(byte md_algor);
Returns the length in bytes of the message digest. The space pointed to by the digest argument of hashFinal() must be at least this long.
boolean hashAlgAvail(byte md_algor);
Indicate whether the byte value indicates a supported message digest algorithm
boolean hashAlgRecognised(byte md_algor);
Indicate whether the byte value indicates a recognised message digest algorithm. This may return TRUE for certain algorithms the hashAlgAvail() returns FALSE, indicating that algorithm is known but not implemented.

Dependencies

Each algorithm supported must implement the following interface, where the name, or some fragment of the name, of the algorithm replaces <ALG>

An initialiser

void <ALG>Init(void **context, size_t *length);

returning the hash context and its length.

a do-it routine

void <ALG>Update(void *context, byte *buff, uint32_t len);

to add a buffer's worth of new data

a closing routine

void <ALG>Final(void **context, byte *digest, size_t length);

concluding the digesting

and #define constant <ALG>HASHSIZE to give the digest size in bytes

The digest algorithms

Currently these supporting routines are defined in 3way.c, haval*.c, md5.c, rmd160.c and sha.c. Each of these algorithms has its own peculiar internal workings, and where possible, a set of test vectors and a test program which can be compiled in stand-alone fashion.. The implementations have all been augmented from their usual forms to support the hash interface specified above. The 3Way based hash algorithm implements one of the procedures whereby a block cipher can be run as a message digest, and provides a way of creating hashed data of the size this algorithm requires as a key. Both SHA and SHA-1 are provided, with the addition of the extra bit rotation in SHA-1 being defined by a run-time flag.

The process of adding new algorithms is mechanical.It requires modifications to several functions in hash.c.  In each, an extra case must be added to a switch statement to process the new message digest, if the hash algorithm matchs the appropriate key value.


webmaster@bifroest.demon.co.uk