Hi all,

I'm trying to implement the SHA-1 algorithm in Java 2, Micro Edition but are having major problems getting it to work.

The first part with message padding works great. The problem is in the hashing routine. I got the following code:

On section d of the FIPS PUB 180-1 they say:

(D) For t=0 to 79 do
TEMP = S^5(A) + f(B,C,D) + E + Wt + Kt
E = D; D = C; C = S^30(B); B = A; A = TEMP;

I've implemented this using the following code:
PHP Code:
for (count 0count 80count++) {
   
Wtemp S(A5) + F(countBCD) + W[count] + K(count);
   
DCS(B30); AWtemp;

For the function S I have:
PHP Code:
int S(int WORDint BITS){
   return (((
WORD) << (BITS)) | ((WORD) >> (32-(BITS)))); 
For the function F I have:
PHP Code:
int F(int posint Bint Cint D) {
   if (
pos 20
      
tempByte = (C) | ((~B) & D);
   else if (
pos 40)
      
tempByte D;
   else if (
pos 60)
      
tempByte = (C) | (D) | (D);
   else
      
tempByte d;

   return 
tempByte;

Using the test vector showed on the FIPS PUB 180-1 (Message = "abc") I get the first 2 rounds correct but the remaining 78 rounds are completely out of whack.

Anyone have any ideas????????????

Mounir