Quadcap Embeddable Database

com.quadcap.crypto.SHA1Digest Class Reference

Inheritance diagram for com.quadcap.crypto.SHA1Digest:

com.quadcap.crypto.Digest List of all members.

Detailed Description

This is a simple port of Steve Reid's SHA-1 code into Java.

I've run his test vectors through the code and they all pass.

Definition at line 76 of file SHA1Digest.java.

Public Member Functions

 SHA1Digest ()
 Default constructor.

void init ()
 SHA1Init - Initialize new context.

void update (byte b)
 Add one byte to the digest.

void update (byte[] b, int off, int len)
 Implementation for arrays just wraps the primitive byte operation.

void update (byte[] buf)
 And the full-array implementation is just a degenerate case of the array-subset implementation:.

byte[] digest ()
 Return the message digest for the accumulated bytes.

String getAlg ()
 Return a string that identifies this algorithm.


Static Public Member Functions

void main (String args[])
 This is a test program for the SHA1 algorithm.


Package Functions

final int rol (int value, int bits)
final int blk0 (int i)
final int blk (int i)
final void R0 (int data[], int v, int w, int x, int y, int z, int i)
final void R1 (int data[], int v, int w, int x, int y, int z, int i)
final void R2 (int data[], int v, int w, int x, int y, int z, int i)
final void R3 (int data[], int v, int w, int x, int y, int z, int i)
final void R4 (int data[], int v, int w, int x, int y, int z, int i)
void transform ()
 Hash a single 512-bit block.


Package Attributes

int dd [] = new int[5]

Private Member Functions

final void finish ()
 Complete processing on the message digest.

String digout ()
 Print out the digest in a form that can be easily compared to the test vectors.


Private Attributes

byte[] digest = null
boolean digestValid = false
int[] state = new int[5]
long count = 0
int[] block = new int[16]
int blockIndex


Constructor & Destructor Documentation

com.quadcap.crypto.SHA1Digest.SHA1Digest  ) 
 

Default constructor.

Definition at line 93 of file SHA1Digest.java.

References com.quadcap.crypto.SHA1Digest.init().

Referenced by com.quadcap.crypto.SHA1Digest.main().


Member Function Documentation

final int com.quadcap.crypto.SHA1Digest.blk int  i  )  [package]
 

Definition at line 206 of file SHA1Digest.java.

References com.quadcap.crypto.SHA1Digest.blk(), and com.quadcap.crypto.SHA1Digest.block.

Referenced by com.quadcap.crypto.SHA1Digest.blk().

final int com.quadcap.crypto.SHA1Digest.blk0 int  i  )  [package]
 

Definition at line 200 of file SHA1Digest.java.

References com.quadcap.crypto.SHA1Digest.blk0(), and com.quadcap.crypto.SHA1Digest.block.

Referenced by com.quadcap.crypto.SHA1Digest.blk0().

byte [] com.quadcap.crypto.SHA1Digest.digest  ) 
 

Return the message digest for the accumulated bytes.

Implements com.quadcap.crypto.Digest.

Definition at line 147 of file SHA1Digest.java.

References com.quadcap.crypto.SHA1Digest.digestValid, com.quadcap.crypto.SHA1Digest.finish(), and com.quadcap.crypto.SHA1Digest.init().

String com.quadcap.crypto.SHA1Digest.digout  )  [private]
 

Print out the digest in a form that can be easily compared to the test vectors.

Definition at line 339 of file SHA1Digest.java.

Referenced by com.quadcap.crypto.SHA1Digest.main().

final void com.quadcap.crypto.SHA1Digest.finish  )  [private]
 

Complete processing on the message digest.

Definition at line 160 of file SHA1Digest.java.

References com.quadcap.crypto.SHA1Digest.blockIndex, com.quadcap.crypto.SHA1Digest.count, com.quadcap.crypto.SHA1Digest.digestValid, and com.quadcap.crypto.SHA1Digest.state.

Referenced by com.quadcap.crypto.SHA1Digest.digest(), and com.quadcap.crypto.SHA1Digest.main().

String com.quadcap.crypto.SHA1Digest.getAlg  ) 
 

Return a string that identifies this algorithm.

Definition at line 181 of file SHA1Digest.java.

void com.quadcap.crypto.SHA1Digest.init  ) 
 

SHA1Init - Initialize new context.

Implements com.quadcap.crypto.Digest.

Definition at line 101 of file SHA1Digest.java.

References com.quadcap.crypto.SHA1Digest.blockIndex, com.quadcap.crypto.SHA1Digest.count, com.quadcap.crypto.SHA1Digest.digest, com.quadcap.crypto.SHA1Digest.digestValid, and com.quadcap.crypto.SHA1Digest.state.

Referenced by com.quadcap.crypto.SHA1Digest.digest(), com.quadcap.crypto.SHA1Digest.main(), and com.quadcap.crypto.SHA1Digest.SHA1Digest().

void com.quadcap.crypto.SHA1Digest.main String  args[]  )  [static]
 

This is a test program for the SHA1 algorithm.

It puts the three test vectors through the algorithm and prints out the results (they should match.) Then it runs the MessageDigest benchmark method to see how fast it is. on my P133 its about 110 - 120K bytes/second.

It then compares it to MD5, which is about 150K bytes/second.

Definition at line 367 of file SHA1Digest.java.

References com.quadcap.crypto.SHA1Digest.digout(), com.quadcap.crypto.SHA1Digest.finish(), com.quadcap.crypto.SHA1Digest.init(), com.quadcap.crypto.SHA1Digest.main(), com.quadcap.crypto.SHA1Digest.SHA1Digest(), and com.quadcap.crypto.SHA1Digest.update().

Referenced by com.quadcap.crypto.SHA1Digest.main().

