X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=host%2Fbigint_test.rb;h=7a756a123c5f873a6e78b3e2d71a4402219c6212;hb=2b0000dcd4848a3231831a79e2cd35c049909ec9;hp=eabaec515390bc3f50f156c4bf69e98f13bb7d25;hpb=5f46191d2615ebe2caa6e111b478031a34f20b9e;p=arm-crypto-lib.git diff --git a/host/bigint_test.rb b/host/bigint_test.rb index eabaec5..7a756a1 100644 --- a/host/bigint_test.rb +++ b/host/bigint_test.rb @@ -246,6 +246,66 @@ def mul_test(a,b) return false end +################################################################################ +# add_scale_test # +################################################################################ + +def add_scale_test(a, b, scale) + begin + line = $sp.gets() + line = "" if line==nil + puts("DBG got: "+line) if $debug + if /^Error:.*/.match(line) + puts line + return false + end + end while not /[\s]*enter a:[\s]*/.match(line) + $sp.print(a.to_s(16)+" ") + begin + line = $sp.gets() + line = "" if line==nil + puts("DBG got: "+line) if $debug + if /^Error:.*/.match(line) + puts line + return false + end + end while not /[\s]*enter b:[\s]*/.match(line) + $sp.print(b.to_s(16)+" ") + begin + line = $sp.gets() + line = "" if line==nil + puts("DBG got: "+line) if $debug + if /^Error:.*/.match(line) + puts line + return false + end + end while not /[\s]*enter scale:[\s]*/.match(line) + $sp.print(scale.to_s(16)+"\n") + begin + line = $sp.gets() + line = "" if line==nil + puts("DBG got: "+line) if $debug + if /^Error:.*/.match(line) + puts line + return false + end + end while not m=/[\s]*([-]?[0-9a-fA-F]*)[\s]+\+[\s]+([+-]?[0-9a-fA-F]*)[\s]*<<8\*[\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) + s_ = m[3].to_i(16) + c_ = m[4].to_i(16) + line.chomp! + if(a_== a && b_ == b && c_ == (a+b)) + $logfile.printf("[pass]: %s\n", line) + return true + else + $logfile.printf("[fail (%s%s%s)]: %s", (a==a_)?"":"a", (b==b_)?"":"b", (c_==a+b)?"":"c",line) + $logfile.printf(" ; should %s + %s = %s\n", a.to_s(16), b.to_s(16), (a+b).to_s(16)) + return false + end + return false +end + ################################################################################ # square_test # ################################################################################ @@ -311,9 +371,8 @@ def reduce_test(a,b) $sp.print(b.to_s(16)+" ") line='' begin - line_tmp = $sp.gets() - line_tmp = '' if line_tmp==nil - line += line_tmp + line = $sp.gets() + line = '' if line==nil puts("DBG got: "+line) if $debug if /^Error:.*/.match(line) puts line @@ -372,9 +431,8 @@ def expmod_test(a,b,c) $sp.print(c.to_s(16)+" ") line='' begin - line_tmp = $sp.gets() - line_tmp = '' if line_tmp==nil - line += line_tmp + line = $sp.gets() + line = '' if line==nil puts("DBG got: "+line) if $debug if /^Error:.*/.match(line) puts line @@ -424,16 +482,14 @@ def gcdext_test(a,b) $sp.print(b.to_s(16)+" ") line='' begin - line_tmp = $sp.gets() - line_tmp = '' if line_tmp==nil - line = '' if line.end_with?('\n') - line += line_tmp + line = $sp.gets() + line = '' if line==nil puts("DBG got: "+line) if $debug if /^Error:.*/.match(line) 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 not m=/gcdext\([\s]*([+-]?[0-9a-fA-F]*)[\s]*,[\s]*([+-]?[0-9a-fA-F]*)[\s]*\)[\s]*=>[\s]*a[\s]*=[\s]*([+-]?[0-9a-fA-F]+);[\s]*b[\s]*=[\s]*([+-]?[0-9a-fA-F]+);[\s]*gcd[\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) @@ -611,7 +667,7 @@ def run_test_gcdext(skip=0) begin $size = length_a_B (0..16).each do |i| - a = rand(256**length_a_B) + a = rand(256**length_a_B)+1 b = rand(256**length_a_B)+1 v = gcdext_test(a, b) $logfile.flush() @@ -619,7 +675,7 @@ def run_test_gcdext(skip=0) end (0..16).each do |i| b_size = rand(length_b_B+1) - a = rand(256**length_a_B) + a = rand(256**length_a_B)+1 b = rand(256**b_size)+1 v = gcdext_test(a, b) $logfile.flush()