63 |
|
|
64 |
public void engineUpdate (byte b) |
public void engineUpdate (byte b) |
65 |
{ |
{ |
|
//int i = (int)bytecount % 64; |
|
66 |
int i = ((int)bytecount) & 0x3f; //wgs |
int i = ((int)bytecount) & 0x3f; //wgs |
|
//int shift = (3 - i % 4) * 8; |
|
67 |
int shift = (3 - i % 4) << 3; |
int shift = (3 - i % 4) << 3; |
68 |
int idx = i / 4; |
int idx = i / 4; |
69 |
|
|
70 |
i = (int)b; |
i = (int)b; |
|
// if you could index ints, this would be: W[idx][shift/8] = b |
|
71 |
W[idx] = (W[idx] & ~(0xff << shift)) | ((i & 0xff) << shift); |
W[idx] = (W[idx] & ~(0xff << shift)) | ((i & 0xff) << shift); |
72 |
|
|
73 |
// if we've filled up a block, then process it |
// if we've filled up a block, then process it |
|
//if ((++ bytecount) % 64 == 0) |
|
74 |
if (((++bytecount) & 0x3f) == 0) |
if (((++bytecount) & 0x3f) == 0) |
75 |
munch (); |
munch (); |
76 |
} |
} |
99 |
|
|
100 |
public byte[] engineDigest () |
public byte[] engineDigest () |
101 |
{ |
{ |
|
//long bitcount = bytecount * 8; |
|
102 |
long bitcount = bytecount << 3; |
long bitcount = bytecount << 3; |
103 |
engineUpdate ((byte)0x80); // 10000000 in binary; the start of the padding |
engineUpdate ((byte)0x80); // 10000000 in binary; the start of the padding |
104 |
|
|
105 |
// add the rest of the padding to fill this block out, but leave 8 |
// add the rest of the padding to fill this block out, but leave 8 |
106 |
// bytes to put in the original bytecount |
// bytes to put in the original bytecount |
|
//while ((int)bytecount % 64 != 56) |
|
107 |
while ((bytecount & 0x3f) != 56) |
while ((bytecount & 0x3f) != 56) |
108 |
engineUpdate ((byte)0); |
engineUpdate ((byte)0); |
109 |
|
|