summaryrefslogtreecommitdiff
path: root/module/crc.m
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2006-12-22 20:52:35 +0000
committerCharles.Forsyth <devnull@localhost>2006-12-22 20:52:35 +0000
commit46439007cf417cbd9ac8049bb4122c890097a0fa (patch)
tree6fdb25e5f3a2b6d5657eb23b35774b631d4d97e4 /module/crc.m
parent37da2899f40661e3e9631e497da8dc59b971cbd0 (diff)
20060303-partial
Diffstat (limited to 'module/crc.m')
-rw-r--r--module/crc.m23
1 files changed, 23 insertions, 0 deletions
diff --git a/module/crc.m b/module/crc.m
new file mode 100644
index 00000000..408af38e
--- /dev/null
+++ b/module/crc.m
@@ -0,0 +1,23 @@
+Crc: module
+{
+ PATH: con "/dis/lib/crc.dis";
+
+ CRCstate: adt {
+ crc: int;
+ crctab: array of int;
+ reg: int;
+ };
+
+ # setup crc table with given polynomial (if 0 default polynomial used)
+ # (the polynomial has an implicit top bit set)
+ # reg is the initial value of the CRC register
+ # (usually 0 but 16rfffffffrf in the CRC32 algorithm for example)
+ init: fn(poly: int, reg: int): ref CRCstate;
+
+ # calculate crc of first nb bytes in given array of bytes and return its value
+ # may be called repeatedly to calculate crc of a series of arrays of bytes
+ crc : fn(state: ref CRCstate, buf: array of byte, nb: int): int;
+
+ # reset crc state to its initial value
+ reset: fn(state: ref CRCstate);
+};