private void finish() { int bufferLen = (int) (length & 63); if (bufferLen > 55) { // Last block is too small; pad, compress, pad another block. buffer[bufferLen++] = (byte) 0x80; Arrays.fill(buffer, bufferLen, 64, (byte) 0); compress(buffer, 0); Arrays.fill(buffer, 0, 56, (byte) 0); } else { // Last block can hold padding and length. buffer[bufferLen++] = (byte) 0x80; Arrays.fill(buffer, bufferLen, 56, (byte) 0); } // SHA-1 appends the length of the message in bits after the // padding block (above). Here length is in bytes. Multiply by // 8 by shifting by 3 as part of storing the 64 bit byte length // into the two words expected in the trailer. NB.encodeInt32(buffer, 56, (int) (length >>> (32 - 3))); NB.encodeInt32(buffer, 60, (int) (length << 3)); compress(buffer, 0); if (foundCollision) { ObjectId id = h.toObjectId(); LOG.warn("possible SHA-1 collision " + id.name()); //$NON-NLS-1$ throw new Sha1CollisionException(id); } }
private void finish() { int bufferLen = (int) (length & 63); if (bufferLen > 55) { // Last block is too small; pad, compress, pad another block. buffer[bufferLen++] = (byte) 0x80; Arrays.fill(buffer, bufferLen, 64, (byte) 0); compress(buffer, 0); Arrays.fill(buffer, 0, 56, (byte) 0); } else { // Last block can hold padding and length. buffer[bufferLen++] = (byte) 0x80; Arrays.fill(buffer, bufferLen, 56, (byte) 0); } // SHA-1 appends the length of the message in bits after the // padding block (above). Here length is in bytes. Multiply by // 8 by shifting by 3 as part of storing the 64 bit byte length // into the two words expected in the trailer. NB.encodeInt32(buffer, 56, (int) (length >>> (32 - 3))); NB.encodeInt32(buffer, 60, (int) (length << 3)); compress(buffer, 0); if (foundCollision) { ObjectId id = h.toObjectId(); LOG.warn("possible SHA-1 collision " + id.name()); //$NON-NLS-1$ throw new Sha1CollisionException(id); } }
/** * Finish the digest and return the resulting hash. * <p> * Once {@code digest()} is called, this instance should be discarded. * * @return the ObjectId for the resulting hash. * @throws org.eclipse.jgit.util.sha1.Sha1CollisionException * if a collision was detected and safeHash is false. */ public ObjectId toObjectId() throws Sha1CollisionException { finish(); return h.toObjectId(); }
/** * Finish the digest and return the resulting hash. * <p> * Once {@code digest()} is called, this instance should be discarded. * * @return the ObjectId for the resulting hash. * @throws org.eclipse.jgit.util.sha1.Sha1CollisionException * if a collision was detected and safeHash is false. */ public ObjectId toObjectId() throws Sha1CollisionException { finish(); return h.toObjectId(); }