[ion] Fix crc32_padded inclusion

This commit is contained in:
Léa Saviot
2018-10-01 10:45:51 +02:00
committed by Émilie Feral
parent 3802639510
commit e619ee0f2c
7 changed files with 29 additions and 23 deletions

View File

@@ -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 \

View File

@@ -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 \

View File

@@ -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 \
)

View File

@@ -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 \

View File

@@ -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);
}

View File

@@ -0,0 +1,24 @@
#include <ion.h>
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);
}

View File

@@ -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 \