/** * {@inheritDoc} */ protected byte[] engineDigest() { byte[] p = pad(); engineUpdate(p, 0, p.length); byte[] digest = { (byte) a, (byte) (a >>> 8), (byte) (a >>> 16), (byte) (a >>> 24), (byte) b, (byte) (b >>> 8), (byte) (b >>> 16), (byte) (b >>> 24), (byte) c, (byte) (c >>> 8), (byte) (c >>> 16), (byte) (c >>> 24), (byte) d, (byte) (d >>> 8), (byte) (d >>> 16), (byte) (d >>> 24) }; engineReset(); return digest; }
/** * {@inheritDoc} */ protected void engineUpdate(byte b) { int pos = (int) (msgLength % BYTE_BLOCK_LENGTH); buffer[pos] = b; msgLength++; // If buffer contains enough data then process it. if (pos == (BYTE_BLOCK_LENGTH - 1)) { process(buffer, 0); } }
/** * {@inheritDoc} */ protected int engineDigest(byte[] buf, int offset, int len) throws DigestException { if (offset < 0 || offset + len >= buf.length) { throw new DigestException( "Wrong offset or not enough space to store the digest"); } int destLength = Math.min(len, BYTE_DIGEST_LENGTH); System.arraycopy(engineDigest(), 0, buf, offset, destLength); return destLength; }
/** * {@inheritDoc} */ protected void engineUpdate(byte[] b, int offset, int len) { int pos = (int) (msgLength % BYTE_BLOCK_LENGTH); int nbOfCharsToFillBuf = BYTE_BLOCK_LENGTH - pos; int blkStart = 0; msgLength += len; // Process each full block if (len >= nbOfCharsToFillBuf) { System.arraycopy(b, offset, buffer, pos, nbOfCharsToFillBuf); process(buffer, 0); for (blkStart = nbOfCharsToFillBuf; blkStart + BYTE_BLOCK_LENGTH - 1 < len; blkStart += BYTE_BLOCK_LENGTH) { process(b, offset + blkStart); } pos = 0; } // Fill buffer with the remaining data if (blkStart < len) { System.arraycopy(b, offset + blkStart, buffer, pos, len - blkStart); } }