www.pudn.com > encryption.rar > SHS.java


/*
Christoforos Pirillos @ Villanova University - May 1999
based on code from the book "Java Network Programming" by Hughes
*/

package encryption;

/** Provides integrity checking on any streams-based communications
channel*/

public class SHS extends Hash {

/**Returns a digest of the specified byte array. The digest is computed
from len bytes of the array, starting from index off*/

public byte[] digest (byte[] text, int off, int len) {
	byte[] message = pad (text, off, len);
	int[] data = new int[80];
	int[] digest = { h0,h1,h2,h3,h4};

	for (int i=0; i>>31);
}

for (int i=0;i<80;++i) {
	int temp = ((a<<5) | (a>>>27)) + e +data[i];
	if (i<20)
		temp += ((b&c) | (~b & d))+k1;
	else if (i<40)
		temp+=(b^c^d)+k2;
	else if (i<60)
		temp+=((b&c) | (b&d) | (c&d))+k3;
	else 
		temp+=(b^c^d)+k4;
	e=d;
	d=c;
	c=((b<<30) | (b>>>2));
	b=a;
	a=temp;
}

digest[0]+=a;
digest[1]+=b;
digest[2]+=c;
digest[3]+=d;
digest[4]+=e;

}

protected static final int k1=0x5A827999;
protected static final int k2=0x6ED9EBA1;
protected static final int k3=0x8F1BBCDC;
protected static final int k4=0xCA62C1D6;

/**This algorithm produces a 160-bit digest or 20 bytes. This returns the
number of bytes used*/

public int digestSize () {
 return 20;
}


} /*end of class SHS */