I have seen two different kinds of CRC algorithms. The one kind is called "direct" the other kind is called "non-direct" or "indirect". The code for both is a bit different. Both are able to calculate the same checksum if direct type is supplied with a converted initial value.

I can successfully run both algorithms and I know how to convert the initial value. So this is no problem.

What I couldn't find out: Why do these two algorithms exist? Is there something that one can do what the other can't? Are they redundant from the user's point of view?

UPDATE You can find a testable online implementation (and C implementations of both aglorithms) here. However these terms (or one of them) are mentioned in some more places. Like here ("direct table algorithm"), in a microcontroller reference document, in forums etc.

  • 1
    Please provide a reference to the "direct" and "indirect" algorithms you are referring to. I have implemented many CRCs, but I have not seen those terms used before. – Mark Adler Apr 29 '16 at 23:01
  • Please see my update. I am not sure if those term are ambiguous but many times writers refer to the fact that the initial value needs conversion so this seems to be about a common feature of CRC algorithms. – Silicomancer Apr 30 '16 at 8:57
up vote 1 down vote accepted

The "direct" is referring to how to avoid processing n zero bits at the end for an n-bit CRC.

The mathematical definition of the CRC is a division of the message with n zero bits appended to it. You can avoid the extra operations by exclusive-oring the message with the CRC before operating on it instead of after. This requires processing the initial value of the register in the normal version through the CRC, and having that be the new initial value.

Since it is not necessary, you will never see a real-world CRC algorithm doing the extra operations.

See the section "10. A Slightly Mangled Table-Driven Implementation" in the document you link for a more detailed explanation.

  • What happens if a direct real-world algorithm does not convert the initial value as it should? I assume it will calculate a different (incorrect) checksum but it will work (with same hamming distance) as long as the same mistake is done consistently... am I correct? – Silicomancer May 1 '16 at 20:55
  • 1
    Yes. The result is simply exclusive-or'ed with a constant. – Mark Adler May 2 '16 at 0:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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