]> git.cryptolib.org Git - avr-crypto-lib.git/blob - host/nessie_check.rb
host tools for verification +testvectors
[avr-crypto-lib.git] / host / nessie_check.rb
1 #!/usr/bin/ruby 
2 # nessie_check.rb
3 =begin
4     This file is part of the AVR-Crypto-Lib.
5     Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
6
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.
11
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.
16
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/>.
19 =end
20
21 def skip_header(file)
22   begin
23     l = file.gets().strip
24   end until /[*]{10,}.*/.match(l)
25   puts("DBG 0.0: "+l)
26   begin
27     l = file.gets().strip
28   end until /[*]{10,}.*/.match(l)
29   puts("DBG 0.1: "+l)
30   begin
31     l = file.gets().strip
32   end until /[=]{5,}.*/.match(l)
33   puts("DBG 0.2: "+l)
34   begin
35     l = file.gets().strip
36   end until /[=]{5,}.*/.match(l)
37   puts("DBG 0.3: "+l)   
38 end
39
40 def get_next_assign(file, i)
41   key = String.new
42   value = String.new
43   if($last_assign[i]==nil)
44     begin
45           return nil if file.eof
46       l = file.gets().strip()
47     end until m=/[\s]*([\w]*)[\s]*=[\s]*([0-9a-fA-F]*).*/.match(l)
48         value = m[2]
49         key = m[1]
50         begin
51           return nil if file.eof
52           l = file.gets().strip()
53           if not /[^=]+=[^=]+/.match(l)
54             value += l if /[0-9A-Fa-f]{5}/.match(l)
55           end
56     end until /[^=]+=[^=]+/.match(l)
57         $last_assign[i] = l
58   else
59     m=/[\s]*([\w]*)[\s]*=[\s]*([0-9a-fA-F]*).*/.match($last_assign[i])
60         value = m[2]
61         key = m[1]
62         begin
63           return nil if file.eof
64           l = file.gets().strip()
65           if not /[^=]+=[^=]+/.match(l)
66             value += l if /[0-9A-Fa-f]{5}/.match(l)
67           end
68     end until /[^=]+=[^=]+/.match(l)
69         $last_assign[i] = l
70   end
71   return [key, value]
72 end
73
74 def compare(fname1, fname2)
75   file1 = File.new(fname1, "r")
76   file2 = File.new(fname2, "r")
77   skip_header(file1)
78   skip_header(file2)
79   pos=0
80   begin
81 #       puts("checking set")
82     a = get_next_assign(file1, 0)
83     b = get_next_assign(file2, 1)
84         return if(a==nil or b==nil)
85         puts("") if pos%$linewidth==0 and pos!=0
86         putc((a==b)?'*':'!')
87 #       puts("a == nil") if a==nil
88 #       puts("b == nil") if b==nil
89         
90         if(a!=b and a!=nil and b!=nil)
91           $error = 1
92           puts("a key: "+a[0]+" value: "+a[1])
93           puts("b key: "+b[0]+" value: "+b[1])
94         end     
95         pos +=1
96   end until a==nil or b==nil
97 end
98
99 $error = 0
100 $linewidth=64
101 $last_assign=[nil, nil]
102
103 if ARGV.size!=2
104   STDERR.print <<EOF
105   Usage: ruby #{$0} file1 file2
106 EOF
107   exit(1)
108 end
109 puts("compare("+ARGV[1]+", "+ARGV[0]+")")
110 compare(ARGV[1], ARGV[0])
111 puts($error==0?"[ok]":"[failed]")
112
113 exit($error)