xref: /inferno-os/module/crc.m (revision 46439007cf417cbd9ac8049bb4122c890097a0fa)
1Crc: module
2{
3	PATH: con "/dis/lib/crc.dis";
4
5	CRCstate: adt {
6		crc: int;
7		crctab: array of int;
8		reg: int;
9	};
10
11	# setup crc table with given polynomial (if 0 default polynomial used)
12	# (the polynomial has an implicit top bit set)
13	# reg is the initial value of the CRC register
14	# (usually 0 but 16rfffffffrf in the CRC32 algorithm for example)
15	init: fn(poly: int, reg: int): ref CRCstate;
16
17	# calculate crc of first nb bytes in given array of bytes and return its value
18	# may be called repeatedly to calculate crc of a series of arrays of bytes
19	crc :	fn(state: ref CRCstate, buf: array of byte, nb: int): int;
20
21	# reset crc state to its initial value
22	reset: fn(state: ref CRCstate);
23};
24