Blame src/hash/ntapi_tt_crc64.c

265305
/********************************************************/
265305
/*  ntapi: Native API core library                      */
59d585
/*  Copyright (C) 2013--2021  Z. Gilboa                 */
265305
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
265305
/********************************************************/
265305
265305
#include <psxtypes/psxtypes.h>
265305
#include <ntapi/nt_crc64.h>
766a63
#include "ntapi_impl.h"
265305
265305
static const uint64_t crc64_table[256] = NTAPI_CRC64_TABLE;
265305
265305
uint64_t __ntapi_tt_buffer_crc64(
265305
	uint64_t	prev_hash,
265305
	const void *	buffer,
265305
	size_t		size)
265305
{
265305
	const unsigned char *	ch;
265305
	uint64_t		crc64;
265305
265305
	crc64	= prev_hash ^ 0xFFFFFFFFFFFFFFFF;
265305
	ch	= buffer;
265305
265305
	for (; size; size--,ch++)
265305
		crc64 = (crc64 >> 8) ^ crc64_table[(crc64 ^ *ch) & 0xFF];
265305
265305
	return (crc64 ^ 0xFFFFFFFFFFFFFFFF);
265305
}
265305
265305
uint64_t __cdecl __ntapi_tt_mbstr_crc64(const void * str)
265305
{
265305
	const unsigned char *	ch;
265305
	uint64_t		crc64;
265305
265305
	crc64	= 0 ^ 0xFFFFFFFFFFFFFFFF;
265305
	ch	= str;
265305
265305
	while (*ch) {
265305
		crc64 = (crc64 >> 8) ^ crc64_table[(crc64 ^ *ch) & 0xFF];
265305
		ch++;
265305
	}
265305
265305
	return (crc64 ^ 0xFFFFFFFFFFFFFFFF);
265305
}
265305
265305
265305
const uint64_t * __cdecl __ntapi_tt_crc64_table(void)
265305
{
265305
	return crc64_table;
265305
}