package pcrc

  1. Overview
  2. Docs
Parameterized CRC8, CRC16, CRC32 and CRC64 implementations

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.25.2.tar.gz
md5=5642f4e7cde7f4027eba1af32312ed5e
sha512=46c460d1077e83ff087bccff35b1e32fdd5dffdce7826ccd1bda6bfd308a336725d6aa479e9075f2dcb47ddc3acab7ece59291f222eb3eff3e1c75f65a9ee43e

Description

A library to instantiate (almost) any CRC-8, CRC-16, CRC-32 or CRC-64 algorithm from a set of CRC model parameters.

Published: 14 Oct 2025

README

Pcrc

A parameterized OCaml library for various CRC-8, CRC-16, CRC-32 and CRC-64 algorithms. It allows to instantiate and use (almost) any possible CRC algorithm of 8, 16, 32 or 64 bits.

Build and Install

It should be possible to install the library with opam like any other OCaml package out there:

$ opam install pcrc

Or it may be built and installed with dune:

$ dune build
$ dune install -p pcrc

There are no external dependencies besides OCaml Stdlib and a C compiler to build the C stubs.

Basic Usage

Instantiate a CRC implementation module. E.g., for a variant of CRC-16 used in XMODEM:

# module CRC16 = Pcrc.CRC16.Make (Pcrc.CRC16.XMODEM);;

Compute CRC-16 checksum with the "Basic" API of the created module:

# CRC16.string "123456789";;
- : CRC16.t = 12739
# CRC16.string ~pos:1 "0123456789";;
- : CRC16.t = 12739
# (CRC16.string ~pos:1 ~len:9 "0123456789ABC" :> int) |> Printf.printf "0x%04X\n";;
0x31C3
- : unit = ()

There's also streaming "Update" API in the generated module:

# let crc = CRC16.Update.init;;
# let crc = CRC16.Update.string crc "123";;
# let crc = CRC16.Update.string crc "45";;
# let crc = CRC16.Update.string crc "6789";;
# let crc = CRC16.Update.finalize crc;;
# Printf.printf "0x%04X\n" (crc :> int);;
0x31C3
- : unit = ()

There are similar Make functors for CRC-8, CRC-32 and CRC-64 algorithms, along with some more predefined parameter modules like Pcrc.CRC16.XMODEM.

See Pcrc module interface for details.

Dependencies (2)

  1. ocaml >= "4.13"
  2. dune >= "3.15"

Dev Dependencies (2)

  1. odoc with-doc
  2. ounit2 with-test

Used by

None

Conflicts

None