/** * Update this {@code Adler32} checksum using the contents of {@code buf}. * * @param buf * bytes to update checksum with. */ public void update(byte[] buf) { update(buf, 0, buf.length); }
@Override public void update(byte[] input, int startIndex, int length) { checkSumGenerator.update(input, startIndex, length); }
/** * Returns the checksum of all but the first 12 bytes of {@code dex}. */ public int computeChecksum() throws IOException { Adler32 adler32 = new Adler32(); byte[] buffer = new byte[8192]; ByteBuffer data = this.data.duplicate(); // positioned ByteBuffers aren't thread safe data.limit(data.capacity()); data.position(CHECKSUM_OFFSET + SizeOf.CHECKSUM); while (data.hasRemaining()) { int count = Math.min(buffer.length, data.remaining()); data.get(buffer, 0, count); adler32.update(buffer, 0, count); } return (int) adler32.getValue(); }
public static void updateChecksum(ByteBuffer buffer, int size) { byte[] data = buffer.array(); MessageDigest digest; try { digest = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { throw new AssertionError(); } digest.update(data, 32, size - 32); byte[] sha1 = digest.digest(); System.arraycopy(sha1, 0, data, 12, sha1.length); Adler32 adler32 = new Adler32(); adler32.update(data, 12, size - 12); int v = (int) adler32.getValue(); buffer.position(8); buffer.putInt(v); }
/** * Calculates the checksum for the <code>.dex</code> file in the * given array, and modify the array to contain it. * * @param bytes non-null; the bytes of the file */ public static void calcChecksum(byte[] bytes) { Adler32 a32 = new Adler32(); a32.update(bytes, 12, bytes.length - 12); int sum = (int) a32.getValue(); bytes[8] = (byte) sum; bytes[9] = (byte) (sum >> 8); bytes[10] = (byte) (sum >> 16); bytes[11] = (byte) (sum >> 24); }
private void updateChecksum(@Nonnull DexDataStore dataStore) throws IOException { Adler32 a32 = new Adler32(); byte[] buffer = new byte[4 * 1024]; InputStream input = dataStore.readAt(HeaderItem.CHECKSUM_DATA_START_OFFSET); int bytesRead = input.read(buffer); while (bytesRead >= 0) { a32.update(buffer, 0, bytesRead); bytesRead = input.read(buffer); } // write checksum, utilizing logic in DexWriter to write the integer value properly OutputStream output = dataStore.outputAt(HeaderItem.CHECKSUM_OFFSET); DexDataWriter.writeInt(output, (int)a32.getValue()); output.close(); }
} else { Adler32 adler32 = new Adler32(); adler32.update( byteArray ); retval = new Long( adler32.getValue() );
@Override public long hash(final byte[] value) { final Adler32 adler = new Adler32(); adler.update(value); return adler.getValue(); }
@Override public long hash(final byte[] value) { final Adler32 adler = new Adler32(); adler.update(value); return adler.getValue(); }
/** * A utility method to calculate Adler-32 checksum. * * @param data data * @return checksum */ public static int calcAdler32Checksum(byte[] data) { Adler32 adler32 = new Adler32(); adler32.update(data); return (int) adler32.getValue(); }
/** * Caller must synchronize * * @param buf 16 bytes starting at off * @param off offset */ private void receiveSubsequent(byte buf[], int off) { _blocks++; int remaining = _size - _nextWrite; int blockUsed = Math.min(BLOCK_SIZE, remaining); if (remaining > 0) { System.arraycopy(buf, off, _dataBuf.getData(), _nextWrite, blockUsed); _nextWrite += blockUsed; remaining -= blockUsed; } if ( (remaining <= 0) && (BLOCK_SIZE - blockUsed < 4) ) { // we've received all the data but not the 4-byte checksum if (_log.shouldLog(Log.DEBUG)) _log.debug("crc wraparound required on block " + _blocks + " in message " + _messagesRead); _crc.update(buf, off, BLOCK_SIZE); return; } else if (remaining <= 0) { receiveLastBlock(buf, off); } else { _crc.update(buf, off, BLOCK_SIZE); } }
private String computeDefaultPrefix(ResourceContext context) { SortedSet<JClassType> gssResources = computeOperableTypes(context); Adler32 checksum = new Adler32(); for (JClassType type : gssResources) { checksum.update(Util.getBytes(type.getQualifiedSourceName())); } int seed = Math.abs((int) checksum.getValue()); return encode(seed) + "-"; }
checksum.update(Util.getBytes(type.getQualifiedSourceName()));
while (conflict != null) { Adler32 hash = new Adler32(); hash.update(Util.getBytes(conflict));
private void readMeta(byte unencrypted[], int off) { Adler32 crc = new Adler32(); crc.update(unencrypted, off, META_SIZE - 4); long expected = crc.getValue(); long read = DataHelper.fromLong(unencrypted, off + META_SIZE - 4, 4); if (read != expected) { if (_log.shouldLog(Log.WARN)) _log.warn("I2NP metadata message had a bad CRC value"); _context.statManager().addRateData("ntcp.corruptMetaCRC", 1); close(); return; } long ts = DataHelper.fromLong(unencrypted, off + 2, 4); receiveTimestamp(ts); }
/** * Update this {@code Adler32} checksum using the contents of {@code buf}. * * @param buf * bytes to update checksum with. */ public void update(byte[] buf) { update(buf, 0, buf.length); }
System.arraycopy(buf, off + 2, _dataBuf.getData(), 0, BLOCK_SIZE - 2); _nextWrite += BLOCK_SIZE - 2; _crc.update(buf, off, BLOCK_SIZE); _blocks++; if (_log.shouldLog(Log.DEBUG))
_context.random().nextBytes(data, 6, 6); Adler32 crc = new Adler32(); crc.update(data, 0, META_SIZE - 4); DataHelper.toLong(data, META_SIZE - 4, 4, crc.getValue()); _context.aes().encrypt(data, 0, data, 0, _sessionKey, _prevWriteEnd, 0, META_SIZE);
buf.crc.update(buf.unencrypted, 0, buf.unencryptedLength-4);
_crc.update(buf, off, BLOCK_SIZE - 4); long val = _crc.getValue(); if (val == expectedCrc) {