diff --git a/avr-makefile.inc b/avr-makefile.inc index 9b6ea71..bb39deb 100644 --- a/avr-makefile.inc +++ b/avr-makefile.inc @@ -1,6 +1,6 @@ MCU_TARGET = atmega644 -OPTIMIZE = -Os +OPTIMIZE = -Os # -Os PROGRAMMER = avr911 DEFS = -D$(call uc, $(MCU_TARGET)) FLASHCMD = avrdude -p $(MCU_TARGET) -P /dev/ttyUSB0 -c $(PROGRAMMER) -U flash:w:# no space at the end diff --git a/bmw/bmw_small.c b/bmw/bmw_small.c index e24fb7c..8a4b165 100644 --- a/bmw/bmw_small.c +++ b/bmw/bmw_small.c @@ -36,13 +36,18 @@ #define ROTL32(a,n) (((a)<<(n))|((a)>>(32-(n)))) #define ROTR32(a,n) (((a)>>(n))|((a)<<(32-(n)))) -#define BUG24 0 -#define BUG_ROT 1 + #define TWEAK 1 +#if TWEAK +# define BUG24 0 +#else +# define BUG24 1 +#endif #define F0_HACK 1 #define DEBUG 0 + #if DEBUG #include "cli.h" @@ -198,19 +203,11 @@ uint32_t bmw_small_expand1(uint8_t j, const uint32_t* q, const void* m, const vo r += s[i%4](q[j+i]); } #if TWEAK -# if BUG_ROT r += ( ROTL32(((uint32_t*)m)[j&0xf], ((j+0)&0xf)+1 ) + ROTL32(((uint32_t*)m)[(j+3)&0xf], ((j+3)&0xf)+1 ) - ROTL32(((uint32_t*)m)[(j+10)&0xf], ((j+10)&0xf)+1 ) + pgm_read_dword(k_lut+j) ) ^ ((uint32_t*)h)[(j+7)&0xf]; -# else - r += ( ROTL32(((uint32_t*)m)[j&0xf], (j+1)&0xf ) - + ROTL32(((uint32_t*)m)[(j+3)&0xf], (j+4)&0xf ) - - ROTL32(((uint32_t*)m)[(j+10)&0xf], (j+11)&0xf ) - + pgm_read_dword(k_lut+j) - ) ^ ((uint32_t*)h)[(j+7)&0xf]; -# endif #else r += pgm_read_dword(k_lut+j); r += ((uint32_t*)m)[j&0xf]; @@ -240,20 +237,11 @@ uint32_t bmw_small_expand2(uint8_t j, const uint32_t* q, const void* m, const vo r += bmw_small_s4(q[j+15]); #endif #if TWEAK -# if BUG_ROT r += ( ROTL32(((uint32_t*)m)[j&0xf], ((j+0)&0xf)+1 ) + ROTL32(((uint32_t*)m)[(j+3)&0xf], ((j+3)&0xf)+1 ) - ROTL32(((uint32_t*)m)[(j+10)&0xf], ((j+10)&0xf)+1 ) + pgm_read_dword(k_lut+j) ) ^ ((uint32_t*)h)[(j+7)&0xf]; -# else - r += ( ROTL32(((uint32_t*)m)[j&0xf], (j+1)&0xf ) - + ROTL32(((uint32_t*)m)[(j+3)&0xf], (j+4)&0xf ) - - ROTL32(((uint32_t*)m)[(j+10)&0xf], (j+11)&0xf ) - + pgm_read_dword(k_lut+j) - ) ^ ((uint32_t*)h)[(j+7)&0xf]; -#endif - #else r += pgm_read_dword(k_lut+j); r += ((uint32_t*)m)[j&0xf]; @@ -284,7 +272,7 @@ uint8_t f0_lut[] PROGMEM = { 12<<1, ( 4<<1)+1, ( 6<<1)+1, ( 9<<1)+1, (13<<1)+0 }; -void bmw_small_f0(uint32_t* q, const uint32_t* h, const void* m){ +void bmw_small_f0(uint32_t* q, uint32_t* h, const void* m){ uint8_t i,j=-1,v,sign,l=0; uint32_t(*s[])(uint32_t)={ bmw_small_s0, bmw_small_s1, bmw_small_s2, bmw_small_s3, bmw_small_s4 }; @@ -324,7 +312,7 @@ void bmw_small_f0(uint32_t* q, const uint32_t* h, const void* m){ } #else -void bmw_small_f0(uint32_t* q, const uint32_t* h, const void* m){ +void bmw_small_f0(uint32_t* q, uint32_t* h, const void* m){ uint8_t i; uint32_t(*s[])(uint32_t)={ bmw_small_s0, bmw_small_s1, bmw_small_s2, bmw_small_s3, bmw_small_s4 }; diff --git a/hfal-basic.c b/hfal-basic.c index 1be95d3..82c040b 100644 --- a/hfal-basic.c +++ b/hfal-basic.c @@ -24,21 +24,23 @@ uint8_t hfal_hash_init(const hfdesc_t* hash_descriptor, hfgen_ctx_t* ctx){ hf_init_fpt f; + uint16_t tmp; ctx->desc_ptr = (hfdesc_t*)hash_descriptor; - if(!(ctx->ctx=malloc(pgm_read_word(&(hash_descriptor->ctxsize_B))))) + tmp = pgm_read_word(&(hash_descriptor->ctxsize_B)); + if(!(ctx->ctx=malloc(tmp))) return 3; f= (hf_init_fpt)pgm_read_word(&(hash_descriptor->init)); f(ctx->ctx); return 0; } - + void hfal_hash_nextBlock(hfgen_ctx_t* ctx, const void* block){ hf_nextBlock_fpt f; hfdesc_t* x=(ctx->desc_ptr); f =(hf_nextBlock_fpt)pgm_read_word(&(x->nextBlock)); f(ctx->ctx, block); } - + void hfal_hash_lastBlock(hfgen_ctx_t* ctx, const void* block, uint16_t length_b){ hf_lastBlock_fpt f; hfdesc_t* x=ctx->desc_ptr; @@ -68,7 +70,7 @@ void hfal_hash_mem(const hfdesc_t* hash_descriptor, void* dest, const void* msg, if(f){ ((hf_mem_fpt)f)(dest, msg, length_b); }else{ - + uint16_t bs,bsb; uint8_t ctx[pgm_read_word(&(hash_descriptor->ctxsize_B))]; f=(void_fpt)pgm_read_word(&(hash_descriptor->init)); @@ -86,7 +88,7 @@ void hfal_hash_mem(const hfdesc_t* hash_descriptor, void* dest, const void* msg, f=(void_fpt)pgm_read_word(&(hash_descriptor->ctx2hash)); ((hf_ctx2hash_fpt)f)(dest, ctx); } -} +} uint16_t hfal_hash_getBlocksize(const hfdesc_t* hash_descriptor){ uint16_t ret; diff --git a/host/shavs_test.rb b/host/shavs_test.rb index 3960bce..e5e3a43 100644 --- a/host/shavs_test.rb +++ b/host/shavs_test.rb @@ -19,16 +19,16 @@ =end $debug = true; -$debug = false; +#$debug = false; require 'rubygems' require 'serialport' def init_system # sleep 1 $sp.print("exit\r") - sleep 0.1 + sleep 0.5 $sp.print("exit\r") - sleep 0.1 + sleep 0.5 $sp.print("echo off \r") print("DBG i: " + "echo off \r"+"\n") if $debug # line = $sp.readlines() @@ -52,16 +52,17 @@ def get_md begin line = $sp.gets() line = "" if line==nil - puts("DBG g: "+line) if $debug + puts("DBG got: "+line) if $debug && line!="" end while not /[\s]*MD[\s]*=.*/.match(line) return line end def send_md(md_string) + sleep(0.15) for i in 0..md_string.length-1 $sp.print(md_string[i].chr) # print("DBG s: "+ md_string[i].chr) if $debug - if(i%20==19) + if(i%5==4) sleep(0.15) end end @@ -100,6 +101,7 @@ def run_test(filename) b.upcase! printf("\n%4d (%4d): ", line, (line-1)*$linewidth) if (pos%$linewidth==0 and $linewidth!=0) line += 1 if (pos%$linewidth==0 and $linewidth!=0) + sleep(1) #putc((a==b)?'*':'!') if(a==b) putc('*') diff --git a/test_src/cli-basics.S b/test_src/cli-basics.S index e3cefc7..363b396 100644 --- a/test_src/cli-basics.S +++ b/test_src/cli-basics.S @@ -56,13 +56,13 @@ cli_getc_cecho: ser r25 ser r24 ret -1: +1: icall lds r20, cli_echo tst r20 brne 2f ret -2: +2: push r2 mov r2, r24 rcall cli_putc @@ -70,7 +70,7 @@ cli_getc_cecho: clr r25 pop r2 ret - + /******************************************************************************/ .global cli_putstr cli_putstr: @@ -84,7 +84,7 @@ cli_putstr: breq 2f rcall cli_putc rjmp 1b -2: +2: pop r29 pop r28 ret @@ -104,7 +104,7 @@ cli_putstr_P: rcall cli_putc adiw r28, 1 rjmp 1b -2: +2: pop r29 pop r28 ret @@ -113,7 +113,7 @@ cli_putstr_P: /* * param s: r24:r25 * param n: r22:r23 - */ + */ .global cli_getsn cli_getsn: push r28 @@ -137,14 +137,46 @@ cli_getsn: st Y+, r24 movw r26, r16 sbiw r26, 1 - movw r16, r24 + movw r16, r26 brne 2b -9: +9: clr r25 mov r24, r20 st Y, r1 pop r17 pop r16 - pop r28 pop r29 + pop r28 ret + +/******************************************************************************/ +/* + * param s: r24:r25 + * param n: r22:r23 + */ +.global cli_getsn_cecho +cli_getsn_cecho: + push r28 + push r29 + push r16 + push r17 + movw r28, r24 + ldi r20, 2 + movw r24, r22 + adiw r24, 0 + breq 9b +1: + movw r16, r22 +2: clr r20 + rcall cli_getc_cecho + cpi r24, '\r' + breq 9b + ldi r20, 1 + tst r24 + breq 9b + st Y+, r24 + movw r26, r16 + sbiw r26, 1 + movw r16, r26 + brne 2b + rjmp 9b diff --git a/test_src/cli-hexdump.S b/test_src/cli-hexdump.S index 0a34984..8976709 100644 --- a/test_src/cli-hexdump.S +++ b/test_src/cli-hexdump.S @@ -19,7 +19,7 @@ #include "avr-asm-macros.S" /******************************************************************************/ -/* cli_hexdump_byte +/* cli_hexdump_byte * param data: r24 */ .global cli_hexdump_byte @@ -43,10 +43,10 @@ cli_hexdump_byte: clr r25 lpm r24, Z rcall cli_putc - ret + ret /******************************************************************************/ -/* cli_hexdump +/* cli_hexdump * param data: r24:r25 * param length: r22:r23 */ @@ -63,19 +63,19 @@ cli_hexdump: breq hexdump_exit 2: ld r24, Y+ - rcall cli_hexdump_byte + rcall cli_hexdump_byte subi r16, 1 - sbc r17, r1 + sbci r17, 0 brne 2b -hexdump_exit: +hexdump_exit: pop r17 pop r16 pop r29 pop r28 ret - + /******************************************************************************/ -/* cli_hexdump_rev +/* cli_hexdump_rev * param data: r24:r25 * param length: r22:r23 */ @@ -94,11 +94,11 @@ cli_hexdump_rev: 1: breq hexdump_exit ld r24, -Y - rcall cli_hexdump_byte + rcall cli_hexdump_byte subi r16, 1 sbci r17, 0 rjmp 1b - + /******************************************************************************/ /* cli_hexdump2 * param data: r24:r25 @@ -114,14 +114,14 @@ cli_hexdump2: movw r16, r22 movw r26, r16 adiw r26, 0 -1: +1: breq hexdump_exit ld r24, Y+ rcall cli_hexdump_byte clr r25 ldi r24,' ' rcall cli_putc - + subi r16, 1 sbci r17, 0 rjmp 1b @@ -158,7 +158,7 @@ cli_hexdump_block: mov WIDTH, r18 mov INDENT, r20 movw DATA_0, r24 - movw LENG_0, r22 + movw LENG_0, r22 2: clr r25 ldi r24, '\r' @@ -184,15 +184,15 @@ cli_hexdump_block: breq 6f brmi 7f mov r22, LENG_0 -6: inc r4 -7: +6: inc r4 +7: rcall cli_hexdump2 add DATA_0, WIDTH adc DATA_1, r1 sub LENG_0, WIDTH sbc LENG_0, r1 tst r4 - breq 2b + breq 2b pop r4 pop LENG_1 pop LENG_0 @@ -201,5 +201,5 @@ cli_hexdump_block: pop INDENT pop WIDTH ret - - + + diff --git a/test_src/cli-stub.c b/test_src/cli-stub.c index ccbb7ba..1db5616 100644 --- a/test_src/cli-stub.c +++ b/test_src/cli-stub.c @@ -102,11 +102,12 @@ int8_t cmd_interface(PGM_VOID_P cmd_desc){ free(cli_buffer); return exit_code; } - cli_putstr(cli_buffer); + /* cli_putstr(cli_buffer); */ memset(cli_buffer, 0, cli_buffer_size); cli_buffer_index=0; - cli_putstr_P(PSTR(" DONE\r\n>")); + /* cli_putstr_P(PSTR(" DONE\r\n>")); */ + cli_putstr_P(PSTR("\r\n>")); completion_failed=0; break; case CLI_BACKSPACE: diff --git a/test_src/cli.h b/test_src/cli.h index dc79a7d..5fb2a17 100644 --- a/test_src/cli.h +++ b/test_src/cli.h @@ -58,6 +58,7 @@ void cli_putc(char c); uint16_t cli_getc(void); uint16_t cli_getc_cecho(void); uint8_t cli_getsn(char* s, uint16_t n); +uint8_t cli_getsn_cecho(char* s, uint16_t n); void cli_putstr(const char* s); void cli_putstr_P(PGM_P s); void cli_hexdump(const void* data, uint16_t length); diff --git a/test_src/main-a5_1-test.c b/test_src/main-a5_1-test.c index c080375..6a0edc8 100644 --- a/test_src/main-a5_1-test.c +++ b/test_src/main-a5_1-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-aes-test.c b/test_src/main-aes-test.c index 765411b..e2d3685 100644 --- a/test_src/main-aes-test.c +++ b/test_src/main-aes-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-aes128-test.c b/test_src/main-aes128-test.c index 98462a1..ce9468f 100644 --- a/test_src/main-aes128-test.c +++ b/test_src/main-aes128-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-aes192-test.c b/test_src/main-aes192-test.c index c37dc7e..850d773 100644 --- a/test_src/main-aes192-test.c +++ b/test_src/main-aes192-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-aes256-test.c b/test_src/main-aes256-test.c index 15d7f83..53c4fe6 100644 --- a/test_src/main-aes256-test.c +++ b/test_src/main-aes256-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-arcfour-test.c b/test_src/main-arcfour-test.c index 7e54892..e66a1d4 100644 --- a/test_src/main-arcfour-test.c +++ b/test_src/main-arcfour-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-base64-test.c b/test_src/main-base64-test.c index a4ce3f3..caf60fa 100644 --- a/test_src/main-base64-test.c +++ b/test_src/main-base64-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-blake-test.c b/test_src/main-blake-test.c index 379ba2b..9ee75f5 100644 --- a/test_src/main-blake-test.c +++ b/test_src/main-blake-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-bmw-test.c b/test_src/main-bmw-test.c index 3228817..efd4829 100644 --- a/test_src/main-bmw-test.c +++ b/test_src/main-bmw-test.c @@ -22,7 +22,6 @@ */ #include "config.h" -#include "serial-tools.h" #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-camellia-test.c b/test_src/main-camellia-test.c index 2401557..2cc6439 100644 --- a/test_src/main-camellia-test.c +++ b/test_src/main-camellia-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-cast5-test.c b/test_src/main-cast5-test.c index fe5915c..a8f8890 100644 --- a/test_src/main-cast5-test.c +++ b/test_src/main-cast5-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-cast6-test.c b/test_src/main-cast6-test.c index d13a100..27e0478 100644 --- a/test_src/main-cast6-test.c +++ b/test_src/main-cast6-test.c @@ -4,7 +4,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-des-test.c b/test_src/main-des-test.c index 5ccf7b6..a674d6e 100644 --- a/test_src/main-des-test.c +++ b/test_src/main-des-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-entropium-test.c b/test_src/main-entropium-test.c index 50ad2b1..36a0987 100644 --- a/test_src/main-entropium-test.c +++ b/test_src/main-entropium-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-grain-test.c b/test_src/main-grain-test.c index d1de7ea..1cd10e1 100644 --- a/test_src/main-grain-test.c +++ b/test_src/main-grain-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" #include "cli.h" diff --git a/test_src/main-groestl-test.c b/test_src/main-groestl-test.c index 545f4eb..a2e9714 100644 --- a/test_src/main-groestl-test.c +++ b/test_src/main-groestl-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-hmac-md5-test.c b/test_src/main-hmac-md5-test.c index f61e119..fcf6dce 100644 --- a/test_src/main-hmac-md5-test.c +++ b/test_src/main-hmac-md5-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-hmac-sha1-test.c b/test_src/main-hmac-sha1-test.c index 33c0600..538d36a 100644 --- a/test_src/main-hmac-sha1-test.c +++ b/test_src/main-hmac-sha1-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-hmac-sha256-test.c b/test_src/main-hmac-sha256-test.c index 0cc773a..b6ca3fa 100644 --- a/test_src/main-hmac-sha256-test.c +++ b/test_src/main-hmac-sha256-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-md5-test.c b/test_src/main-md5-test.c index fdafb20..08c03cd 100644 --- a/test_src/main-md5-test.c +++ b/test_src/main-md5-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-mickey128-test.c b/test_src/main-mickey128-test.c index cd83212..cf30da5 100644 --- a/test_src/main-mickey128-test.c +++ b/test_src/main-mickey128-test.c @@ -4,7 +4,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" #include "cli.h" diff --git a/test_src/main-mugi-test.c b/test_src/main-mugi-test.c index d8f3898..7dd5691 100644 --- a/test_src/main-mugi-test.c +++ b/test_src/main-mugi-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-noekeon-test.c b/test_src/main-noekeon-test.c index a08f38f..fa0c323 100644 --- a/test_src/main-noekeon-test.c +++ b/test_src/main-noekeon-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-omac-noekeon-test.c b/test_src/main-omac-noekeon-test.c index 3df0d2e..117a2e1 100644 --- a/test_src/main-omac-noekeon-test.c +++ b/test_src/main-omac-noekeon-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-present-test.c b/test_src/main-present-test.c index 1ae9ad6..c7c65d2 100644 --- a/test_src/main-present-test.c +++ b/test_src/main-present-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-rc5-test.c b/test_src/main-rc5-test.c index e154020..640c65f 100644 --- a/test_src/main-rc5-test.c +++ b/test_src/main-rc5-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-rc6-test.c b/test_src/main-rc6-test.c index 57f249a..c3bb0f0 100644 --- a/test_src/main-rc6-test.c +++ b/test_src/main-rc6-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-seed-test.c b/test_src/main-seed-test.c index cd2a5e8..4e06559 100644 --- a/test_src/main-seed-test.c +++ b/test_src/main-seed-test.c @@ -27,7 +27,7 @@ * */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-serpent-test.c b/test_src/main-serpent-test.c index 142e993..896d879 100644 --- a/test_src/main-serpent-test.c +++ b/test_src/main-serpent-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-sha1-test.c b/test_src/main-sha1-test.c index cde507b..dc6f531 100644 --- a/test_src/main-sha1-test.c +++ b/test_src/main-sha1-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-sha256-test.c b/test_src/main-sha256-test.c index 61ee231..2312e95 100644 --- a/test_src/main-sha256-test.c +++ b/test_src/main-sha256-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-shabal-test.c b/test_src/main-shabal-test.c index b08d800..17f303f 100644 --- a/test_src/main-shabal-test.c +++ b/test_src/main-shabal-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-shabea-test.c b/test_src/main-shabea-test.c index 5a6c5fa..8605640 100644 --- a/test_src/main-shabea-test.c +++ b/test_src/main-shabea-test.c @@ -26,7 +26,7 @@ * */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-shacal1_enc-test.c b/test_src/main-shacal1_enc-test.c index 96aad56..137a35f 100644 --- a/test_src/main-shacal1_enc-test.c +++ b/test_src/main-shacal1_enc-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-shacal2_enc-test.c b/test_src/main-shacal2_enc-test.c index 6a8a4ea..c3e39c3 100644 --- a/test_src/main-shacal2_enc-test.c +++ b/test_src/main-shacal2_enc-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-skein-test.c b/test_src/main-skein-test.c index b1e8464..6ecf598 100644 --- a/test_src/main-skein-test.c +++ b/test_src/main-skein-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-skipjack-test.c b/test_src/main-skipjack-test.c index 2e31179..c37f2bc 100644 --- a/test_src/main-skipjack-test.c +++ b/test_src/main-skipjack-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-tdes-test.c b/test_src/main-tdes-test.c index dd025d0..ab6cd5e 100644 --- a/test_src/main-tdes-test.c +++ b/test_src/main-tdes-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-threefish-test.c b/test_src/main-threefish-test.c index f0af2b5..fd233bd 100644 --- a/test_src/main-threefish-test.c +++ b/test_src/main-threefish-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-trivium-test.c b/test_src/main-trivium-test.c index cbc3c7c..867f324 100644 --- a/test_src/main-trivium-test.c +++ b/test_src/main-trivium-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" #include "cli.h" diff --git a/test_src/main-twister-test.c b/test_src/main-twister-test.c index 0f6fc49..b4efd94 100644 --- a/test_src/main-twister-test.c +++ b/test_src/main-twister-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-ubi-test.c b/test_src/main-ubi-test.c index b9ae810..c7a0508 100644 --- a/test_src/main-ubi-test.c +++ b/test_src/main-ubi-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/main-xtea-test.c b/test_src/main-xtea-test.c index bc13d95..aaebdf3 100644 --- a/test_src/main-xtea-test.c +++ b/test_src/main-xtea-test.c @@ -22,7 +22,7 @@ */ #include "config.h" -#include "serial-tools.h" + #include "uart_i.h" #include "debug.h" diff --git a/test_src/serial-tools.c b/test_src/serial-tools.c deleted file mode 100644 index 6fb36bc..0000000 --- a/test_src/serial-tools.c +++ /dev/null @@ -1,84 +0,0 @@ -/* serial-tools.c */ -/* - This file is part of the AVR-Crypto-Lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - * - * Author: Daniel Otte - * Date: 16.05.2006 - * - * This tools should help to parse some input. - * - */ - -#include "config.h" -#include "uart_i.h" -#include -#include - -int getnextwordn(char *s, int n){ /* words are seperated by spaces, lf or cr */ - char c = ' '; - do{ - c=uart0_getc(); - }while(c==' ' || c=='\r' || c=='\n'); - *s++ = c; - do{ - *s++ = c = uart0_getc(); - }while(c!=' ' && c!='\r' && c!='\n' && --n); - *(s-1) = '\0'; - return n; -} - - -void readhex2buffer(void* buffer, int n){ - char c; - uint8_t i; - -// DEBUG_S("\r\nDBG: n="); DEBUG_B(n&0xff); DEBUG_S("\r\n"); - for(i=0; i=c){ - ((uint8_t*)buffer)[i] = c - '0'; - } else { - c &= ~('A' ^ 'a'); /* make all uppercase */ - if ('A'<= c && 'F'>=c){ - ((uint8_t*)buffer)[i] = c - 'A' + 10; - } else { - /* oh shit, wrong char */ - } - } - - ((uint8_t*)buffer)[i] <<= 4; - - c = uart0_getc(); - if ('0'<= c && '9'>=c){ - ((uint8_t*)buffer)[i] |= c - '0'; - } else { - c &= ~('A' ^ 'a'); /* make all uppercase */ - if ('A'<= c && 'F'>=c){ - ((uint8_t*)buffer)[i] |= c - 'A' + 10; - } else { - /* oh shit, wrong char */ - } - } - } /* for i=0 .. n */ -} - -void uart0_putptr(void* p){ - uart0_hexdump((void*) &p,2); -} - diff --git a/test_src/shavs.c b/test_src/shavs.c index b6cd4e1..5712be5 100644 --- a/test_src/shavs.c +++ b/test_src/shavs.c @@ -1,7 +1,7 @@ /* shavs.c */ /* This file is part of the AVR-Crypto-Lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + Copyright (C) 2006 2007 2008 2009 Daniel Otte (daniel.otte@rub.de) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "hashfunction_descriptor.h" #include "hfal-basic.h" @@ -34,6 +35,18 @@ #include "string-extras.h" #include "cli.h" + +#ifdef DEBUG +# undef DEBUG +#endif + +#define DEBUG 0 + +#if DEBUG +# include "config.h" +# include +#endif + hfdesc_t* shavs_algo=NULL; hfdesc_t** shavs_algolist=NULL; @@ -86,144 +99,175 @@ void shavs_setalgo(char* param){ } } -static uint16_t buffer_idx=0; -static uint8_t in_byte=0; -static uint16_t blocks=0; -static uint8_t* buffer; -static uint16_t buffersize_B; -static hfgen_ctx_t ctx; +typedef struct { + uint16_t buffer_idx; + uint16_t buffersize_B; + uint32_t blocks; + hfgen_ctx_t ctx; + uint8_t* buffer; + uint8_t in_byte; +} shavs_ctx_t; + +static shavs_ctx_t shavs_ctx; -static uint8_t buffer_add(char c){ uint8_t v,t; - if(buffer_idx==buffersize_B){ - hfal_hash_nextBlock(&ctx, buffer); - ++blocks; - buffer_idx=0; - in_byte=0; + if(shavs_ctx.buffer_idx==shavs_ctx.buffersize_B){ + hfal_hash_nextBlock(&(shavs_ctx.ctx), shavs_ctx.buffer); + ++shavs_ctx.blocks; + shavs_ctx.buffer_idx=0; + shavs_ctx.in_byte=0; + cli_putc('.'); } if(c>='0' && c<='9'){ v=c-'0'; }else{ - if(c>='a' && c<='f'){ - v=c-'a'+10; + c &= (uint8_t)~('a' ^ 'A'); + if(c>='A' && c<='F'){ + v=c-'A'+10; }else{ - if(c>='A' && c<='F'){ - v=c-'A'+10; - }else{ - return 1; - } + return 1; } } - t=buffer[buffer_idx]; - if(in_byte){ + t=shavs_ctx.buffer[shavs_ctx.buffer_idx]; + if(shavs_ctx.in_byte){ t = (t&0xF0) | v; - buffer[buffer_idx]=t; - buffer_idx++; + shavs_ctx.buffer[shavs_ctx.buffer_idx]=t; + shavs_ctx.buffer_idx++; }else{ t = (t&0x0F) | (v<<4); - buffer[buffer_idx]=t; + shavs_ctx.buffer[shavs_ctx.buffer_idx]=t; } - in_byte ^= 1; + shavs_ctx.in_byte ^= 1; return 0; } -void shavs_test1(void){ +int32_t getLength(void){ + uint32_t len=0; char lenstr[21]; char* len2; + for(;;){ + memset(lenstr, 0, 21); + cli_getsn_cecho(lenstr, 20); + len2 = strstrip(lenstr); + if(!strncasecmp_P(len2, PSTR("LEN"), 3)){ + while(*len2 && *len2!='=') + len2++; + if(*len2=='='){ + do{ + len2++; + }while(*len2 && !isdigit(*len2)); + len=(uint32_t)strtoul(len2, NULL, 10); + return len; + } + } else { + if(!strncasecmp_P(len2, PSTR("EXIT"), 4)){ + return -1; + } + } + } +} + +void shavs_test1(void){ uint32_t length=0; - uint8_t len_set=0; + int32_t expect_input=0; + if(!shavs_algo){ cli_putstr_P(PSTR("\r\nERROR: select algorithm first!")); return; } - - buffersize_B=pgm_read_word(&(shavs_algo->blocksize_b))/8; - cli_putstr_P(PSTR("\r\nbuffer allocated for 0x")); - cli_hexdump(&buffersize_B, 2); + uint8_t diggest[pgm_read_word(shavs_algo->hashsize_b)/8]; + shavs_ctx.buffersize_B=pgm_read_word(&(shavs_algo->blocksize_b))/8; + uint8_t buffer[shavs_ctx.buffersize_B]; + shavs_ctx.buffer = buffer; + cli_putstr_P(PSTR("\r\nbuffer_size = 0x")); + cli_hexdump_rev(&(shavs_ctx.buffersize_B), 2); cli_putstr_P(PSTR(" bytes")); - buffer = malloc(buffersize_B); - if(buffer==NULL){ - cli_putstr_P(PSTR("\r\n allocating memory for buffer failed!")); - return; - } for(;;){ - blocks = 0; - do{ - cli_putstr_P(PSTR("\r\n")); - cli_getsn(lenstr, 20); - len2 = strstrip(lenstr); - if(!strncasecmp_P(len2, PSTR("LEN"), 3)){ - while(*len2 && *len2!='=') - len2++; - if(*len2=='='){ - len2++; - length=strtoul(len2, NULL, 0); - len_set=1; - } - } else { - if(!strncasecmp_P(len2, PSTR("EXIT"), 4)){ - free(buffer); - return; - } - } - }while(!len_set); - volatile int32_t expect_input; + shavs_ctx.blocks = 0; char c; + length = getLength(); + if(length<0){ + return; + } +#if DEBUG + cli_putstr_P(PSTR("\r\nLen == ")); + cli_hexdump_rev(&length, 4); +#endif if(length==0){ expect_input=2; }else{ - expect_input=((length+7)/8)*2; + expect_input=((length+7)>>2)&(~1L); } - - buffer_idx = 0; - in_byte=0; - len_set = 0; +#if DEBUG + cli_putstr_P(PSTR("\r\nexpected_input == ")); + cli_hexdump_rev(&expect_input, 4); + if(expect_input==0) + cli_putstr_P(PSTR("\r\nexpected_input == 0 !!!")); +#endif + shavs_ctx.buffer_idx = 0; + shavs_ctx.in_byte = 0; + shavs_ctx.blocks = 0; uint8_t ret; -// cli_putstr_P(PSTR("\r\n HFAL init")); - ret = hfal_hash_init(shavs_algo, &ctx); +#if DEBUG + cli_putstr_P(PSTR("\r\n HFAL init")); + cli_putstr_P(PSTR("\r\n (2) expected_input == ")); + cli_hexdump_rev(&expect_input, 4); +#endif + ret = hfal_hash_init(shavs_algo, &(shavs_ctx.ctx)); + //ret=0; if(ret){ cli_putstr_P(PSTR("\r\n HFAL init returned with: ")); cli_hexdump(&ret, 1); - free(buffer); return; } -// cli_putstr_P(PSTR("\r\n")); +#if DEBUG + cli_putstr_P(PSTR("\r\n (3) expected_input == ")); + cli_hexdump_rev(&expect_input, 4); + cli_putstr_P(PSTR("\r\n")); +#endif while((c=cli_getc_cecho())!='M' && c!='m'){ if(!isblank(c)){ cli_putstr_P(PSTR("\r\nERROR: wrong input (1) [0x")); cli_hexdump(&c, 1); cli_putstr_P(PSTR("]!\r\n")); - free(buffer); + hfal_hash_free(&(shavs_ctx.ctx)); return; } } if((c=cli_getc_cecho())!='s' && c!='S'){ cli_putstr_P(PSTR("\r\nERROR: wrong input (2)!\r\n")); - free(buffer); + hfal_hash_free(&(shavs_ctx.ctx)); return; } if((c=cli_getc_cecho())!='g' && c!='G'){ cli_putstr_P(PSTR("\r\nERROR: wrong input (3)!\r\n")); - free(buffer); + hfal_hash_free(&(shavs_ctx.ctx)); return; } while((c=cli_getc_cecho())!='='){ if(!isblank(c)){ cli_putstr_P(PSTR("\r\nERROR: wrong input (4)!\r\n")); - free(buffer); + hfal_hash_free(&(shavs_ctx.ctx)); return; } } - - buffer_idx=0; +#if DEBUG + cli_putstr_P(PSTR("\r\nparsing started")); +#endif + shavs_ctx.buffer_idx = 0; + shavs_ctx.in_byte = 0; + shavs_ctx.blocks = 0; while(expect_input>0){ c=cli_getc_cecho(); - cli_putstr_P(PSTR("+(")); - cli_hexdump_rev((uint8_t*)&expect_input, 4); +#if DEBUG + cli_putstr_P(PSTR("\r\n\t(")); + cli_hexdump_rev(&expect_input, 4); cli_putstr_P(PSTR(") ")); + _delay_ms(500); +#endif if(buffer_add(c)==0){ --expect_input; }else{ @@ -231,23 +275,38 @@ void shavs_test1(void){ cli_putstr_P(PSTR("\r\nERROR: wrong input (5) (")); cli_putc(c); cli_putstr_P(PSTR(")!\r\n")); - free(buffer); + hfal_hash_free(&(shavs_ctx.ctx)); return; } } } -// cli_putstr_P(PSTR("\r\n starting finalisation")); - uint8_t diggest[pgm_read_word(shavs_algo->hashsize_b)/8]; -// cli_putstr_P(PSTR("\r\n starting last block")); - hfal_hash_lastBlock(&ctx, buffer, length-blocks*(buffersize_B*8)); -// cli_putstr_P(PSTR("\r\n starting ctx2hash")); - hfal_hash_ctx2hash(diggest, &ctx); -// cli_putstr_P(PSTR("\r\n starting hash free")); - hfal_hash_free(&ctx); +#if DEBUG + cli_putstr_P(PSTR("\r\n starting finalisation")); + cli_putstr_P(PSTR("\r\n\tblocks == ")); + cli_hexdump_rev(&(shavs_ctx.blocks),4); + cli_putstr_P(PSTR("\r\n\tbuffer_idx == ")); + cli_hexdump_rev(&(shavs_ctx.buffer_idx),2); + cli_putstr_P(PSTR("\r\n\tin_byte == ")); + cli_hexdump_rev(&(shavs_ctx.in_byte),1); + _delay_ms(500); + + cli_putstr_P(PSTR("\r\n starting last block")); +#endif + hfal_hash_lastBlock( &(shavs_ctx.ctx), + shavs_ctx.buffer, + length-(shavs_ctx.blocks)*((shavs_ctx.buffersize_B)*8)); +#if DEBUG + cli_putstr_P(PSTR("\r\n starting ctx2hash")); + _delay_ms(500); +#endif + hfal_hash_ctx2hash(diggest, &(shavs_ctx.ctx)); +#if DEBUG + cli_putstr_P(PSTR("\r\n starting hash free")); +#endif + hfal_hash_free(&(shavs_ctx.ctx)); cli_putstr_P(PSTR("\r\n MD = ")); cli_hexdump(diggest, pgm_read_word(&(shavs_algo->hashsize_b))/8); } - free(buffer); }