mrhooray / crc-rs

Rust implementation of CRC(16, 32, 64) with support of various standards

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow MSB first generation of CRC table

kitlith opened this issue · comments

Such a table could also be generated (I believe) with something like this: (pseudocode)~~

for i in 0..256 {
    msb_first_table[i] = lsb_first_table[bitswap(i)]
}

EDIT: nope, there's more going on with it than that.

It's typically done as a seperate function though. Here's an untested example based off of your make_table implementation: (and random implementations elsewhere)

pub fn make_msb_table_crc64(poly: u64) -> [u64; 256] {
    let mut table = [0u64; 256];
    for i in 0..256 {
        let mut value = i as u64;
        for _ in 0..8 {
            value = if (value >> 63) == 1 {
                (value << 1) ^ poly
            } else {
                value << 1
            }
        }
        table[i] = value;
    }
    table
}

wanna share what problem/use cases this solves/supports?

So, I have a CRC algorithm that uses a standard polynomial, but reversed to how this does it. I can't change what is used, because I'm going for compatibility with something that already exists.

Essentially, there's a few unsupported general CRC parameters (it seems like), one of which I need. Perhaps it would be better to look at everything that might be missing as a group. Or, perhaps, I am misunderstanding how to use what is already available. (I will be the first to confess that I've done little with CRC in the past, and am only really working with it because of a particular project I'm working on.)

http://www.ross.net/crc/download/crc_v3.txt section 15 seems to have the parameters that some have settled on.