com.fasteasytrade.JRandTest.Algo
Class SHA1test

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

public class SHA1test
extends Object
implements Cloneable

Author:
Zur Aougav

Field Summary
(package private)  int A
          Shared variables between ProcessBlock method and rounds A, B, C, D, E redefines H[1..H.length]
(package private)  int B
          Shared variables between ProcessBlock method and rounds A, B, C, D, E redefines H[1..H.length]
(package private)  int C
          Shared variables between ProcessBlock method and rounds A, B, C, D, E redefines H[1..H.length]
(package private)  int D
          Shared variables between ProcessBlock method and rounds A, B, C, D, E redefines H[1..H.length]
(package private)  int E
          Shared variables between ProcessBlock method and rounds A, B, C, D, E redefines H[1..H.length]
(package private)  int[] H
          working IV - the default is copied from int[] IH.
private static char[] hex
          Used to convert number to Hex strings
(package private)  int[] IH
          default IV
(package private)  int K0
           
(package private)  int K1
           
(package private)  int K2
           
(package private)  int K3
           
(package private)  int[] Mblock
           
(package private)  long Numblocks
           
private  boolean reset
          Wherever next update should start from scratch
(package private)  int SHA1_BITBLOCKLEN
           
(package private)  int SHA1_BITHASHLEN
           
(package private)  int SHA1_BYTEBLOCKLEN
           
(package private)  int SHA1_BYTEHASHLEN
           
(package private)  int SHA1_INT32BLOCKLEN
           
(package private)  int SHA1_INT32HASHLEN
           
(package private)  byte[] tbuf
          temporary buffer to keep data if tail length of buffer is < SHA1_BYTEBLOCKLEN.
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
(package private)  int[] Wbuff
          working buffer for each round
 
Constructor Summary
SHA1test()
          default constructor - calls SHA1_Init()
SHA1test(int[] IH)
           
 
Method Summary
(package private)  void bshr(byte[] buffer, int len)
          right shift buffer 1 bit
 Object clone()
           
 int[] digest32()
           
 byte[] digest8()
           
(package private)  void expand(int x)
           
(package private)  int f1(int x, int y, int z)
           
(package private)  int f2(int x, int y, int z)
          Rounds 20-39
(package private)  int f3(int x, int y, int z)
           
 int[] getH()
           
 byte[] getHAsBytes()
           
 int[] getMblock()
           
 byte[] getMblockAsBytes()
           
static void main(String[] args)
          Method to self-test the class from command line.
(package private)  void ProcessBlock()
          This is the routine that implements the SHA.
(package private)  int RotateLeft1(int x)
           
(package private)  int RotateLeft30(int x)
           
(package private)  int RotateLeft5(int x)
           
(package private)  void Round2(int count)
           
(package private)  void Round3(int count)
           
(package private)  void Round4(int count)
           
static void selfTest()
          Self test using standard tests and write to standard output the result.
 SHA1test SHA1_Final()
          SHA1_Final does the hashing of the last block of the message.
 void SHA1_Init()
          SHA initialization routine.
 void SHA1_Init2(int[] IH)
          SHA initialization routine.
 SHA1test SHA1_Update(byte[] buffer)
          SHA1_Update hashes full 512 bit blocks.
(package private)  void sub1Round1(int count)
           
(package private)  void sub2Round1(int count)
           
static String toHex(byte[] v)
          Formats a number in an hex string.
(package private)  void xor(byte[] A, byte[] x, byte[] y, int l)
          xor - xor one array into another
(package private)  void xor(int[] A, int[] X, byte[] Y, int l)
          xor - xor one array into another.
(package private)  void xor(int[] A, int[] x, int[] y, int l)
          xor - xor one array into another
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

K0

final int K0
See Also:
Constant Field Values

K1

final int K1
See Also:
Constant Field Values

K2

final int K2
See Also:
Constant Field Values

K3

final int K3
See Also:
Constant Field Values

SHA1_BITBLOCKLEN

final int SHA1_BITBLOCKLEN
See Also:
Constant Field Values

SHA1_BYTEBLOCKLEN

final int SHA1_BYTEBLOCKLEN
See Also:
Constant Field Values

