21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

#include <br />

CRC_START_BLOCK(test)<br />

int test_routine(int a) {<br />

while (a < 12) a = (a - (a * 3)) + 1;<br />

return a;<br />

}<br />

CRC_END_BLOCK(test)<br />

typedef void (*crc_check_fn)(unsigned long *);<br />

static void crc_check(unsigned long *crc);<br />

static void crc_nib2 (unsigned long *crc);<br />

static void crc_nib3 (unsigned long *crc);<br />

static void crc_nib4 (unsigned long *crc);<br />

static void crc_nib5 (unsigned long *crc);<br />

static void crc_nib6 (unsigned long *crc);<br />

static void crc_nib7 (unsigned long *crc);<br />

static void crc_nib8 (unsigned long *crc);<br />

crc_check_fn b1[16] = {0,}, b2[16] = {0,}, b3[16] = {0,}, b4[16] = {0,},<br />

b5[16] = {0,}, b6[16] = {0,}, b7[16] = {0,}, b8[16] = {0,};<br />

#define CRC_TABLE_LOOKUP(table) \<br />

int index = *crc & 0x0F; \<br />

crc_check_fn next = table[index]; \<br />

*crc >>= 4; \<br />

(*next)(crc)<br />

static void crc_check(unsigned long *crc) { CRC_TABLE_LOOKUP(b1); }<br />

static void crc_nib2 (unsigned long *crc) { CRC_TABLE_LOOKUP(b2); }<br />

static void crc_nib3 (unsigned long *crc) { CRC_TABLE_LOOKUP(b3); }<br />

static void crc_nib4 (unsigned long *crc) { CRC_TABLE_LOOKUP(b4); }<br />

static void crc_nib5 (unsigned long *crc) { CRC_TABLE_LOOKUP(b5); }<br />

static void crc_nib6 (unsigned long *crc) { CRC_TABLE_LOOKUP(b6); }<br />

static void crc_nib7 (unsigned long *crc) { CRC_TABLE_LOOKUP(b7); }<br />

static void crc_nib8 (unsigned long *crc) { CRC_TABLE_LOOKUP(b8); }<br />

static void crc_good(unsigned long *crc) {<br />

printf("CRC is valid.\n");<br />

}<br />

int main(int argc, char *argv[ ]) {<br />

unsigned long crc;<br />

crc = crc32_calc(CRC_BLOCK_ADDR(test), CRC_BLOCK_LEN(test));<br />

#ifdef TEST_BUILD<br />

printf("CRC32 %#08X\n", crc);<br />

#else<br />

crc_check(&crc);<br />

#endif<br />

return 0;<br />

}<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.<br />

Detecting Modification | 657

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!