Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mpeg2 crc32 #33

Closed
dholroyd opened this issue May 15, 2018 · 6 comments
Closed

mpeg2 crc32 #33

dholroyd opened this issue May 15, 2018 · 6 comments

Comments

@dholroyd
Copy link

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!

@mrhooray
Copy link
Owner

mrhooray commented May 16, 2018

@dholroyd try 0xEDB88320 as suggested from crc wiki?

@CLomanno
Copy link
Contributor

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.

@dholroyd
Copy link
Author

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

@mrhooray
Copy link
Owner

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

@CLomanno
Copy link
Contributor

CLomanno commented May 17, 2018

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

@mrhooray
Copy link
Owner

Going to close this as duplicate of #31

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants