Blame src/hash/ntapi_tt_crc32.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
dd89bb
/*  Copyright (C) 2013,2014,2015  Z. Gilboa             */
dd89bb
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
dd89bb
/********************************************************/
dd89bb
dd89bb
#include <psxtypes/psxtypes.h>
dd89bb
#include <ntapi/nt_crc32.h>
dd89bb
dd89bb
static const uint32_t crc32_table[256] = NTAPI_CRC32_TABLE;
dd89bb
dd89bb
uint32_t __ntapi_tt_buffer_crc32(
dd89bb
	uint32_t	prev_hash,
dd89bb
	const void *	buffer,
dd89bb
	size_t		size)
dd89bb
{
dd89bb
	unsigned char *	ch;
dd89bb
	uint32_t	crc32;
dd89bb
dd89bb
	crc32	= prev_hash ^ 0xFFFFFFFF;
dd89bb
	ch	= (unsigned char *)buffer;
dd89bb
dd89bb
	for (; size; size--,ch++)
dd89bb
		crc32 = (crc32 >> 8) ^ crc32_table[(crc32 ^ *ch) & 0xFF];
dd89bb
dd89bb
	return (crc32 ^ 0xFFFFFFFF);
dd89bb
}
dd89bb
dd89bb
dd89bb
uint32_t __cdecl __ntapi_tt_mbstr_crc32(const void * str)
dd89bb
{
dd89bb
	uint32_t	crc32;
dd89bb
	unsigned char *	ch;
dd89bb
dd89bb
	crc32	= 0 ^ 0xFFFFFFFF;
dd89bb
	ch	= (unsigned char *)str;
dd89bb
dd89bb
	while (*ch) {
dd89bb
		crc32 = (crc32 >> 8) ^ crc32_table[(crc32 ^ *ch) & 0xFF];
dd89bb
		ch++;
dd89bb
	}
dd89bb
dd89bb
	return (crc32 ^ 0xFFFFFFFF);
dd89bb
}
dd89bb
dd89bb
dd89bb
const uint32_t * __cdecl __ntapi_tt_crc32_table(void)
dd89bb
{
dd89bb
	return crc32_table;
dd89bb
}