/** * 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); } }
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 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); } }
/** * 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); } }
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 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); } }