From e2f0151054af721d383a39543c7c5847c99eb5a0 Mon Sep 17 00:00:00 2001 From: Youness Alaoui Date: Thu, 12 Feb 2009 18:34:03 -0500 Subject: [PATCH] stupid WLM 2009 CRC32 typo workaround (ugly, I know...) --- stun/stunagent.c | 9 +++++++++ stun/stuncrc32.c | 9 +++++++-- stun/stuncrc32.h | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/stun/stunagent.c b/stun/stunagent.c index faad925..7679c8d 100644 --- a/stun/stunagent.c +++ b/stun/stunagent.c @@ -146,6 +146,11 @@ StunValidationStatus stun_agent_validate (StunAgent *agent, StunMessage *msg, return STUN_VALIDATION_BAD_REQUEST; } + if (agent->compatibility == STUN_COMPATIBILITY_WLM2009) + wlm2009_stupid_crc32_typo = 1; + else + wlm2009_stupid_crc32_typo = 0; + /* Checks FINGERPRINT */ crc32 = stun_fingerprint (msg->buffer, stun_message_length (msg)); fpr = ntohl (fpr); @@ -575,6 +580,10 @@ size_t stun_agent_finish_message (StunAgent *agent, StunMessage *msg, } + if (agent->compatibility == STUN_COMPATIBILITY_WLM2009) + wlm2009_stupid_crc32_typo = 1; + else + wlm2009_stupid_crc32_typo = 0; fpr = stun_fingerprint (msg->buffer, stun_message_length (msg)); memcpy (ptr, &fpr, sizeof (fpr)); diff --git a/stun/stuncrc32.c b/stun/stuncrc32.c index 29289b7..0f3fa66 100644 --- a/stun/stuncrc32.c +++ b/stun/stuncrc32.c @@ -89,6 +89,7 @@ #include "stuncrc32.h" +int wlm2009_stupid_crc32_typo = 0; static const uint32_t crc32_tab[] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, @@ -147,8 +148,12 @@ uint32_t crc32 (const crc_data *data, size_t n) const uint8_t *p = data[i].buf; size_t size = data[i].len; - while (size--) - crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); + while (size--) { + uint32_t lkp = crc32_tab[(crc ^ *p++) & 0xFF]; + if (lkp == 0x8bbeb8ea && wlm2009_stupid_crc32_typo) + lkp = 0x8bbe8ea; + crc = lkp ^ (crc >> 8); + } } return crc ^ 0xffffffff; diff --git a/stun/stuncrc32.h b/stun/stuncrc32.h index 2aeb579..0ebd2c2 100644 --- a/stun/stuncrc32.h +++ b/stun/stuncrc32.h @@ -53,6 +53,7 @@ typedef struct { } crc_data; +int wlm2009_stupid_crc32_typo; uint32_t crc32 (const crc_data *data, size_t n); #endif /* _CRC32_H */ -- 2.11.4.GIT