From: bg Date: Fri, 7 Oct 2011 19:38:22 +0000 (+0200) Subject: 'hardening' infrastucture against toolchain bugs X-Git-Url: https://git.cryptolib.org/?a=commitdiff_plain;h=a0b23b3327c8bc2ecd7278c95662fdebf6f15d6b;p=arm-crypto-lib.git 'hardening' infrastucture against toolchain bugs --- diff --git a/hfal/hfal-nessie.c b/hfal/hfal-nessie.c index 75f2ea8..4d541af 100644 --- a/hfal/hfal-nessie.c +++ b/hfal/hfal-nessie.c @@ -34,7 +34,7 @@ void hfal_nessie(const hfdesc_t* hd){ return; nessie_hash_ctx.hashsize_b = hd->hashsize_b; - nessie_hash_ctx.name = (char*)(hd->name); /* needs a nicer fix */ + nessie_hash_ctx.name = hd->name; nessie_hash_ctx.blocksize_B = hd->blocksize_b/8; nessie_hash_ctx.ctx_size_B = hd->ctxsize_B; nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)(hd->init); diff --git a/test_src/cli.c b/test_src/cli.c index 8176d5f..c9e1b31 100644 --- a/test_src/cli.c +++ b/test_src/cli.c @@ -102,7 +102,8 @@ uint8_t cli_getsn(char* s, uint32_t n){ char c; if(n==0) return 2; - while((c=cli_getc_cecho())!='\0' && c!='\r' && n--){ + while((c=cli_getc_cecho())!='\0' && c!='\r' && n){ + --n; *s++=c; } *s='\0'; diff --git a/test_src/main-sha512-test.c b/test_src/main-sha512-test.c index df33fba..5501b65 100644 --- a/test_src/main-sha512-test.c +++ b/test_src/main-sha512-test.c @@ -196,6 +196,9 @@ const cmdlist_entry_t cmdlist[] = { int main(void) { main_setup(); + shavs_algolist=(hfdesc_t**)algolist; + shavs_algo=(hfdesc_t*)&sha512_desc; + for(;;){ welcome_msg(algo_name); cmd_interface(cmdlist); diff --git a/test_src/nessie_common.c b/test_src/nessie_common.c index 0990ce1..9c4a6d7 100644 --- a/test_src/nessie_common.c +++ b/test_src/nessie_common.c @@ -34,6 +34,7 @@ #include "cli.h" #include "string-extras.h" + #ifdef NESSIE_ALIVE void nessie_send_alive(void){ cli_putc(NESSIE_ALIVE_CHAR); @@ -129,9 +130,10 @@ void nessie_print_header(const char* name, uint16_t i; cli_putstr("\r\n\r\n" "********************************************************************************\r\n" - "* ARM-Crypto-Lib - crypto primitives for ARM microcontrolles by Daniel Otte *\r\n" + "* ARM-Crypto-Lib - crypto primitives for ARM microcontrollers by Daniel Otte *\r\n" "********************************************************************************\r\n" "\r\n"); + cli_putstr("Primitive Name: "); cli_putstr(name); cli_putstr("\r\n"); @@ -139,7 +141,7 @@ void nessie_print_header(const char* name, for(i=0; i<16+strlen(name); ++i){ cli_putc('='); } - char str[6]; /* must catch numbers up to 65535 + terminatin \0 */ + char str[6]; /* must catch numbers up to 65535 + terminating \0 */ if(keysize_b){ cli_putstr("\r\nKey size: "); ustoa(keysize_b, str, 10); @@ -158,6 +160,7 @@ void nessie_print_header(const char* name, cli_putstr(str); cli_putstr(" bits"); } + if(macsize_b){ cli_putstr("\r\nMac size: "); ustoa(macsize_b, str, 10); diff --git a/test_src/nessie_hash_test.h b/test_src/nessie_hash_test.h index 40704f2..cad39fc 100644 --- a/test_src/nessie_hash_test.h +++ b/test_src/nessie_hash_test.h @@ -31,7 +31,7 @@ typedef struct nessie_hash_ctx_st{ uint16_t hashsize_b; uint16_t blocksize_B; uint16_t ctx_size_B; - char* name; + const char* name; nessie_hash_init_fpt hash_init; nessie_hash_next_fpt hash_next; nessie_hash_last_fpt hash_last; diff --git a/test_src/shavs.c b/test_src/shavs.c index 5d26413..8ef9619 100644 --- a/test_src/shavs.c +++ b/test_src/shavs.c @@ -42,6 +42,7 @@ #define DEBUG 0 #if DEBUG +#include "uart_lowlevel.h" //# include "config.h" //# include #endif @@ -143,9 +144,26 @@ uint8_t buffer_add(char c){ return 0; } +static +uint32_t my_strtoul(const char* str){ + uint32_t r=0; + while(*str && (*str<'0' || *str>'9')){ + str++; + } + if(!*str){ + return 0; + } + while(*str && (*str>='0' && *str<='9')){ + r *= 10; + r += *str-'0'; + str++; + } + return r; +} + int32_t getLength(void){ uint32_t len=0; - char lenstr[21]; + char lenstr[25]; char* len2; for(;;){ memset(lenstr, 0, 21); @@ -158,7 +176,8 @@ int32_t getLength(void){ do{ len2++; }while(*len2 && !isdigit((uint8_t)*len2)); - len=(uint32_t)strtoul(len2, NULL, 10); + len = my_strtoul(len2); + //len=(uint32_t)strtoul(len2, NULL, 10); return len; } } else { @@ -189,13 +208,19 @@ void shavs_test1(void){ /* KAT tests */ shavs_ctx.blocks = 0; memset(buffer, 0, shavs_ctx.buffersize_B); length = getLength(); - if(length<0){ + if((int32_t)length<0){ +#if DEBUG + cli_putstr("\r\n(x) Len == "); + cli_hexdump_rev(&length, 4); + uart_flush(0); +#endif return; } #if DEBUG cli_putstr("\r\nLen == "); cli_hexdump_rev(&length, 4); + uart_flush(0); #endif if(length==0){ expect_input=2; diff --git a/test_src/string-extras.c b/test_src/string-extras.c index 5293a1f..18cf67f 100644 --- a/test_src/string-extras.c +++ b/test_src/string-extras.c @@ -96,7 +96,11 @@ char* ultoa(unsigned long a, char* buffer, uint8_t radix){ return buffer; } while(a){ + /* toolchain bug?? result = div(a, radix); + */ + result.quot = a/radix; + result.rem = a%radix; *ptr = result.rem; if(result.rem<10){ *ptr += '0'; diff --git a/test_src/uart_i.c b/test_src/uart_i.c index 1eb421e..539dc22 100644 --- a/test_src/uart_i.c +++ b/test_src/uart_i.c @@ -272,6 +272,8 @@ void uart_flush(uint8_t uartno){ if(uartno>UART_MAX){ return; } + while(circularbytebuffer_cnt(&(uart_tx_buffer[uartno]))) + ; while((HW_REG(uart_base[uartno]+UARTCTL_OFFSET)&_BV(UART_EOT)) == 0) ; }