Class CrcParameters

java.lang.Object
com.scurrilous.circe.params.CrcParameters
All Implemented Interfaces:
HashParameters

public class CrcParameters extends Object implements HashParameters
Hash parameters used to define a cyclic redundancy check (CRC). Includes some commonly used sets of parameters.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final CrcParameters
    Parameters for CRC-16, used in the ARC and LHA compression utilities.
    static final CrcParameters
    Parameters for CRC-16/CCITT, used in the Kermit protocol.
    static final CrcParameters
    Parameters for CRC-16/XMODEM, used in the XMODEM protocol.
    static final CrcParameters
    Parameters for CRC-32, used in Ethernet, SATA, PKZIP, ZMODEM, etc.
    static final CrcParameters
    Parameters for CRC-32/BZIP2, used in BZIP2.
    static final CrcParameters
    Parameters for CRC-32/MPEG-2, used in MPEG-2.
    static final CrcParameters
    Parameters for CRC-32/POSIX, used in the cksum utility.
    static final CrcParameters
    Parameters for CRC-32C, used in iSCSI and SCTP.
    static final CrcParameters
    Parameters for CRC-64, used in the ECMA-182 standard for DLT-1 tapes.
    static final CrcParameters
    Parameters for CRC-64/XZ, used in the .xz file format.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CrcParameters(String name, int bitWidth, long polynomial, long initial, long xorOut, boolean reflected)
    Constructs a CrcParameters with the given parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the canonical name of the hash algorithm.
    int
    Returns the width in bits of the CRC function.
    boolean
     
    int
     
    long
    Returns the initial value of the CRC register.
    boolean
    match(int bitWidth, long polynomial, long initial, long xorOut, boolean reflected)
    Returns whether this object matches the given CRC parameters.
    long
    Returns the binary form of polynomial that defines the CRC function (with the implicit top bit omitted).
    boolean
    Returns whether the CRC function is "reflected".
    long
    Returns the value XOR'ed with the CRC register when it is read to determine the output value.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CRC16

      public static final CrcParameters CRC16
      Parameters for CRC-16, used in the ARC and LHA compression utilities.
    • CRC16_CCITT

      public static final CrcParameters CRC16_CCITT
      Parameters for CRC-16/CCITT, used in the Kermit protocol.
    • CRC16_XMODEM

      public static final CrcParameters CRC16_XMODEM
      Parameters for CRC-16/XMODEM, used in the XMODEM protocol.
    • CRC32

      public static final CrcParameters CRC32
      Parameters for CRC-32, used in Ethernet, SATA, PKZIP, ZMODEM, etc.
    • CRC32_BZIP2

      public static final CrcParameters CRC32_BZIP2
      Parameters for CRC-32/BZIP2, used in BZIP2.
    • CRC32C

      public static final CrcParameters CRC32C
      Parameters for CRC-32C, used in iSCSI and SCTP.
    • CRC32_MPEG2

      public static final CrcParameters CRC32_MPEG2
      Parameters for CRC-32/MPEG-2, used in MPEG-2.
    • CRC32_POSIX

      public static final CrcParameters CRC32_POSIX
      Parameters for CRC-32/POSIX, used in the cksum utility.
    • CRC64

      public static final CrcParameters CRC64
      Parameters for CRC-64, used in the ECMA-182 standard for DLT-1 tapes.
    • CRC64_XZ

      public static final CrcParameters CRC64_XZ
      Parameters for CRC-64/XZ, used in the .xz file format.
  • Constructor Details

    • CrcParameters

      public CrcParameters(String name, int bitWidth, long polynomial, long initial, long xorOut, boolean reflected)
      Constructs a CrcParameters with the given parameters.
      Parameters:
      name - the canonical name of the CRC function
      bitWidth - the width of the CRC function
      polynomial - the polynomial in binary form (non-reflected)
      initial - the initial value of the CRC register
      xorOut - a value XOR'ed with the CRC when it is read
      reflected - indicates whether the CRC is reflected (LSB-first)
      Throws:
      IllegalArgumentException - if the width is less than 1 or greater than 64
  • Method Details

    • algorithm

      public String algorithm()
      Description copied from interface: HashParameters
      Returns the canonical name of the hash algorithm.
      Specified by:
      algorithm in interface HashParameters
      Returns:
      the name of the hash algorithm
    • bitWidth

      public int bitWidth()
      Returns the width in bits of the CRC function. The width is also the position of the implicit set bit at the top of the polynomial.
      Returns:
      the CRC width in bits
    • polynomial

      public long polynomial()
      Returns the binary form of polynomial that defines the CRC function (with the implicit top bit omitted). For instance, the CRC-16 polynomial x16 + x15 + x2 + 1 is represented as 1000 0000 0000 0101 (0x8005).
      Returns:
      the CRC polynomial
    • initial

      public long initial()
      Returns the initial value of the CRC register.
      Returns:
      the CRC initial value
    • xorOut

      public long xorOut()
      Returns the value XOR'ed with the CRC register when it is read to determine the output value.
      Returns:
      the final XOR value
    • reflected

      public boolean reflected()
      Returns whether the CRC function is "reflected". Reflected CRCs process data LSB-first, whereas "normal" CRCs are MSB-first.
      Returns:
      whether the CRC function is reflected
    • match

      public boolean match(int bitWidth, long polynomial, long initial, long xorOut, boolean reflected)
      Returns whether this object matches the given CRC parameters.
      Parameters:
      bitWidth - the width of the CRC function
      polynomial - the polynomial in binary form (non-reflected)
      initial - the initial value of the CRC register
      xorOut - a value XOR'ed with the CRC when it is read
      reflected - indicates whether the CRC is reflected (LSB-first)
      Returns:
      true if all parameters match exactly, false otherwise
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object