summaryrefslogtreecommitdiffhomepage
path: root/src/hash
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2017-02-02 22:48:07 -0500
committermidipix <writeonce@midipix.org>2017-02-02 22:48:07 -0500
commit2653052944aef689484299c3f257db993dda106d (patch)
treec51e8ab2a1a206b4581a5e156681b458bd668cee /src/hash
parent85b39215b7264022460d3895e755e337485807b8 (diff)
downloadntapi-2653052944aef689484299c3f257db993dda106d.tar.bz2
ntapi-2653052944aef689484299c3f257db993dda106d.tar.xz
added crc64 definitions and interfaces.
Diffstat (limited to 'src/hash')
-rw-r--r--src/hash/ntapi_tt_crc64.c49
1 files changed, 49 insertions, 0 deletions
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 <psxtypes/psxtypes.h>
+#include <ntapi/nt_crc64.h>
+
+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;
+}