2 * Distributed under the terms of the GNU GPL version 2.
3 * Copyright (c) 2007, 2008 The Board of Trustees of The Leland
4 * Stanford Junior University
7 #include <linux/string.h>
8 #include <linux/kernel.h>
15 print_error(unsigned int poly, char *data,
16 unsigned int expected, unsigned int calculated)
18 unit_fail("crc error: poly=%x data=%s expected=%x calculated=%x\n",
19 poly, data, expected, calculated);
26 unsigned int val, i, j;
28 char *data[3] = { "h3rei$@neX@mp13da7@sTr117G0fCH@r$",
29 "1324lkqasdf0-[LKJD0;asd,.cv;/asd0:\"'~`co29",
32 unsigned int polys[2] = { 0x04C11DB7,
35 unsigned int crc_values[2][3] = {
36 { 0xDE1040C3, 0x65343A0B, 0xCEB42022 },
37 { 0x6C149FAE, 0x470A6B73, 0x4D3AA134 } };
38 for (i = 0; i < 2; i++) {
39 crc32_init(&crc, polys[i]);
40 for (j = 0; j < 3; j++) {
41 val = crc32_calculate(&crc, data[j], strlen(data[j]));
42 if (val != crc_values[i][j]) {
43 print_error(polys[i], data[j], crc_values[i][j], val);