iaik.me.security.md
Class MD5

java.lang.Object
  |
  +--iaik.me.security.MessageDigest
        |
        +--iaik.me.security.md.MD5

public class MD5
extends MessageDigest

This class implements the MD5 message digest algorithm.

A message digest algorithm represents the functionality of an one-way hash function for computing a fixed sized data value (message digest, hash) from input data of arbitrary size. The length of the resulting hash value usually is shorter than the length of the input data. Using a one-way hash function will make it easy to compute the hash from the given data, but hard to go the reverse way for calculating the input data when only the hash is known. Furthermore, a proper hash function should avoid any collision, meaning that it has to be hard to find two different messages producing the same hash value.

The MD5 message digest algorithm produces a 128-Bit hash-value of the given input data. First the input data is properly padded and subsequently extended by a 64-Bit representation of the data´s original length to become a multiple of 512 Bit. The resulting text is devided into 512-Bit blocks, each of it again devided into sixteen 32-Bit sub-blocks. Each of the 512-Bit blocks is processed in a main loop. Input of the main loop are four 32-Bit variables, which are properly initialized with constant values for the first main loop run processing the first 512-Bit block. Each main loop run is featured with a new 512-Bit block as long as there blocks available. Each main loop run produces an output of four 32-Bit variables which are added to the initial four 32-bit variables to be fed into the next main loop run for pocessing the next 512-Bit block. When no further 512-Bit block is available, the algorithm leaves the main loop and calculates the final 128-Bit hash output by concatenating the four 32-Bit variables resulting from the last main loop run. The main loop consists of four rounds based on a certain nonlinear function (see "Applied Cryptography", Bruce Schneier, ISBN 0-471-59756-2).

This class extends the iaik.me.security.MessageDigest class and applications should use one of the getInstance methods presented there to create a MessageDigest-MD5 object. Generally, an application wishing to compute the message digest of some data has to perform three steps:

When the hash value successfully has been computed, the MD5 MessageDigest object automatically resets for being able to be supplied with new data to be hashed.

See Also:
MessageDigest

Fields inherited from class iaik.me.security.MessageDigest
buffer, count, digestLength, padding
 
Constructor Summary
MD5()
          Creates a new MD5 message digest object.
 
Method Summary
 Object clone()
          Returns a clone of this Md5 Object.
protected  void compress(byte[] input, int offset)
          The heart of MD5.
 int digest(byte[] output, int offset)
          SPI: Returns the result of this hash computation and resets this MD5 message digest object for being supplied with new data to be hashed.
 byte[][] getEncodedDigestInfo()
          Returns the pregenerated ASN1 encoding of the DigestInfo structure for the corresponding digest algorithm, see .
 void reset()
          SPI: Resets this MD5 message digest object for being supplied with new data.
 
Methods inherited from class iaik.me.security.MessageDigest
digest, digest, getAlgorithm, getDigestLength, getInstance, register, update, update, update
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MD5

public MD5()
Creates a new MD5 message digest object. Applications do not use this constructor. They shall use
 MessageDigest.getInstance("MD5");
for creating a MesssageDigest object.
See Also:
MessageDigest.getInstance(java.lang.String)
Method Detail

reset

public void reset()
SPI: Resets this MD5 message digest object for being supplied with new data.

This method is after the actual hash computation has been finished to automatically reset the message digest object for being supplied with new data for starting a new hash computation.

Overrides:
reset in class MessageDigest

clone

public Object clone()
Returns a clone of this Md5 Object.
Overrides:
clone in class MessageDigest
Returns:
a clone of this Md5 Object

digest

public int digest(byte[] output,
                  int offset)
SPI: Returns the result of this hash computation and resets this MD5 message digest object for being supplied with new data to be hashed.
Overrides:
digest in class MessageDigest
Returns:
a byte array holding the calculated hash value

compress

protected void compress(byte[] input,
                        int offset)
The heart of MD5.
Overrides:
compress in class MessageDigest

getEncodedDigestInfo

public byte[][] getEncodedDigestInfo()
Description copied from class: MessageDigest
Returns the pregenerated ASN1 encoding of the DigestInfo structure for the corresponding digest algorithm, see . The digest value is of course NOT included. The two dimensional array cotains the enconding with (index = 0) and without the ASN1 parameter NULL (index = 1).
Overrides:
getEncodedDigestInfo in class MessageDigest
Following copied from class: iaik.me.security.MessageDigest
Returns:
a two dimensional byte array containing the digestinfo encodings

This Javadoc may contain text parts from IETF Internet Standard specifications, see copyright note) and RSA Data Security Public-Key Cryptography Standards (see copyright note).

IAIK-JCE ME 3.04, (c) 2002 IAIK, (c) 2003 to 2006 Stiftung SIC