]> git.cryptolib.org Git - avr-crypto-lib.git/commitdiff
verification seems to work now...
authorbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Thu, 5 Nov 2009 05:33:56 +0000 (05:33 +0000)
committerbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Thu, 5 Nov 2009 05:33:56 +0000 (05:33 +0000)
53 files changed:
avr-makefile.inc
bmw/bmw_small.c
hfal-basic.c
host/shavs_test.rb
test_src/cli-basics.S
test_src/cli-hexdump.S
test_src/cli-stub.c
test_src/cli.h
test_src/main-a5_1-test.c
test_src/main-aes-test.c
test_src/main-aes128-test.c
test_src/main-aes192-test.c
test_src/main-aes256-test.c
test_src/main-arcfour-test.c
test_src/main-base64-test.c
test_src/main-blake-test.c
test_src/main-bmw-test.c
test_src/main-camellia-test.c
test_src/main-cast5-test.c
test_src/main-cast6-test.c
test_src/main-des-test.c
test_src/main-entropium-test.c
test_src/main-grain-test.c
test_src/main-groestl-test.c
test_src/main-hmac-md5-test.c
test_src/main-hmac-sha1-test.c
test_src/main-hmac-sha256-test.c
test_src/main-md5-test.c
test_src/main-mickey128-test.c
test_src/main-mugi-test.c
test_src/main-noekeon-test.c
test_src/main-omac-noekeon-test.c
test_src/main-present-test.c
test_src/main-rc5-test.c
test_src/main-rc6-test.c
test_src/main-seed-test.c
test_src/main-serpent-test.c
test_src/main-sha1-test.c
test_src/main-sha256-test.c
test_src/main-shabal-test.c
test_src/main-shabea-test.c
test_src/main-shacal1_enc-test.c
test_src/main-shacal2_enc-test.c
test_src/main-skein-test.c
test_src/main-skipjack-test.c
test_src/main-tdes-test.c
test_src/main-threefish-test.c
test_src/main-trivium-test.c
test_src/main-twister-test.c
test_src/main-ubi-test.c
test_src/main-xtea-test.c
test_src/serial-tools.c [deleted file]
test_src/shavs.c

index 9b6ea710e11dd1f3a3ce5ea259c1f595341b6732..bb39deb0d0c9abcceabd916537c232a248d39701 100644 (file)
@@ -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
index e24fb7cf49a79248168b9c1036f40b1e673256d8..8a4b1652734605710eddee45eae90683b3346045 100644 (file)
 #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 };
index 1be95d37baf310735a7ddb067773fb8473a60c7b..82c040bca00425931d525583e695a20308921017 100644 (file)
 
 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;
index 3960bce443138c246f5f836dcab5f8a87d7f0018..e5e3a43c375d4656b24a3551fc7a8d3db37996a2 100644 (file)
 =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('*')
index e3cefc74cd52fa0c6220ed592738520a17db1113..363b396eb87e6d9864d1425b696d37445bc77e36 100644 (file)
@@ -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
index 0a34984ffd344bd97909e327463af47edad0b159..89767093fe4846ab040db29c1fdb1489168414e5 100644 (file)
@@ -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
-       
-       
+
+
index ccbb7ba8d9b2106394fd17690f8067c02695524e..1db56168a59baf2c5f097c17ac5bd42b7193906b 100644 (file)
@@ -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:
index dc79a7da16c1aee0f333ef4c5961a3a3a2d73ef6..5fb2a1711eaf20d16ef4e5a592ff38a1ff3bb1da 100644 (file)
@@ -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);
index c0803755cd3d55c77d5fe5ca85a4f39fbfc4de5d..6a0edc8d7db6a794f97d5330b6bf063ac07c42e5 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 765411bf7594b6da3ec6bf5faa875983a706747c..e2d3685d6e0ec813dcac488e06053143b71a435f 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 98462a19c3831057d07cce3ce2ffb65a34169be7..ce9468f1c4d65c1ec70904e67b3c32c7b744e96e 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index c37dc7e967b51b51d36029f4ed845162fdfe21b5..850d773956e0311d7d4aed76b6c8f7ec2f207434 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 15d7f838a31ed0937487ce02206df401dd7073fb..53c4fe60448f4dd1db7ca2c60c620e668893f064 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 7e5489220743ca22447c97027dfb7979fb51b396..e66a1d4b13957caa0b4da1100f2674453730d0f1 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index a4ce3f38b8146d066007d8dd575fda27c4a44d3e..caf60fa4723864f485add9cea8836a7e3795e684 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 379ba2bea2a2cc142327ee638e38b6720287d771..9ee75f5de25fadbc8b3cd06f9145dbd023f6d402 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 3228817a9358008dddcda6d5f0b3901f83e7d803..efd48293cf80c403e4845843be75d012d265503d 100644 (file)
@@ -22,7 +22,6 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
 #include "uart_i.h"
 #include "debug.h"
 
index 2401557d59fe0000cb610d2886e65abf1536f3a5..2cc64390858b0dd4cba03d9c3b222100eee72e23 100644 (file)
@@ -22,7 +22,7 @@
  */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index fe5915cf660b48346198d874b20af15186fe4bf4..a8f88900e2ec341e362cb14eba82da359e0aa413 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index d13a100cdf0c9238f271dc5d4e16e4810ce184f8..27e047892aa40b8b6c72322b9bdbde75a304ac32 100644 (file)
