-
Notifications
You must be signed in to change notification settings - Fork 10
/
verify-preimage.pl
68 lines (54 loc) · 1.37 KB
/
verify-preimage.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use strict;
use warnings;
my $nr_rounds;
my %vars;
my $cnf = shift;
open my $cnffd, '<', $cnf or die $!;
while ($_ = <$cnffd>) {
chomp;
if (m/^[c\*] parameter nr_rounds = (\d+)$/) {
$nr_rounds = $1;
} elsif (my ($var, $width, $name) = m/^[c\*] var (\d+)\/(\d+) (.*)$/) {
$vars{$name} = $var;
}
}
close $cnffd;
my %valuation;
my $output = shift;
open my $outputfd, '<', $output or die $!;
while ($_ = <$outputfd>) {
chomp;
next if m/^c/;
s/^v //;
for (split m/\s+/) {
if (m/^-x?(\d+)$/) {
$valuation{$1} = 0;
} elsif (m/^x?(\d+)$/) {
$valuation{$1} = 1;
}
}
}
close $outputfd;
printf "%u\n", $nr_rounds;
printf "%08x %08x %08x %08x %08x %08x %08x %08x\n%08x %08x %08x %08x %08x %08x %08x %08x\n",
value("w[0]"), value("w[1]"), value("w[2]"), value("w[3]"),
value("w[4]"), value("w[5]"), value("w[6]"), value("w[7]"),
value("w[8]"), value("w[9]"), value("w[10]"), value("w[11]"),
value("w[12]"), value("w[13]"), value("w[14]"), value("w[15]");
printf "%08x %08x %08x %08x %08x\n",
value("h_in0"), value("h_in1"),
value("h_in2"), value("h_in3"),
value("h_in4");
printf "%08x %08x %08x %08x %08x\n",
value("h_out0"), value("h_out1"),
value("h_out2"), value("h_out3"),
value("h_out4");
sub value {
my $name = shift;
my $var = $vars{$name};
my $value = 0;
for (my $i = 0; $i < 32; ++$i) {
$value |= ($valuation{$var + $i} || 0) << $i;
}
return $value;
}