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

mpeg2 crc32

dholroyd opened this issue · comments

I'd like to replace the following code implementing the 'mpeg2' crc32 with usage the crc-rs crate,

https://github.com/dholroyd/mpeg2ts-reader/blob/master/src/mpegts_crc.rs

Just plugging in the polynomial (0x04C11DB7 I think) didn't seem to work. Are there some extra pre/post processing steps required? I believe I tried inverting the result, but that didn't seem to be correct either.

Thanks!

@dholroyd try 0xEDB88320 as suggested from crc wiki?

This may be related to the PR #32 I have open. The current crc-rs code does not implement the full CRC32 algorithm.

Currently crc-rs only works for calculating the sums of inverted algorithms. Once I clean up #32 and get it accepted, you should be able to use it.

Thanks for your responses. For what its worth I've just tried the following combinations of options (I still don't really know what I'm doing mind you, sorry if some of this doesn't make sense!)

expected 0x4a1709ae
initial 0x00000000 polynomial 0x04c11db7 xor 0x00000000 => actual 0xfff38c35 :(
initial 0x00000000 polynomial 0x04c11db7 xor 0xffffffff => actual 0x000c73ca :(
initial 0x00000000 polynomial 0xedb88321 xor 0x00000000 => actual 0x28deb8cc :(
initial 0x00000000 polynomial 0xedb88321 xor 0xffffffff => actual 0xd7214733 :(
initial 0x00000000 polynomial 0xdb710641 xor 0x00000000 => actual 0xc360441a :(
initial 0x00000000 polynomial 0xdb710641 xor 0xffffffff => actual 0x3c9fbbe5 :(
initial 0x00000000 polynomial 0x82608edb xor 0x00000000 => actual 0x216125fd :(
initial 0x00000000 polynomial 0x82608edb xor 0xffffffff => actual 0xde9eda02 :(
initial 0xffffffff polynomial 0x04c11db7 xor 0x00000000 => actual 0xf839619d :(
initial 0xffffffff polynomial 0x04c11db7 xor 0xffffffff => actual 0x07c69e62 :(
initial 0xffffffff polynomial 0xedb88321 xor 0x00000000 => actual 0x3b26a840 :(
initial 0xffffffff polynomial 0xedb88321 xor 0xffffffff => actual 0xc4d957bf :(
initial 0xffffffff polynomial 0xdb710641 xor 0x00000000 => actual 0x212057bc :(
initial 0xffffffff polynomial 0xdb710641 xor 0xffffffff => actual 0xdedfa843 :(
initial 0xffffffff polynomial 0x82608edb xor 0x00000000 => actual 0x3511c0e1 :(
initial 0xffffffff polynomial 0x82608edb xor 0xffffffff => actual 0xcaee3f1e :(

playground here:
https://play.rust-lang.org/?gist=35049f73c80e807e6885a790639eaf8e&version=stable&mode=debug

looks like the check value for b"13456789" is 0x0376E6E7 from various sources
@CLomanno does your expanded implementation produce above result?

Yes.

I match the case initial 0xffffffff polynomial 0x04c11db7 xor 0x00000000 => actual 0xf839619d :(

Run this code snippet using my branch.
let poly = 0x04c11db7;
const FS: u32 = 0xFFFFFFFF;
const ZS: u32 = 0x00000000;
let mut digest_cust = crc32::Digest::new_with_initial_and_final(poly, FS as u32, false, ZS as u32);
digest_cust.write(&data);
println!("Poly: {:#X}, Initial: {:#X}, Reflect: FALSE, Final Xor: {:#X}\nExpected '0x4A1709AE' calc: {:#X}\n", poly, FS, ZS, digest_cust.sum32());
Result:
Poly: 0x4C11DB7, Initial: 0xFFFFFFFF, Reflect: FALSE, Final Xor: 0x0
Expected '0x4A1709AE' calc: 0x4A1709AE

Going to close this as duplicate of #31

also @CLomanno has taken #32 a long way towards finish line