X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=host%2Fbigint_test.rb;h=835cd4b57ae532e65bf4fe142671c5d725a9a667;hb=d3b4df851c0d7fb1cfe38162c6d0781ba3afa910;hp=42f6080d84892af524c6f3a525f79d3429ba5980;hpb=a012cfa921853fb9b8bd484981ab471a9ba25ec9;p=avr-crypto-lib.git diff --git a/host/bigint_test.rb b/host/bigint_test.rb index 42f6080..835cd4b 100644 --- a/host/bigint_test.rb +++ b/host/bigint_test.rb @@ -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) } @@ -80,6 +80,7 @@ end ################################################################################ def gcdext(x,y) + return [0, 0, 0] if(x == 0 || y == 0) g=1 while(x&1==0 && y&1==0) do x>>=1 @@ -158,7 +159,7 @@ def wait_for_prompt(prompt) return false end acc += line - end while not m=prompt.match(acc) + end while ! m=prompt.match(acc) return m end @@ -187,7 +188,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() @@ -197,7 +198,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() @@ -207,7 +208,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) @@ -236,7 +237,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() @@ -246,7 +247,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() @@ -256,7 +257,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) @@ -330,7 +331,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() @@ -340,7 +341,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! @@ -368,7 +369,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() @@ -378,7 +379,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 @@ -390,7 +391,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) @@ -412,6 +413,7 @@ end def expmod_test(a,b,c) begin + printf("[testing] expmod(%#x, %#x, %#x)\n",a,b,c) if $debug line = $sp.gets() line = "" if line==nil puts("DBG got: "+line) if $debug @@ -419,7 +421,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() @@ -429,7 +431,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() @@ -439,7 +441,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 @@ -451,7 +453,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) @@ -473,6 +475,7 @@ end ################################################################################ def gcdext_test(a,b) + $logfile.printf("[testing] gcdext(%s, %s)\n", a.to_s(16), b.to_s(16)) begin line = $sp.gets() line = "" if line==nil @@ -481,7 +484,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() @@ -491,7 +494,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 @@ -504,7 +507,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) @@ -834,17 +837,21 @@ 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') printf("logfile: %s\n", logfilename) - +$logfile.sync = true $logfile.printf("bigint test from: %s\n", Time.now.to_s) $logfile.printf("skip = %s\n", opts['s']) if opts['s'] $logfile.printf("seed = 0x%X\n", 0xdeadbeef)