From 2653052944aef689484299c3f257db993dda106d Mon Sep 17 00:00:00 2001 From: midipix Date: Thu, 2 Feb 2017 22:48:07 -0500 Subject: added crc64 definitions and interfaces. --- include/ntapi/nt_crc64.h | 89 ++++++++++++++++++++++++++++++++++++++++++++++ include/ntapi/ntapi.h | 6 ++++ project/common.mk | 1 + project/headers.mk | 1 + src/hash/ntapi_tt_crc64.c | 49 +++++++++++++++++++++++++ src/internal/ntapi.c | 6 ++++ src/internal/ntapi_fnapi.h | 5 +++ 7 files changed, 157 insertions(+) create mode 100644 include/ntapi/nt_crc64.h create mode 100644 src/hash/ntapi_tt_crc64.c diff --git a/include/ntapi/nt_crc64.h b/include/ntapi/nt_crc64.h new file mode 100644 index 0000000..7bc4b12 --- /dev/null +++ b/include/ntapi/nt_crc64.h @@ -0,0 +1,89 @@ +#ifndef _NT_CRC64_H_ +#define _NT_CRC64_H_ + +#include "nt_abi.h" + +#define NTAPI_CRC64_POLY 0xd56ca934d35a6b40 + +#define NTAPI_CRC64_TABLE { \ + 0x0000000000000000, 0xd4c67066bafcdf96, 0x0355b2a4d34d69ad, 0xd793c2c269b1b63b, \ + 0x06ab6549a69ad35a, 0xd26d152f1c660ccc, 0x05fed7ed75d7baf7, 0xd138a78bcf2b6561, \ + 0x0d56ca934d35a6b4, 0xd990baf5f7c97922, 0x0e0378379e78cf19, 0xdac508512484108f, \ + 0x0bfdafdaebaf75ee, 0xdf3bdfbc5153aa78, 0x08a81d7e38e21c43, 0xdc6e6d18821ec3d5, \ + 0x1aad95269a6b4d68, 0xce6be540209792fe, 0x19f82782492624c5, 0xcd3e57e4f3dafb53, \ + 0x1c06f06f3cf19e32, 0xc8c08009860d41a4, 0x1f5342cbefbcf79f, 0xcb9532ad55402809, \ + 0x17fb5fb5d75eebdc, 0xc33d2fd36da2344a, 0x14aeed1104138271, 0xc0689d77beef5de7, \ + 0x11503afc71c43886, 0xc5964a9acb38e710, 0x12058858a289512b, 0xc6c3f83e18758ebd, \ + 0x355b2a4d34d69ad0, 0xe19d5a2b8e2a4546, 0x360e98e9e79bf37d, 0xe2c8e88f5d672ceb, \ + 0x33f04f04924c498a, 0xe7363f6228b0961c, 0x30a5fda041012027, 0xe4638dc6fbfdffb1, \ + 0x380de0de79e33c64, 0xeccb90b8c31fe3f2, 0x3b58527aaaae55c9, 0xef9e221c10528a5f, \ + 0x3ea68597df79ef3e, 0xea60f5f1658530a8, 0x3df337330c348693, 0xe9354755b6c85905, \ + 0x2ff6bf6baebdd7b8, 0xfb30cf0d1441082e, 0x2ca30dcf7df0be15, 0xf8657da9c70c6183, \ + 0x295dda22082704e2, 0xfd9baa44b2dbdb74, 0x2a086886db6a6d4f, 0xfece18e06196b2d9, \ + 0x22a075f8e388710c, 0xf666059e5974ae9a, 0x21f5c75c30c518a1, 0xf533b73a8a39c737, \ + 0x240b10b14512a256, 0xf0cd60d7ffee7dc0, 0x275ea215965fcbfb, 0xf398d2732ca3146d, \ + 0x6ab6549a69ad35a0, 0xbe7024fcd351ea36, 0x69e3e63ebae05c0d, 0xbd259658001c839b, \ + 0x6c1d31d3cf37e6fa, 0xb8db41b575cb396c, 0x6f4883771c7a8f57, 0xbb8ef311a68650c1, \ + 0x67e09e0924989314, 0xb326ee6f9e644c82, 0x64b52cadf7d5fab9, 0xb0735ccb4d29252f, \ + 0x614bfb408202404e, 0xb58d8b2638fe9fd8, 0x621e49e4514f29e3, 0xb6d83982ebb3f675, \ + 0x701bc1bcf3c678c8, 0xa4ddb1da493aa75e, 0x734e7318208b1165, 0xa788037e9a77cef3, \ + 0x76b0a4f5555cab92, 0xa276d493efa07404, 0x75e516518611c23f, 0xa12366373ced1da9, \ + 0x7d4d0b2fbef3de7c, 0xa98b7b49040f01ea, 0x7e18b98b6dbeb7d1, 0xaadec9edd7426847, \ + 0x7be66e6618690d26, 0xaf201e00a295d2b0, 0x78b3dcc2cb24648b, 0xac75aca471d8bb1d, \ + 0x5fed7ed75d7baf70, 0x8b2b0eb1e78770e6, 0x5cb8cc738e36c6dd, 0x887ebc1534ca194b, \ + 0x59461b9efbe17c2a, 0x8d806bf8411da3bc, 0x5a13a93a28ac1587, 0x8ed5d95c9250ca11, \ + 0x52bbb444104e09c4, 0x867dc422aab2d652, 0x51ee06e0c3036069, 0x8528768679ffbfff, \ + 0x5410d10db6d4da9e, 0x80d6a16b0c280508, 0x574563a96599b333, 0x838313cfdf656ca5, \ + 0x4540ebf1c710e218, 0x91869b977dec3d8e, 0x46155955145d8bb5, 0x92d32933aea15423, \ + 0x43eb8eb8618a3142, 0x972dfededb76eed4, 0x40be3c1cb2c758ef, 0x94784c7a083b8779, \ + 0x481621628a2544ac, 0x9cd0510430d99b3a, 0x4b4393c659682d01, 0x9f85e3a0e394f297, \ + 0x4ebd442b2cbf97f6, 0x9a7b344d96434860, 0x4de8f68ffff2fe5b, 0x992e86e9450e21cd, \ + 0xd56ca934d35a6b40, 0x01aad95269a6b4d6, 0xd6391b90001702ed, 0x02ff6bf6baebdd7b, \ + 0xd3c7cc7d75c0b81a, 0x0701bc1bcf3c678c, 0xd0927ed9a68dd1b7, 0x04540ebf1c710e21, \ + 0xd83a63a79e6fcdf4, 0x0cfc13c124931262, 0xdb6fd1034d22a459, 0x0fa9a165f7de7bcf, \ + 0xde9106ee38f51eae, 0x0a5776888209c138, 0xddc4b44aebb87703, 0x0902c42c5144a895, \ + 0xcfc13c1249312628, 0x1b074c74f3cdf9be, 0xcc948eb69a7c4f85, 0x1852fed020809013, \ + 0xc96a595befabf572, 0x1dac293d55572ae4, 0xca3febff3ce69cdf, 0x1ef99b99861a4349, \ + 0xc297f6810404809c, 0x165186e7bef85f0a, 0xc1c24425d749e931, 0x150434436db536a7, \ + 0xc43c93c8a29e53c6, 0x10fae3ae18628c50, 0xc769216c71d33a6b, 0x13af510acb2fe5fd, \ + 0xe0378379e78cf190, 0x34f1f31f5d702e06, 0xe36231dd34c1983d, 0x37a441bb8e3d47ab, \ + 0xe69ce630411622ca, 0x325a9656fbeafd5c, 0xe5c95494925b4b67, 0x310f24f228a794f1, \ + 0xed6149eaaab95724, 0x39a7398c104588b2, 0xee34fb4e79f43e89, 0x3af28b28c308e11f, \ + 0xebca2ca30c23847e, 0x3f0c5cc5b6df5be8, 0xe89f9e07df6eedd3, 0x3c59ee6165923245, \ + 0xfa9a165f7de7bcf8, 0x2e5c6639c71b636e, 0xf9cfa4fbaeaad555, 0x2d09d49d14560ac3, \ + 0xfc317316db7d6fa2, 0x28f703706181b034, 0xff64c1b20830060f, 0x2ba2b1d4b2ccd999, \ + 0xf7ccdccc30d21a4c, 0x230aacaa8a2ec5da, 0xf4996e68e39f73e1, 0x205f1e0e5963ac77, \ + 0xf167b9859648c916, 0x25a1c9e32cb41680, 0xf2320b214505a0bb, 0x26f47b47fff97f2d, \ + 0xbfdafdaebaf75ee0, 0x6b1c8dc8000b8176, 0xbc8f4f0a69ba374d, 0x68493f6cd346e8db, \ + 0xb97198e71c6d8dba, 0x6db7e881a691522c, 0xba242a43cf20e417, 0x6ee25a2575dc3b81, \ + 0xb28c373df7c2f854, 0x664a475b4d3e27c2, 0xb1d98599248f91f9, 0x651ff5ff9e734e6f, \ + 0xb427527451582b0e, 0x60e12212eba4f498, 0xb772e0d0821542a3, 0x63b490b638e99d35, \ + 0xa5776888209c1388, 0x71b118ee9a60cc1e, 0xa622da2cf3d17a25, 0x72e4aa4a492da5b3, \ + 0xa3dc0dc18606c0d2, 0x771a7da73cfa1f44, 0xa089bf65554ba97f, 0x744fcf03efb776e9, \ + 0xa821a21b6da9b53c, 0x7ce7d27dd7556aaa, 0xab7410bfbee4dc91, 0x7fb260d904180307, \ + 0xae8ac752cb336666, 0x7a4cb73471cfb9f0, 0xaddf75f6187e0fcb, 0x79190590a282d05d, \ + 0x8a81d7e38e21c430, 0x5e47a78534dd1ba6, 0x89d465475d6cad9d, 0x5d121521e790720b, \ + 0x8c2ab2aa28bb176a, 0x58ecc2cc9247c8fc, 0x8f7f000efbf67ec7, 0x5bb97068410aa151, \ + 0x87d71d70c3146284, 0x53116d1679e8bd12, 0x8482afd410590b29, 0x5044dfb2aaa5d4bf, \ + 0x817c7839658eb1de, 0x55ba085fdf726e48, 0x8229ca9db6c3d873, 0x56efbafb0c3f07e5, \ + 0x902c42c5144a8958, 0x44ea32a3aeb656ce, 0x9379f061c707e0f5, 0x47bf80077dfb3f63, \ + 0x9687278cb2d05a02, 0x424157ea082c8594, 0x95d29528619d33af, 0x4114e54edb61ec39, \ + 0x9d7a8856597f2fec, 0x49bcf830e383f07a, 0x9e2f3af28a324641, 0x4ae94a9430ce99d7, \ + 0x9bd1ed1fffe5fcb6, 0x4f179d7945192320, 0x98845fbb2ca8951b, 0x4c422fdd96544a8d \ +} + + +typedef uint64_t __cdecl ntapi_tt_buffer_crc64( + uint64_t prev_hash, + const void * buffer, + size_t size); + + +typedef uint64_t __cdecl ntapi_tt_mbstr_crc64( + const void * str); + + +typedef const uint64_t * __cdecl ntapi_tt_crc64_table(void); + + +#endif diff --git a/include/ntapi/ntapi.h b/include/ntapi/ntapi.h index 07d2ecf..5aa97bd 100644 --- a/include/ntapi/ntapi.h +++ b/include/ntapi/ntapi.h @@ -5,6 +5,7 @@ #include "nt_compiler.h" #include "nt_status.h" #include "nt_crc32.h" +#include "nt_crc64.h" #include "nt_object.h" #include "nt_sysinfo.h" #include "nt_memory.h" @@ -374,6 +375,11 @@ typedef struct _ntapi_vtbl { ntapi_tt_mbstr_crc32 * tt_mbstr_crc32; ntapi_tt_crc32_table * tt_crc32_table; + /* nt_crc64.h */ + ntapi_tt_buffer_crc64 * tt_buffer_crc64; + ntapi_tt_mbstr_crc64 * tt_mbstr_crc64; + ntapi_tt_crc64_table * tt_crc64_table; + /* nt_file.h */ ntapi_tt_get_file_handle_type * tt_get_file_handle_type; ntapi_tt_open_logical_parent_directory * tt_open_logical_parent_directory; diff --git a/project/common.mk b/project/common.mk index ef8b350..e04e1f3 100644 --- a/project/common.mk +++ b/project/common.mk @@ -17,6 +17,7 @@ COMMON_SRCS = \ src/fs/ntapi_tt_statfs.c \ src/guid/ntapi_tt_guid.c \ src/hash/ntapi_tt_crc32.c \ + src/hash/ntapi_tt_crc64.c \ src/hash/ntapi_tt_populate_hashed_import_table.c \ src/internal/ntapi.c \ src/internal/ntapi_debug.c \ diff --git a/project/headers.mk b/project/headers.mk index 327e8e9..bb502bf 100644 --- a/project/headers.mk +++ b/project/headers.mk @@ -9,6 +9,7 @@ API_HEADERS = \ $(SOURCE_DIR)/include/$(PACKAGE)/./nt_blitter.h \ $(SOURCE_DIR)/include/$(PACKAGE)/./nt_compiler.h \ $(SOURCE_DIR)/include/$(PACKAGE)/./nt_crc32.h \ + $(SOURCE_DIR)/include/$(PACKAGE)/./nt_crc64.h \ $(SOURCE_DIR)/include/$(PACKAGE)/./nt_daemon.h \ $(SOURCE_DIR)/include/$(PACKAGE)/./nt_dalist.h \ $(SOURCE_DIR)/include/$(PACKAGE)/./nt_debug.h \ diff --git a/src/hash/ntapi_tt_crc64.c b/src/hash/ntapi_tt_crc64.c new file mode 100644 index 0000000..fd76ec5 --- /dev/null +++ b/src/hash/ntapi_tt_crc64.c @@ -0,0 +1,49 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013--2017 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include +#include + +static const uint64_t crc64_table[256] = NTAPI_CRC64_TABLE; + +uint64_t __ntapi_tt_buffer_crc64( + uint64_t prev_hash, + const void * buffer, + size_t size) +{ + const unsigned char * ch; + uint64_t crc64; + + crc64 = prev_hash ^ 0xFFFFFFFFFFFFFFFF; + ch = buffer; + + for (; size; size--,ch++) + crc64 = (crc64 >> 8) ^ crc64_table[(crc64 ^ *ch) & 0xFF]; + + return (crc64 ^ 0xFFFFFFFFFFFFFFFF); +} + +uint64_t __cdecl __ntapi_tt_mbstr_crc64(const void * str) +{ + const unsigned char * ch; + uint64_t crc64; + + crc64 = 0 ^ 0xFFFFFFFFFFFFFFFF; + ch = str; + + while (*ch) { + crc64 = (crc64 >> 8) ^ crc64_table[(crc64 ^ *ch) & 0xFF]; + ch++; + } + + return (crc64 ^ 0xFFFFFFFFFFFFFFFF); +} + + +const uint64_t * __cdecl __ntapi_tt_crc64_table(void) +{ + return crc64_table; +} diff --git a/src/internal/ntapi.c b/src/internal/ntapi.c index c3f5817..5c60ffd 100644 --- a/src/internal/ntapi.c +++ b/src/internal/ntapi.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -152,6 +153,11 @@ static int32_t __fastcall __ntapi_init_once(ntapi_vtbl ** pvtbl) __ntapi->tt_mbstr_crc32 = __ntapi_tt_mbstr_crc32; __ntapi->tt_crc32_table = __ntapi_tt_crc32_table; + /* nt_crc64.h */ + __ntapi->tt_buffer_crc64 = __ntapi_tt_buffer_crc64; + __ntapi->tt_mbstr_crc64 = __ntapi_tt_mbstr_crc64; + __ntapi->tt_crc64_table = __ntapi_tt_crc64_table; + /* nt_file.h */ __ntapi->tt_get_file_handle_type = __ntapi_tt_get_file_handle_type; __ntapi->tt_open_logical_parent_directory = __ntapi_tt_open_logical_parent_directory; diff --git a/src/internal/ntapi_fnapi.h b/src/internal/ntapi_fnapi.h index 75621f7..93e38bd 100644 --- a/src/internal/ntapi_fnapi.h +++ b/src/internal/ntapi_fnapi.h @@ -32,6 +32,11 @@ ntapi_tt_buffer_crc32 __ntapi_tt_buffer_crc32; ntapi_tt_mbstr_crc32 __ntapi_tt_mbstr_crc32; ntapi_tt_crc32_table __ntapi_tt_crc32_table; +/* nt_crc64.h */ +ntapi_tt_buffer_crc64 __ntapi_tt_buffer_crc64; +ntapi_tt_mbstr_crc64 __ntapi_tt_mbstr_crc64; +ntapi_tt_crc64_table __ntapi_tt_crc64_table; + /* nt_file.h */ ntapi_tt_get_file_handle_type __ntapi_tt_get_file_handle_type; ntapi_tt_open_logical_parent_directory __ntapi_tt_open_logical_parent_directory; -- cgit v1.2.3