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