Oscar_Mariani
Oscar_Mariani

Reputation: 768

I am looking for standardised test vectors for a CRC32 algorithm implementation

I had to substitute the CRC32 implementation on the system I am working on, the algorithm that was implemented before used a size 256 look up table and that was too big to use in the boot loader. The new algorithm I've implemented uses a size 16 look up table.

I am using the same polynomial as before, but the results are different. Online calculators throw even more random results and most of them are not very clear on what they are doing, ie which polynomial they are using, what format is the input data or what is the initial crc value.

Does anyone know where can I find a reliable, standardised test vector for CRC32 implementations?

Thanks!

Upvotes: 3

Views: 5100

Answers (3)

Nathan Moinvaziri
Nathan Moinvaziri

Reputation: 5638

Ironclad repository has some test vectors which may be useful:

;;; standard tests for crc32

(:digest-test #a"" #h"00000000")
(:digest-test #a"a" #h"e8b7be43")
(:digest-test #a"abc" #h"352441c2")
(:digest-test #a"message digest" #h"20159d7f")
(:digest-test #a"abcdefghijklmnopqrstuvwxyz" #h"4c2750bd")
(:digest-test #a"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" #h"1fc2e6d2")
(:digest-test #a"12345678901234567890123456789012345678901234567890123456789012345678901234567890" #h"7ca94a72")

https://github.com/froydnj/ironclad/blob/master/testing/test-vectors/crc32.testvec

There are some tests in zlib-ng too:

https://github.com/zlib-ng/zlib-ng/blob/develop/test/crc32_test.c

Upvotes: 3

Mark Adler
Mark Adler

Reputation: 112394

Yes, this catalog of CRCs. Included with each CRC definition is a check value — which is that CRC's output for the nine-byte string “123456789” input in ASCII / UTF-8. For example, CRC-32("123456789", 9) = 0xcbf43926.

Why don't you simply compare your new implementation to your old implementation?

Upvotes: 5

Anton Samsonov
Anton Samsonov

Reputation: 1422

Not standardised in any kind, — just gathered for convenience:

// Trivial one.
UINT32_C(0x00000000), ""

// Source: https://rosettacode.org/wiki/CRC-32
UINT32_C(0x414FA339), "The quick brown fox jumps over the lazy dog"

// Source: http://cryptomanager.com/tv.html
UINT32_C(0x9BD366AE), "various CRC algorithms input data"

// Source: http://www.febooti.com/products/filetweak/members/hash-and-crc/test-vectors/
UINT32_C(0x0C877F61), "Test vector from febooti.com"

What if your results do not match? Be sure to check which flavor of CRC you are implementing and comparing to, — a nice example of such digging can be found in “CRC32 Checksums; The Good, The Bad, And The Ugly” article, where it is shown that some programs may do additional processing after otherwise identical operations, like piping the length of the message through checksumming, too, which may or may not be covered in documentation.

Upvotes: 1

Related Questions