4 This file is part of the AVR-Crypto-Lib.
5 Copyright (C) 2008, 2009 Daniel Otte (daniel.otte@rub.de)
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 $conffile_check = Hash.new
30 $conffile_check.default = 0
40 ################################################################################
42 ################################################################################
44 def readconfigfile(fname, conf)
45 return conf if $conffile_check[fname]==1
46 $conffile_check[fname]=1
48 if ! File.exists?(fname)
51 file = File.open(fname, "r")
54 next if /[\s]*#/.match(line)
55 if m=/\[[\s]*([^\s]*)[\s]*\]/.match(line)
60 next if ! /=/.match(line)
61 m=/[\s]*([^\s]*)[\s]*=[\s]*([^\s]*)/.match(line)
63 Dir.glob(m[2]){ |fn| conf = readconfigfile(fn, conf) }
65 conf[section][m[1]] = m[2]
72 ################################################################################
74 ################################################################################
76 def expmod(base, power, mod)
79 result = (result * base) % mod if power & 1 == 1
80 base = (base * base) % mod
86 ################################################################################
88 ################################################################################
91 return [0, 0, 0] if(x == 0 || y == 0)
93 while(x&1==0 && y&1==0) do
98 u=x; v=y; a=1; b=0; c=0; d=1
123 ################################################################################
125 ################################################################################
134 ################################################################################
136 ################################################################################
138 def init_system(test_prog)
142 $sp.print("echo off \r")
143 print("DBG i: " + "echo off \r"+"\n") if $debug
145 $sp.print("#{test_prog}\r")
146 print("DBG i: " + "#{test_prog} \r"+"\n") if $debug
150 ################################################################################
152 ################################################################################
154 def wait_for_prompt(prompt)
155 prompt = /[\s]*#{prompt}[\s]*/ if(prompt.class == String)
156 start_time = Time.now.to_i
160 puts("DBG got (#{__LINE__}): "+line) if $debug && line
161 line = "" if line==nil
162 if /^(Error:|Crypto-VS).*/.match(line)
166 if (Time.now.to_i- start_time) > $max_timeout
170 end while ! m=prompt.match(acc)
174 ################################################################################
176 ################################################################################
177 def screen_progress(v)
179 printf("\n%5d [%04d]: ", $testno, $size)
181 putc((v)?('*'):('!'))
183 $linepos = ($linepos+1) % $linewidth
186 ################################################################################
188 ################################################################################
193 line = "" if line==nil
194 puts("DBG got: "+line) if $debug
195 if /^Error:.*/.match(line)
199 end while ! /[\s]*enter a:[\s]*/.match(line)
200 $sp.print(a.to_s(16)+" ")
203 line = "" if line==nil
204 puts("DBG got: "+line) if $debug
205 if /^Error:.*/.match(line)
209 end while ! /[\s]*enter b:[\s]*/.match(line)
210 $sp.print(b.to_s(16)+" ")
213 line = "" if line==nil
214 puts("DBG got: "+line) if $debug
215 if /^Error:.*/.match(line)
219 end while ! m=/[\s]*([-]?[0-9a-fA-F]*)[\s]+\+[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]*)/.match(line)
224 if(a_== a && b_ == b && c_ == (a+b))
225 $logfile.printf("[pass (%d)]: %s\n", $testno, line)
228 $logfile.printf("[fail (%s%s%s) (%d)]: %s",
229 (a == a_) ? "" : "a",
230 (b == b_) ? "" : "b",
231 (c_ == a + b) ? "" : "c", $testno, line)
232 $logfile.printf(" ; should %s + %s = %s\n", a.to_s(16), b.to_s(16), (a+b).to_s(16))
238 ################################################################################
240 ################################################################################
245 line = "" if line==nil
246 puts("DBG got: "+line) if $debug
247 if /^Error:.*/.match(line)
251 end while ! /[\s]*enter a:[\s]*/.match(line)
252 $sp.print(a.to_s(16)+" ")
255 line = "" if line==nil
256 puts("DBG got: "+line) if $debug
257 if /^Error:.*/.match(line)
261 end while ! /[\s]*enter b:[\s]*/.match(line)
262 $sp.print(b.to_s(16)+" ")
265 line = "" if line==nil
266 puts("DBG got: "+line) if $debug
267 if /^Error:.*/.match(line)
271 end while ! m=/[\s]*([-]?[0-9a-fA-F]*)[\s]+\-[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]*)/.match(line)
276 if(a_== a && b_ == b && c_ == (a - b))
277 $logfile.printf("[pass (%d)]: %s\n", $testno, line)
280 $logfile.printf("[fail (%s%s%s) (%d)]: %s",
281 (a == a_) ? "" : "a",
282 (b == b_) ? "" : "b",
283 (c_ == a - b) ? "" : "c", $testno, line)
284 $logfile.printf(" ; should %s - %s = %s\n", a.to_s(16), b.to_s(16), (a - b).to_s(16))
290 ################################################################################
292 ################################################################################
297 line = "" if line==nil
298 puts("DBG got: "+line) if $debug
299 if /^Error:.*/.match(line)
303 end while ! /[\s]*enter a:[\s]*/.match(line)
304 $sp.print(a.to_s(16)+" ")
307 line = "" if line==nil
308 puts("DBG got: "+line) if $debug
309 if /^Error:.*/.match(line)
313 end while ! /[\s]*enter b:[\s]*/.match(line)
314 $sp.print(b.to_s(16)+" ")
317 line = "" if line==nil
318 puts("DBG got: "+line) if $debug
319 if /^Error:.*/.match(line)
323 end while ! m=/[\s]*([+-]?[0-9a-fA-F]*)[\s]+\*[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]*)/.match(line)
328 if(a_== a && b_ == b && c_ == (a*b))
329 $logfile.printf("[pass]: %s\n", line)
332 $logfile.printf("[fail (%s%s%s)]: %s", (a==a_)?"":"a", (b==b_)?"":"b", (c_==a*b)?"":"c",line)
333 $logfile.printf(" ; should %s * %s = %s\n", a.to_s(16), b.to_s(16), (a*b).to_s(16))
339 ################################################################################
341 ################################################################################
342 def add_scale_test_dummy(a, b, scale)
343 should = a + (b<<(8*scale))
344 printf("[dummy] %s + %s <<8*%04x = %s\n",a.to_s(16), b.to_s(16), scale, should.to_s(16))
347 def add_scale_test(a, b, scale)
348 m = wait_for_prompt("enter a:")
350 puts("DBG put (#{__LINE__}): "+a.to_s(16)+" ") if $debug
351 $sp.print(a.to_s(16)+" ")
352 m = wait_for_prompt("enter b:")
354 puts("DBG put (#{__LINE__}): "+b.to_s(16)+" ") if $debug
355 $sp.print(b.to_s(16)+" ")
356 m = wait_for_prompt("enter scale:")
358 puts("DBG put (#{__LINE__}): "+scale.to_s(10)+" ") if $debug
359 $sp.print(scale.to_s(10)+"\r")
360 should = a + (b<<(8*scale))
361 m = wait_for_prompt(/[\s]*([-]?[0-9a-fA-F]+)[\s]+\+[\s]+([+-]?[0-9a-fA-F]+)[\s]*<<8\*[\s]*([+-]?[0-9a-fA-F]+)[\s]*=[\s]*([+-]?[0-9a-fA-F]+)/)
363 $logfile.printf("[fail (CRASH)]:")
364 $logfile.printf(" ; should %s + %s << 8*%s = %s\n", a.to_s(16), b.to_s(16), scale.to_s(16), should.to_s(16))
373 if(a_== a && b_ == b && s_ == scale && c_ == should )
374 $logfile.printf("[pass]: %s\n", line)
377 $logfile.printf("[fail (%s%s%s%s)]: %s", (a==a_)?"":"a", (b==b_)?"":"b", (scale==s_)?"":"s",(c_==should)?"":"c",line)
378 $logfile.printf(" ; should %s + %s << 8*%s = %s\n", a.to_s(16), b.to_s(16), scale.to_s(16), should.to_s(16))
384 ################################################################################
386 ################################################################################
391 line = "" if line==nil
392 puts("DBG got: "+line) if $debug
393 if /^Error:.*/.match(line)
397 end while ! /[\s]*enter a:[\s]*/.match(line)
398 $sp.print(a.to_s(16)+" ")
401 line = "" if line==nil
402 puts("DBG got: "+line) if $debug
403 if /^Error:.*/.match(line)
407 end while ! m=/[\s]*([+-]?[0-9a-fA-F]*)[\s]*\*\*2[\s]*=[\s]*([+-]?[0-9a-fA-F]*)/.match(line)
411 if(a_== a && c_ == (a**2))
412 $logfile.printf("[pass]: %s\n", line)
415 $logfile.printf("[fail (%s%s)]: %s", (a==a_)?"":"a", (c_==a**2)?"":"c",line)
416 $logfile.printf(" ; should %s **2 = %s\n", a.to_s(16), (a**2).to_s(16))
422 ################################################################################
424 ################################################################################
429 line = "" if line==nil
430 puts("DBG got: "+line) if $debug
431 if /^Error:.*/.match(line)
435 end while ! /[\s]*enter a:[\s]*/.match(line)
436 $sp.print(a.to_s(16)+" ")
439 line = "" if line==nil
440 puts("DBG got: "+line) if $debug
441 if /^Error:.*/.match(line)
445 end while ! /[\s]*enter b:[\s]*/.match(line)
446 $sp.print(b.to_s(16)+" ")
449 line_tmp = $sp.gets()
450 line_tmp = '' if line_tmp==nil
452 puts("DBG got: "+line) if $debug
453 if /^Error:.*/.match(line)
457 end while ! m=/[\s]*([+-]?[0-9a-fA-F]*)[\s]+%[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]+)/.match(line)
462 if(a_== a && b_ == b && c_ == (a%b))
463 $logfile.printf("[pass (%d)]: %s\n", $testno, line)
466 $logfile.printf("[fail (%s%s%s) (%d)]: %s",
467 (a == a_) ? "" : "a",
468 (b == b_) ? "" : "b",
469 (c_ == a % b) ? "" : "c", $testno, line)
470 $logfile.printf(" ; should %s %% %s = %s\n", a.to_s(16), b.to_s(16), (a % b).to_s(16))
476 ################################################################################
478 ################################################################################
480 def mulmod_test(a,b,c)
482 printf("[testing] mulmod(%#x, %#x, %#x)\n",a,b,c) if $debug
484 line = "" if line==nil
485 puts("DBG got: "+line) if $debug
486 if /^Error:.*/.match(line)
490 end while ! /[\s]*enter a:[\s]*/.match(line)
491 $sp.print(a.to_s(16)+" ")
494 line = "" if line==nil
495 puts("DBG got: "+line) if $debug
496 if /^Error:.*/.match(line)
500 end while ! /[\s]*enter b:[\s]*/.match(line)
501 $sp.print(b.to_s(16)+" ")
504 line = "" if line==nil
505 puts("DBG got: "+line) if $debug
506 if /^Error:.*/.match(line)
510 end while ! /[\s]*enter c:[\s]*/.match(line)
511 $sp.print(c.to_s(16)+" ")
514 line_tmp = $sp.gets()
515 line_tmp = '' if line_tmp==nil
517 puts("DBG got: "+line) if $debug
518 if /^Error:.*/.match(line)
522 m = /[\s]*\([\s]*([+-]?[0-9a-fA-F]*)[\s]*\*[\s]*([+-]?[0-9a-fA-F]*)[\s]*\)[\s]+%[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]+)/.match(line)
523 puts("DBG: line did not match pattern (" + line + ")") if !m && $debug
530 if(a_== a && b_ == b && c_ == c && d_ == (a * b % c) )
531 $logfile.printf("[pass]: %s\n", line)
534 $logfile.printf("[fail (%s%s%s%s)]: %s", (a == a_) ? '' : 'a', (b == b_) ? '' : 'b', (c_ == c) ? '' : 'c', (d_== (a * b % c)) ? '' : 'd',line)
535 $logfile.printf(" ; should (%s * %s) %% %s = %s\n", a.to_s(16), b.to_s(16), c.to_s(16), (a * b % c).to_s(16))
541 ################################################################################
543 ################################################################################
545 def expmod_test(a,b,c)
547 printf("[testing] expmod(%#x, %#x, %#x)\n",a,b,c) if $debug
549 line = "" if line==nil
550 puts("DBG got: "+line) if $debug
551 if /^Error:.*/.match(line)
555 end while ! /[\s]*enter a:[\s]*/.match(line)
556 $sp.print(a.to_s(16)+" ")
559 line = "" if line==nil
560 puts("DBG got: "+line) if $debug
561 if /^Error:.*/.match(line)
565 end while ! /[\s]*enter b:[\s]*/.match(line)
566 $sp.print(b.to_s(16)+" ")
569 line = "" if line==nil
570 puts("DBG got: "+line) if $debug
571 if /^Error:.*/.match(line)
575 end while ! /[\s]*enter c:[\s]*/.match(line)
576 $sp.print(c.to_s(16)+" ")
579 line_tmp = $sp.gets()
580 line_tmp = '' if line_tmp == nil
582 puts("DBG got: "+line) if $debug
583 if /^Error:/.match(line)
587 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)
593 if(a_== a && b_ == b && c_ == c && d_ ==expmod(a,b,c) )
594 $logfile.printf("[pass]: %s\n", line)
597 $logfile.printf("[fail (%s%s%s%s)]: %s", (a==a_)?'':'a', (b==b_)?'':'b', (c_==c)?'':'c', (d_==expmod(a,b,c))?'':'d',line)
598 $logfile.printf(" ; should %s**%s %% %s = %s\n", a.to_s(16), b.to_s(16), c.to_s(16), expmod(a,b,c).to_s(16))
604 ################################################################################
606 ################################################################################
609 $logfile.printf("[testing] gcdext(%s, %s)\n", a.to_s(16), b.to_s(16))
612 line = "" if line==nil
613 puts("DBG got: "+line) if $debug
614 if /^Error:.*/.match(line)
618 end while ! /[\s]*enter a:[\s]*/.match(line)
619 $sp.print(a.to_s(16)+" ")
622 line = "" if line==nil
623 puts("DBG got: "+line) if $debug
624 if /^Error:.*/.match(line)
628 end while ! /[\s]*enter b:[\s]*/.match(line)
629 $sp.print(b.to_s(16)+" ")
632 line_tmp = $sp.gets()
633 line_tmp = '' if line_tmp==nil
634 line = '' if line.end_with?('\n')
636 puts("DBG got: "+line) if $debug
637 if /^Error:.*/.match(line)
641 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)
651 if(a_== a && b_ == b && c_ == ref[1] && d_ == ref[2] && e_== ref[0])
652 $logfile.printf("[pass (%d)]: %s\n", $testno, line)
655 $logfile.printf("[fail (%s%s%s%s%s) (%d)]: %s",
656 (a == a_) ? '' : 'a',
657 (b == b_) ? '' : 'b',
658 (c_ == ref[1]) ? '' : 'c',
659 (d_ == ref[2]) ? '' : 'd',
660 (e_ == ref[0]) ? '' : 'e', $testno, line)
661 $logfile.printf(" ; should gcdext( %s, %s) => a = %s; b = %s; gcd = %s\n",
662 a.to_s(16), b.to_s(16), ref[1].to_s(16), ref[2].to_s(16), ref[0].to_s(16))
668 ################################################################################
670 ################################################################################
672 def run_test_add(skip=0)
678 a = rand(256**length_a_B)
679 b = rand(256**length_a_B)
686 b_size = rand(length_b_B+1)
687 a = rand(256**length_a_B)
688 b = rand(256**b_size)
696 end while length_a_B<4096/8
699 ################################################################################
701 ################################################################################
703 def run_test_sub(skip = 0)
704 length_a_B = skip + 1
705 length_b_B = skip + 1
709 a = rand(256 ** length_a_B)
715 b_size = rand(length_b_B + 1)
716 a = rand(256 ** length_a_B)
717 b = rand(min(256 ** b_size, a + 1))
723 end while length_a_B < 4096 / 8
727 ################################################################################
728 # run_test_add_scale #
729 ################################################################################
731 def run_test_add_scale(skip=0)
738 16.times { scales << rand(301) }
740 scales.each do |scale|
741 a = rand(256**length_a_B)
742 b = rand(256**length_a_B)
743 v = add_scale_test(a, b, scale)
745 v = add_scale_test(b, a, scale)
751 16.times { scales << rand(301) }
753 scales.each do |scale|
754 b_size = rand(length_b_B+1)+1
755 a = rand(256**length_a_B)
756 b = rand(256**b_size)
757 v = add_scale_test(a, b, scale)
759 v = add_scale_test(b, a, scale)
765 end while length_a_B<4096/8
768 def run_test_add_scale_dummy(skip=0)
775 16.times { scales << rand(301) }
777 scales.each do |scale|
778 a = rand(256**length_a_B)
779 b = rand(256**length_a_B)
780 v = add_scale_test_dummy(a, b, scale)
781 v = add_scale_test_dummy(b, a, scale)
786 16.times { scales << rand(301) }
788 scales.each do |scale|
789 b_size = rand(length_b_B+1)
790 a = rand(256**length_a_B)
791 b = rand(256**b_size)
792 v = add_scale_test_dummy(a, b, scale)
793 v = add_scale_test_dummy(b, a, scale)
798 end while length_a_B<4096/8
801 ################################################################################
803 ################################################################################
805 def run_test_mul(skip=0)
813 a = rand(256**length_a_B) * s_a
814 b = rand(256**length_a_B) * s_b
823 b_size = rand(length_b_B+1)
824 a = rand(256**length_a_B) * s_a
825 b = rand(256**b_size) * s_b
833 end while length_a_B<4096/8
836 ################################################################################
837 # run_test_mul_word #
838 ################################################################################
840 def run_test_mul_word(skip=0)
846 a = rand(256 ** length_a_B)
851 end while length_a_B < 4096 / 8
854 ################################################################################
856 ################################################################################
858 def run_test_square(skip=0)
863 a = rand(256**length_a_B)
868 end while length_a_B<4096/8
871 ################################################################################
873 ################################################################################
875 def run_test_reduce(skip=0)
881 a = rand(256**length_a_B)
882 b = rand(256**length_a_B)+1
883 v = reduce_test(a, b)
887 b_size = rand(length_b_B+1)
888 a = rand(256**length_a_B)
889 b = rand(256**b_size)+1
890 v = reduce_test(a, b)
895 end while length_a_B<4096/8
898 ################################################################################
900 ################################################################################
902 def run_test_expmod(skip=0)
903 length_a_B = skip + 1
904 length_b_B = skip + 1
905 length_c_B = skip + 1
909 a = rand(256 ** length_a_B)
910 b = rand(256 ** length_b_B) + 1
911 c = rand(256 ** length_c_B) + 1
912 v = expmod_test(a, b, c)
916 b_size = rand(length_b_B+1)
917 a = rand(256 ** length_a_B)
918 b = rand(256 ** b_size) + 1
919 c = rand(256 ** b_size) + 1
920 v = expmod_test(a, b, c)
925 end while length_a_B<4096/8
928 ################################################################################
929 # run_test_expmodmont #
930 ################################################################################
932 def run_test_expmodmont(skip=0)
933 length_a_B = skip + 1
934 length_b_B = skip + 1
935 length_c_B = skip + 1
939 a = rand(256 ** length_a_B)
940 b = rand(256 ** length_b_B) + 1
941 c = rand(256 ** length_c_B) / 2 * 2 +1
942 v = expmod_test(a, b, c)
946 b_size = rand(length_b_B + 10)
947 a = rand(256 ** length_a_B)
948 b = rand(256 ** b_size) + 1
949 c = rand(256 ** b_size) / 2 * 2 +1
950 v = expmod_test(a, b, c)
955 end while length_a_B<4096/8
958 ################################################################################
960 ################################################################################
962 def run_test_mulmod(skip=0)
969 a = rand(256**length_a_B)
970 b = rand(256**length_b_B)
971 c = (rand(256**length_c_B) / 2 * 2) + 1
974 v = mulmod_test(a, b, c)
978 b_size = rand(length_b_B+1)
979 a = rand(256**length_a_B)
980 b = rand(256**b_size)
981 c = (rand(256**length_c_B) / 2 * 2) + 1
984 v = mulmod_test(a, b, c)
990 end while length_a_B<4096/8
993 ################################################################################
995 ################################################################################
997 def run_test_gcdext(skip=0)
1003 a = rand(256**length_a_B)
1004 b = rand(256**length_a_B)+1
1005 v = gcdext_test(a, b)
1010 b_size = rand(length_b_B+1)
1011 a = rand(256**length_a_B)
1012 b = rand(256**b_size)+1
1013 v = gcdext_test(a, b)
1019 end while length_a_B<4096/8
1022 def init_serialport(conf)
1023 puts("serial port interface version: " + SerialPort::VERSION);
1027 params = { "baud" => conf["PORT"]["baud"].to_i,
1028 "data_bits" => conf["PORT"]["databits"].to_i,
1029 "stop_bits" => conf["PORT"]["stopbits"].to_i,
1030 "parity" => SerialPort::NONE }
1031 params["paraty"] = SerialPort::ODD if conf["PORT"]["paraty"].downcase == "odd"
1032 params["paraty"] = SerialPort::EVEN if conf["PORT"]["paraty"].downcase == "even"
1033 params["paraty"] = SerialPort::MARK if conf["PORT"]["paraty"].downcase == "mark"
1034 params["paraty"] = SerialPort::SPACE if conf["PORT"]["paraty"].downcase == "space"
1036 puts("\nPort: "+conf["PORT"]["port"]+"@" +
1037 params["baud"].to_s +
1039 params["data_bits"].to_s +
1040 conf["PORT"]["paraty"][0,1].upcase +
1041 params["stop_bits"].to_s +
1044 $sp = SerialPort.new(conf["PORT"]["port"], params)
1046 $sp.read_timeout = 100; # 5 minutes
1047 $sp.flow_control = SerialPort::SOFT
1052 ################################################################################
1054 ################################################################################
1056 opts = Getopt::Std.getopts("r:s:f:i:a:hd")
1059 conf = readconfigfile("/etc/testport.conf", conf)
1060 conf = readconfigfile("~/.testport.conf", conf)
1061 conf = readconfigfile("testport.conf", conf)
1062 conf = readconfigfile(opts["f"], conf) if opts["f"]
1065 init_serialport(conf)
1067 $max_timeout = 5 * 60
1074 random_seed = opts['r'].to_i(0)
1076 random_seed = 0xdeadbeef
1079 logfilename = conf['PORT']['testlogbase']+'bigint.txt'
1080 if File.exists?(logfilename)
1083 logfilename = sprintf('%s%04d%s', conf['PORT']['testlogbase']+'bigint_',i,'.txt')
1085 end while(File.exists?(logfilename))
1087 n1 = sprintf('%s%04d%s', conf['PORT']['testlogbase']+'bigint_',i-2,'.txt')
1088 n2 = sprintf('%s%04d%s', conf['PORT']['testlogbase']+'bigint_',i-1,'.txt')
1090 # printf("%s -> %s\n", n1, n2)
1093 n1 = sprintf('%s%s', conf['PORT']['testlogbase'],'bigint.txt')
1094 n2 = sprintf('%s%04d%s', conf['PORT']['testlogbase']+'bigint_',1,'.txt')
1096 printf("%s -> %s\n", n1, n2)
1097 logfilename = conf['PORT']['testlogbase']+'bigint.txt'
1099 $logfile = File.open(logfilename, 'w')
1100 printf("logfile: %s\n", logfilename)
1101 $logfile.sync = true
1102 $logfile.printf("bigint test from: %s\n", Time.now.to_s)
1103 $logfile.printf("skip = %s\n", opts['s']) if opts['s']
1104 $logfile.printf("seed = 0x%X\n", random_seed)
1107 tests['a'] = proc {|x| run_test_add(x) }
1108 tests['b'] = proc {|x| run_test_sub(x) }
1109 tests['m'] = proc {|x| run_test_mul(x) }
1110 tests['M'] = proc {|x| run_test_mulmod(x) }
1111 tests['n'] = proc {|x| run_test_mul_word(x) }
1112 tests['x'] = proc {|x| run_test_add_scale(x) }
1113 tests['s'] = proc {|x| run_test_square(x) }
1114 tests['r'] = proc {|x| run_test_reduce(x) }
1115 tests['e'] = proc {|x| run_test_expmod(x) }
1116 tests['E'] = proc {|x| run_test_expmodmont(x) }
1117 tests['g'] = proc {|x| run_test_gcdext(x) }
1119 init_str['a'] = 'add-test'
1120 init_str['b'] = 'sub-test'
1121 init_str['x'] = 'add-scale-test'
1122 init_str['m'] = 'mul-test'
1123 init_str['M'] = 'mul-mont-test'
1124 init_str['n'] = 'mul-word-test'
1125 init_str['s'] = 'square-test'
1126 init_str['r'] = 'reduce-test'
1127 init_str['e'] = 'expmod-test'
1128 init_str['E'] = 'expmod-mont-test'
1129 init_str['g'] = 'gcdext-test'
1134 opts['a'].each_char do |x|
1137 init_system(init_str[x])
1138 tests[x].call(opts['s']?opts['s'].to_i():0)
1140 puts "no test defined for '#{x}'"
1144 'amsrMeE'.each_char do |x|
1147 init_system(init_str[x])
1148 tests[x].call(opts['s']?opts['s'].to_i():0)
1150 puts "no test defined for '#{x}'"