iaik.utils
Class PretendedMessageDigest

java.lang.Object
  |
  +--java.security.MessageDigestSpi
        |
        +--java.security.MessageDigest
              |
              +--iaik.utils.PretendedMessageDigest
All Implemented Interfaces:
Cloneable

public class PretendedMessageDigest
extends MessageDigest
implements Cloneable

This class pretends to be a MessageDigest engine.

This class does not actually compute a message digest value. Calling one of the update methods only will write the supplied data to a internal buffer. Calling the final digest method only will return the contents of this buffer; no digest computation ever has been performed.
Intended purpose of this class is to allow usage of MessageDigest engines with raw signature engines where the MessageDigest value already has been calculated outside the Signature engine and therefore no digest computation has to be done by the Signature engine´s internal digest machine.

Since this class does not (cannot) know the hash algorithm actually used for hashing the data an application has to take care to provide a proper hash value when calling an update method; no check is (can be) performed if the supplied hash value corresponds to the hash algorithm in use (e.g. has the correct length).

Version:
File Revision 6

Constructor Summary
PretendedMessageDigest()
          Default constructor.
PretendedMessageDigest(String name, int digestLength)
          Creates a PretendedMessageDigest engine with given name and digest length.
 
Method Summary
 Object clone()
          Returns a clone of this object.
protected  byte[] engineDigest()
          Returns the final digest value.
 int engineGetDigestLength()
          SPI: Returns the length of the digest in bytes.
protected  void engineReset()
          Resets the buffer.
protected  void engineUpdate(byte input)
          SPI: Updates the internal buffer with the specified byte.
protected  void engineUpdate(byte[] input, int offset, int len)
          SPI: Updates the internal buffer with the specified number of bytes, beginning at the specified offset within the given byte array.
 
Methods inherited from class java.security.MessageDigest
digest, digest, digest, getAlgorithm, getDigestLength, getInstance, getInstance, getProvider, isEqual, reset, toString, update, update, update
 
Methods inherited from class java.security.MessageDigestSpi
engineDigest
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PretendedMessageDigest

public PretendedMessageDigest()
Default constructor.

PretendedMessageDigest

public PretendedMessageDigest(String name,
                              int digestLength)
Creates a PretendedMessageDigest engine with given name and digest length.
Parameters:
name - the name of the digest algorithm this class represents
digestLength - the length of the digest value produce by this engine
Method Detail

engineUpdate

protected final void engineUpdate(byte input)
SPI: Updates the internal buffer with the specified byte. No digest computation is performed.
Overrides:
engineUpdate in class MessageDigestSpi
Parameters:
input - the byte to be written to the internal buffer

engineUpdate

protected final void engineUpdate(byte[] input,
                                  int offset,
                                  int len)
SPI: Updates the internal buffer with the specified number of bytes, beginning at the specified offset within the given byte array. No digest computation is performed.
Overrides:
engineUpdate in class MessageDigestSpi
Parameters:
input - the byte array holding the data to be used for this update operation.
offset - the offset, indicating the start position within the given byte array.
len - the number of bytes to be obtained from the given byte array, starting at the given position.

engineDigest

protected byte[] engineDigest()
Returns the final digest value. This method only returns the contents of the internal buffer.
Overrides:
engineDigest in class MessageDigestSpi

engineGetDigestLength

public int engineGetDigestLength()
SPI: Returns the length of the digest in bytes. The value returned by this method only may represent the actual digest length when method digest already has been called. Otherwise this method may return 0.
Overrides:
engineGetDigestLength in class MessageDigestSpi
Returns:
the length of the digest in bytes.

engineReset

protected void engineReset()
Resets the buffer.
Overrides:
engineReset in class MessageDigestSpi

clone

public Object clone()
Returns a clone of this object.
Overrides:
clone in class MessageDigest
Returns:
a clone of this pretended MessageDigest engine holding the current buffer state

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK