diff options
author | Benny Prijono <bennylp@teluu.com> | 2009-03-13 12:28:00 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2009-03-13 12:28:00 +0000 |
commit | 917b8cc5871f112cf446b6c89b1c73332aa139fb (patch) | |
tree | b77d75d92b24bb07c54269a5e2e02673bde6d31d /pjlib-util/src | |
parent | 87e7c10c51282edde56fd891d4ad24566982adea (diff) |
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
Diffstat (limited to 'pjlib-util/src')
-rw-r--r-- | pjlib-util/src/pjlib-util/crc32.c | 7 |
1 files changed, 6 insertions, 1 deletions
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); } |