ostore.util
Class SHA1NativeIF

java.lang.Object
  |
  +--java.security.MessageDigestSpi
        |
        +--ostore.util.SHA1NativeIF

public class SHA1NativeIF
extends MessageDigestSpi

SHA1HashNativeIF is an interface to a native C implementation of a SHA-1 MessageDigest. The result of SHA1NativeIF is used by the SHA1Hash and SHA1HashBuffer class and by all entities which are SHA1 hashes. (In the prototype, this means Guids and VHashes).

Version:
$Id: SHA1NativeIF.java,v 1.3 2002/09/07 02:19:28 strib Exp $
Author:
Hakim Weatherspoon

Field Summary
static boolean available
          available indicates if the C implementation of SHA-1 is available.
 
Constructor Summary
SHA1NativeIF()
          Construct according to the given fields.
 
Method Summary
 byte[] engineDigest()
          engineDigest completes the hash computation by performing final operations such as padding.
 int engineDigest(byte[] buf, int offset, int len)
          engineDigest completes the hash computation by performing final operations such as padding.
 int engineGetDigestLength()
          engineGetDigestLength returns the digest length in bytes.
 void engineInit()
          engineInit initializes the digest for further use.
 void engineReset()
          engineReset resets the digest for further use.
 void engineUpdate(byte input)
          engineUpdate updates the digest using the specified byte.
 void engineUpdate(byte[] input, int offset, int len)
          engineUpdate updates the digest using the specified array of bytes, starting at the specified offset.
 int engineUpdateAndDigest(byte[] buf, int out_off, int out_len, byte[] input, int in_off, int in_len)
          engineUpdateAndDigest in one call updates the digest using the specified array of bytes, starting at the specified offset.
 long testTput(int arrSz, int iterations)
          Tests the throughput of SHA1Native from entirely within C.
 
Methods inherited from class java.security.MessageDigestSpi
clone
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

available

public static boolean available
available indicates if the C implementation of SHA-1 is available.

Constructor Detail

SHA1NativeIF

public SHA1NativeIF()
Construct according to the given fields.

Method Detail

engineInit

public void engineInit()
engineInit initializes the digest for further use.


engineReset

public void engineReset()
engineReset resets the digest for further use.

Specified by:
engineReset in class MessageDigestSpi

engineGetDigestLength

public int engineGetDigestLength()
engineGetDigestLength returns the digest length in bytes.

Overrides:
engineGetDigestLength in class MessageDigestSpi
Returns:
The digest length in bytes.

engineUpdate

public void engineUpdate(byte input)
engineUpdate updates the digest using the specified byte.

Specified by:
engineUpdate in class MessageDigestSpi
Parameters:
input - The byte to use for the update.

engineUpdate

public void engineUpdate(byte[] input,
                         int offset,
                         int len)
engineUpdate updates the digest using the specified array of bytes, starting at the specified offset.

Specified by:
engineUpdate in class MessageDigestSpi
Parameters:
input - The array of bytes to use for the update.
offset - The offset to start from in the array of bytes.
len - The number of bytes to use, starting at offset.

engineDigest

public byte[] engineDigest()
engineDigest completes the hash computation by performing final operations such as padding. Once engineDigest has been called, the engine should is reset (see engineReset).

Specified by:
engineDigest in class MessageDigestSpi
Returns:
The array of bytes for the resulting hash value.

engineDigest

public int engineDigest(byte[] buf,
                        int offset,
                        int len)
                 throws DigestException
engineDigest completes the hash computation by performing final operations such as padding. Once engineDigest has been called, the engine is reset (see engineReset).

Overrides:
engineDigest in class MessageDigestSpi
Parameters:
buf - The output buffer in which to store the digest.
offset - Offset to start from in the output buffer.
len - Number of bytes within buf allotted for the digest. The presence of this parameter is solely for consistency in our API's. If the value of this parameter is less than the actual digest length, the method will throw a DigestException. This parameter is ignored if its value is greater than or equal to the actual digest length.
Returns:
the length of the digest stored in the output buffer.
Throws:
DigestException - if an error occurs.

engineUpdateAndDigest

public int engineUpdateAndDigest(byte[] buf,
                                 int out_off,
                                 int out_len,
                                 byte[] input,
                                 int in_off,
                                 int in_len)
                          throws DigestException
engineUpdateAndDigest in one call updates the digest using the specified array of bytes, starting at the specified offset. And completes the hash computation by performing final operations such as padding. Once engineUpdateAndDigest has been called, the engine is reset (see engineReset).

Parameters:
buf - The output buffer in which to store the digest.
out_off - Offset to start from in the output buffer.
out_len - Number of bytes within buf allotted for the digest. The presence of this parameter is solely for consistency in our API's. If the value of this parameter is less than the actual digest length, the method will throw a DigestException. This parameter is ignored if its value is greater than or equal to the actual digest length.
input - The array of bytes to use for the update.
in_off - The offset to start from in the array of bytes.
in_len - The number of bytes to use, starting at offset.
Returns:
The length of the digest stored in the output buffer.
Throws:
DigestException - if an error occurs.

testTput

public long testTput(int arrSz,
                     int iterations)
Tests the throughput of SHA1Native from entirely within C. Creates random byte arrays of size arrSz and times how long it takes to hash iterations of them.

Parameters:
arrSz - The number of bytes to hash
iterations - The number of times to hash
Returns:
The number of milliseconds it took to perform the hashes