Silicomancer
Silicomancer

Reputation: 9156

Difference between direct and indirect CRC

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.

Upvotes: 3

Views: 2964

Answers (1)

Mark Adler
Mark Adler

Reputation: 112239

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.

Upvotes: 1

Related Questions