Class CrcCombineChecksumUtil

java.lang.Object
software.amazon.awssdk.checksums.internal.CrcCombineChecksumUtil

public final class CrcCombineChecksumUtil extends Object
Utility class that provides methods for combining CRC checksums using Galois Field arithmetic. This class allows combining two CRC values into a single CRC that represents the concatenated data, without recalculating the CRC from scratch.

The implementation of CRC combination was taken from the zlib source code here: https://github.com/luvit/zlib/blob/master/crc32.c

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    combine(long crc1, long crc2, long originalLengthOfCrc2, long[][] combineMatrices)
    Combines two CRC values into a single CRC using the specified combine matrices.
    static long[][]
    generateCombineMatrices(long polynomial)
    Generates the combine matrices for CRC calculations.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • generateCombineMatrices

      public static long[][] generateCombineMatrices(long polynomial)
      Generates the combine matrices for CRC calculations.
      Parameters:
      polynomial - The CRC polynomial.
      Returns:
      A 2D array representing the combine matrices.
    • combine

      public static long combine(long crc1, long crc2, long originalLengthOfCrc2, long[][] combineMatrices)
      Combines two CRC values into a single CRC using the specified combine matrices. The combination is performed using Galois Field arithmetic to effectively merge two CRC checksums that correspond to two separate data blocks. This method allows calculating the CRC for the concatenated data without having to recompute the CRC from scratch, which can significantly improve performance for large datasets.

      THIS COMBINE FUNCTION HAS BEEN MODIFIED FROM THE ORIGINAL VERSION. The code comes from https://github.com/luvit/zlib/blob/master/crc32.c.

      Parameters:
      crc1 - The first CRC value.
      crc2 - The second CRC value.
      originalLengthOfCrc2 - The length of the original data for the second CRC. This represents the length of data used to compute crc2.
      combineMatrices - The combine matrices used for combining CRCs. These matrices are precomputed to facilitate efficient combination.
      Returns:
      The combined CRC value representing the CRC for the concatenated data of both CRC values.
      Throws:
      IllegalArgumentException - if originalLengthOfCrc2 is negative.