final void com.quadcap.crypto.SHA1Digest.R0 int  data[],
int  v,
int  w,
int  x,
int  y,
int  z,
int  i
[package]
 

Definition at line 212 of file SHA1Digest.java.

References com.quadcap.crypto.SHA1Digest.R0().

Referenced by com.quadcap.crypto.SHA1Digest.R0().

final void com.quadcap.crypto.SHA1Digest.R1 int  data[],
int  v,
int  w,
int  x,
int  y,
int  z,
int  i
[package]
 

Definition at line 218 of file SHA1Digest.java.

References com.quadcap.crypto.SHA1Digest.R1().

Referenced by com.quadcap.crypto.SHA1Digest.R1().

final void com.quadcap.crypto.SHA1Digest.R2 int  data[],
int  v,
int  w,
int  x,
int  y,
int  z,
int  i
[package]
 

Definition at line 224 of file SHA1Digest.java.

References com.quadcap.crypto.SHA1Digest.R2().

Referenced by com.quadcap.crypto.SHA1Digest.R2().

final void com.quadcap.crypto.SHA1Digest.R3 int  data[],
int  v,
int  w,
int  x,
int  y,
int  z,
int  i
[package]
 

Definition at line 230 of file SHA1Digest.java.

References com.quadcap.crypto.SHA1Digest.R3().

Referenced by com.quadcap.crypto.SHA1Digest.R3().

final void com.quadcap.crypto.SHA1Digest.R4 int  data[],
int  v,
int  w,
int  x,
int  y,
int  z,
int  i
[package]
 

Definition at line 237 of file SHA1Digest.java.

References com.quadcap.crypto.SHA1Digest.R4().

Referenced by com.quadcap.crypto.SHA1Digest.R4().

final int com.quadcap.crypto.SHA1Digest.rol int  value,
int  bits
[package]
 

Definition at line 195 of file SHA1Digest.java.

References com.quadcap.crypto.SHA1Digest.rol().

Referenced by com.quadcap.crypto.SHA1Digest.rol().

void com.quadcap.crypto.SHA1Digest.transform  )  [package]
 

Hash a single 512-bit block.

This is the core of the algorithm.

Note that working with arrays is very inefficent in Java as it does a class cast check each time you store into the array.

Definition at line 278 of file SHA1Digest.java.

References com.quadcap.crypto.SHA1Digest.dd, and com.quadcap.crypto.SHA1Digest.state.

Referenced by com.quadcap.crypto.SHA1Digest.update().

void com.quadcap.crypto.SHA1Digest.update byte[]  buf  ) 
 

And the full-array implementation is just a degenerate case of the array-subset implementation:.

Implements com.quadcap.crypto.Digest.

Definition at line 142 of file SHA1Digest.java.

void com.quadcap.crypto.SHA1Digest.update byte[]  b,
int  off,
int  len
 

Implementation for arrays just wraps the primitive byte operation.

Implements com.quadcap.crypto.Digest.

Definition at line 134 of file SHA1Digest.java.

void com.quadcap.crypto.SHA1Digest.update byte  b  ) 
 

Add one byte to the digest.

When this is implemented all of the abstract class methods end up calling this method for types other than bytes.

Implements com.quadcap.crypto.Digest.

Definition at line 119 of file SHA1Digest.java.

References com.quadcap.crypto.SHA1Digest.block, com.quadcap.crypto.SHA1Digest.blockIndex, com.quadcap.crypto.SHA1Digest.count, com.quadcap.crypto.SHA1Digest.transform(), and com.quadcap.crypto.SHA1Digest.update().

Referenced by com.quadcap.crypto.SHA1Digest.main(), and com.quadcap.crypto.SHA1Digest.update().


Member Data Documentation

int [] com.quadcap.crypto.SHA1Digest.block = new int[16] [private]
 

Definition at line 87 of file SHA1Digest.java.

Referenced by com.quadcap.crypto.SHA1Digest.blk(), com.quadcap.crypto.SHA1Digest.blk0(), and com.quadcap.crypto.SHA1Digest.update().

int com.quadcap.crypto.SHA1Digest.blockIndex [private]
 

Definition at line 88 of file SHA1Digest.java.

Referenced by com.quadcap.crypto.SHA1Digest.finish(), com.quadcap.crypto.SHA1Digest.init(), and com.quadcap.crypto.SHA1Digest.update().

long com.quadcap.crypto.SHA1Digest.count = 0 [private]
 

Definition at line 80 of file SHA1Digest.java.

Referenced by com.quadcap.crypto.SHA1Digest.finish(), com.quadcap.crypto.SHA1Digest.init(), and com.quadcap.crypto.SHA1Digest.update().

int com.quadcap.crypto.SHA1Digest.dd[] = new int[5] [package]
 

Definition at line 268 of file SHA1Digest.java.

Referenced by com.quadcap.crypto.SHA1Digest.transform().

byte [] com.quadcap.crypto.SHA1Digest.digest = null [private]
 

Definition at line 77 of file SHA1Digest.java.

Referenced by com.quadcap.crypto.SHA1Digest.init().

boolean com.quadcap.crypto.SHA1Digest.digestValid = false [private]
 

Definition at line 78 of file SHA1Digest.java.

Referenced by com.quadcap.crypto.SHA1Digest.digest(), com.quadcap.crypto.SHA1Digest.finish(), and com.quadcap.crypto.SHA1Digest.init().

int [] com.quadcap.crypto.SHA1Digest.state = new int[5] [private]
 

Definition at line 79 of file SHA1Digest.java.

Referenced by com.quadcap.crypto.SHA1Digest.finish(), com.quadcap.crypto.SHA1Digest.init(), and com.quadcap.crypto.SHA1Digest.transform().