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); } }
d += s3(e, a, b, c,w[ 56]); a = rotateLeft( a, 30); c += s3(d, e, a, b,w[ 57]); e = rotateLeft( e, 30); state58.save(a, b, c, d, e); b += s3(c, d, e, a,w[ 58]); d = rotateLeft( d, 30); a += s3(b, c, d, e,w[ 59]); c = rotateLeft( c, 30); b += s4(c, d, e, a,w[ 63]); d = rotateLeft( d, 30); a += s4(b, c, d, e,w[ 64]); c = rotateLeft( c, 30); state65.save(a, b, c, d, e); e += s4(a, b, c, d,w[ 65]); b = rotateLeft( b, 30); d += s4(e, a, b, c,w[ 66]); a = rotateLeft( a, 30); h.save(h.a + a, h.b + b, h.c + c, h.d + d, h.e + e);
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 SHA1() { h.init(); }
final void init() { // Magic initialization constants defined by FIPS180. save(0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0); }
/** * 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(); }
/** * Reset this instance to compute another hash. * * @return {@code this}. */ public SHA1 reset() { h.init(); length = 0; foundCollision = false; return this; }
d += s3(e, a, b, c,w[ 56]); a = rotateLeft( a, 30); c += s3(d, e, a, b,w[ 57]); e = rotateLeft( e, 30); state58.save(a, b, c, d, e); b += s3(c, d, e, a,w[ 58]); d = rotateLeft( d, 30); a += s3(b, c, d, e,w[ 59]); c = rotateLeft( c, 30); b += s4(c, d, e, a,w[ 63]); d = rotateLeft( d, 30); a += s4(b, c, d, e,w[ 64]); c = rotateLeft( c, 30); state65.save(a, b, c, d, e); e += s4(a, b, c, d,w[ 65]); b = rotateLeft( b, 30); d += s4(e, a, b, c,w[ 66]); a = rotateLeft( a, 30); h.save(h.a + a, h.b + b, h.c + c, h.d + d, h.e + e);
private SHA1() { h.init(); }
/** * 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(); }
final void init() { // Magic initialization constants defined by FIPS180. save(0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0); }
/** * Reset this instance to compute another hash. * * @return {@code this}. */ public SHA1 reset() { h.init(); length = 0; foundCollision = false; return this; }