/** * Create a new context to compute a SHA-1 hash of data. * * @return a new context to compute a SHA-1 hash of data. */ public static SHA1 newInstance() { return new SHA1(); }
private void compress(byte[] block, int p) { initBlock(block, p); int ubcDvMask = detectCollision ? UbcCheck.check(w) : 0; compress(); while (ubcDvMask != 0) { int b = numberOfTrailingZeros(lowestOneBit(ubcDvMask)); UbcCheck.DvInfo dv = UbcCheck.DV[b]; for (int i = 0; i < 80; i++) { w2[i] = w[i] ^ dv.dm[i]; } recompress(dv.testt); if (eq(hTmp, h)) { foundCollision = true; break; } ubcDvMask &= ~(1 << b); } }
private byte[] computeHash(InputStream in, long length) throws IOException { SHA1 contentDigest = SHA1.newInstance(); final byte[] contentReadBuffer = state.contentReadBuffer; contentDigest.update(hblob); contentDigest.update((byte) ' '); long sz = length; if (sz == 0) { contentDigest.update((byte) '0'); } else { final int bufn = contentReadBuffer.length; int p = bufn; do { contentReadBuffer[--p] = digits[(int) (sz % 10)]; sz /= 10; } while (sz > 0); contentDigest.update(contentReadBuffer, p, bufn - p); } contentDigest.update((byte) 0); for (;;) { final int r = in.read(contentReadBuffer); if (r <= 0) break; contentDigest.update(contentReadBuffer, 0, r); sz += r; } if (sz != length) return zeroid; return contentDigest.digest(); }
/** * Compute the name of an object, without inserting it. * * @param type * type code of the object to store. * @param data * complete content of the object. * @param off * first position within {@code data}. * @param len * number of bytes to copy from {@code data}. * @return the name of the object. */ public ObjectId idFor(int type, byte[] data, int off, int len) { SHA1 md = SHA1.newInstance(); md.update(Constants.encodedTypeString(type)); md.update((byte) ' '); md.update(Constants.encodeASCII(len)); md.update((byte) 0); md.update(data, off, len); return md.toObjectId(); }
e += s1(a, b, c, d,w[ 0]); b = rotateLeft( b, 30); d += s1(e, a, b, c,w[ 1]); a = rotateLeft( a, 30); c += s1(d, e, a, b,w[ 2]); e = rotateLeft( e, 30); b += s1(c, d, e, a,w[ 3]); d = rotateLeft( d, 30); a += s1(b, c, d, e,w[ 4]); c = rotateLeft( c, 30); e += s1(a, b, c, d,w[ 5]); b = rotateLeft( b, 30); d += s1(e, a, b, c,w[ 6]); a = rotateLeft( a, 30); c += s1(d, e, a, b,w[ 7]); e = rotateLeft( e, 30); b += s1(c, d, e, a,w[ 8]); d = rotateLeft( d, 30); a += s1(b, c, d, e,w[ 9]); c = rotateLeft( c, 30); e += s1(a, b, c, d,w[ 10]); b = rotateLeft( b, 30); d += s1(e, a, b, c,w[ 11]); a = rotateLeft( a, 30); c += s1(d, e, a, b,w[ 12]); e = rotateLeft( e, 30); b += s1(c, d, e, a,w[ 13]); d = rotateLeft( d, 30); a += s1(b, c, d, e,w[ 14]); c = rotateLeft( c, 30); e += s1(a, b, c, d,w[ 15]); b = rotateLeft( b, 30); d += s1(e, a, b, c,w[ 16]); a = rotateLeft( a, 30); c += s1(d, e, a, b,w[ 17]); e = rotateLeft( e, 30); b += s1(c, d, e, a,w[ 18]); d = rotateLeft( d, 30); a += s1(b, c, d, e,w[ 19]); c = rotateLeft( c, 30); e += s2(a, b, c, d,w[ 20]); b = rotateLeft( b, 30); d += s2(e, a, b, c,w[ 21]); a = rotateLeft( a, 30); c += s2(d, e, a, b,w[ 22]); e = rotateLeft( e, 30); b += s2(c, d, e, a,w[ 23]); d = rotateLeft( d, 30); a += s2(b, c, d, e,w[ 24]); c = rotateLeft( c, 30); e += s2(a, b, c, d,w[ 25]); b = rotateLeft( b, 30); d += s2(e, a, b, c,w[ 26]); a = rotateLeft( a, 30); c += s2(d, e, a, b,w[ 27]); e = rotateLeft( e, 30);
/** * Update the digest computation by adding a byte. * * @param b a byte. */ public void update(byte b) { int bufferLen = (int) (length & 63); length++; buffer[bufferLen] = b; if (bufferLen == 63) { compress(buffer, 0); } }
/** * 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(); }
/** * Compute digest to help compute an ObjectId * * @return digest to help compute an ObjectId * @since 4.7 */ protected SHA1 digest() { return hasher.reset(); }
/** Wraps a delegate ObjectInserter. */ public static abstract class Filter extends ObjectInserter { /** @return delegate ObjectInserter to handle all processing. */ protected abstract ObjectInserter delegate(); @Override protected byte[] buffer() { return delegate().buffer(); } @Override public ObjectId idFor(int type, byte[] data) { return delegate().idFor(type, data); } @Override public ObjectId idFor(int type, byte[] data, int off, int len) { return delegate().idFor(type, data, off, len); } @Override public ObjectId idFor(int objectType, long length, InputStream in) throws IOException { return delegate().idFor(objectType, length, in); } @Override public ObjectId idFor(TreeFormatter formatter) { return delegate().idFor(formatter); }
{ c = rotateRight( c, 30); a -= s4(b, c, d, e,w2[ 64]);} { d = rotateRight( d, 30); b -= s4(c, d, e, a,w2[ 63]);} { e = rotateRight( e, 30); c -= s4(d, e, a, b,w2[ 62]);} { a = rotateRight( a, 30); d -= s4(e, a, b, c,w2[ 61]);} { b = rotateRight( b, 30); e -= s4(a, b, c, d,w2[ 60]);} { c = rotateRight( c, 30); a -= s3(b, c, d, e,w2[ 59]);} { d = rotateRight( d, 30); b -= s3(c, d, e, a,w2[ 58]);} { e = rotateRight( e, 30); c -= s3(d, e, a, b,w2[ 57]);} { a = rotateRight( a, 30); d -= s3(e, a, b, c,w2[ 56]);} { b = rotateRight( b, 30); e -= s3(a, b, c, d,w2[ 55]);} { c = rotateRight( c, 30); a -= s3(b, c, d, e,w2[ 54]);} { d = rotateRight( d, 30); b -= s3(c, d, e, a,w2[ 53]);} { e = rotateRight( e, 30); c -= s3(d, e, a, b,w2[ 52]);} { a = rotateRight( a, 30); d -= s3(e, a, b, c,w2[ 51]);} { b = rotateRight( b, 30); e -= s3(a, b, c, d,w2[ 50]);} { c = rotateRight( c, 30); a -= s3(b, c, d, e,w2[ 49]);} { d = rotateRight( d, 30); b -= s3(c, d, e, a,w2[ 48]);} { e = rotateRight( e, 30); c -= s3(d, e, a, b,w2[ 47]);} { a = rotateRight( a, 30); d -= s3(e, a, b, c,w2[ 46]);} { b = rotateRight( b, 30); e -= s3(a, b, c, d,w2[ 45]);} { c = rotateRight( c, 30); a -= s3(b, c, d, e,w2[ 44]);} { d = rotateRight( d, 30); b -= s3(c, d, e, a,w2[ 43]);} { e = rotateRight( e, 30); c -= s3(d, e, a, b,w2[ 42]);} { a = rotateRight( a, 30); d -= s3(e, a, b, c,w2[ 41]);} { b = rotateRight( b, 30); e -= s3(a, b, c, d,w2[ 40]);} { c = rotateRight( c, 30); a -= s2(b, c, d, e,w2[ 39]);}
SHA1 md = SHA1.newInstance(); md.update(Constants.encodedTypeString(objectType)); md.update((byte) ' '); md.update(Constants.encodeASCII(length)); md.update((byte) 0); byte[] buf = buffer(); while (length > 0) { if (n < 0) throw new EOFException(JGitText.get().unexpectedEndOfInput); md.update(buf, 0, n); length -= n; return md.toObjectId();
private byte[] computeHash(InputStream in, long length) throws IOException { SHA1 contentDigest = SHA1.newInstance(); final byte[] contentReadBuffer = state.contentReadBuffer; contentDigest.update(hblob); contentDigest.update((byte) ' '); long sz = length; if (sz == 0) { contentDigest.update((byte) '0'); } else { final int bufn = contentReadBuffer.length; int p = bufn; do { contentReadBuffer[--p] = digits[(int) (sz % 10)]; sz /= 10; } while (sz > 0); contentDigest.update(contentReadBuffer, p, bufn - p); } contentDigest.update((byte) 0); for (;;) { final int r = in.read(contentReadBuffer); if (r <= 0) break; contentDigest.update(contentReadBuffer, 0, r); sz += r; } if (sz != length) return zeroid; return contentDigest.digest(); }
/** * Finish the digest and return the resulting hash. * <p> * Once {@code digest()} is called, this instance should be discarded. * * @param id * destination to copy the digest to. * @throws org.eclipse.jgit.util.sha1.Sha1CollisionException * if a collision was detected and safeHash is false. */ public void digest(MutableObjectId id) throws Sha1CollisionException { finish(); id.set(h.a, h.b, h.c, h.d, h.e); }
/** * Compute digest to help compute an ObjectId * * @return digest to help compute an ObjectId * @since 4.7 */ protected SHA1 digest() { return hasher.reset(); }
/** Wraps a delegate ObjectInserter. */ public static abstract class Filter extends ObjectInserter { /** @return delegate ObjectInserter to handle all processing. */ protected abstract ObjectInserter delegate(); @Override protected byte[] buffer() { return delegate().buffer(); } @Override public ObjectId idFor(int type, byte[] data) { return delegate().idFor(type, data); } @Override public ObjectId idFor(int type, byte[] data, int off, int len) { return delegate().idFor(type, data, off, len); } @Override public ObjectId idFor(int objectType, long length, InputStream in) throws IOException { return delegate().idFor(objectType, length, in); } @Override public ObjectId idFor(TreeFormatter formatter) { return delegate().idFor(formatter); }
byte[] finishPack() throws IOException { // Overwrite placeholder header with actual object count, then hash. This // method intentionally uses direct seek/write calls rather than the // wrappers which keep track of atEnd. This leaves atEnd, the file // pointer, and out's counter in an inconsistent state; that's ok, since // this method closes the file anyway. try { file.seek(0); out.write(hdrBuf, 0, writePackHeader(hdrBuf, objectList.size())); byte[] buf = buffer(); SHA1 md = digest().reset(); file.seek(0); while (true) { int r = file.read(buf); if (r < 0) { break; } md.update(buf, 0, r); } byte[] packHash = md.digest(); out.write(packHash, 0, packHash.length); return packHash; } finally { close(); } }
e += s1(a, b, c, d,w[ 0]); b = rotateLeft( b, 30); d += s1(e, a, b, c,w[ 1]); a = rotateLeft( a, 30); c += s1(d, e, a, b,w[ 2]); e = rotateLeft( e, 30); b += s1(c, d, e, a,w[ 3]); d = rotateLeft( d, 30); a += s1(b, c, d, e,w[ 4]); c = rotateLeft( c, 30); e += s1(a, b, c, d,w[ 5]); b = rotateLeft( b, 30); d += s1(e, a, b, c,w[ 6]); a = rotateLeft( a, 30); c += s1(d, e, a, b,w[ 7]); e = rotateLeft( e, 30); b += s1(c, d, e, a,w[ 8]); d = rotateLeft( d, 30); a += s1(b, c, d, e,w[ 9]); c = rotateLeft( c, 30); e += s1(a, b, c, d,w[ 10]); b = rotateLeft( b, 30); d += s1(e, a, b, c,w[ 11]); a = rotateLeft( a, 30); c += s1(d, e, a, b,w[ 12]); e = rotateLeft( e, 30); b += s1(c, d, e, a,w[ 13]); d = rotateLeft( d, 30); a += s1(b, c, d, e,w[ 14]); c = rotateLeft( c, 30); e += s1(a, b, c, d,w[ 15]); b = rotateLeft( b, 30); d += s1(e, a, b, c,w[ 16]); a = rotateLeft( a, 30); c += s1(d, e, a, b,w[ 17]); e = rotateLeft( e, 30); b += s1(c, d, e, a,w[ 18]); d = rotateLeft( d, 30); a += s1(b, c, d, e,w[ 19]); c = rotateLeft( c, 30); e += s2(a, b, c, d,w[ 20]); b = rotateLeft( b, 30); d += s2(e, a, b, c,w[ 21]); a = rotateLeft( a, 30); c += s2(d, e, a, b,w[ 22]); e = rotateLeft( e, 30); b += s2(c, d, e, a,w[ 23]); d = rotateLeft( d, 30); a += s2(b, c, d, e,w[ 24]); c = rotateLeft( c, 30); e += s2(a, b, c, d,w[ 25]); b = rotateLeft( b, 30); d += s2(e, a, b, c,w[ 26]); a = rotateLeft( a, 30); c += s2(d, e, a, b,w[ 27]); e = rotateLeft( e, 30);
/** * Compute the name of an object, without inserting it. * * @param type * type code of the object to store. * @param data * complete content of the object. * @param off * first position within {@code data}. * @param len * number of bytes to copy from {@code data}. * @return the name of the object. */ public ObjectId idFor(int type, byte[] data, int off, int len) { SHA1 md = SHA1.newInstance(); md.update(Constants.encodedTypeString(type)); md.update((byte) ' '); md.update(Constants.encodeASCII(len)); md.update((byte) 0); md.update(data, off, len); return md.toObjectId(); }