#include #include #include "crc64.h" uint64_t crc_tab64[256]; /* * void init_crc64_tab( void ); * * For optimal speed, the CRC64 calculation uses a table with pre-calculated * bit patterns which are used in the XOR operations in the program. This table * is generated during compilation of the library and added to the library as a * table with constant values. */ void init_crc64_tab( uint64_t poly ) { uint64_t i; uint64_t j; uint64_t c; uint64_t crc; for (i=0; i<256; i++) { crc = 0; c = i << 56; for (j=0; j<8; j++) { if ( ( crc ^ c ) & 0x8000000000000000ull ) crc = ( crc << 1 ) ^ poly; else crc = crc << 1; c = c << 1; } crc_tab64[i] = crc; } } /* init_crc64_tab */ /* * uint64_t crc_64_ecma( const unsigned char *input_str, size_t num_bytes ); * * The function crc_64() calculates in one pass the 64 bit CRC value * for a byte string that is passed to the function together with a parameter * indicating the length. * This is used for CRC64-ECMA and CRC64-ISO */ uint64_t crc_64(const unsigned char *input_str, size_t num_bytes) { uint64_t crc; const unsigned char *ptr; size_t a; crc = CRC_START_64; ptr = input_str; if ( ptr != NULL ) { for (a=0; a> 56) ^ (uint64_t) *ptr++) & 0x00000000000000FFull ]; } return crc; } /* crc_64 */ /* * The function crc_64_inv() calculates in one pass the CRC64 64 bit CRC * value for a byte string that is passed to the function together with a * parameter indicating the length. * This is used for CRC64-WE */ uint64_t crc_64_inv( const unsigned char *input_str, size_t num_bytes ) { uint64_t crc; const unsigned char *ptr; size_t a; crc = CRC_START_64_INV; ptr = input_str; if ( ptr != NULL ) for (a=0; a> 56) ^ (uint64_t) *ptr++) & 0x00000000000000FFull ]; } return crc ^ 0xFFFFFFFFFFFFFFFFull; } /* crc_64_inv */