]> git.cryptolib.org Git - arm-crypto-lib.git/blobdiff - host/bigint_test.rb
starting to make bigint more portable/32-bit efficient
[arm-crypto-lib.git] / host / bigint_test.rb
index 78de1a12c74210c2b7fe43210c292103a061467c..2ef961677db1793e42d5f7f266dbaf7da2db6bb2 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/ruby
 # bigint_test.rb
 =begin
-    This file is part of the ARM-Crypto-Lib.
+    This file is part of the AVR-Crypto-Lib.
     Copyright (C) 2008, 2009  Daniel Otte (daniel.otte@rub.de)
 
     This program is free software: you can redistribute it and/or modify
@@ -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