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

CRC Results between two versions appears to be different #29

Closed
gtracy opened this issue Nov 28, 2014 · 7 comments
Closed

CRC Results between two versions appears to be different #29

gtracy opened this issue Nov 28, 2014 · 7 comments

Comments

@gtracy
Copy link

gtracy commented Nov 28, 2014

This feels like user error, but the use case is so simple, it appears as a defect.

The following code snippet produces two different results in version 0.2.0 and 3.2.1

var crc = require('crc');

var buff = new Buffer('AR0AAAGP2KJc/vg/AAAAErgGAK8dAAgLAQAAPpo=', 'base64');
var stored_crc = buff.readUInt16LE(27);
var chunked_buff = buff.slice(0,27);
var computed_crc = crc.crc16(chunked_buff);

console.log(buff);
console.log(chunked_buff);
console.log('crc: ' + stored_crc.toString(16));
console.log('computed crc: ' + computed_crc.toString(16));

0.2.0 Results

Note that this version has a slightly different implementation. the crc16 (line 6) has the following syntax,
crc.buffer.crc16(chunked_buff);

node index.js
Buffer 01 1d 00 00 01 8f d8 a2 5c fe f8 3f 00 00 00 12 b8 06 00 af 1d 00 08 0b 01 00 00 3e 9a
Buffer 01 1d 00 00 01 8f d8 a2 5c fe f8 3f 00 00 00 12 b8 06 00 af 1d 00 08 0b 01 00 00
crc: 9a3e
computed crc: 9a3e

3.2.1 Results

node index.js
Buffer 01 1d 00 00 01 8f d8 a2 5c fe f8 3f 00 00 00 12 b8 06 00 af 1d 00 08 0b 01 00 00 3e 9a
Buffer 01 1d 00 00 01 8f d8 a2 5c fe f8 3f 00 00 00 12 b8 06 00 af 1d 00 08 0b 01 00 00
crc: 9a3e
computed crc: f57c

@gtracy gtracy changed the title CRC Results between two versions and the recent version appears to be wrong CRC Results between two versions and the recent version appears to be different Nov 28, 2014
@gtracy gtracy changed the title CRC Results between two versions and the recent version appears to be different CRC Results between two versions appears to be different Nov 28, 2014
@alexgorbatchev
Copy link
Owner

Unfortunately older version used code found online without any actual checks. When this module started getting popular I rewrote it based on pycrc tables and all tests now compare values against reference pycrc implementation.

In short, it's possible that older version produced results that aren't necessarily compatible with other libraries. I have a note in the readme about it:

If you've used crc module prior to version 2.x, you might have some inconsistencies with the current implementation because it relied on very old code and wasn't checked against reference implementation. If you upgrading from 1.x, please take special care.

Basically, if you are happy with 0.x version, just stick with it. Sorry about the confusion.

@gtracy
Copy link
Author

gtracy commented Nov 28, 2014

Got it.

How did the crc16ccitt() algorithm get validated? That's the one that seems to be at odds with my results.

@alexgorbatchev
Copy link
Owner

Currently all results are validated against pycrc.

@gtracy
Copy link
Author

gtracy commented Nov 28, 2014

It still feels like there is a defect here. I'm comparing a computed value against a value created by another system and it fails. Every example I've run this against fails the test.

I'm still trying to get my hands on the third-party code sample.

@alexgorbatchev
Copy link
Owner

Sorry, I misunderstood you. Are you saying that 3.x version computes values that don't match values generated by other systems?

@gtracy
Copy link
Author

gtracy commented Nov 28, 2014

That's right. I pointed to the differences in versions because that's how I first noticed the problem (post-upgrade). That probably wasn't the clearest way to communicate. :)

The 28th and 29th bytes of the Buffer in the example is the checksum of the first 27 bytes.

alexgorbatchev added a commit that referenced this issue Nov 28, 2014
@alexgorbatchev
Copy link
Owner

I just added a test case for your values and f57c matches pycrc. I can suggest that perhaps the original checksum is incorrect. It's possible if you used 0.x version of this module. Does that make sense?

alexgorbatchev added a commit that referenced this issue May 5, 2015
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

2 participants