cerlc

A Custom Configurable Cyclic Redundancy Check (CRC), Function Generator

Erlang CI

Build

rebar3 compile

Test

rebar3 eunit

Use

In an Erlang application

% Add to list of dependencies in rebar.config
{deps, [
    {cerlc, "0.2.0"}
]}.

% Example: Using a predefined CRC algorithm
CrcDefn = cerlc:init(crc16_aug_ccitt),

% Data may be a binary or list of bytes
Crc = cerlc:calc_crc(Data, CrcDefn)

% Example: Creating a custom CRC algorithm
% Custom CRC parameters: {Bits, Polynomial, InitValue, FinalXorValue, Reflected}
CustomDefn = cerlc:init({8, 16#4F, 0, 16#FF, false}),

Crc = cerlc:calc_crc(Data, CustomDefn)

In an Elixir application

# Add to list of dependencies in mix.exs
def deps do
  [
    {:cerlc, "~> 0.2.0"}
  ]
end


# Example: Using a predefined CRC algorithm
crc8_defn = :cerlc.init(:crc8)

# Data may be a binary or list of bytes
crc = :cerlc.calc_crc(data, crc8_defn)

# Example: Creating a custom CRC algorithm
# Custom CRC parameters: {bits, polynomial, init_value, final_xor_value, reflected}
custom_defn = :cerlc.init({16, 0x1234, 0xFFFF, 0xFFFF, true}),

crc = :cerlc.calc_crc(data, custom_defn)

# Example: Using a module attribute to evaluate init() function at compile time
@crc32_defn :cerlc.init(:crc32_c)

crc = :cerlc.calc_crc(data, @crc32_defn)

Performance

cerlc is slower than Erlang's built in crc32() function and CRC's implemented using 'C' language NIF's.

cerlc is useful for quickly generating CRC's with little code and no other dependencies.

Docs

Generate HTML docs locally with:

rebar3 ex_doc

The output is written to _build/default/lib/cerlc/doc/index.html.

Sources of CRC Definitions