Blame src/hash/ntapi_tt_crc32.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
64e606
/*  Copyright (C) 2013--2021  SysDeer Technologies, LLC */
dd89bb
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
dd89bb
/********************************************************/
dd89bb
dd89bb
#include <psxtypes/psxtypes.h>
dd89bb
#include <ntapi/nt_crc32.h>
766a63
#include "ntapi_impl.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
{
6b8034
	const unsigned char *	ch;
6b8034
	uint32_t		crc32;
dd89bb
dd89bb
	crc32	= prev_hash ^ 0xFFFFFFFF;
6b8034
	ch	= 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
{
6b8034
	const unsigned char *	ch;
6b8034
	uint32_t		crc32;
dd89bb
dd89bb
	crc32	= 0 ^ 0xFFFFFFFF;
6b8034
	ch	= 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
}