ds.ov2.util
Class Message_digest_wrapper

java.lang.Object
  extended by ds.ov2.util.Message_digest_wrapper

public class Message_digest_wrapper
extends Object

Wrap an java.security.MessageDigest instance into an javacard.security.MessageDigest interface. With this wrapper code that is shared between host and card does not have to care about the different interfaces of MessageDigest objects. The abstraction is achieved in the following way: Shared code should declare its MessageDigest objects with MESSAGE_DIGEST, which will expand to MessageDigest on the card and Message_digest_wrapper on the host. New digest objects can be created with Misc.get_message_digest(). On the host this will return an instance of this class.

This class is only for SHA-1 160 bit digests.

CPP Preprocessing
no cpp preprocessing needed, however, other code usually refers through MESSAGE_DIGEST to this class
Execution Environment:
host
Author:
Hendrik Tews
Version:
$Revision: 1.6 $
Last Commit:
$Date: 2009-04-09 10:42:17 $ by $Author: tews $

Field Summary
private  MessageDigest digest
          The wrapped MessageDigest instance.
 
Constructor Summary
Message_digest_wrapper()
          Create an instance that wraps a SHA-1 160 bit message digest object.
 
Method Summary
 void doFinal(byte[] in_buff, short in_off, short in_len, byte[] out_buff, short out_off)
          Fed the digest with in_len bytes from in_buff, starting at in_off.
 void update(byte[] in_buf, short offset, short len)
          Fed the digest with len bytes from in_buf, starting at offset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

digest

private MessageDigest digest
The wrapped MessageDigest instance.

Constructor Detail

Message_digest_wrapper

public Message_digest_wrapper()
Create an instance that wraps a SHA-1 160 bit message digest object.

Method Detail

update

public void update(byte[] in_buf,
                   short offset,
                   short len)
Fed the digest with len bytes from in_buf, starting at offset.

Parameters:
in_buf - data buffer
offset - starting offset in in_buf
len - number of bytes to digest
See Also:
javacard.security.MessageDigest.update, java.security.MessageDigest.update

doFinal

public void doFinal(byte[] in_buff,
                    short in_off,
                    short in_len,
                    byte[] out_buff,
                    short out_off)
Fed the digest with in_len bytes from in_buff, starting at in_off. Afterwards finish the hash computation and copy the digest into out_buff at index out_off.

If there is not enough place in out_buff (less then 20 bytes starting at out_off) an IndexOutOfBoundsException is thrown.

Parameters:
in_buff - data buffer
in_off - starting offset in in_buf
in_len - number of bytes to digest
out_buff - buffer for the digest
out_off - starting index to copy the result digest to
Throws:
IndexOutOfBoundsException - if there is not enough place in out_buff
See Also:
javacard.security.MessageDigest.doFinal, java.security.MessageDigest.update, java.security.MessageDigest.digest