diff --git a/ion/Makefile b/ion/Makefile index c61f8e087..e123b4595 100644 --- a/ion/Makefile +++ b/ion/Makefile @@ -17,6 +17,7 @@ initializer_list = $(shell echo $(1) | sed "s/\(.\)/'\1',/g")0 ion/src/shared/platform_info.o: SFLAGS += -DPATCH_LEVEL="$(call initializer_list,$(PATCH_LEVEL))" -DEPSILON_VERSION="$(call initializer_list,$(EPSILON_VERSION))" objs += $(addprefix ion/src/shared/, \ + crc32_padded.o\ events.o \ platform_info.o \ storage.o \ diff --git a/ion/src/blackbox/Makefile b/ion/src/blackbox/Makefile index e65cecac8..931d9f7b2 100644 --- a/ion/src/blackbox/Makefile +++ b/ion/src/blackbox/Makefile @@ -9,6 +9,7 @@ objs += $(addprefix ion/src/shared/, \ console_line.o \ console_stdio.o \ crc32.o \ + crc32_padded.o \ events.o \ power.o \ random.o \ diff --git a/ion/src/device/Makefile b/ion/src/device/Makefile index 91ecd5569..3d243bd47 100644 --- a/ion/src/device/Makefile +++ b/ion/src/device/Makefile @@ -6,6 +6,7 @@ ion/src/shared/platform_info.o: SFLAGS += -DHEADER_SECTION="__attribute__((secti objs += $(addprefix ion/src/shared/, \ console_line.o \ + crc32_padded.o\ events_modifier.o \ ) diff --git a/ion/src/emscripten/Makefile b/ion/src/emscripten/Makefile index 67085a188..69b2d5d1f 100644 --- a/ion/src/emscripten/Makefile +++ b/ion/src/emscripten/Makefile @@ -6,6 +6,7 @@ objs += $(addprefix ion/src/emscripten/, \ objs += $(addprefix ion/src/shared/, \ crc32.o \ + crc32_padded.o \ events.o \ events_modifier.o \ power.o \ diff --git a/ion/src/shared/crc32.cpp b/ion/src/shared/crc32.cpp index df2c5ef04..8f9f50a6b 100644 --- a/ion/src/shared/crc32.cpp +++ b/ion/src/shared/crc32.cpp @@ -23,26 +23,3 @@ uint32_t Ion::crc32(const uint32_t * data, size_t length) { } return crc; } - -uint32_t Ion::crc32PaddedString(const char * s, int length) { - /* s is a char array. Its length in Bytes is not necessarily a multiple of 4. - * However, crc32 method awaits input in a form of uint32_t table. To limit - * the use of additional memory, we compute 2 crc32: - * - one corresponding to s with a byte length truncated to be a multiple of 4 - * - the other corresponds to the remaining chars in s padded with 0 to be 4 - * bytes long - * The CRC32 of s is the crc32 of both. */ - - // CRC32 of the truncated string - uint32_t c[2] = {0, 0}; - size_t crc32TruncatedInputSize = length*sizeof(char)/sizeof(uint32_t); - c[0] = Ion::crc32((const uint32_t *)s, crc32TruncatedInputSize); - - // CRC32 of the tail of the string - uint32_t tailName = 0; - size_t tailLength = length - crc32TruncatedInputSize*sizeof(uint32_t)/sizeof(char); - strlcpy((char *)&tailName, s+crc32TruncatedInputSize*sizeof(uint32_t)/sizeof(char), tailLength+1); //+1 because strlcpy assures null termination - c[1] = Ion::crc32(&tailName, 1); - - return Ion::crc32((const uint32_t *)c, 2); -} diff --git a/ion/src/shared/crc32_padded.cpp b/ion/src/shared/crc32_padded.cpp new file mode 100644 index 000000000..47975758f --- /dev/null +++ b/ion/src/shared/crc32_padded.cpp @@ -0,0 +1,24 @@ +#include + +uint32_t Ion::crc32PaddedString(const char * s, int length) { + /* s is a char array. Its length in Bytes is not necessarily a multiple of 4. + * However, crc32 method awaits input in a form of uint32_t table. To limit + * the use of additional memory, we compute 2 crc32: + * - one corresponding to s with a byte length truncated to be a multiple of 4 + * - the other corresponds to the remaining chars in s padded with 0 to be 4 + * bytes long + * The CRC32 of s is the crc32 of both. */ + + // CRC32 of the truncated string + uint32_t c[2] = {0, 0}; + size_t crc32TruncatedInputSize = length*sizeof(char)/sizeof(uint32_t); + c[0] = Ion::crc32((const uint32_t *)s, crc32TruncatedInputSize); + + // CRC32 of the tail of the string + uint32_t tailName = 0; + size_t tailLength = length - crc32TruncatedInputSize*sizeof(uint32_t)/sizeof(char); + strlcpy((char *)&tailName, s+crc32TruncatedInputSize*sizeof(uint32_t)/sizeof(char), tailLength+1); //+1 because strlcpy assures null termination + c[1] = Ion::crc32(&tailName, 1); + + return Ion::crc32((const uint32_t *)c, 2); +} diff --git a/ion/src/simulator/Makefile b/ion/src/simulator/Makefile index f9965da9f..dc4a9d250 100644 --- a/ion/src/simulator/Makefile +++ b/ion/src/simulator/Makefile @@ -8,6 +8,7 @@ objs += $(addprefix ion/src/simulator/keyboard/, fltkkbd.o) objs += $(addprefix ion/src/shared/, \ crc32.o \ + crc32_padded.o \ console_line.o \ console_stdio.o \ events_modifier.o \