diff options
author | midipix <writeonce@midipix.org> | 2015-07-27 04:01:18 -0400 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2015-07-27 04:01:18 -0400 |
commit | dd89bb8ad4fe184a34b5dbdda237e640fc82121b (patch) | |
tree | 5e80d2da35f5892f92be29f57982b2708e6bd99b /src/hash/ntapi_tt_crc32.c | |
parent | dcdadc2702712fa750ed255ed1dfa354522797a0 (diff) | |
download | ntapi-dd89bb8ad4fe184a34b5dbdda237e640fc82121b.tar.bz2 ntapi-dd89bb8ad4fe184a34b5dbdda237e640fc82121b.tar.xz |
entered advanced internal development stage.
Diffstat (limited to 'src/hash/ntapi_tt_crc32.c')
-rw-r--r-- | src/hash/ntapi_tt_crc32.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/hash/ntapi_tt_crc32.c b/src/hash/ntapi_tt_crc32.c new file mode 100644 index 0000000..7ce25d3 --- /dev/null +++ b/src/hash/ntapi_tt_crc32.c @@ -0,0 +1,50 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include <psxtypes/psxtypes.h> +#include <ntapi/nt_crc32.h> + +static const uint32_t crc32_table[256] = NTAPI_CRC32_TABLE; + +uint32_t __ntapi_tt_buffer_crc32( + uint32_t prev_hash, + const void * buffer, + size_t size) +{ + unsigned char * ch; + uint32_t crc32; + + crc32 = prev_hash ^ 0xFFFFFFFF; + ch = (unsigned char *)buffer; + + for (; size; size--,ch++) + crc32 = (crc32 >> 8) ^ crc32_table[(crc32 ^ *ch) & 0xFF]; + + return (crc32 ^ 0xFFFFFFFF); +} + + +uint32_t __cdecl __ntapi_tt_mbstr_crc32(const void * str) +{ + uint32_t crc32; + unsigned char * ch; + + crc32 = 0 ^ 0xFFFFFFFF; + ch = (unsigned char *)str; + + while (*ch) { + crc32 = (crc32 >> 8) ^ crc32_table[(crc32 ^ *ch) & 0xFF]; + ch++; + } + + return (crc32 ^ 0xFFFFFFFF); +} + + +const uint32_t * __cdecl __ntapi_tt_crc32_table(void) +{ + return crc32_table; +} |