X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=test_src%2Fshavs.c;h=41a15514d0920c43c18023982c80cdf1b7916612;hb=92e0ee3f719d375d69300c7c1c48138d52330fcf;hp=5d2641366905ac2be9b66439d68cc696a5f4e830;hpb=498cf95d73faff93a848d2c0ffec3987769670bb;p=arm-crypto-lib.git diff --git a/test_src/shavs.c b/test_src/shavs.c index 5d26413..41a1551 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 @@ -109,6 +110,7 @@ typedef struct { static shavs_ctx_t shavs_ctx; +static uint8_t buffer_add(char c){ uint8_t v,t; if(shavs_ctx.buffer_idx==shavs_ctx.buffersize_B){ @@ -143,9 +145,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 +177,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 +209,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; @@ -343,11 +369,11 @@ void shavs_test2(void){ /* Monte Carlo tests for SHA-1 & SHA-2 */ return; } } - if((c=cli_getc_cecho())!='e' && c!='e'){ + if((c=cli_getc_cecho())!='e' && c!='E'){ cli_putstr("\r\nERROR: wrong input (2)!\r\n"); return; } - if((c=cli_getc_cecho())!='e' && c!='e'){ + if((c=cli_getc_cecho())!='e' && c!='E'){ cli_putstr("\r\nERROR: wrong input (3)!\r\n"); return; } @@ -428,11 +454,11 @@ void shavs_test3(void){ /* Monte Carlo tests for SHA-3 */ return; } } - if((c=cli_getc_cecho())!='e' && c!='e'){ + if((c=cli_getc_cecho())!='e' && c!='E'){ cli_putstr("\r\nERROR: wrong input (2)!\r\n"); return; } - if((c=cli_getc_cecho())!='e' && c!='e'){ + if((c=cli_getc_cecho())!='e' && c!='E'){ cli_putstr("\r\nERROR: wrong input (3)!\r\n"); return; }