CRC checksums (CRC-16, CRC-32, CRC-32C) for OCaml
OCaml 90.2%
Dune 3.5%
Other 6.3%
13 1 0

Clone this repository

https://tangled.org/gazagnaire.org/ocaml-crc https://tangled.org/did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-crc
git@git.recoil.org:gazagnaire.org/ocaml-crc git@git.recoil.org:did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-crc

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

ocaml-crc — CRC checksums for OCaml#

Pure OCaml table-based implementations of common CRC algorithms.

Algorithms#

Algorithm Polynomial Init Reflect XOR Out Check ("123456789") Standard
CRC-16-CCITT 0x1021 0xFFFF No None 0x29B1 ITU-T V.41, CCSDS FECF
CRC-16-X.25 0x1021 0xFFFF Yes 0xFFFF 0x906E ITU-T X.25, RFC 9171
CRC-32 0xEDB88320 0xFFFFFFFF Yes 0xFFFFFFFF 0xCBF43926 ISO 3309, ITU-T V.42
CRC-32C 0x82F63B78 0xFFFFFFFF Yes 0xFFFFFFFF 0xE3069283 RFC 3720 (iSCSI)

Usage#

let () =
  let data = "Hello, world!" in
  Printf.printf "CRC-16-CCITT: 0x%04X\n" (Crc.crc16_ccitt data);
  Printf.printf "CRC-16-X.25:  0x%04X\n" (Crc.crc16_x25 data);
  Printf.printf "CRC-32:       0x%08X\n" (Crc.crc32 data);
  Printf.printf "CRC-32C:      0x%08X\n" (Crc.crc32c data)

Sub-range variants for bytes buffers:

let buf = Bytes.of_string "Hello, world!" in
let crc16 = Crc.crc16_ccitt_bytes buf 0 5 in  (* CRC of "Hello" *)
let crc32c = Crc.crc32c_bytes buf 7 6 in      (* CRC of "world!" *)

Install#

opam install crc

Test vectors#

All check values are verified against Python's crcmod library and standard test vectors from ITU-T V.41, ISO 3309, and RFC 3720 Section 12.1.

License#

ISC