Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Freenet.crypt
Class SHA1  view SHA1 download SHA1.java

java.lang.Object
  extended byFreenet.crypt.SHA1

public class SHA1
extends java.lang.Object

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.


Field Summary
private  int[] block
           
private  int blockIndex
           
private  long count
           
private  int[] dd
           
private  byte[] digestBits
           
private  boolean digestValid
           
private  boolean NSA
           
private  int[] state
           
 
Constructor Summary
SHA1()
          Simple constructor for SHA-1
SHA1(boolean b)
          Variant constructor
 
Method Summary
private  int blk(int i)
           
private  int blk0(int i)
           
 byte[] digest()
          Return completed digest.
protected  java.lang.String digout()
          Print out the digest in a form that can be easily compared to the test vectors.
 java.lang.String doHash(java.lang.String s)
          This takes a string and return a hash of that string.
 void extract(int[] digest, int offset)
          retrieve the value of a hash
protected  void finish()
          Complete processing on the message digest.
 void frob()
          zero the count and state arrays; used to support Pegwit's anomalous 2-barrel hsahing
protected  void init()
          Initializes new context
static void main(java.lang.String[] args)
          test driver
private  void R0(int[] data, int v, int w, int x, int y, int z, int i)
           
private  void R1(int[] data, int v, int w, int x, int y, int z, int i)
           
private  void R2(int[] data, int v, int w, int x, int y, int z, int i)
           
private  void R3(int[] data, int v, int w, int x, int y, int z, int i)
           
private  void R4(int[] data, int v, int w, int x, int y, int z, int i)
           
private  int rol(int value, int bits)
           
static void SHAselfTest()
          perfoms a self-test - spits out the test vector outputs on System.out
private  void transform()
          Hash a single 512-bit block.
 void update(byte b)
          Add one byte to the digest.
 void update(byte[] data, int offset, int length)
          Add many bytes to the digest.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

state

private int[] state

count

private long count

digestValid

private boolean digestValid

digestBits

private byte[] digestBits

NSA

private boolean NSA

block

private int[] block

blockIndex

private int blockIndex

dd

private int[] dd
Constructor Detail

SHA1

public SHA1(boolean b)
Variant constructor


SHA1

public SHA1()
Simple constructor for SHA-1

Method Detail

doHash

public java.lang.String doHash(java.lang.String s)
This takes a string and return a hash of that string.


extract

public void extract(int[] digest,
                    int offset)
retrieve the value of a hash


rol

private final int rol(int value,
                      int bits)

blk0

private final int blk0(int i)

blk

private final int blk(int i)

R0

private final void R0(int[] data,
                      int v,
                      int w,
                      int x,
                      int y,
                      int z,
                      int i)

R1

private final void R1(int[] data,
                      int v,
                      int w,
                      int x,
                      int y,
                      int z,
                      int i)

R2

private final void R2(int[] data,
                      int v,
                      int w,
                      int x,
                      int y,
                      int z,
                      int i)

R3

private final void R3(int[] data,
                      int v,
                      int w,
                      int x,
                      int y,
                      int z,
                      int i)

R4

private final void R4(int[] data,
                      int v,
                      int w,
                      int x,
                      int y,
                      int z,
                      int i)

transform

private void transform()
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.


frob

public void frob()
zero the count and state arrays; used to support Pegwit's anomalous 2-barrel hsahing


init

protected void init()
Initializes new context


update

public void 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.


update

public void update(byte[] data,
                   int offset,
                   int length)
Add many bytes to the digest.


digest

public byte[] digest()
Return completed digest.


finish

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


digout

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


main

public static void main(java.lang.String[] args)
test driver


SHAselfTest

public static void SHAselfTest()
perfoms a self-test - spits out the test vector outputs on System.out