dovecot-2.0-sslstream: crc32*() didn't return a standard CRC32 v...

dovecot at dovecot.org dovecot at dovecot.org
Sat Feb 13 03:00:39 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0-sslstream/rev/dcfcedb32ea2
changeset: 10640:dcfcedb32ea2
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Feb 06 00:36:11 2010 +0200
description:
crc32*() didn't return a standard CRC32 value.

diffstat:

5 files changed, 23 insertions(+), 2 deletions(-)
src/lib/Makefile.am  |    1 +
src/lib/crc32.c      |    8 ++++++--
src/lib/test-crc32.c |   14 ++++++++++++++
src/lib/test-lib.c   |    1 +
src/lib/test-lib.h   |    1 +

diffs (89 lines):

diff -r 05ae3f2e079e -r dcfcedb32ea2 src/lib/Makefile.am
--- a/src/lib/Makefile.am	Fri Feb 05 22:59:04 2010 +0200
+++ b/src/lib/Makefile.am	Sat Feb 06 00:36:11 2010 +0200
@@ -222,6 +222,7 @@ test_lib_SOURCES = \
 	test-base64.c \
 	test-bsearch-insert-pos.c \
 	test-buffer.c \
+	test-crc32.c \
 	test-hex-binary.c \
 	test-istream-concat.c \
 	test-istream-crlf.c \
diff -r 05ae3f2e079e -r dcfcedb32ea2 src/lib/crc32.c
--- a/src/lib/crc32.c	Fri Feb 05 22:59:04 2010 +0200
+++ b/src/lib/crc32.c	Sat Feb 06 00:36:11 2010 +0200
@@ -60,28 +60,32 @@ static uint32_t crc32tab[256] = {
 
 uint32_t crc32_data(const void *data, size_t size)
 {
-	return crc32_data_more((uint32_t)-1, data, size);
+	return crc32_data_more(0, data, size);
 }
 
 uint32_t crc32_data_more(uint32_t crc, const void *data, size_t size)
 {
 	const uint8_t *p = data, *end = p + size;
 
+	crc ^= 0xffffffff;
 	for (; p != end; p++)
 		crc = (crc >> 8) ^ crc32tab[((crc ^ *p) & 0xff)];
+	crc ^= 0xffffffff;
 	return crc;
 }
 
 uint32_t crc32_str(const char *str)
 {
-	return crc32_str_more((uint32_t)-1, str);
+	return crc32_str_more(0, str);
 }
 
 uint32_t crc32_str_more(uint32_t crc, const char *str)
 {
 	const uint8_t *p = (const uint8_t *)str;
 
+	crc ^= 0xffffffff;
 	for (; *p != '\0'; p++)
 		crc = (crc >> 8) ^ crc32tab[((crc ^ *p) & 0xff)];
+	crc ^= 0xffffffff;
 	return crc;
 }
diff -r 05ae3f2e079e -r dcfcedb32ea2 src/lib/test-crc32.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/test-crc32.c	Sat Feb 06 00:36:11 2010 +0200
@@ -0,0 +1,14 @@
+/* Copyright (c) 2010 Dovecot authors, see the included COPYING file */
+
+#include "test-lib.h"
+#include "crc32.h"
+
+void test_crc32(void)
+{
+	const char str[] = "foo\0bar";
+
+	test_begin("crc32");
+	test_assert(crc32_str(str) == 0x8c736521);
+	test_assert(crc32_data(str, sizeof(str)) == 0x32c9723d);
+	test_end();
+}
diff -r 05ae3f2e079e -r dcfcedb32ea2 src/lib/test-lib.c
--- a/src/lib/test-lib.c	Fri Feb 05 22:59:04 2010 +0200
+++ b/src/lib/test-lib.c	Sat Feb 06 00:36:11 2010 +0200
@@ -10,6 +10,7 @@ int main(void)
 		test_base64,
 		test_bsearch_insert_pos,
 		test_buffer,
+		test_crc32,
 		test_hex_binary,
 		test_istream_concat,
 		test_istream_crlf,
diff -r 05ae3f2e079e -r dcfcedb32ea2 src/lib/test-lib.h
--- a/src/lib/test-lib.h	Fri Feb 05 22:59:04 2010 +0200
+++ b/src/lib/test-lib.h	Sat Feb 06 00:36:11 2010 +0200
@@ -9,6 +9,7 @@ void test_base64(void);
 void test_base64(void);
 void test_bsearch_insert_pos(void);
 void test_buffer(void);
+void test_crc32(void);
 void test_hex_binary(void);
 void test_istream_concat(void);
 void test_istream_crlf(void);


More information about the dovecot-cvs mailing list