63 |
|
|
64 |
public void engineUpdate (byte b) |
public void engineUpdate (byte b) |
65 |
{ |
{ |
66 |
int i = (int)bytecount % 64; |
//int i = (int)bytecount % 64; |
67 |
int shift = (3 - i % 4) * 8; |
int i = ((int)bytecount) & 0x3f; //wgs |
68 |
|
//int shift = (3 - i % 4) * 8; |
69 |
|
int shift = (3 - i % 4) << 3; |
70 |
int idx = i / 4; |
int idx = i / 4; |
71 |
|
|
72 |
|
i = (int)b; |
73 |
// if you could index ints, this would be: W[idx][shift/8] = b |
// if you could index ints, this would be: W[idx][shift/8] = b |
74 |
W[idx] = (W[idx] & ~(0xff << shift)) | ((b & 0xff) << shift); |
W[idx] = (W[idx] & ~(0xff << shift)) | ((i & 0xff) << shift); |
75 |
|
|
76 |
// if we've filled up a block, then process it |
// if we've filled up a block, then process it |
77 |
if ((++ bytecount) % 64 == 0) |
//if ((++ bytecount) % 64 == 0) |
78 |
|
if (((++bytecount) & 0x3f) == 0) |
79 |
munch (); |
munch (); |
80 |
} |
} |
81 |
|
|
103 |
|
|
104 |
public byte[] engineDigest () |
public byte[] engineDigest () |
105 |
{ |
{ |
106 |
long bitcount = bytecount * 8; |
//long bitcount = bytecount * 8; |
107 |
|
long bitcount = bytecount << 3; |
108 |
engineUpdate ((byte)0x80); // 10000000 in binary; the start of the padding |
engineUpdate ((byte)0x80); // 10000000 in binary; the start of the padding |
109 |
|
|
110 |
// 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 |
111 |
// bytes to put in the original bytecount |
// bytes to put in the original bytecount |
112 |
while ((int)bytecount % 64 != 56) |
//while ((int)bytecount % 64 != 56) |
113 |
|
while ((bytecount & 0x3f) != 56) |
114 |
engineUpdate ((byte)0); |
engineUpdate ((byte)0); |
115 |
|
|
116 |
// add the length of the original, unpadded block to the end of |
// add the length of the original, unpadded block to the end of |