-2
$\begingroup$

Background

I need to implement this algorithm in Node.js, but after searching everywhere I can't find an implementation.

Code

My first approach was reviewed by a member of StackOverflow and was considered correct:

However, it didn't work with the test vectors. So at this point I am assuming that I missed or miss interpreted something and that I implemented the wrong algorithm.

Questions

  1. Where can I find an implementation of CRC-16-IBM, Reversed 0xA001, Little Endian (DCBA) ?
  2. Is there a way to know given N test vectors which algorithm is being used to create the CRC?

PS: if it is in Javascript, perfect, if not, I can convert it.


Test message:

00000000000000C1080500000164880D438001014CC5F918ACC14200000000000000F00301F00002B60000430E8B000000000164880C68C000014CC5F918ACC14200000000000000000301F00102B60000430E97000000000164880CA35800014CC5F918ACC14200000000000000000301F00102B60000430E99000000000164880CDDF000014CC5F918ACC14200000000000000000301F00102B60000430E99000000000164880D188800014CC5F918ACC14200000000000000000301F00102B60000430E9800000500008DC5

CRC for this message:

00008DC5

$\endgroup$
5
  • $\begingroup$ The relation to crypto is so thin as to be invisible.. $\endgroup$
    – fgrieu
    Jul 16, 2018 at 10:56
  • $\begingroup$ I thought that CRC16 was a crypto checksum (searchsecurity.techtarget.com/definition/cryptographic-checksum). Am I mistaken? $\endgroup$ Jul 16, 2018 at 11:21
  • $\begingroup$ I'm putting this question on hold as off-topic because it is not about cryptography as defined in our help center. As a heads-up: Cyclic Redundancy Check codes are used for error-detection and correction. They are not related to cryptography because CRCs are easily reversible functions... in contrast to (for example) cryptographic hash functions (like SHA-256). $\endgroup$
    – e-sushi
    Jul 16, 2018 at 12:44
  • $\begingroup$ @Flame_Phoenix: as a rule, if the whole difficulty preventing computing the right value is the algorithm, then it is not cryptography. In cryptography-as-a-science, ever since Kerchoff's principle (actually the second principle in the original French text of 1883), there's always a key, and it always has a secret component. $\endgroup$
    – fgrieu
    Jul 16, 2018 at 13:00
  • $\begingroup$ @fgrieu Ah, so if my problem doesn't include a key, I should not post it here, correct? Thanks for explaining ! $\endgroup$ Jul 16, 2018 at 13:02

1 Answer 1

1
$\begingroup$

The CRC-16 polynomial 0xCD83 will produce the byte-swapped checksum of your data. It is implemented in the following C++ routine:

uint16_t crc16(uint16_t state, uint8_t byte) {
  uint16_t mask;
  uint16_t crc = state ^ uint16_t(byte);
  for (int j = 7; j >= 0; j--) {
    mask = -(crc & uint16_t(1));
    crc = (crc >> 1) ^ (mask & uint16_t(0xCD83));
  }
  return crc;
}

If you initialize state=0 and feed this routine your test vector

state = crc(state, data[i]);

Then after processing the state will equal 0xC58D which is the byte-swapped checksum that you wanted.

There is no 16-bit polynomial that will produce the checksum with the other byte ordering (0x8DC5).

$\endgroup$
3
  • $\begingroup$ Since according to @e-sushi, CRCs are easily reversible, is there a way, that given any test vector, to find out the CRC algorithm used to compute it? $\endgroup$ Jul 16, 2018 at 13:02
  • $\begingroup$ @Flame_Phoenix: Yes: Berlekamp-Massey. If we only care about specific length(s) of messages; there's a different method working for any affine transformation (including CRCs with whatever bogus byte order and variant the implementor may have used). $\endgroup$
    – fgrieu
    Jul 16, 2018 at 13:13
  • $\begingroup$ This answer is wrong for two reasons: First you included the expected CRC into the message. Second: With your construction you cannot reproduce the expected CRC for the other given test vector. I did not found any CRC-16 algorithm which can do this. $\endgroup$ Jul 16, 2018 at 14:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.