Package com.scurrilous.circe.params
Class CrcParameters
- java.lang.Object
-
- com.scurrilous.circe.params.CrcParameters
-
- All Implemented Interfaces:
HashParameters
public class CrcParameters extends java.lang.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 CrcParametersCRC16Parameters for CRC-16, used in the ARC and LHA compression utilities.static CrcParametersCRC16_CCITTParameters for CRC-16/CCITT, used in the Kermit protocol.static CrcParametersCRC16_XMODEMParameters for CRC-16/XMODEM, used in the XMODEM protocol.static CrcParametersCRC32Parameters for CRC-32, used in Ethernet, SATA, PKZIP, ZMODEM, etc.static CrcParametersCRC32_BZIP2Parameters for CRC-32/BZIP2, used in BZIP2.static CrcParametersCRC32_MPEG2Parameters for CRC-32/MPEG-2, used in MPEG-2.static CrcParametersCRC32_POSIXParameters for CRC-32/POSIX, used in thecksumutility.static CrcParametersCRC32CParameters for CRC-32C, used in iSCSI and SCTP.static CrcParametersCRC64Parameters for CRC-64, used in the ECMA-182 standard for DLT-1 tapes.static CrcParametersCRC64_XZParameters for CRC-64/XZ, used in the.xzfile format.
-
Constructor Summary
Constructors Constructor Description CrcParameters(java.lang.String name, int bitWidth, long polynomial, long initial, long xorOut, boolean reflected)Constructs aCrcParameterswith the given parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringalgorithm()Returns the canonical name of the hash algorithm.intbitWidth()Returns the width in bits of the CRC function.booleanequals(java.lang.Object obj)inthashCode()longinitial()Returns the initial value of the CRC register.booleanmatch(int bitWidth, long polynomial, long initial, long xorOut, boolean reflected)Returns whether this object matches the given CRC parameters.longpolynomial()Returns the binary form of polynomial that defines the CRC function (with the implicit top bit omitted).booleanreflected()Returns whether the CRC function is "reflected".longxorOut()Returns the value XOR'ed with the CRC register when it is read to determine the output value.
-
-
-
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 thecksumutility.
-
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.xzfile format.
-
-
Constructor Detail
-
CrcParameters
public CrcParameters(java.lang.String name, int bitWidth, long polynomial, long initial, long xorOut, boolean reflected)Constructs aCrcParameterswith the given parameters.- Parameters:
name- the canonical name of the CRC functionbitWidth- the width of the CRC functionpolynomial- the polynomial in binary form (non-reflected)initial- the initial value of the CRC registerxorOut- a value XOR'ed with the CRC when it is readreflected- 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:HashParametersReturns the canonical name of the hash algorithm.- Specified by:
algorithmin interfaceHashParameters- 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 as1000 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 functionpolynomial- the polynomial in binary form (non-reflected)initial- the initial value of the CRC registerxorOut- a value XOR'ed with the CRC when it is readreflected- 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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-