Skip to content

mdsebald/cerlc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cerlc

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

Erlang CI

Implemented in native Erlang. No NIFs or depenencies required.

Select from over 50 predefined CRC algorithms.

See src/cerlc.erl for complete list

OR Generate custom CRC algorithms by manually specifying the parameters.

bit width, polynomial, initial value, final XOR value, and data reflected or not 

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)


% Example: Using a macro to evaluate init() function at compile time
-define(CRC_DEFN, cerlc:init(crc16_aug_ccitt)).

Crc = cerlc:calc_crc(Data, ?CRC_DEFN),

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.

Sources of CRC Definitions

Javascript CRC Calculator

crccalc

About

A Native Erlang Library of CRC Algorithms.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages