]> git.cryptolib.org Git - arm-crypto-lib.git/blob - host/nessie_check.rb
Adding Khazad
[arm-crypto-lib.git] / host / nessie_check.rb
1 #!/usr/bin/ruby
2 # nessie_check.rb
3 =begin
4     This file is part of the ARM-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   begin
26     l = file.gets().strip
27   end until /[*]{10,}.*/.match(l)
28   begin
29     l = file.gets().strip
30   end until /[=]{5,}.*/.match(l)
31   begin
32     l = file.gets().strip
33   end until /[=]{5,}.*/.match(l)
34 end
35
36 def get_next_assign(file, i)
37   key = String.new
38   value = String.new
39   if($last_assign[i]==nil)
40     begin
41           return nil if file.eof
42       l = file.gets().strip()
43     end until m=/[\s]*([\w]*)[\s]*=[\s]*([0-9a-fA-F]*).*/.match(l)
44         value = m[2]
45         key = m[1]
46         begin
47           return nil if file.eof
48           l = file.gets().strip()
49           if not /[^=]+=[^=]+/.match(l)
50             value += l if /^[0-9A-Fa-f]{5}/.match(l)
51           end
52     end until /[^=]+=[^=]+/.match(l)
53         $last_assign[i] = l
54   else
55     m=/[\s]*([\w]*)[\s]*=[\s]*([0-9a-fA-F]*).*/.match($last_assign[i])
56         value = m[2]
57         key = m[1]
58         begin
59           return nil if file.eof
60           l = file.gets().strip()
61           if not /[^=]+=[^=]+/.match(l)
62             value += l if /^[0-9A-Fa-f]{5}/.match(l)
63           end
64     end until /[^=]+=[^=]+/.match(l)
65         $last_assign[i] = l
66   end
67   return [key, value]
68 end
69
70 def compare(fname1, fname2)
71   file1 = File.new(fname1, "r")
72   file2 = File.new(fname2, "r")
73   skip_header(file1)
74   skip_header(file2)
75   pos=0
76   begin
77 #       puts("checking set")
78     a = get_next_assign(file1, 0)
79     b = get_next_assign(file2, 1)
80         return if(a==nil or b==nil)
81         if not $quiet
82       puts("") if pos%$linewidth==0 and pos!=0
83           putc((a==b)?'*':'!')
84       pos +=1
85         end
86         if(a!=b and a!=nil and b!=nil)
87           $error += 1
88 #         puts("a key: "+a[0]+" value: "+a[1])
89 #         puts("b key: "+b[0]+" value: "+b[1])
90         end
91   end until a==nil or b==nil
92 end
93
94 $error = 0
95 $linewidth=64
96 $last_assign=[nil, nil]
97
98 if ARGV.size<2 or ARGV.size>3
99   STDERR.print <<EOF
100   Usage: ruby #{$0} [-q|-v] file1 file2
101 EOF
102   exit(1)
103 end
104 $quiet = false
105 if ARGV.size==3
106   f1 = ARGV[1]
107   f2 = ARGV[2]
108   if ARGV[0]=="-q"
109     $quiet=true
110   end
111 else
112   f1 = ARGV[0]
113   f2 = ARGV[1]
114 end
115
116 puts("compare("+f1+", "+f2+")")
117 compare(f1, f2)
118 if $error!=0
119   puts("[failed] ("+$error.to_s()+")")
120 else
121   puts("[ok]")
122 end
123
124 exit($error)