From 917b8cc5871f112cf446b6c89b1c73332aa139fb Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Fri, 13 Mar 2009 12:28:00 +0000 Subject: Ticket #751: Incorrect table based CRC32 calculation on big endian platforms (thanks Ruud Klaver for the fix) git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2511 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib-util/src/pjlib-util/crc32.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'pjlib-util') diff --git a/pjlib-util/src/pjlib-util/crc32.c b/pjlib-util/src/pjlib-util/crc32.c index 3a682eb3..3d634645 100644 --- a/pjlib-util/src/pjlib-util/crc32.c +++ b/pjlib-util/src/pjlib-util/crc32.c @@ -22,6 +22,7 @@ #define CRC32_INDEX(c) (c & 0xff) #define CRC32_SHIFTED(c) (c >> 8) +#define CRC32_SWAP(c) (c) static const pj_uint32_t crc_tab[] = { 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, @@ -82,6 +83,10 @@ static const pj_uint32_t crc_tab[] = { #elif defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN != 0 #define CRC32_INDEX(c) (c >> 24) #define CRC32_SHIFTED(c) (c << 8) +#define CRC32_SWAP(c) ((((c) & 0xff000000) >> 24) | \ + (((c) & 0x00ff0000) >> 8) | \ + (((c) & 0x0000ff00) << 8) | \ + (((c) & 0x000000ff) << 24)) static const pj_uint32_t crc_tab[] = { 0x00000000L, 0x96300777L, 0x2c610eeeL, 0xba510999L, 0x19c46d07L, @@ -179,7 +184,7 @@ PJ_DEF(pj_uint32_t) pj_crc32_update(pj_crc32_context *ctx, PJ_DEF(pj_uint32_t) pj_crc32_final(pj_crc32_context *ctx) { - return ctx->crc_state; + return CRC32_SWAP(ctx->crc_state); } -- cgit v1.2.3