From f2da68c5992fe2c29cced7e51709d0a45e0bb3b4 Mon Sep 17 00:00:00 2001 From: Joshua Wise Date: Sun, 14 Dec 2008 19:25:18 -0500 Subject: [PATCH] Modify crc32 users to behave better when crcing multiple things into one CRC. --- include/crc32.h | 2 +- lib/crc32.c | 6 +++--- video/generic.c | 2 +- video/text.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/crc32.h b/include/crc32.h index f7d568a..a384bcc 100644 --- a/include/crc32.h +++ b/include/crc32.h @@ -3,7 +3,7 @@ #include -extern uint32_t crc32(unsigned char *buf, int len); +extern uint32_t crc32(unsigned char *buf, int len, uint32_t crc0); extern void crc32_init(); #endif diff --git a/lib/crc32.c b/lib/crc32.c index fd7bd49..43f9d7a 100644 --- a/lib/crc32.c +++ b/lib/crc32.c @@ -5,15 +5,15 @@ uint32_t crc32_table[256]; -uint32_t crc32(uint8_t *buf, int len) +uint32_t crc32(uint8_t *buf, int len, uint32_t crc0) { uint8_t *p; uint32_t crc; - crc = 0xffffffff; /* preload shift register, per CRC-32 spec */ + crc = crc0; for (p = buf; len > 0; ++p, --len) crc = (crc << 8) ^ crc32_table[(crc >> 24) ^ *p]; - return ~crc; /* transmit complement, per CRC-32 spec */ + return crc; } /* diff --git a/video/generic.c b/video/generic.c index 8c6866d..95f564f 100644 --- a/video/generic.c +++ b/video/generic.c @@ -17,7 +17,7 @@ uint32_t checksum_rect_generic32(int x, int y, int width, int height) { for (i = 0; i < height; i++) { lineaddr = fb->fbaddr + (i + y) * scanline + (4 * x); - sum ^= crc32(lineaddr, width * 4); + sum = crc32(lineaddr, width * 4, sum); } return sum; diff --git a/video/text.c b/video/text.c index 25fe245..7fe30c9 100644 --- a/video/text.c +++ b/video/text.c @@ -91,7 +91,7 @@ uint32_t text_checksum(int x, int y, int w, int h) cx = x; texty = cy / 14; textx = cx / 9; - cksm ^= crc32(video + texty * 160 + textx * 2, (w / 9 + 1) * 2); /* Err on the side of 'too many'. */ + cksm = crc32(video + texty * 160 + textx * 2, (w / 9) * 2 + 2, cksm); /* Err on the side of 'too many'. */ } smram_restore_state(old_state); -- 2.43.0