From 3196390167e5079ca742b600ef8dc0ea592dc691 Mon Sep 17 00:00:00 2001 From: core software devel Date: Tue, 27 Aug 2024 10:51:17 +0000 Subject: [PATCH] add crc64 hash calculation, update ldb_table type --- src/crc64.c | 371 ++++++++++++++++++++++++++++++++++++++++++++++++ src/ldb.h | 2 +- src/ldb/types.h | 2 +- src/md5.c | 103 -------------- 4 files changed, 373 insertions(+), 105 deletions(-) create mode 100644 src/crc64.c diff --git a/src/crc64.c b/src/crc64.c new file mode 100644 index 0000000..a21fcfe --- /dev/null +++ b/src/crc64.c @@ -0,0 +1,371 @@ +//============================================================================= +// Uses: Implementation of CRC-64/XZ,CRC-64/GO-ECMA. +// Notes: +// Auto-generated by http://crc.drque.net/ +//============================================================================= + +#include +#include + +#include +#include +#include +#include +#include "ldb.h" + + +// Word for this CRC. +typedef uint64_t CRC64_XZ_Type; + +// Polynomial, initial CRC and post CRC XOR value. +static CRC64_XZ_Type const CRC64_XZ_POLYNOMIAL = UINT64_C(0xC96C5795D7870F42); // 0x42F0E1EBA9EA3693 reflected. +static CRC64_XZ_Type const CRC64_XZ_INITIAL = UINT64_C(0xFFFFFFFFFFFFFFFF); // 0xFFFFFFFFFFFFFFFF reflected. +static CRC64_XZ_Type const CRC64_XZ_FINIAL = UINT64_C(0xFFFFFFFFFFFFFFFF); // 0xFFFFFFFFFFFFFFFF reflected. + +//----------------------------------------------------------------------------- +// Uses: +// Finalize CRC. Call once all data has been added to CRC. +// Input: +// crc - Current CRC. +// Output: +// Finalized CRC. +// Note: +// In most cases the CRC can simply be XORed by the 'CRC64_XZ_FINIAL' +// and this function isn't necessary. +//----------------------------------------------------------------------------- +static inline CRC64_XZ_Type crc64_XZ_Finalize(CRC64_XZ_Type crc) +{ + crc ^= CRC64_XZ_FINIAL; + + return crc; +} + +// Size of the CRC lookup table. +enum +{ + CRC64_XZ_TALBE_SIZE = 0x100 +}; + +//----------------------------------------------------------------------------- +// Uses: +// Update CRC by byte. +// Input: +// crc - Initial CRC. +// byte - New byte to accumulate. +// Output: +// Updated CRC. +//----------------------------------------------------------------------------- +static inline CRC64_XZ_Type crc64_XZ_Byte(CRC64_XZ_Type crc, uint8_t byte) +{ + extern CRC64_XZ_Type const crc64_XZ_Table[CRC64_XZ_TALBE_SIZE]; + uint8_t index; + + index = byte ^ crc; + crc = crc64_XZ_Table[index] ^ (crc >> 8); + + return crc; +} + +//----------------------------------------------------------------------------- +// Uses: +// Compute CRC of buffer. +// Input: +// crc - Current CRC or initial value (i.e. 'CRC64_XZ_INITIAL'). +// buffer - Pointer to bytes to add to CRC. +// bufferSize - Number of bytes in 'buffer'. +// Output: +// Updated CRC. +//----------------------------------------------------------------------------- +static inline CRC64_XZ_Type crc64_XZ_Buffer( + CRC64_XZ_Type crc, + uint8_t const *buffer, + unsigned bufferSize) +{ + for (unsigned index = 0; index < bufferSize; index += 1) + crc = crc64_XZ_Byte(crc, buffer[index]); + + return crc; +} + +CRC64_XZ_Type const crc64_XZ_Table[CRC64_XZ_TALBE_SIZE] = + { + UINT64_C(0x0000000000000000), + UINT64_C(0xB32E4CBE03A75F6F), + UINT64_C(0xF4843657A840A05B), + UINT64_C(0x47AA7AE9ABE7FF34), + UINT64_C(0x7BD0C384FF8F5E33), + UINT64_C(0xC8FE8F3AFC28015C), + UINT64_C(0x8F54F5D357CFFE68), + UINT64_C(0x3C7AB96D5468A107), + UINT64_C(0xF7A18709FF1EBC66), + UINT64_C(0x448FCBB7FCB9E309), + UINT64_C(0x0325B15E575E1C3D), + UINT64_C(0xB00BFDE054F94352), + UINT64_C(0x8C71448D0091E255), + UINT64_C(0x3F5F08330336BD3A), + UINT64_C(0x78F572DAA8D1420E), + UINT64_C(0xCBDB3E64AB761D61), + UINT64_C(0x7D9BA13851336649), + UINT64_C(0xCEB5ED8652943926), + UINT64_C(0x891F976FF973C612), + UINT64_C(0x3A31DBD1FAD4997D), + UINT64_C(0x064B62BCAEBC387A), + UINT64_C(0xB5652E02AD1B6715), + UINT64_C(0xF2CF54EB06FC9821), + UINT64_C(0x41E11855055BC74E), + UINT64_C(0x8A3A2631AE2DDA2F), + UINT64_C(0x39146A8FAD8A8540), + UINT64_C(0x7EBE1066066D7A74), + UINT64_C(0xCD905CD805CA251B), + UINT64_C(0xF1EAE5B551A2841C), + UINT64_C(0x42C4A90B5205DB73), + UINT64_C(0x056ED3E2F9E22447), + UINT64_C(0xB6409F5CFA457B28), + UINT64_C(0xFB374270A266CC92), + UINT64_C(0x48190ECEA1C193FD), + UINT64_C(0x0FB374270A266CC9), + UINT64_C(0xBC9D3899098133A6), + UINT64_C(0x80E781F45DE992A1), + UINT64_C(0x33C9CD4A5E4ECDCE), + UINT64_C(0x7463B7A3F5A932FA), + UINT64_C(0xC74DFB1DF60E6D95), + UINT64_C(0x0C96C5795D7870F4), + UINT64_C(0xBFB889C75EDF2F9B), + UINT64_C(0xF812F32EF538D0AF), + UINT64_C(0x4B3CBF90F69F8FC0), + UINT64_C(0x774606FDA2F72EC7), + UINT64_C(0xC4684A43A15071A8), + UINT64_C(0x83C230AA0AB78E9C), + UINT64_C(0x30EC7C140910D1F3), + UINT64_C(0x86ACE348F355AADB), + UINT64_C(0x3582AFF6F0F2F5B4), + UINT64_C(0x7228D51F5B150A80), + UINT64_C(0xC10699A158B255EF), + UINT64_C(0xFD7C20CC0CDAF4E8), + UINT64_C(0x4E526C720F7DAB87), + UINT64_C(0x09F8169BA49A54B3), + UINT64_C(0xBAD65A25A73D0BDC), + UINT64_C(0x710D64410C4B16BD), + UINT64_C(0xC22328FF0FEC49D2), + UINT64_C(0x85895216A40BB6E6), + UINT64_C(0x36A71EA8A7ACE989), + UINT64_C(0x0ADDA7C5F3C4488E), + UINT64_C(0xB9F3EB7BF06317E1), + UINT64_C(0xFE5991925B84E8D5), + UINT64_C(0x4D77DD2C5823B7BA), + UINT64_C(0x64B62BCAEBC387A1), + UINT64_C(0xD7986774E864D8CE), + UINT64_C(0x90321D9D438327FA), + UINT64_C(0x231C512340247895), + UINT64_C(0x1F66E84E144CD992), + UINT64_C(0xAC48A4F017EB86FD), + UINT64_C(0xEBE2DE19BC0C79C9), + UINT64_C(0x58CC92A7BFAB26A6), + UINT64_C(0x9317ACC314DD3BC7), + UINT64_C(0x2039E07D177A64A8), + UINT64_C(0x67939A94BC9D9B9C), + UINT64_C(0xD4BDD62ABF3AC4F3), + UINT64_C(0xE8C76F47EB5265F4), + UINT64_C(0x5BE923F9E8F53A9B), + UINT64_C(0x1C4359104312C5AF), + UINT64_C(0xAF6D15AE40B59AC0), + UINT64_C(0x192D8AF2BAF0E1E8), + UINT64_C(0xAA03C64CB957BE87), + UINT64_C(0xEDA9BCA512B041B3), + UINT64_C(0x5E87F01B11171EDC), + UINT64_C(0x62FD4976457FBFDB), + UINT64_C(0xD1D305C846D8E0B4), + UINT64_C(0x96797F21ED3F1F80), + UINT64_C(0x2557339FEE9840EF), + UINT64_C(0xEE8C0DFB45EE5D8E), + UINT64_C(0x5DA24145464902E1), + UINT64_C(0x1A083BACEDAEFDD5), + UINT64_C(0xA9267712EE09A2BA), + UINT64_C(0x955CCE7FBA6103BD), + UINT64_C(0x267282C1B9C65CD2), + UINT64_C(0x61D8F8281221A3E6), + UINT64_C(0xD2F6B4961186FC89), + UINT64_C(0x9F8169BA49A54B33), + UINT64_C(0x2CAF25044A02145C), + UINT64_C(0x6B055FEDE1E5EB68), + UINT64_C(0xD82B1353E242B407), + UINT64_C(0xE451AA3EB62A1500), + UINT64_C(0x577FE680B58D4A6F), + UINT64_C(0x10D59C691E6AB55B), + UINT64_C(0xA3FBD0D71DCDEA34), + UINT64_C(0x6820EEB3B6BBF755), + UINT64_C(0xDB0EA20DB51CA83A), + UINT64_C(0x9CA4D8E41EFB570E), + UINT64_C(0x2F8A945A1D5C0861), + UINT64_C(0x13F02D374934A966), + UINT64_C(0xA0DE61894A93F609), + UINT64_C(0xE7741B60E174093D), + UINT64_C(0x545A57DEE2D35652), + UINT64_C(0xE21AC88218962D7A), + UINT64_C(0x5134843C1B317215), + UINT64_C(0x169EFED5B0D68D21), + UINT64_C(0xA5B0B26BB371D24E), + UINT64_C(0x99CA0B06E7197349), + UINT64_C(0x2AE447B8E4BE2C26), + UINT64_C(0x6D4E3D514F59D312), + UINT64_C(0xDE6071EF4CFE8C7D), + UINT64_C(0x15BB4F8BE788911C), + UINT64_C(0xA6950335E42FCE73), + UINT64_C(0xE13F79DC4FC83147), + UINT64_C(0x521135624C6F6E28), + UINT64_C(0x6E6B8C0F1807CF2F), + UINT64_C(0xDD45C0B11BA09040), + UINT64_C(0x9AEFBA58B0476F74), + UINT64_C(0x29C1F6E6B3E0301B), + UINT64_C(0xC96C5795D7870F42), + UINT64_C(0x7A421B2BD420502D), + UINT64_C(0x3DE861C27FC7AF19), + UINT64_C(0x8EC62D7C7C60F076), + UINT64_C(0xB2BC941128085171), + UINT64_C(0x0192D8AF2BAF0E1E), + UINT64_C(0x4638A2468048F12A), + UINT64_C(0xF516EEF883EFAE45), + UINT64_C(0x3ECDD09C2899B324), + UINT64_C(0x8DE39C222B3EEC4B), + UINT64_C(0xCA49E6CB80D9137F), + UINT64_C(0x7967AA75837E4C10), + UINT64_C(0x451D1318D716ED17), + UINT64_C(0xF6335FA6D4B1B278), + UINT64_C(0xB199254F7F564D4C), + UINT64_C(0x02B769F17CF11223), + UINT64_C(0xB4F7F6AD86B4690B), + UINT64_C(0x07D9BA1385133664), + UINT64_C(0x4073C0FA2EF4C950), + UINT64_C(0xF35D8C442D53963F), + UINT64_C(0xCF273529793B3738), + UINT64_C(0x7C0979977A9C6857), + UINT64_C(0x3BA3037ED17B9763), + UINT64_C(0x888D4FC0D2DCC80C), + UINT64_C(0x435671A479AAD56D), + UINT64_C(0xF0783D1A7A0D8A02), + UINT64_C(0xB7D247F3D1EA7536), + UINT64_C(0x04FC0B4DD24D2A59), + UINT64_C(0x3886B22086258B5E), + UINT64_C(0x8BA8FE9E8582D431), + UINT64_C(0xCC0284772E652B05), + UINT64_C(0x7F2CC8C92DC2746A), + UINT64_C(0x325B15E575E1C3D0), + UINT64_C(0x8175595B76469CBF), + UINT64_C(0xC6DF23B2DDA1638B), + UINT64_C(0x75F16F0CDE063CE4), + UINT64_C(0x498BD6618A6E9DE3), + UINT64_C(0xFAA59ADF89C9C28C), + UINT64_C(0xBD0FE036222E3DB8), + UINT64_C(0x0E21AC88218962D7), + UINT64_C(0xC5FA92EC8AFF7FB6), + UINT64_C(0x76D4DE52895820D9), + UINT64_C(0x317EA4BB22BFDFED), + UINT64_C(0x8250E80521188082), + UINT64_C(0xBE2A516875702185), + UINT64_C(0x0D041DD676D77EEA), + UINT64_C(0x4AAE673FDD3081DE), + UINT64_C(0xF9802B81DE97DEB1), + UINT64_C(0x4FC0B4DD24D2A599), + UINT64_C(0xFCEEF8632775FAF6), + UINT64_C(0xBB44828A8C9205C2), + UINT64_C(0x086ACE348F355AAD), + UINT64_C(0x34107759DB5DFBAA), + UINT64_C(0x873E3BE7D8FAA4C5), + UINT64_C(0xC094410E731D5BF1), + UINT64_C(0x73BA0DB070BA049E), + UINT64_C(0xB86133D4DBCC19FF), + UINT64_C(0x0B4F7F6AD86B4690), + UINT64_C(0x4CE50583738CB9A4), + UINT64_C(0xFFCB493D702BE6CB), + UINT64_C(0xC3B1F050244347CC), + UINT64_C(0x709FBCEE27E418A3), + UINT64_C(0x3735C6078C03E797), + UINT64_C(0x841B8AB98FA4B8F8), + UINT64_C(0xADDA7C5F3C4488E3), + UINT64_C(0x1EF430E13FE3D78C), + UINT64_C(0x595E4A08940428B8), + UINT64_C(0xEA7006B697A377D7), + UINT64_C(0xD60ABFDBC3CBD6D0), + UINT64_C(0x6524F365C06C89BF), + UINT64_C(0x228E898C6B8B768B), + UINT64_C(0x91A0C532682C29E4), + UINT64_C(0x5A7BFB56C35A3485), + UINT64_C(0xE955B7E8C0FD6BEA), + UINT64_C(0xAEFFCD016B1A94DE), + UINT64_C(0x1DD181BF68BDCBB1), + UINT64_C(0x21AB38D23CD56AB6), + UINT64_C(0x9285746C3F7235D9), + UINT64_C(0xD52F0E859495CAED), + UINT64_C(0x6601423B97329582), + UINT64_C(0xD041DD676D77EEAA), + UINT64_C(0x636F91D96ED0B1C5), + UINT64_C(0x24C5EB30C5374EF1), + UINT64_C(0x97EBA78EC690119E), + UINT64_C(0xAB911EE392F8B099), + UINT64_C(0x18BF525D915FEFF6), + UINT64_C(0x5F1528B43AB810C2), + UINT64_C(0xEC3B640A391F4FAD), + UINT64_C(0x27E05A6E926952CC), + UINT64_C(0x94CE16D091CE0DA3), + UINT64_C(0xD3646C393A29F297), + UINT64_C(0x604A2087398EADF8), + UINT64_C(0x5C3099EA6DE60CFF), + UINT64_C(0xEF1ED5546E415390), + UINT64_C(0xA8B4AFBDC5A6ACA4), + UINT64_C(0x1B9AE303C601F3CB), + UINT64_C(0x56ED3E2F9E224471), + UINT64_C(0xE5C372919D851B1E), + UINT64_C(0xA26908783662E42A), + UINT64_C(0x114744C635C5BB45), + UINT64_C(0x2D3DFDAB61AD1A42), + UINT64_C(0x9E13B115620A452D), + UINT64_C(0xD9B9CBFCC9EDBA19), + UINT64_C(0x6A978742CA4AE576), + UINT64_C(0xA14CB926613CF817), + UINT64_C(0x1262F598629BA778), + UINT64_C(0x55C88F71C97C584C), + UINT64_C(0xE6E6C3CFCADB0723), + UINT64_C(0xDA9C7AA29EB3A624), + UINT64_C(0x69B2361C9D14F94B), + UINT64_C(0x2E184CF536F3067F), + UINT64_C(0x9D36004B35545910), + UINT64_C(0x2B769F17CF112238), + UINT64_C(0x9858D3A9CCB67D57), + UINT64_C(0xDFF2A94067518263), + UINT64_C(0x6CDCE5FE64F6DD0C), + UINT64_C(0x50A65C93309E7C0B), + UINT64_C(0xE388102D33392364), + UINT64_C(0xA4226AC498DEDC50), + UINT64_C(0x170C267A9B79833F), + UINT64_C(0xDCD7181E300F9E5E), + UINT64_C(0x6FF954A033A8C131), + UINT64_C(0x28532E49984F3E05), + UINT64_C(0x9B7D62F79BE8616A), + UINT64_C(0xA707DB9ACF80C06D), + UINT64_C(0x14299724CC279F02), + UINT64_C(0x5383EDCD67C06036), + UINT64_C(0xE0ADA17364673F59), +}; +void longToBytes(uint64_t value, uint8_t *buffer) +{ + // Convertir el valor entero a bytes en formato little-endian + for (int i = 0; i < 8; i++) + { + buffer[i] = (uint8_t)(value >> (i * 8)); + } +} +void long_to_bytes(uint64_t value, uint8_t *buffer) +{ + for (int i = 0; i < sizeof(value); ++i) + { + buffer[i] = (value >> (8 * (sizeof(value) - 1 - i))) & 0xFF; + } +} + +void ldb_crc64(const unsigned char * data, int len, uint8_t * output) +{ + uint64_t crc = 0xFFFFFFFFFFFFFFFF; + crc = crc64_XZ_Buffer(crc, data, len); + crc = crc64_XZ_Finalize(crc); + long_to_bytes(crc, output); +} \ No newline at end of file diff --git a/src/ldb.h b/src/ldb.h index 9081545..644ac03 100644 --- a/src/ldb.h +++ b/src/ldb.h @@ -100,7 +100,7 @@ bool ldb_reverse_memcmp(uint8_t *a, uint8_t *b, int bytes); void md5_string(const unsigned char *input, int len, unsigned char output[16]); uint8_t * md5_file(char *path); -void ldb_hash_mode_select(int key_ln); +void ldb_crc64(const unsigned char * data, int len, uint8_t * output); #define MD5(a, b, c) md5_string(a, b, c) diff --git a/src/ldb/types.h b/src/ldb/types.h index 28e5479..c899940 100644 --- a/src/ldb/types.h +++ b/src/ldb/types.h @@ -18,7 +18,7 @@ #include "definitions.h" -typedef size_t (*hash_calc_t) (const unsigned char *input, int len, unsigned char * output); +typedef void (*hash_calc_t) (const unsigned char *input, int len, unsigned char * output); struct ldb_table { diff --git a/src/md5.c b/src/md5.c index f1389f1..77a05dd 100644 --- a/src/md5.c +++ b/src/md5.c @@ -1,112 +1,9 @@ #include "ldb.h" #include -typedef enum -{ - HASH_MODE_MD5=0, - HASH_MODE_CRC64 -} hashing_mode_t; - -static hashing_mode_t hash_mode = HASH_MODE_MD5; - -void ldb_hash_mode_select(int key_ln) -{ - if (key_ln == 8) - hash_mode = HASH_MODE_CRC64; - else - hash_mode = HASH_MODE_MD5; -} - -static const uint64_t crc64_ecma_table[256] = { - 0x0000000000000000ULL, 0x7ad870c830358979ULL, 0xf5b0e190606b12f2ULL, 0x8f689158505e9b8bULL, - 0xc038e5739841b68fULL, 0xbae095bba8743ff6ULL, 0x358804e3f82aa47dULL, 0x4f50742bc81f2d04ULL, - 0xab28ecb46814fe75ULL, 0xd1f09c7c5821770cULL, 0x5e980d24087fec87ULL, 0x24407dec384a65feULL, - 0x6b1009c7f05548faULL, 0x11c8790fc060c183ULL, 0x9ea0e857903e5a08ULL, 0xe478989fa00bd371ULL, - 0x7d08ff3b88be6f81ULL, 0x07d08ff3b88be6f8ULL, 0x88b81eabe8d57d73ULL, 0xf2606e63d8e0f40aULL, - 0xbd301a4810ffd90eULL, 0xc7e86a8020ca5077ULL, 0x4880fbd87094cbfcULL, 0x32588b1040a14285ULL, - 0xd620138fe0aa91f4ULL, 0xacf86347d09f188dULL, 0x2390f21f80c18306ULL, 0x594882d7b0f40a7fULL, - 0x1618f6fc78eb277bULL, 0x6cc0863448deae02ULL, 0xe3a8176c18803589ULL, 0x997067a428b5bcf0ULL, - 0xfa11fe77117cdf02ULL, 0x80c98ebf2149567bULL, 0x0fa11fe77117cdf0ULL, 0x75796f2f41224489ULL, - 0x3a291b04893d698dULL, 0x40f16bccb908e0f4ULL, 0xcf99fa94e9567b7fULL, 0xb5418a5cd963f206ULL, - 0x513912c379682177ULL, 0x2be1620b495da80eULL, 0xa489f35319033385ULL, 0xde51839b2936bafcULL, - 0x9101f7b0e12997f8ULL, 0xebd98778d11c1e81ULL, 0x64b116208142850aULL, 0x1e6966e8b1770c73ULL, - 0x8719014c99c2b083ULL, 0xfdc17184a9f739faULL, 0x72a9e0dcf9a9a271ULL, 0x08719014c99c2b08ULL, - 0x4721e43f0183060cULL, 0x3df994f731b68f75ULL, 0xb29105af61e814feULL, 0xc849756751dd9d87ULL, - 0x2c31edf8f1d64ef6ULL, 0x56e99d30c1e3c78fULL, 0xd9810c6891bd5c04ULL, 0xa3597ca0a188d57dULL, - 0xec09088b6997f879ULL, 0x96d1784359a27100ULL, 0x19b9e91b09fcea8bULL, 0x636199d339c963f2ULL, - 0xdf7adabd7a6e2d6fULL, 0xa5a2aa754a5ba416ULL, 0x2aca3b2d1a053f9dULL, 0x50124be52a30b6e4ULL, - 0x1f423fcee22f9be0ULL, 0x659a4f06d21a1299ULL, 0xeaf2de5e82448912ULL, 0x902aae96b271006bULL, - 0x74523609127ad31aULL, 0x0e8a46c1224f5a63ULL, 0x81e2d7997211c1e8ULL, 0xfb3aa75142244891ULL, - 0xb46ad37a8a3b6595ULL, 0xceb2a3b2ba0eececULL, 0x41da32eaea507767ULL, 0x3b024222da65fe1eULL, - 0xa2722586f2d042eeULL, 0xd8aa554ec2e5cb97ULL, 0x57c2c41692bb501cULL, 0x2d1ab4dea28ed965ULL, - 0x624ac0f56a91f461ULL, 0x1892b03d5aa47d18ULL, 0x97fa21650afae693ULL, 0xed2251ad3acf6feaULL, - 0x095ac9329ac4bc9bULL, 0x7382b9faaaf135e2ULL, 0xfcea28a2faafae69ULL, 0x8632586aca9a2710ULL, - 0xc9622c4102850a14ULL, 0xb3ba5c8932b0836dULL, 0x3cd2cdd162ee18e6ULL, 0x460abd1952db919fULL, - 0x256b24ca6b12f26dULL, 0x5fb354025b277b14ULL, 0xd0dbc55a0b79e09fULL, 0xaa03b5923b4c69e6ULL, - 0xe553c1b9f35344e2ULL, 0x9f8bb171c366cd9bULL, 0x10e3202993385610ULL, 0x6a3b50e1a30ddf69ULL, - 0x8e43c87e03060c18ULL, 0xf49bb8b633338561ULL, 0x7bf329ee636d1eeaULL, 0x012b592653589793ULL, - 0x4e7b2d0d9b47ba97ULL, 0x34a35dc5ab7233eeULL, 0xbbcbcc9dfb2ca865ULL, 0xc113bc55cb19211cULL, - 0x5863dbf1e3ac9decULL, 0x22bbab39d3991495ULL, 0xadd33a6183c78f1eULL, 0xd70b4aa9b3f20667ULL, - 0x985b3e827bed2b63ULL, 0xe2834e4a4bd8a21aULL, 0x6debdf121b863991ULL, 0x1733afda2bb3b0e8ULL, - 0xf34b37458bb86399ULL, 0x8993478dbb8deae0ULL, 0x06fbd6d5ebd3716bULL, 0x7c23a61ddbe6f812ULL, - 0x3373d23613f9d516ULL, 0x49aba2fe23cc5c6fULL, 0xc6c333a67392c7e4ULL, 0xbc1b436e43a74e9dULL, - 0x95ac9329ac4bc9b5ULL, 0xef74e3e19c7e40ccULL, 0x601c72b9cc20db47ULL, 0x1ac40271fc15523eULL, - 0x5594765a340a7f3aULL, 0x2f4c0692043ff643ULL, 0xa02497ca54616dc8ULL, 0xdafce7026454e4b1ULL, - 0x3e847f9dc45f37c0ULL, 0x445c0f55f46abeb9ULL, 0xcb349e0da4342532ULL, 0xb1eceec59401ac4bULL, - 0xfebc9aee5c1e814fULL, 0x8464ea266c2b0836ULL, 0x0b0c7b7e3c7593bdULL, 0x71d40bb60c401ac4ULL, - 0xe8a46c1224f5a634ULL, 0x927c1cda14c02f4dULL, 0x1d148d82449eb4c6ULL, 0x67ccfd4a74ab3dbfULL, - 0x289c8961bcb410bbULL, 0x5244f9a98c8199c2ULL, 0xdd2c68f1dcdf0249ULL, 0xa7f41839ecea8b30ULL, - 0x438c80a64ce15841ULL, 0x3954f06e7cd4d138ULL, 0xb63c61362c8a4ab3ULL, 0xcce411fe1cbfc3caULL, - 0x83b465d5d4a0eeceULL, 0xf96c151de49567b7ULL, 0x76048445b4cbfc3cULL, 0x0cdcf48d84fe7545ULL, - 0x6fbd6d5ebd3716b7ULL, 0x15651d968d029fceULL, 0x9a0d8ccedd5c0445ULL, 0xe0d5fc06ed698d3cULL, - 0xaf85882d2576a038ULL, 0xd55df8e515432941ULL, 0x5a3569bd451db2caULL, 0x20ed197575283bb3ULL, - 0xc49581ead523e8c2ULL, 0xbe4df122e51661bbULL, 0x3125607ab548fa30ULL, 0x4bfd10b2857d7349ULL, - 0x04ad64994d625e4dULL, 0x7e7514517d57d734ULL, 0xf11d85092d094cbfULL, 0x8bc5f5c11d3cc5c6ULL, - 0x12b5926535897936ULL, 0x686de2ad05bcf04fULL, 0xe70573f555e26bc4ULL, 0x9ddd033d65d7e2bdULL, - 0xd28d7716adc8cfb9ULL, 0xa85507de9dfd46c0ULL, 0x273d9686cda3dd4bULL, 0x5de5e64efd965432ULL, - 0xb99d7ed15d9d8743ULL, 0xc3450e196da80e3aULL, 0x4c2d9f413df695b1ULL, 0x36f5ef890dc31cc8ULL, - 0x79a59ba2c5dc31ccULL, 0x037deb6af5e9b8b5ULL, 0x8c157a32a5b7233eULL, 0xf6cd0afa9582aa47ULL, - 0x4ad64994d625e4daULL, 0x300e395ce6106da3ULL, 0xbf66a804b64ef628ULL, 0xc5bed8cc867b7f51ULL, - 0x8aeeace74e645255ULL, 0xf036dc2f7e51db2cULL, 0x7f5e4d772e0f40a7ULL, 0x05863dbf1e3ac9deULL, - 0xe1fea520be311aafULL, 0x9b26d5e88e0493d6ULL, 0x144e44b0de5a085dULL, 0x6e963478ee6f8124ULL, - 0x21c640532670ac20ULL, 0x5b1e309b16452559ULL, 0xd476a1c3461bbed2ULL, 0xaeaed10b762e37abULL, - 0x37deb6af5e9b8b5bULL, 0x4d06c6676eae0222ULL, 0xc26e573f3ef099a9ULL, 0xb8b627f70ec510d0ULL, - 0xf7e653dcc6da3dd4ULL, 0x8d3e2314f6efb4adULL, 0x0256b24ca6b12f26ULL, 0x788ec2849684a65fULL, - 0x9cf65a1b368f752eULL, 0xe62e2ad306bafc57ULL, 0x6946bb8b56e467dcULL, 0x139ecb4366d1eea5ULL, - 0x5ccebf68aecec3a1ULL, 0x2616cfa09efb4ad8ULL, 0xa97e5ef8cea5d153ULL, 0xd3a62e30fe90582aULL, - 0xb0c7b7e3c7593bd8ULL, 0xca1fc72bf76cb2a1ULL, 0x45775673a732292aULL, 0x3faf26bb9707a053ULL, - 0x70ff52905f188d57ULL, 0x0a2722586f2d042eULL, 0x854fb3003f739fa5ULL, 0xff97c3c80f4616dcULL, - 0x1bef5b57af4dc5adULL, 0x61372b9f9f784cd4ULL, 0xee5fbac7cf26d75fULL, 0x9487ca0fff135e26ULL, - 0xdbd7be24370c7322ULL, 0xa10fceec0739fa5bULL, 0x2e675fb4576761d0ULL, 0x54bf2f7c6752e8a9ULL, - 0xcdcf48d84fe75459ULL, 0xb71738107fd2dd20ULL, 0x387fa9482f8c46abULL, 0x42a7d9801fb9cfd2ULL, - 0x0df7adabd7a6e2d6ULL, 0x772fdd63e7936bafULL, 0xf8474c3bb7cdf024ULL, 0x829f3cf387f8795dULL, - 0x66e7a46c27f3aa2cULL, 0x1c3fd4a417c62355ULL, 0x935745fc4798b8deULL, 0xe98f353477ad31a7ULL, - 0xa6df411fbfb21ca3ULL, 0xdc0731d78f8795daULL, 0x536fa08fdfd90e51ULL, 0x29b7d047efec8728ULL, -}; - -uint64_t crc64_ecma(const void *data, size_t length) { - uint64_t crc = 0xFFFFFFFFFFFFFFFFULL; - const uint8_t *p = (const uint8_t *)data; - - while (length--) { - uint8_t table_index = (uint8_t)(crc ^ *p++); - crc = crc64_ecma_table[table_index] ^ (crc >> 8); - } - - return crc ^ 0xFFFFFFFFFFFFFFFFULL; -} - /* Adapter function for compatibility with openssl*/ void md5_string(const unsigned char *input, int len, unsigned char output[16]) { - - if (hash_mode == HASH_MODE_CRC64) - { - uint64_t result = crc64_ecma(input, len); - memset(output, 0, MD5_LEN); - memcpy(output, &result, sizeof(uint64_t)); - return; - } gcry_md_hd_t h; gcry_md_open(&h, GCRY_MD_MD5, GCRY_MD_FLAG_SECURE); // initialize the hash context gcry_md_write(h, input, len); // hash the input data