SHA1_INT32BLOCKLEN

final int SHA1_INT32BLOCKLEN
See Also:
Constant Field Values

SHA1_BITHASHLEN

final int SHA1_BITHASHLEN
See Also:
Constant Field Values

SHA1_BYTEHASHLEN

final int SHA1_BYTEHASHLEN
See Also:
Constant Field Values

SHA1_INT32HASHLEN

final int SHA1_INT32HASHLEN
See Also:
Constant Field Values

IH

final int[] IH
default IV


H

int[] H
working IV - the default is copied from int[] IH.


Mblock

int[] Mblock

Numblocks

long Numblocks

A

int A
Shared variables between ProcessBlock method and rounds

A, B, C, D, E redefines H[1..H.length]


B

int B
Shared variables between ProcessBlock method and rounds

A, B, C, D, E redefines H[1..H.length]


C

int C
Shared variables between ProcessBlock method and rounds

A, B, C, D, E redefines H[1..H.length]


D

int D
Shared variables between ProcessBlock method and rounds

A, B, C, D, E redefines H[1..H.length]


E

int E
Shared variables between ProcessBlock method and rounds

A, B, C, D, E redefines H[1..H.length]


Wbuff

int[] Wbuff
working buffer for each round


tbuf

byte[] tbuf
temporary buffer to keep data if tail length of buffer is < SHA1_BYTEBLOCKLEN.


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

SHA1test

public SHA1test()
default constructor - calls SHA1_Init()


SHA1test

public SHA1test(int[] IH)
Method Detail

SHA1_Init

public void SHA1_Init()
SHA initialization routine. Clears all fields in the SHA Context structure and primes the hash with the initialization vector.


SHA1_Init2

public void SHA1_Init2(int[] IH)
SHA initialization routine. Clears all fields in the SHA Context structure and primes the hash with the user supplied initialization vector.

Parameters:
IH - init vector

SHA1_Update

public SHA1test SHA1_Update(byte[] buffer)
SHA1_Update hashes full 512 bit blocks. Assumes that bitcount is a multiple of SHABLOCKLEN until the final buffer is being processed. In this case, the data has less than 512 bits then it saves the data for a subsequent call to SHAFinal.


SHA1_Final

public SHA1test SHA1_Final()
SHA1_Final does the hashing of the last block of the message. It is this routine that does the necessary padding of zeros and sets the length of the data at the end.


ProcessBlock

void ProcessBlock()
This is the routine that implements the SHA.


xor

void xor(byte[] A,
         byte[] x,
         byte[] y,
         int l)
xor - xor one array into another

Parameters:
A - result array
x - input array x
y - input array y
l - length of bytes to xor

xor

void xor(int[] A,
         int[] X,
         byte[] Y,
         int l)
xor - xor one array into another.

int[] A = int[]X ^ byte[]y.

Parameters:
A - result int array
l - length of bytes to xor

xor

void xor(int[] A,
         int[] x,
         int[] y,
         int l)
xor - xor one array into another

Parameters:
A - result array
x - input array x
y - input array y
l - length of ints to xor

bshr

void bshr(byte[] buffer,
          int len)
right shift buffer 1 bit

Parameters:
buffer - data to be shift right
len - length of buffer

RotateLeft1

int RotateLeft1(int x)

RotateLeft5

int RotateLeft5(int x)

RotateLeft30

int RotateLeft30(int x)

f1

int f1(int x,
       int y,
       int z)

f3

int f3(int x,
       int y,
       int z)

f2

int f2(int x,
       int y,
       int z)
Rounds 20-39


expand

void expand(int x)

sub1Round1

void sub1Round1(int count)

sub2Round1

void sub2Round1(int count)

Round2

void Round2(int count)

Round3

void Round3(int count)

Round4

void Round4(int count)

getMblock

public int[] getMblock()

getMblockAsBytes

public byte[] getMblockAsBytes()

getH

public int[] getH()

getHAsBytes

public byte[] getHAsBytes()

digest32

public int[] digest32()

digest8

public byte[] digest8()

clone

public Object clone()

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

selfTest

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


main

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

Parameters:
args - command line parameters


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