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