Completes the hash computation by performing final operations such as padding. At the return of this engineDigest, the MD engine is reset. @return the array of bytes for the resulting hash value.
()
| 159 | * @return the array of bytes for the resulting hash value. |
| 160 | */ |
| 161 | public byte[] engineDigest() { |
| 162 | // pad output to 56 mod 64; as RFC1320 puts it: congruent to 448 mod 512 |
| 163 | int bufferNdx = (int) (count % BLOCK_LENGTH); |
| 164 | int padLen = (bufferNdx < 56) ? (56 - bufferNdx) : (120 - bufferNdx); |
| 165 | |
| 166 | // padding is alwas binary 1 followed by binary 0s |
| 167 | byte[] tail = new byte[padLen + 8]; |
| 168 | tail[0] = (byte) 0x80; |
| 169 | |
| 170 | // append length before final transform: |
| 171 | // save number of bits, casting the long to an array of 8 bytes |
| 172 | // save low-order byte first. |
| 173 | for (int i = 0; i < 8; i++) |
| 174 | tail[padLen + i] = (byte) ((count * 8) >>> (8 * i)); |
| 175 | |
| 176 | engineUpdate(tail, 0, tail.length); |
| 177 | |
| 178 | byte[] result = new byte[16]; |
| 179 | // cast this MD4's context (array of 4 ints) into an array of 16 bytes. |
| 180 | for (int i = 0; i < 4; i++) |
| 181 | for (int j = 0; j < 4; j++) |
| 182 | result[i * 4 + j] = (byte) (context[i] >>> (8 * j)); |
| 183 | |
| 184 | // reset the engine |
| 185 | engineReset(); |
| 186 | return result; |
| 187 | } |
| 188 | |
| 189 | // own methods |
| 190 | //........................................................................... |