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