]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - host/nessie_check.rb
new and more compact aes
[avr-crypto-lib.git] / host / nessie_check.rb
index 9ec83b2560539ba1f11f0bd62a633a21f0cd15e0..3af1dfa3dbb3b99a6e023d57ae3463db7cd2be66 100644 (file)
@@ -1,8 +1,8 @@
-#!/usr/bin/ruby 
+#!/usr/bin/ruby
 # nessie_check.rb
 =begin
     This file is part of the AVR-Crypto-Lib.
-    Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
+    Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
 
     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
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 =end
 
+$debug = true
+
 def skip_header(file)
   begin
     l = file.gets().strip
+    l = '' if !l
   end until /[*]{10,}.*/.match(l)
-  puts("DBG 0.0: "+l)
   begin
     l = file.gets().strip
+    l = '' if !l
   end until /[*]{10,}.*/.match(l)
-  puts("DBG 0.1: "+l)
   begin
     l = file.gets().strip
+    l = '' if !l
   end until /[=]{5,}.*/.match(l)
-  puts("DBG 0.2: "+l)
   begin
     l = file.gets().strip
+    l = '' if !l
   end until /[=]{5,}.*/.match(l)
-  puts("DBG 0.3: "+l)  
 end
 
 def get_next_assign(file, i)
@@ -51,7 +53,7 @@ def get_next_assign(file, i)
          return nil if file.eof
          l = file.gets().strip()
          if not /[^=]+=[^=]+/.match(l)
-           value += l if /[0-9A-Fa-f]{5}/.match(l)
+           value += l if /^[0-9A-Fa-f]{5}/.match(l)
          end
     end until /[^=]+=[^=]+/.match(l)
        $last_assign[i] = l
@@ -63,7 +65,7 @@ def get_next_assign(file, i)
          return nil if file.eof
          l = file.gets().strip()
          if not /[^=]+=[^=]+/.match(l)
-           value += l if /[0-9A-Fa-f]{5}/.match(l)
+           value += l if /^[0-9A-Fa-f]{5}/.match(l)
          end
     end until /[^=]+=[^=]+/.match(l)
        $last_assign[i] = l
@@ -82,17 +84,16 @@ def compare(fname1, fname2)
     a = get_next_assign(file1, 0)
     b = get_next_assign(file2, 1)
        return if(a==nil or b==nil)
-       puts("") if pos%$linewidth==0 and pos!=0
-       putc((a==b)?'*':'!')
-#      puts("a == nil") if a==nil
-#      puts("b == nil") if b==nil
-       
+       if not $quiet
+      puts("") if pos%$linewidth==0 and pos!=0
+         putc((a==b)?'*':'!')
+      pos +=1
+       end
        if(a!=b and a!=nil and b!=nil)
-         $error = 1
-         puts("a key: "+a[0]+" value: "+a[1])
-         puts("b key: "+b[0]+" value: "+b[1])
-       end     
-       pos +=1
+         $error += 1
+         puts("a key: "+a[0]+" value: "+a[1]) if $debug
+         puts("b key: "+b[0]+" value: "+b[1]) if $debug
+       end
   end until a==nil or b==nil
 end
 
@@ -100,14 +101,30 @@ $error = 0
 $linewidth=64
 $last_assign=[nil, nil]
 
-if ARGV.size!=2
+if ARGV.size<2 or ARGV.size>3
   STDERR.print <<EOF
-  Usage: ruby #{$0} file1 file2
+  Usage: ruby #{$0} [-q|-v] file1 file2
 EOF
   exit(1)
 end
-puts("compare("+ARGV[1]+", "+ARGV[0]+")")
-compare(ARGV[1], ARGV[0])
-puts($error==0?"[ok]":"[failed]")
+$quiet = false
+if ARGV.size==3
+  f1 = ARGV[1]
+  f2 = ARGV[2]
+  if ARGV[0]=="-q"
+    $quiet=true
+  end
+else
+  f1 = ARGV[0]
+  f2 = ARGV[1]
+end
+
+puts("compare("+f1+", "+f2+")")
+compare(f1, f2)
+if $error!=0
+  puts("[failed] ("+$error.to_s()+")")
+else
+  puts("[ok]")
+end
 
 exit($error)