@@ -4,7 +4,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 5ccf7b66204a28bc30a524f065bd8f8c0df33f29..a674d6e56485a5d655c1235cb1d06b7c2c1e4f14 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 50ad2b191703659fb8b0325eec9544b62dadce18..36a098754b0087e41b7ef5ce7fc326635f364e53 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index d1de7eafed7a8d5246dada45d571e437b7ead813..1cd10e182cec4012ae089511c7db80cc0a7b3220 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 #include "cli.h"
index 545f4eb2eca48848ecd584117a2687a8a49cded9..a2e9714763121d187a3090ea3f4ba87b67ad254a 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index f61e1191ad28107d0d92a8acfc8c0770bd9b5c93..fcf6dcec1cb0b917b0192ff0b224bd2a804a359c 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 33c06006bae780e4aee2abc6e69b621ca612e899..538d36accc255d460524278b4e6dc4fe499bfd32 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 0cc773af58f97b41fb0f98eb37f609d037f06132..b6ca3fab23057b8e42335389332580c6e0b649f9 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index fdafb204e517b27992cf805a034dfe9fe62c872c..08c03cd620f2db282d761175696ed0d070418fbe 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index cd83212a859431e67df676cf2a7c10c35b49873a..cf30da5ada43aab5b4d31853b307b1cd796ddb64 100644 (file)
@@ -4,7 +4,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 #include "cli.h"
index d8f38985419b67821a9fc6da5542df66c73bad8a..7dd5691fd4cac51983c22469a9800c3332b1f91e 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index a08f38ff3271d8c1089e541902ce665c9ee624dc..fa0c3238cc035c7d5691b7252121e1fb2d813b61 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 3df0d2e754cfc5aa26740d6e627a24b0ab9a4977..117a2e14fca3d2e35c8211e6b1edeb3ccfb0fe82 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 1ae9ad60924f90c313b6c5ca47417529bb72e744..c7c65d23639179613c9d6463ebd577d0daee6359 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index e154020e948117cdf42b26b94c19fbc91897bae6..640c65fc15614d1172e35d9730923d9c4879df5f 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 57f249ada23912ed1cb0bf5d2a02575902c93957..c3bb0f029789fb855157c2cd8de6adb460234069 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index cd2a5e859acb72a5c9b3da261d04a498cfbcf8d0..4e0655965ef2f581937b8c3151958db29d6e689b 100644 (file)
@@ -27,7 +27,7 @@
  * 
  */
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 142e993fa0c6ee4d8c133f259c57ab78139e1113..896d879b22afac2211a81eb67e869b5e4fe37f43 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index cde507b81873527801ee83196bff7dd9d05a4738..dc6f5315d663b22a771ccfffbede6f466ae57954 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 61ee2313e6666d048c0c4564fbca0e3eb56340c2..2312e95f63b98358a58a50f0671cb26dcfb17b71 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index b08d800e6c2f74dc4606bfc39023affea60d4266..17f303f636c4cae39322a72e2f2ba3490cc649d0 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 5a6c5fa273c1aa7d524f955b897e4b50722c6927..8605640271c9b2127df660567944091f9ffc8de8 100644 (file)
@@ -26,7 +26,7 @@
  * 
  */
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 96aad56a267f2876e35d821434e8e5ec9ffc798a..137a35f998bc0318059776973d1e0b7d6b7a32eb 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 6a8a4eadd29011e35bd6a0a43966f9b60353b8fa..c3e39c38b65890d41344984f9c63fedaaddabdf1 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index b1e846406021ca2161dd9e1293533cb576e24787..6ecf5988d683f143dab05463bd8f0dba61dee1c5 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index 2e311792554dc5a8f68bf05555c9068036350775..c37f2bc16680ee787405f8109a66536a1e15667d 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index dd025d03ec0c0c8fba174389fcc38aae36f16579..ab6cd5e88bbacd9a82c8cc4d493e9e964b5dcb6f 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index f0af2b526d1239d1da4f348df749ed78543fe984..fd233bd451e94a5f324a924c03848aefd4fd7934 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index cbc3c7cd96ebcf68770e790be59c12e6810fca41..867f32487f449a28aa6a83a777884ad855f4fb90 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 #include "cli.h"
index 0f6fc492772b8b7f840413ba0c4674d2f33a7092..b4efd944763823e7b4e4392cdb9d4e49ba6a93fa 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index b9ae8103364fc0445a8793e1b787296a2595123b..c7a050839e172f174093d30ccd726eb7e5fbbf8c 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "config.h"
-#include "serial-tools.h"
+
 #include "uart_i.h"
 #include "debug.h"
 
index bc13d95dcf1cf15942760dd3d905a90941145b3f..aaebdf35d72476d97c0eca03f1fbf461fc07f6d1 100644 (file)
@@ -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 (file)
index 6fb36bc..0000000
+++ /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 <http://www.gnu.org/licenses/>.
-*/
-/**
- * 
- * Author:     Daniel Otte
- * Date:               16.05.2006
- * 
- * This tools should help to parse some input. 
- * 
- */
-
-#include "config.h"
-#include "uart_i.h"
-#include <string.h>
-#include <stdint.h>
-
-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<n; ++i){
-               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 */
-                       }
-               }
-               
-               ((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);
-}
-
index b6cd4e1873950e7f724027d942358a7f67912fc2..5712be5f1c4f07e2eff3a1b47576fdde19306625 100644 (file)
@@ -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 <avr/pgmspace.h>
 #include <stdint.h>
 #include <stdlib.h>
+#include <string.h>
 #include <ctype.h>
 #include "hashfunction_descriptor.h"
 #include "hfal-basic.h"
 #include "string-extras.h"
 #include "cli.h"
 
+
+#ifdef DEBUG
+#  undef DEBUG
+#endif
+
+#define DEBUG 0
+
+#if DEBUG
+#  include "config.h"
+#  include <util/delay.h>
+#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);
 }