]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - host/bigint_test.rb
adding RSA-OAEP
[avr-crypto-lib.git] / host / bigint_test.rb
index cb9de13d19aa144d6f0ac2e48dd8d99b52ffbe8e..d942b3748737cc6ca5bbdd8f76a6f67507a1487c 100644 (file)
@@ -23,7 +23,7 @@ $debug = false
 require 'rubygems'
 require 'serialport'
 require 'getopt/std'
-require 'ftools'
+require 'fileutils'
 require 'date'
 $buffer_size = 0
 $conffile_check = Hash.new
@@ -37,7 +37,7 @@ def readconfigfile(fname, conf)
   return conf if $conffile_check[fname]==1
   $conffile_check[fname]=1
   section = "default"
-  if not File.exists?(fname)
+  if ! File.exists?(fname)
     return conf
   end
   file = File.open(fname, "r")
@@ -49,7 +49,7 @@ def readconfigfile(fname, conf)
          conf[m[1]] = Hash.new
          next
        end
-       next if not /=/.match(line)
+       next if ! /=/.match(line)
        m=/[\s]*([^\s]*)[\s]*=[\s]*([^\s]*)/.match(line)
        if m[1]=="include"
          Dir.glob(m[2]){ |fn| conf = readconfigfile(fn, conf) }
@@ -145,6 +145,7 @@ end
 def wait_for_prompt(prompt)
   prompt = /[\s]*#{prompt}[\s]*/ if(prompt.class == String)
   start_time = Time.now.to_i
+  acc = ''
   begin
     line = $sp.gets()
     puts("DBG got (#{__LINE__}): "+line) if $debug && line
@@ -156,7 +157,8 @@ def wait_for_prompt(prompt)
     if (Time.now.to_i- start_time) > $max_timeout
       return false
     end
-  end while not m=prompt.match(line)
+  acc += line
+  end while ! m=prompt.match(acc)
   return m
 end
 
@@ -185,7 +187,7 @@ def add_test(a,b)
       puts line
       return false
     end
-  end while not /[\s]*enter a:[\s]*/.match(line)
+  end while ! /[\s]*enter a:[\s]*/.match(line)
   $sp.print(a.to_s(16)+" ")
   begin
     line = $sp.gets()
@@ -195,7 +197,7 @@ def add_test(a,b)
       puts line
       return false
     end
-  end while not /[\s]*enter b:[\s]*/.match(line)
+  end while ! /[\s]*enter b:[\s]*/.match(line)
   $sp.print(b.to_s(16)+" ")
   begin
     line = $sp.gets()
@@ -205,7 +207,7 @@ def add_test(a,b)
       puts line
       return false
     end
-  end while not m=/[\s]*([-]?[0-9a-fA-F]*)[\s]+\+[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]*)/.match(line)
+  end while ! m=/[\s]*([-]?[0-9a-fA-F]*)[\s]+\+[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]*)/.match(line)
   a_ = m[1].to_i(16)
   b_ = m[2].to_i(16)
   c_ = m[3].to_i(16)
@@ -234,7 +236,7 @@ def mul_test(a,b)
       puts line
       return false
     end
-  end while not /[\s]*enter a:[\s]*/.match(line)
+  end while ! /[\s]*enter a:[\s]*/.match(line)
   $sp.print(a.to_s(16)+" ")
   begin
     line = $sp.gets()
@@ -244,7 +246,7 @@ def mul_test(a,b)
       puts line
       return false
     end
-  end while not /[\s]*enter b:[\s]*/.match(line)
+  end while ! /[\s]*enter b:[\s]*/.match(line)
   $sp.print(b.to_s(16)+" ")
   begin
     line = $sp.gets()
@@ -254,7 +256,7 @@ def mul_test(a,b)
       puts line
       return false
     end
-  end while not m=/[\s]*([+-]?[0-9a-fA-F]*)[\s]+\*[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]*)/.match(line)
+  end while ! m=/[\s]*([+-]?[0-9a-fA-F]*)[\s]+\*[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]*)/.match(line)
   a_ = m[1].to_i(16)
   b_ = m[2].to_i(16)
   c_ = m[3].to_i(16)
@@ -328,7 +330,7 @@ def square_test(a)
       puts line
       return false
     end
-  end while not /[\s]*enter a:[\s]*/.match(line)
+  end while ! /[\s]*enter a:[\s]*/.match(line)
   $sp.print(a.to_s(16)+" ")
   begin
     line = $sp.gets()
@@ -338,7 +340,7 @@ def square_test(a)
       puts line
       return false
     end
-  end while not m=/[\s]*([+-]?[0-9a-fA-F]*)[\s]*\*\*2[\s]*=[\s]*([+-]?[0-9a-fA-F]*)/.match(line)
+  end while ! m=/[\s]*([+-]?[0-9a-fA-F]*)[\s]*\*\*2[\s]*=[\s]*([+-]?[0-9a-fA-F]*)/.match(line)
   a_ = m[1].to_i(16)
   c_ = m[2].to_i(16)
   line.chomp!
@@ -366,7 +368,7 @@ def reduce_test(a,b)
       puts line
       return false
     end
-  end while not /[\s]*enter a:[\s]*/.match(line)
+  end while ! /[\s]*enter a:[\s]*/.match(line)
   $sp.print(a.to_s(16)+" ")
   begin
     line = $sp.gets()
@@ -376,7 +378,7 @@ def reduce_test(a,b)
       puts line
       return false
     end
