summaryrefslogtreecommitdiffhomepage
path: root/src/crc/mdso_crc64.c
blob: c69bc9229213c5c59fae76fa5b2849f0df9b3509 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/****************************************************************/
/*  mdso: midipix dso scavenger                                 */
/*  Copyright (C) 2015--2021  Z. Gilboa                         */
/*  Released under GPLv2 and GPLv3; see COPYING.MDSO.           */
/****************************************************************/

#include <stdint.h>
#include <unistd.h>

#include <mdso/mdso.h>
#include <mdso/mdso_crc64.h>

static const uint64_t crc64_table[256] = MDSO_CRC64_TABLE;

uint64_t mdso_crc64_mbstr(const unsigned char * str, size_t * symlen)
{
	const unsigned char *	ch;
	uint64_t		crc64;

	crc64	= 0 ^ 0xFFFFFFFFFFFFFFFF;
	ch	= str;

	while (*ch) {
		crc64 = (crc64 >> 8) ^ crc64_table[(crc64 ^ *ch) & 0xFF];
		ch++;
	}

	if (symlen)
		*symlen = ch - str;

	return (crc64 ^ 0xFFFFFFFFFFFFFFFF);
}