Module: sip-router Branch: janakj/kcore Commit: eed7087d808428e208db4c14ae44e0d73582432b URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=eed7087d...
Author: Jan Janak jan@iptel.org Committer: Jan Janak jan@iptel.org Date: Tue Mar 3 03:00:29 2009 +0100
Adding crc32_uint
This function is was added by kamailio to crc32.c
---
lib/kcore/km_crc.c | 30 ++++++++++++++++++++++++++++++ lib/kcore/km_crc.h | 9 +++++++++ 2 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/lib/kcore/km_crc.c b/lib/kcore/km_crc.c new file mode 100644 index 0000000..0950f4e --- /dev/null +++ b/lib/kcore/km_crc.c @@ -0,0 +1,30 @@ +#include "km_crc.h" + +/*! + * \brief CRC32 value from source string + * \param source_string source string + * \param hash_ret calulated CRC32 + */ +void crc32_uint (str *source_string, unsigned int *hash_ret) +{ + unsigned int hash; + unsigned int len; + const char *data; + + hash = 0xffffffff; + data = source_string->s; + + for (len = source_string->len / 4; len--; data += 4) { + hash = crc_32_tab[((unsigned char)hash) ^ data[0]] ^ (hash >> 8); + hash = crc_32_tab[((unsigned char)hash) ^ data[1]] ^ (hash >> 8); + hash = crc_32_tab[((unsigned char)hash) ^ data[2]] ^ (hash >> 8); + hash = crc_32_tab[((unsigned char)hash) ^ data[3]] ^ (hash >> 8); + } + + for (len = source_string->len % 4; len--; data++) { + hash = crc_32_tab[((unsigned char)hash) ^ *data] ^ (hash >> 8); + } + + *hash_ret = hash; +} + diff --git a/lib/kcore/km_crc.h b/lib/kcore/km_crc.h new file mode 100644 index 0000000..43efd54 --- /dev/null +++ b/lib/kcore/km_crc.h @@ -0,0 +1,9 @@ +#ifndef _KM_CRC_H +#define _KM_CRC_H + +#include "../../crc.h" +#include "../../str.h" + +void crc32_uint (str *source_string, unsigned int *hash_ret); + +#endif /* _KM_CRC_H */