Fixed undefined reference error when "make recover" in EON

In fd233832ef
the linker flag -lgcc might not work on EON as it does not have the
correct library.

The fix was a workaround in sha.c such that we no longer need to import
function __aeabi_llsr from library, by replacing right shift operation
with const argument.

E.g.,
uint64_t a = b >> i // requires __aeabi_llsr from libgcc
uint64_t a = b >> 2 // does not require external library

Resolves: #522
master
kernyan 2019-02-08 15:15:46 -05:00 committed by Riccardo
parent c91f038eab
commit e0dd55841a
2 changed files with 31 additions and 5 deletions

View File

@ -55,7 +55,7 @@ obj/$(PROJ_NAME).bin: obj/$(STARTUP_FILE).o obj/main.$(PROJ_NAME).o
obj/bootstub.$(PROJ_NAME).bin: obj/$(STARTUP_FILE).o obj/bootstub.$(PROJ_NAME).o obj/sha.$(PROJ_NAME).o obj/rsa.$(PROJ_NAME).o
$(CC) $(CFLAGS) -o obj/bootstub.$(PROJ_NAME).elf $^ -lgcc
$(CC) $(CFLAGS) -o obj/bootstub.$(PROJ_NAME).elf $^
$(OBJCOPY) -v -O binary obj/bootstub.$(PROJ_NAME).elf $@
clean:

View File

@ -127,10 +127,36 @@ const uint8_t* SHA_final(SHA_CTX* ctx) {
while ((ctx->count & 63) != 56) {
SHA_update(ctx, (uint8_t*)"\0", 1);
}
for (i = 0; i < 8; ++i) {
uint8_t tmp = (uint8_t) (cnt >> ((7 - i) * 8));
SHA_update(ctx, &tmp, 1);
}
/* Hack - right shift operator with non const argument requires
* libgcc.a which is missing in EON
* thus expanding for loop from
for (i = 0; i < 8; ++i) {
uint8_t tmp = (uint8_t) (cnt >> ((7 - i) * 8));
SHA_update(ctx, &tmp, 1);
}
to
*/
uint8_t tmp = 0;
tmp = (uint8_t) (cnt >> ((7 - 0) * 8));
SHA_update(ctx, &tmp, 1);
tmp = (uint8_t) (cnt >> ((7 - 1) * 8));
SHA_update(ctx, &tmp, 1);
tmp = (uint8_t) (cnt >> ((7 - 2) * 8));
SHA_update(ctx, &tmp, 1);
tmp = (uint8_t) (cnt >> ((7 - 3) * 8));
SHA_update(ctx, &tmp, 1);
tmp = (uint8_t) (cnt >> ((7 - 4) * 8));
SHA_update(ctx, &tmp, 1);
tmp = (uint8_t) (cnt >> ((7 - 5) * 8));
SHA_update(ctx, &tmp, 1);
tmp = (uint8_t) (cnt >> ((7 - 6) * 8));
SHA_update(ctx, &tmp, 1);
tmp = (uint8_t) (cnt >> ((7 - 7) * 8));
SHA_update(ctx, &tmp, 1);
for (i = 0; i < 5; i++) {
uint32_t tmp = ctx->state[i];