Java Randomness Test Suite

JRandTest at SourceForge

com.fasteasytrade.JRandTest.Algo
Class SHA1

java.lang.Object
  extended bycom.fasteasytrade.JRandTest.Algo.Cipher
      extended bycom.fasteasytrade.JRandTest.Algo.SHA1
All Implemented Interfaces:
Cloneable

public final class SHA1
extends Cipher
implements Cloneable

SHA-1 Message Digest class.
LapInt number theory library Copyright (c) 2001-2002 Lapo Luchini <lapo@lapo.it>
From package lapint.crypto.

Follows the FIPS PUB 180-1 standard which elaborates a message digest from given data (length <2^64 bytes).
As of version 1.10 I obtained the following stats using Linux 2.4.8 on a P3-850:

and the following stats using Win2000 on a dual P3-450:

Author:
Lapo Luchini <lapo@lapo.it>

Field Summary
private  int[] H
          Partial hash
private static char[] hex
          Used to convert number to Hex strings
private  boolean reset
          Wherever next update should start from scratch
static int[] TEST_0_HASH
          First official test result
static String TEST_0_STRING
          First official test
static int[] TEST_1_HASH
          Second official test result
static String TEST_1_STRING
          Second official test
static int[] TEST_2_HASH
          Third official test result
static String TEST_2_STRING
          Third official test
private  long totb
          Total bytes digested
private  int[] W
          Internal buffer
 
Constructor Summary
SHA1()
          Creates a SHA1 object.
 
Method Summary
 Object clone()
           
private  void digest_finalize()
          Finalize the hash calculation, as defined in the standard.
 int[] digest32()
          Returns the digest and resets the object to calculate another digest.
 byte[] digest8()
          Returns the digest and resets the object to calculate another digest.
 int[] getH()
          get internal hash vector
 byte[] getHAsBytes()
          get internal hash vector as vector of bytes
 void getHAsBytes(byte[] v)
          get internal hash vector as vector of bytes
 void init(byte[] m)
          init internal buffer with IV (of bytes)
 void init(int[] m)
          init internal buffer with IV (of ints)
static void main(String[] args)
          Method to self-test the class from command line.
static void selfTest()
          Self test using standard tests and write to standard output the result.
static String toHex(byte[] v)
          Formats a number in an hex string.
private  void update_buffers()
          Internally used when the buffer is ready for the digest.
 void update(byte m)
           
 void update(byte[] m)
          Feeds more bytes to the digest.
 void update(int[] m)
          Updates the hash with more ints (big-endian).
 void update(long[] m)
          Updates the hash with more longs (big-endian).
 
Methods inherited from class com.fasteasytrade.JRandTest.Algo.Cipher
compareBytes
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

H

private int[] H
Partial hash


W

private transient int[] W
Internal buffer


totb

private long totb
Total bytes digested


reset

private boolean reset
Wherever next update should start from scratch


hex

private static char[] hex
Used to convert number to Hex strings


TEST_0_STRING

public static final String TEST_0_STRING
First official test

See Also:
Constant Field Values

TEST_1_STRING

public static final String TEST_1_STRING
Second official test

See Also:
Constant Field Values

TEST_2_STRING

public static final String TEST_2_STRING
Third official test

See Also:
Constant Field Values

TEST_0_HASH

public static final int[] TEST_0_HASH
First official test result


TEST_1_HASH

public static final int[] TEST_1_HASH
Second official test result


TEST_2_HASH

public static final int[] TEST_2_HASH
Third official test result

Constructor Detail

SHA1

public SHA1()
Creates a SHA1 object.
A single SHA1 object can (sequentially) elaborate many hashes.

Method Detail

clone

public Object clone()

digest8

public byte[] digest8()
Returns the digest and resets the object to calculate another digest.
The array returned will NOT be reused by this object.
Please note that calculating the digest finalizes the digest and next update()will start from scratch.
You can use clone()to get partial digests.

Returns:
byte[20] array containing the required hash

digest32

public int[] digest32()
Returns the digest and resets the object to calculate another digest.
The array returned will NOT be reused by this object.
Please note that calculating the digest finalizes the digest and next update()will start from scratch.
You can use clone()to get partial digests.

Returns:
int[5] array containing the required hash

digest_finalize

private void digest_finalize()
Finalize the hash calculation, as defined in the standard.


update

public void update(byte m)

init

public void init(byte[] m)
init internal buffer with IV (of bytes)

Parameters:
m - IV vector of bytes

init

public void init(int[] m)
init internal buffer with IV (of ints)

Parameters:
m - IV vector of integers (32 bits)

update

public void update(byte[] m)
Feeds more bytes to the digest.

Parameters:
m - bytes to elaborate (any length is valid)

update

public void update(int[] m)
Updates the hash with more ints (big-endian).

Parameters:
m - an array of ints to add

update

public void update(long[] m)
Updates the hash with more longs (big-endian).

Parameters:
m - an array of ints to add

update_buffers

private final void update_buffers()
Internally used when the buffer is ready for the digest.
Completely unrolled for maximum performance.


main

public static void main(String[] args)
Method to self-test the class from command line.

Parameters:
args - command line parameters

selfTest

public static void selfTest()
Self test using standard tests and write to standard output the result.


toHex

public static final String toHex(byte[] v)
Formats a number in an hex string.

Parameters:
v - number to format
Returns:
hex string of the number

getH

public int[] getH()
get internal hash vector

Returns:
internal hash vector

getHAsBytes

public byte[] getHAsBytes()
get internal hash vector as vector of bytes

Returns:
internal hash vector

getHAsBytes

public void getHAsBytes(byte[] v)
get internal hash vector as vector of bytes

Parameters:
v - H interbnal vector is copied into v

Java Randomness Test Suite

JRandTest at SourceForge

JRandTest at SourceForge
Copyright © 2005 Zur Aougav. All Rights Reserved.