X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=test_src%2Fshavs.c;h=1dfc56db3468194e8e730e82086202bfcd020b64;hb=b97b5aeaa3569443d9b95a77a388c6615b33f9e3;hp=39b862b67899b43b1dcc5f498b7b0523ee9e94b1;hpb=1b51cba0fd060fa2d4aeb085bb51a634c542181d;p=avr-crypto-lib.git diff --git a/test_src/shavs.c b/test_src/shavs.c index 39b862b..1dfc56d 100644 --- a/test_src/shavs.c +++ b/test_src/shavs.c @@ -116,9 +116,7 @@ uint8_t buffer_add(char c){ hfal_hash_nextBlock(&(shavs_ctx.ctx), shavs_ctx.buffer); ++shavs_ctx.blocks; shavs_ctx.buffer_idx=0; - shavs_ctx.in_byte=0; cli_putc('.'); - memset(shavs_ctx.buffer, 0, shavs_ctx.buffersize_B); } if(c>='0' && c<='9'){ v=c-'0'; @@ -133,17 +131,34 @@ uint8_t buffer_add(char c){ t=shavs_ctx.buffer[shavs_ctx.buffer_idx]; if(shavs_ctx.in_byte){ t |= v; - shavs_ctx.buffer[shavs_ctx.buffer_idx]=t; + shavs_ctx.buffer[shavs_ctx.buffer_idx] = t; shavs_ctx.buffer_idx++; shavs_ctx.in_byte = 0; }else{ - t |= v<<4; - shavs_ctx.buffer[shavs_ctx.buffer_idx]=t; + t = v<<4; + shavs_ctx.buffer[shavs_ctx.buffer_idx] = t; shavs_ctx.in_byte = 1; } 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]; @@ -158,8 +173,9 @@ int32_t getLength(void){ if(*len2=='='){ do{ len2++; - }while(*len2 && !isdigit(*len2)); - len=(uint32_t)strtoul(len2, NULL, 10); + }while(*len2 && !isdigit((uint8_t)*len2)); + len = my_strtoul(len2); + //len=(uint32_t)strtoul(len2, NULL, 10); return len; } } else { @@ -201,7 +217,7 @@ void shavs_test1(void){ /* KAT tests */ if(length==0){ expect_input=2; }else{ - expect_input=((length+7)>>2)&(~1L); + expect_input=((length + 7) >> 2) & (~1L); } #if DEBUG cli_putstr_P(PSTR("\r\nexpected_input == ")); @@ -307,10 +323,7 @@ void shavs_test1(void){ /* KAT tests */ #else uint16_t temp=length-(shavs_ctx.blocks)*((shavs_ctx.buffersize_B)*8); #endif - /* cli_putstr_P(PSTR("\r\n\t (temp) == ")); - cli_hexdump_rev(&temp,2); */ hfal_hash_lastBlock( &(shavs_ctx.ctx), buffer, /* be aware of freaking compilers!!! */ -// length-(shavs_ctx.blocks)*((shavs_ctx.buffersize_B)*8)); temp ); #if DEBUG cli_putstr_P(PSTR("\r\n starting ctx2hash"));