Class: Omnizip::Checksums::Crc64
- Defined in:
- lib/omnizip/checksums/crc64.rb
Overview
CRC64 checksum implementation using ECMA-182 polynomial.
This implementation uses the ECMA-182 polynomial for CRC64 calculation as used in the XZ file format and 7-Zip archives. This is the standard 64-bit CRC polynomial for data integrity verification in compressed archives.
The algorithm uses a 256-entry pre-computed lookup table with 64-bit values for efficient O(1) per-byte processing.
Polynomial: 0xC96C5795D7870F42 (ECMA-182) Initial value: 0xFFFFFFFFFFFFFFFF Final XOR: 0xFFFFFFFFFFFFFFFF Bit width: 64
Constant Summary collapse
- POLYNOMIAL =
ECMA-182 polynomial (reversed representation) This is the standard polynomial used in XZ format
0xC96C5795D7870F42- MASK_64 =
64-bit mask for truncating values
0xFFFFFFFFFFFFFFFF- TABLE =
Pre-computed lookup table for CRC64 calculation Generated using the ECMA-182 polynomial This table is computed once at class load time for performance
generate_table(POLYNOMIAL, 64).freeze
Instance Attribute Summary
Attributes inherited from CrcBase
Class Method Summary collapse
-
.lookup_table ⇒ Array<Integer>
Get the lookup table for CRC64.
Instance Method Summary collapse
-
#final_xor ⇒ Integer
Get the final XOR value for CRC64.
-
#initial_value ⇒ Integer
Get the initial CRC64 value.
-
#process_byte(crc, byte) ⇒ Integer
Process a single byte through the CRC64 algorithm.
Methods inherited from CrcBase
calculate, #finalize, generate_table, #initialize, #reset, #update
Constructor Details
This class inherits a constructor from Omnizip::Checksums::CrcBase
Class Method Details
.lookup_table ⇒ Array<Integer>
Get the lookup table for CRC64.
94 95 96 |
# File 'lib/omnizip/checksums/crc64.rb', line 94 def self.lookup_table TABLE end |
Instance Method Details
#final_xor ⇒ Integer
Get the final XOR value for CRC64.
The final result is XORed with all 1s to invert the bits, which is part of the CRC64 standard.
87 88 89 |
# File 'lib/omnizip/checksums/crc64.rb', line 87 def final_xor MASK_64 end |
#initial_value ⇒ Integer
Get the initial CRC64 value.
CRC64 starts with all bits set to 1, which helps detect leading zeros in the data stream.
77 78 79 |
# File 'lib/omnizip/checksums/crc64.rb', line 77 def initial_value MASK_64 end |
#process_byte(crc, byte) ⇒ Integer
Process a single byte through the CRC64 algorithm.
Uses the lookup table for efficient computation: new_crc = (old_crc >> 8) ^ table[(old_crc ^ byte) & 0xFF]
66 67 68 69 |
# File 'lib/omnizip/checksums/crc64.rb', line 66 def process_byte(crc, byte) index = (crc ^ byte) & 0xFF (crc >> 8) ^ TABLE[index] end |