static boolean validateChecksum(ByteBuff buf, String pathName, long offset, int hdrSize) {
    ChecksumType ctype = ChecksumType.codeToType(buf.get(HFileBlock.Header.CHECKSUM_TYPE_INDEX));
    if (ctype == ChecksumType.NULL) {
      return true;// No checksum validations needed for this block.
    }

    // read in the stored value of the checksum size from the header.
    int bytesPerChecksum = buf.getInt(HFileBlock.Header.BYTES_PER_CHECKSUM_INDEX);
    DataChecksum dataChecksum =
      DataChecksum.newDataChecksum(ctype.getDataChecksumType(), bytesPerChecksum);
    assert dataChecksum != null;
    int onDiskDataSizeWithHeader =
      buf.getInt(HFileBlock.Header.ON_DISK_DATA_SIZE_WITH_HEADER_INDEX);
    LOG.trace(
      "dataLength={}, sizeWithHeader={}, checksumType={}, file={}, "
        + "offset={}, headerSize={}, bytesPerChecksum={}",
      buf.capacity(), onDiskDataSizeWithHeader, ctype.getName(), pathName, offset, hdrSize,
      bytesPerChecksum);
    ByteBuff data = buf.duplicate().position(0).limit(onDiskDataSizeWithHeader);
    ByteBuff checksums = buf.duplicate().position(onDiskDataSizeWithHeader).limit(buf.limit());
    return verifyChunkedSums(dataChecksum, data, checksums, pathName);
  }
Validates that the data in the specified HFileBlock matches the checksum. Generates the
checksums for the data and then validate that it matches those stored in the end of the data.
@param buf      Contains the data in following order: HFileBlock header, data, checksums.
@param pathName Path of the HFile to which the {@code data} belongs. Only used for logging.
@param offset   offset of the data being validated. Only used for logging.
@param hdrSize  Size of the block header in {@code data}. Only used for logging.
@return True if checksum matches, else false.
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/ChecksumUtil.java