Class CrcParameters

    • Constructor Summary

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String algorithm()
      Returns the canonical name of the hash algorithm.
      int bitWidth()
      Returns the width in bits of the CRC function.
      boolean equals​(java.lang.Object obj)  
      int hashCode()  
      long initial()
      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 polynomial()
      Returns the binary form of polynomial that defines the CRC function (with the implicit top bit omitted).
      boolean reflected()
      Returns whether the CRC function is "reflected".
      long xorOut()
      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 Detail

      • 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 Detail

      • CrcParameters

        public CrcParameters​(java.lang.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:
        java.lang.IllegalArgumentException - if the width is less than 1 or greater than 64
    • Method Detail

      • algorithm

        public java.lang.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​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object