]> git.cryptolib.org Git - arm-crypto-lib.git/commitdiff
'hardening' infrastucture against toolchain bugs
authorbg <daniel.otte@rub.de>
Fri, 7 Oct 2011 19:38:22 +0000 (21:38 +0200)
committerbg <daniel.otte@rub.de>
Fri, 7 Oct 2011 19:38:22 +0000 (21:38 +0200)
hfal/hfal-nessie.c
test_src/cli.c
test_src/main-sha512-test.c
test_src/nessie_common.c
test_src/nessie_hash_test.h
test_src/shavs.c
test_src/string-extras.c
test_src/uart_i.c

index 75f2ea88cad729405cb7a916d221f609de9c4492..4d541af36c1b86e0268010a7dcb457fb4296634b 100644 (file)
@@ -34,7 +34,7 @@ void hfal_nessie(const hfdesc_t* hd){
                return;
        
        nessie_hash_ctx.hashsize_b  = hd->hashsize_b;
                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);
        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);
index 8176d5ff8cc4e7d655cce4ab006ecf0eacfebb9d..c9e1b31aabc3a144a4cc512b063c99d6f99bec65 100644 (file)
@@ -102,7 +102,8 @@ uint8_t cli_getsn(char* s, uint32_t n){
        char c;
        if(n==0)
                return 2;
        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';
                *s++=c;
        }
        *s='\0';
index df33fba96f6a8b8aa8c503f37b265279c8946903..5501b65ae8731299500fd00cefa8bf5e6a97a782 100644 (file)
@@ -196,6 +196,9 @@ const cmdlist_entry_t cmdlist[]  = {
 int main(void) {
        main_setup();
 
 int main(void) {
        main_setup();
 
+       shavs_algolist=(hfdesc_t**)algolist;
+       shavs_algo=(hfdesc_t*)&sha512_desc;
+
        for(;;){
                welcome_msg(algo_name);
                cmd_interface(cmdlist);
        for(;;){
                welcome_msg(algo_name);
                cmd_interface(cmdlist);
index 0990ce1aeba4f818befcb560baf9fe2370d41e9a..9c4a6d7f8dfa3186a5fc0a8b50dd153f2b03b421 100644 (file)
@@ -34,6 +34,7 @@
 #include "cli.h"
 #include "string-extras.h"
 
 #include "cli.h"
 #include "string-extras.h"
 
+
 #ifdef NESSIE_ALIVE
 void nessie_send_alive(void){
        cli_putc(NESSIE_ALIVE_CHAR);
 #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"
        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");
        "********************************************************************************\r\n"
        "\r\n");
+
        cli_putstr("Primitive Name: ");
        cli_putstr(name);
        cli_putstr("\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('=');
        }
        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);
        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");
        }
                cli_putstr(str);
                cli_putstr(" bits");
        }
+
        if(macsize_b){
                cli_putstr("\r\nMac size: ");
                ustoa(macsize_b, str, 10);
        if(macsize_b){
                cli_putstr("\r\nMac size: ");
                ustoa(macsize_b, str, 10);
index 40704f2a4f6876ad3bdd2d662f432bbb623241c5..cad39fcf1e130dd420f5c8c99c9916152fe9e927 100644 (file)
@@ -31,7 +31,7 @@ typedef struct nessie_hash_ctx_st{
        uint16_t hashsize_b;
        uint16_t blocksize_B;
        uint16_t ctx_size_B;
        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;
        nessie_hash_init_fpt hash_init;
        nessie_hash_next_fpt hash_next;
        nessie_hash_last_fpt hash_last;
index 5d2641366905ac2be9b66439d68cc696a5f4e830..8ef96191def19a2151f0d02468de5b29e943a85f 100644 (file)
@@ -42,6 +42,7 @@
 #define DEBUG 0
 
 #if DEBUG
 #define DEBUG 0
 
 #if DEBUG
+#include "uart_lowlevel.h"
 //#  include "config.h"
 //#  include <util/delay.h>
 #endif
 //#  include "config.h"
 //#  include <util/delay.h>
 #endif
@@ -143,9 +144,26 @@ uint8_t buffer_add(char c){
        return 0;
 }
 
        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;
 int32_t getLength(void){
        uint32_t len=0;
-       char lenstr[21];
+       char lenstr[25];
        char* len2;
        for(;;){
                memset(lenstr, 0, 21);
        char* len2;
        for(;;){
                memset(lenstr, 0, 21);
@@ -158,7 +176,8 @@ int32_t getLength(void){
                                do{
                                        len2++;
                                }while(*len2 && !isdigit((uint8_t)*len2));
                                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 {
                                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();
                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);
                        return;
                }
 
 #if DEBUG
                cli_putstr("\r\nLen == ");
                cli_hexdump_rev(&length, 4);
+               uart_flush(0);
 #endif
                if(length==0){
                        expect_input=2;
 #endif
                if(length==0){
                        expect_input=2;
index 5293a1ff9db9da35a82a98b8838916cd8581548f..18cf67f6f5ced5fc8cbdc8d080ca1ff462bff334 100644 (file)
@@ -96,7 +96,11 @@ char* ultoa(unsigned long a, char* buffer, uint8_t radix){
                return buffer;
        }
        while(a){
                return buffer;
        }
        while(a){
+               /* toolchain bug??
                result = div(a, radix);
                result = div(a, radix);
+               */
+               result.quot = a/radix;
+               result.rem = a%radix;
                *ptr = result.rem;
                if(result.rem<10){
                        *ptr += '0';
                *ptr = result.rem;
                if(result.rem<10){
                        *ptr += '0';
index 1eb421edd6fcce62a0bb9c64c9ba07bba60f2f5f..539dc222c81d72d1d145ec73cce4a91750f4060a 100644 (file)
@@ -272,6 +272,8 @@ void uart_flush(uint8_t uartno){
        if(uartno>UART_MAX){
                return;
        }
        if(uartno>UART_MAX){
                return;
        }
+       while(circularbytebuffer_cnt(&(uart_tx_buffer[uartno])))
+               ;
        while((HW_REG(uart_base[uartno]+UARTCTL_OFFSET)&_BV(UART_EOT)) == 0)
                ;
 }
        while((HW_REG(uart_base[uartno]+UARTCTL_OFFSET)&_BV(UART_EOT)) == 0)
                ;
 }