#crc #macro #checksum #algorithm

no-std embedded-crc-macros

Macros implementing portable CRC calculation algorithms for use in no_std

2 releases (1 stable)

1.0.0 May 13, 2021
0.1.0 Aug 9, 2020

#1566 in Embedded development

Download history 1615/week @ 2023-02-02 2803/week @ 2023-02-09 1561/week @ 2023-02-16 2026/week @ 2023-02-23 1281/week @ 2023-03-02 1292/week @ 2023-03-09 927/week @ 2023-03-16 837/week @ 2023-03-23 695/week @ 2023-03-30 269/week @ 2023-04-06 1721/week @ 2023-04-13 426/week @ 2023-04-20 784/week @ 2023-04-27 523/week @ 2023-05-04 257/week @ 2023-05-11 291/week @ 2023-05-18

1,892 downloads per month
Used in 3 crates (via smbus-pec)


144 lines

Rust Portable CRC Calculation Macros

crates.io Docs Build Status Coverage Status

This crate provides macros that define portable CRC-8 algorithm implementations with the parameters directly provided at compile time and without any dependencies. Intended for use in no_std.

How this crate compares to others

There is a number of crates implementing CRC algorithms but their intention is to be configurable, generic, use acceleration via SIMD instructions, etc.

This crate provides macros that define portable and non-configurable CRC-8 algorithm implementations with the parameters provided at compile time (optionally using a pre-calculated lookup table) and without any dependencies.

This should allow the compiler to make good optimizations and allows for use of the algorithm in any target architecture with minimal code bloat.

Furthermore, this crate provides macros to generate the lookup tables on build time.

This makes this crate specially well suited for use in no_std environments.


use embedded_crc_macros::crc8;

crc8!(fn pec, 7 /* x^8+x^2+x+1 */, 0, "SMBus Packet Error Code");

const ADDRESS: u8 = 0x5A;
const REGISTER: u8 = 0x06;

fn main() {
    let crc = pec(&[ADDRESS << 1, REGISTER, 0xAB, 0xCD]);
    println!("PEC: {}", crc); // prints 95


For questions, issues, feature requests, other changes, or just feedback, please file an issue in the github project.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps