crc_core/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2
3//! core functions shared between source and build script of [crc](https://crates.io/crates/crc) crate
4
5pub fn make_table_crc32(poly: u32) -> [u32; 256] {
6    let mut table = [0u32; 256];
7    for i in 0..256 {
8        let mut value = i as u32;
9        for _ in 0..8 {
10            value = if (value & 1) == 1 {
11                (value >> 1) ^ poly
12            } else {
13                value >> 1
14            }
15        }
16        table[i] = value;
17    }
18    table
19}
20
21pub fn make_table_crc64(poly: u64) -> [u64; 256] {
22    let mut table = [0u64; 256];
23    for i in 0..256 {
24        let mut value = i as u64;
25        for _ in 0..8 {
26            value = if (value & 1) == 1 {
27                (value >> 1) ^ poly
28            } else {
29                value >> 1
30            }
31        }
32        table[i] = value;
33    }
34    table
35}