de.cscc.crypto.provider
Class RIPEMD160MessageDigestEngine

java.lang.Object
  extended byjava.security.MessageDigestSpi
      extended byde.cscc.crypto.provider.RIPEMD160MessageDigestEngine
All Implemented Interfaces:
Cloneable

public final class RIPEMD160MessageDigestEngine
extends MessageDigestSpi
implements Cloneable

RIPEMD160MessageDigestEngine Class. This class does the RIPEMD-160 algorithm via delegation to RIPEMD160MessageDigestImpl and is implemented as JCA (Java Cryptogrphy Architecture) Service Provider. You can not instance these class direct, because it is enabled through the JCA API.

The sum of all added bytes from engineUpdate(byte) and engineUpdate(byte[], int, int) are processed by the RIPEMD-160 message digest algorithm with engineDigest() or engineDigest(byte[], int, int).


 How does it work:
 =================

 RIPEMD-160 works only with whole 512 bit blocks.

        512bits == 64 bytes == 16 words
 -------------------------------------------------
 |00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|
 -------------------------------------------------
                    /  \
                   /    \
                  /      \
                 /        \
                /          \
               -------------
               |32 bit word|   <-- 32 bit word = 4 byte
               -------------
               |00|01|02|03|   <-- 4 bytes = 4 x 8 bit = 32 bit
               -------------

 

Here is a simple Code Example:


 import java.security.Security;
 import java.security.Provider;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import de.cscc.crypto.provider.HBCI;
 import java.io.IOException;

 public class MyMessageDigest{
  public static void main(String args[]){
   
    // add Provider
    int i = Security.addProvider(new de.cscc.crypto.provider.JHBCI());
    System.out.println("Provider inserted at position " + i + ".");

    // get provider
    Provider p = Security.getProvider("JHBCI");
    System.out.println("My Provider Name is " + p.getName());
    System.out.println("My Provider Version is " + p.getVersion());
    System.out.println("My Provider Info is " + p.getInfo());

    // get MessageDigest Object through the JCA API
    MessageDigest myRIPEMD1 = null;
    MessageDigest myRIPEMD2 = null,

    try{
        myRIPEMD1 = MessageDigest.getInstance("RIPEMD160");
    } catch(NoSuchAlgorithmException e){
        e.printStackTrace();
    }

    // put the messaeg in the MessageDigest object
    byte[] myByte = {'a','b','c'};
    myRIPEMD1.update(myByte);

    // clone the object
    try {
        myRIPEMD2 = myRIPEMD1.clone
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }

    // get the Message Digests
    byte[] messageDigest1 = myRIPEMD1.digest();
    byte[] messageDigest2 = myRIPEMD2.digest();

    // now the byte arrays messageDigest[12] holds a 20 byte long message
    // digest of the message "abc" and should be in binary form:
    // 0x8eb208f7e05d987a9b044a8e98c6b087f15a0bfc

    // verify the two digests
    boolean verify = MessageDigest.isEqual(messageDigest1, messageDigest2);
    System.out.println("The two digests are equal: " + verify);
  }
 }
 

Version:
$Revision: 1.6 $
Author:
Uwe Günther

Constructor Summary
RIPEMD160MessageDigestEngine()
          Creates new RIPEMD160MessageDigestEngine.
 
Method Summary
 Object clone()
          Creates and returns a deep of this object.
protected  byte[] engineDigest()
          If the whole message added to the message digest object, you should invoke the digest method at your API object (MessageDigest).
protected  int engineDigest(byte[] buf, int offset, int len)
          If the whole message added to the message digest object, you should invoke the digest method at your API Object (MessageDigest).
protected  int engineGetDigestLength()
          Returns the length of the message digest in byte.
protected  void engineReset()
          Resets the message digest object, for further use.
protected  void engineUpdate(byte value)
          Updates the internal message buffer with byte value.
protected  void engineUpdate(byte[] values, int offset, int len)
          Updates the internal message buffer with byte[] value, starting at offset, ending at len.
 boolean equals(Object obj)
          Compares two RIPEMD160MessageDigestEngine objects.
 int hashCode()
          Returns a hash code value for the object.
 String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RIPEMD160MessageDigestEngine

public RIPEMD160MessageDigestEngine()
Creates new RIPEMD160MessageDigestEngine. This default constructor is invoked from java.security.MessageDigest.getInstance().

Method Detail

clone

public Object clone()
             throws CloneNotSupportedException
Creates and returns a deep of this object.

Returns:
a clone of this instance.
Throws:
CloneNotSupportedException - if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.
See Also:
Cloneable

equals

public boolean equals(Object obj)
Compares two RIPEMD160MessageDigestEngine objects. If the private members of obj are equal wtih the private members of this object the method will return true, otherwise false.

Parameters:
obj - RIPEMD160MessageDigestEngine object to compare.
Returns:
true if the objects are deeply equal.

hashCode

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.

Returns:
a hash code value for this object.
See Also:
equals(java.lang.Object), Hashtable

toString

public String toString()
Returns a string representation of the object.

Returns:
a string representation of the object.

engineDigest

protected byte[] engineDigest()
If the whole message added to the message digest object, you should invoke the digest method at your API object (MessageDigest). The wraper invokes these method to return the 160 bit RIPEMD-160 digest at a byte array (20 byte or 160 bit).

Returns:
the message digest in 20 byte long byte array. This byte array contains the 160 bit digest in binary form.

engineDigest

protected int engineDigest(byte[] buf,
                           int offset,
                           int len)
                    throws DigestException
If the whole message added to the message digest object, you should invoke the digest method at your API Object (MessageDigest). The Wraper invokes these method to return the 160 bit RIPEMD-160 digest at a byte array (20 byte or 160 bit).

Parameters:
buf - the message digest in 20 byte long byte array. This byte array contains the 160 bit digest in binary form.
offset - begin of buffer.
len - end of buffer.
Returns:
the length of the digest stored in the output buffer.
Throws:
DigestException - If the difference between len-offset less than 20 bytes a DigestException will be thrown.

engineGetDigestLength

protected int engineGetDigestLength()
Returns the length of the message digest in byte. In case of RIPEMD-160 it will be 20.

Returns:
digest length (20) in byte.

engineReset

protected void engineReset()
Resets the message digest object, for further use. So if you have calculated your digest, you should invoke reset() through the JCA API that invokes this engineReset method to reset the object to calculate an new digest from a new message.


engineUpdate

protected void engineUpdate(byte value)
Updates the internal message buffer with byte value.

Parameters:
value - message byte.

engineUpdate

protected void engineUpdate(byte[] values,
                            int offset,
                            int len)
Updates the internal message buffer with byte[] value, starting at offset, ending at len.

Parameters:
values - message byte array.
offset - begin of message byte array.
len - end of message byte array.


Copyright © 2001, 2002 by Uwe GŁnther. See the COPYING file for more details. Browse the source as HTML.