Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crc32: add re wrapper #526

Merged
merged 1 commit into from
Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,9 @@ elseif(UNIX)
endif()
endif()

if(NOT ZLIB_FOUND)
list(APPEND SRCS
src/crc32/crc32.c
)
endif()
list(APPEND SRCS
src/crc32/crc32.c
)

if(HAVE_THREADS)
#Do nothing
Expand Down
6 changes: 1 addition & 5 deletions include/re_crc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@
*/


#ifdef USE_ZLIB
#include <zlib.h>
#else
uint32_t crc32(uint32_t crc, const void *buf, uint32_t size);
#endif
uint32_t re_crc32(uint32_t crc, const void *buf, uint32_t size);
15 changes: 14 additions & 1 deletion src/crc32/crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
#include <re_crc32.h>


#ifdef USE_ZLIB
#include <zlib.h>
#else


static const uint32_t crc32_tab[] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
Expand Down Expand Up @@ -94,6 +99,9 @@ static const uint32_t crc32_tab[] = {
};


#endif


/**
* A function that calculates the CRC-32 based on the table above is
* given below for documentation purposes. An equivalent implementation
Expand All @@ -106,12 +114,17 @@ static const uint32_t crc32_tab[] = {
*
* @return CRC value
*/
uint32_t crc32(uint32_t crc, const void *buf, uint32_t size)
uint32_t re_crc32(uint32_t crc, const void *buf, uint32_t size)
{

#ifdef USE_ZLIB
return (uint32_t)crc32(crc, buf, size);
#else
const uint8_t *p = buf;

crc = ~crc;
while (size--)
crc = crc32_tab[(crc ^ *p++) & 0xff] ^ (crc >> 8);
return crc ^ ~0U;
#endif
}
2 changes: 0 additions & 2 deletions src/crc32/mod.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@
# Copyright (C) 2010 Creytiv.com
#

ifeq ($(USE_ZLIB),)
SRCS += crc32/crc32.c
endif
2 changes: 1 addition & 1 deletion src/stun/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct stun_msg {

static uint32_t fingerprint(const uint8_t *buf, size_t len)
{
return (uint32_t)crc32(0, buf, (unsigned int)len) ^ 0x5354554e;
return re_crc32(0, buf, (unsigned int)len) ^ 0x5354554e;
}


Expand Down