]> git.cryptolib.org Git - avr-crypto-lib.git/commitdiff
[blake] fixing bugs and removing bug compatibility mode
authorbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Tue, 10 Nov 2009 19:37:44 +0000 (19:37 +0000)
committerbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Tue, 10 Nov 2009 19:37:44 +0000 (19:37 +0000)
blake/blake_large.c
blake/blake_small.c
host/shavs_test2.rb

index b3d6dac5bd3cace105ec79da43cc68f78af24780..7daa26174a7dfef38cb9853a31532853b1286b19 100644 (file)
 #include "blake_large.h"
 #include "blake_common.h"
 
-#include "cli.h"
-
-#define BUG_3 0 /* bug compatibility with reference code */
-#define BUG_4 0 /* bug compatibility with reference code */
-
 uint64_t pgm_read_qword(void* p){
        union{
                uint64_t v64;
@@ -91,11 +86,8 @@ void blake_large_changeendian(void* dest, const void* src){
 void blake_large_compress(uint64_t* v,const void* m){
        uint8_t r,i;
        uint8_t a,b,c,d, s0, s1;
-//     cli_putstr_P(PSTR("\r\nblock:"));
-//     cli_hexdump_block(m, 128, 5, 8);
        for(r=0; r<14; ++r){
                for(i=0; i<8; ++i){
-       //              blake_large_g(r%10, i, v, (uint64_t*)m);
                        a = pgm_read_byte(blake_index_lut+4*i+0);
                        b = pgm_read_byte(blake_index_lut+4*i+1);
                        c = pgm_read_byte(blake_index_lut+4*i+2);
@@ -111,15 +103,6 @@ void blake_large_compress(uint64_t* v,const void* m){
                        v[c] += v[d];
                        v[b]  = ROTR64(v[b]^v[c], 11);
                }
-/*
-               cli_putstr_P(PSTR("\r\nv:"));
-               for(i=0; i<16; ++i){
-                       if(i%4==0)
-                               cli_putstr_P(PSTR("\r\n    "));
-                       cli_hexdump_rev(&(v[i]), 8);
-                       cli_putc(' ');
-               }
-*/
        }
 }
 
@@ -162,31 +145,18 @@ void blake_large_lastBlock(blake_large_ctx_t* ctx, const void* msg, uint16_t len
        buffer[length_b/8] |= 0x80 >> (length_b&0x7);
        blake_large_changeendian(buffer, buffer);
        blake_large_expand(v, ctx);
-#if BUG_3
-       uint8_t x=0;
-       if(length_b%1024<895 && length_b%8)
-               x=0x40;
-       v[12] ^= ctr + x;
-       v[13] ^= ctr + x;
-
-#else
-       if(length_b){
+       if(length_b>1024-128-2){
                v[12] ^= ctr;
                v[13] ^= ctr;
-       }
-#endif
-       if(length_b>1024-128-2){
-#if BUG_4
-               if(length_b<1017){
-                       blake_large_compress(v, buffer);
-                       blake_large_collapse(ctx, v);
-               }
-#else
                blake_large_compress(v, buffer);
                blake_large_collapse(ctx, v);
-#endif
                memset(buffer, 0, 128-8);
                blake_large_expand(v, ctx);
+       } else {
+               if(length_b){
+                       v[12] ^= ctr;
+                       v[13] ^= ctr;
+               }
        }
        if(ctx->appendone)
                buffer[128-16-8] |= 0x01;
index 874a513ea5e53179af7d6251dc165169966b24ee..b25da516c66a2053ec99d94ca4123364a329a2c4 100644 (file)
@@ -160,12 +160,14 @@ void blake_small_lastBlock(blake_small_ctx_t* ctx, const void* msg, uint16_t len
        buffer[length_b/8] |= 0x80 >> (length_b&0x7);
        blake_small_changeendian(buffer, buffer);
        blake_small_expand(v, ctx);
-if(length_b){
+/*
+if(length_b<505 && length_b){
        v[12] ^= ctr.v32[0];
        v[13] ^= ctr.v32[0];
        v[14] ^= ctr.v32[1];
        v[15] ^= ctr.v32[1];
 }
+*/
 #if BUG_2
        if(length_b>=505)
                ctr.v32[0] = tmp;
@@ -177,10 +179,21 @@ if(length_b){
        }
 #endif
        if(length_b>512-64-2){
+               v[12] ^= ctr.v32[0];
+               v[13] ^= ctr.v32[0];
+               v[14] ^= ctr.v32[1];
+               v[15] ^= ctr.v32[1];
                blake_small_compress(v, buffer);
                blake_small_collapse(ctx, v);
                memset(buffer, 0, 64-8);
                blake_small_expand(v, ctx);
+       }else{
+               if(length_b){
+                       v[12] ^= ctr.v32[0];
+                       v[13] ^= ctr.v32[0];
+                       v[14] ^= ctr.v32[1];
+                       v[15] ^= ctr.v32[1];
+               }
        }
        if(ctx->appendone)
                buffer[64-8-4] |= 0x01;
index f6e4af1d5873c79fbd32f98a3322bc739cfbc089..ad242f4445b81a671b190666e573a89c51248085 100644 (file)
@@ -68,18 +68,11 @@ def scan_system
 end
 
 def init_system(algo_select)
-#  sleep 1
   $sp.print("echo off \r")
   print("DBG i: " + "echo off \r"+"\n") if $debug
-#  line = $sp.readlines()
-#  print("DBG 0.0: ")
-#  print(line)
-  sleep 1
+ sleep 1
   $sp.print("shavs_set #{algo_select}\r")
   print("DBG i: " + "shavs_set #{$algo_select} \r"+"\n") # if $debug
-#  line = $sp.readlines()
-#  print("DBG 0.1: ")
-#  print(line)
   sleep 1
   $sp.print("shavs_test1 \r")
   print("DBG i: " + "shavs_test1 \r"+"\n") if $debug
@@ -87,9 +80,6 @@ def init_system(algo_select)
     line=$sp.gets()
   end while not m=/buffer_size[\s]*=[\s]*0x([0-9A-Fa-f]*)/.match(line)
   $buffer_size = m[1].to_i(16)
-#  line = $sp.readlines()
-#  print("DBG 0.2: ")
-#  print(line)
 end
 
 def get_md
@@ -102,18 +92,19 @@ def get_md
 end
 
 def send_md(md_string)
+  $sp.print("Msg = ")
   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%$buffer_size==$buffer_size-1)
-               begin
-                       line=$sp.gets()
-               end while not /\./.match(line)
+       if((i%($buffer_size*2)==0)&&(i!=0))
+         begin
+               line=$sp.gets()
+         end while not /\./.match(line)
        end
   end
 end
 
-def run_test(filename)
+def run_test(filename, skip=0)
   nerrors = 0
   line=1
   if not File.exist?(filename)
@@ -123,20 +114,24 @@ def run_test(filename)
   pos = 0
   file = File.new(filename, "r");
   until file.eof
-    sleep(0.5)
     begin
       lb=file.gets()
     end while not (file.eof or (/[\s]*Len[\s]*=.*/.match(lb)))
+    len = /[\s]*Len[\s]*=[\s]*([0-9]*)/.match(lb)[1].to_i
     puts("DBG sending: "+lb) if $debug
        return if file.eof
+       if(skip>0)
+         skip -= 1
+         redo
+       end
        $sp.print(lb.strip)
        $sp.print("\r")
     begin
          lb=file.gets()
-    end while not (file.eof or (/[\s]*Msg[\s]*=.*/.match(lb)))
+    end while not (file.eof or (m=/[\s]*Msg[\s]*=[\s]*([0-9a-fA-F]*)/.match(lb)))
     return if file.eof
     puts("DBG sending: "+lb) if $debug
-       send_md(lb.strip)
+       send_md(m[1])
        avr_md = get_md()
     begin
          lb=file.gets()
@@ -145,15 +140,15 @@ def run_test(filename)
        b = (/[\s]*MD[\s]*=[\s]*([0-9a-fA-F]*).*/.match(avr_md))[1];
        a.upcase!
        b.upcase!
-       printf("\n%4d (%4d): ", line, (line-1)*$linewidth) if (pos%$linewidth==0 and $linewidth!=0)
+       printf("\n%4d (%4d) [%5d]: ", line, (line-1)*$linewidth, len) if (pos%$linewidth==0 and $linewidth!=0)
        line += 1               if (pos%$linewidth==0 and $linewidth!=0)
-       sleep(1)
+       #sleep(1)
        #putc((a==b)?'*':'!')
        if(a==b)
          putc('*')
        else
          putc('!')
-         printf("\nshould: %s\ngot:   %s\n",lb,avr_md)
+         printf("<%d>",len)
          nerrors += 1
        end
        pos += 1
@@ -165,7 +160,7 @@ conf = Hash.new
 conf = readconfigfile("/etc/testport.conf", conf)
 conf = readconfigfile("~/.testport.conf", conf)
 conf = readconfigfile("testport.conf", conf)
-puts conf.inspect
+#puts conf.inspect
 
 puts("serial port interface version: " + SerialPort::VERSION);
 $linewidth = 64
@@ -190,14 +185,13 @@ $sp = SerialPort.new(conf["PORT"]["port"], params)
 
 $sp.read_timeout=1000; # 5 minutes
 $sp.flow_control = SerialPort::SOFT
-#$algo_select = ARGV[4]
-#irb
 
 reset_system()
 algos=scan_system()
-puts algos.inspect
+#puts algos.inspect
 
-algos.each_key do |algo|
+algos.sort.each do |algoa|
+  algo = algoa[0]
   if conf[algo]==nil
     puts("No test-set defined for #{algo} \r\n")
     next
@@ -207,8 +201,8 @@ algos.each_key do |algo|
        while conf[algo]["file_#{i}"] != nil
          puts("Testing #{algo} with #{conf[algo]["file_#{i}"]}")
          reset_system()
-         init_system(algos[algo])
-         nerrors=run_test(conf[algo]["file_#{i}"])
+         init_system(algoa[1])
+         nerrors=run_test(conf[algo]["file_#{i}"], 0)
       if nerrors == 0
         puts("\n[ok]")
         logfile.puts("[ok] "+conf[algo]["file_#{i}"]+ " ("+Time.now.to_s()+")")