-  end while not /[\s]*enter b:[\s]*/.match(line)
+  end while ! /[\s]*enter b:[\s]*/.match(line)
   $sp.print(b.to_s(16)+" ")
   line=''
   begin
@@ -388,7 +390,7 @@ def reduce_test(a,b)
       puts line
       return false
     end
-  end while not m=/[\s]*([+-]?[0-9a-fA-F]*)[\s]+%[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]+)/.match(line)
+  end while ! m=/[\s]*([+-]?[0-9a-fA-F]*)[\s]+%[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]+)/.match(line)
   a_ = m[1].to_i(16)
   b_ = m[2].to_i(16)
   c_ = m[3].to_i(16)
@@ -417,7 +419,7 @@ def expmod_test(a,b,c)
       puts line
       return false
     end
-  end while not /[\s]*enter a:[\s]*/.match(line)
+  end while ! /[\s]*enter a:[\s]*/.match(line)
   $sp.print(a.to_s(16)+" ")
   begin
     line = $sp.gets()
@@ -427,7 +429,7 @@ def expmod_test(a,b,c)
       puts line
       return false
     end
-  end while not /[\s]*enter b:[\s]*/.match(line)
+  end while ! /[\s]*enter b:[\s]*/.match(line)
   $sp.print(b.to_s(16)+" ")
   begin
     line = $sp.gets()
@@ -437,7 +439,7 @@ def expmod_test(a,b,c)
       puts line
       return false
     end
-  end while not /[\s]*enter c:[\s]*/.match(line)
+  end while ! /[\s]*enter c:[\s]*/.match(line)
   $sp.print(c.to_s(16)+" ")
   line=''
   begin
@@ -449,7 +451,7 @@ def expmod_test(a,b,c)
       puts line
       return false
     end
-  end while not m=/[\s]*([+-]?[0-9a-fA-F]*)\*\*([+-]?[0-9a-fA-F]*)[\s]+%[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]+)/.match(line)
+  end while ! m=/[\s]*([+-]?[0-9a-fA-F]*)\*\*([+-]?[0-9a-fA-F]*)[\s]+%[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]+)/.match(line)
   a_ = m[1].to_i(16)
   b_ = m[2].to_i(16)
   c_ = m[3].to_i(16)
@@ -479,7 +481,7 @@ def gcdext_test(a,b)
       puts line
       return false
     end
-  end while not /[\s]*enter a:[\s]*/.match(line)
+  end while ! /[\s]*enter a:[\s]*/.match(line)
   $sp.print(a.to_s(16)+" ")
   begin
     line = $sp.gets()
@@ -489,7 +491,7 @@ def gcdext_test(a,b)
       puts line
       return false
     end
-  end while not /[\s]*enter b:[\s]*/.match(line)
+  end while ! /[\s]*enter b:[\s]*/.match(line)
   $sp.print(b.to_s(16)+" ")
   line=''
   begin
@@ -502,7 +504,7 @@ def gcdext_test(a,b)
       puts line
       return false
     end
-  end while not m=/gcdext\([\s]*([+-]?[0-9a-fA-F]*)[\s]*,[\s]*([+-]?[0-9a-fA-F]*)[\s]*\)[\s]*=> a = ([+-]?[0-9a-fA-F]+); b = ([+-]?[0-9a-fA-F]+); gcd = ([+-]?[0-9a-fA-F]+)/.match(line)
+  end while ! m=/gcdext\([\s]*([+-]?[0-9a-fA-F]*)[\s]*,[\s]*([+-]?[0-9a-fA-F]*)[\s]*\)[\s]*=> a = ([+-]?[0-9a-fA-F]+); b = ([+-]?[0-9a-fA-F]+); gcd = ([+-]?[0-9a-fA-F]+)/.match(line)
   a_ = m[1].to_i(16)
   b_ = m[2].to_i(16)
   c_ = m[3].to_i(16)
@@ -818,7 +820,7 @@ conf = readconfigfile(opts["f"], conf) if opts["f"]
 #puts conf.inspect
 init_serialport(conf)
 
-  $max_timeout = 2 * 60
+  $max_timeout = 5 * 60
 
 if opts['d']
   $debug = true
@@ -832,12 +834,16 @@ if File.exists?(logfilename)
     i+=1
   end while(File.exists?(logfilename))
   while(i>2) do
-    File.move(sprintf('%s%04d%s', conf['PORT']['testlogbase']+'bigint_',i-2,'.txt'), 
-              sprintf('%s%04d%s', conf['PORT']['testlogbase']+'bigint_',i-1,'.txt'), true)
+    n1 = sprintf('%s%04d%s', conf['PORT']['testlogbase']+'bigint_',i-2,'.txt')
+    n2 = sprintf('%s%04d%s', conf['PORT']['testlogbase']+'bigint_',i-1,'.txt')
+    File.rename(n1, n2)
+    printf("%s -> %s\n", n1, n2) 
     i-=1
   end
-    File.move(sprintf('%s%s', conf['PORT']['testlogbase'],'bigint.txt'), 
-              sprintf('%s%04d%s', conf['PORT']['testlogbase']+'bigint_',1,'.txt'), true)
+  n1 = sprintf('%s%s', conf['PORT']['testlogbase'],'bigint.txt')
+  n2 = sprintf('%s%04d%s', conf['PORT']['testlogbase']+'bigint_',1,'.txt')
+  File.rename(n1, n2) 
+  printf("%s -> %s\n", n1, n2)  
   logfilename = conf['PORT']['testlogbase']+'bigint.txt' 
 end
 $logfile = File.open(logfilename, 'w')