line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::SHAVS; |
2
|
|
|
|
|
|
|
|
3
|
33
|
|
|
33
|
|
798299
|
use strict; |
|
33
|
|
|
|
|
85
|
|
|
33
|
|
|
|
|
1435
|
|
4
|
33
|
|
|
33
|
|
167
|
use vars qw($VERSION); |
|
33
|
|
|
|
|
70
|
|
|
33
|
|
|
|
|
25294
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$VERSION = 0.02; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
32
|
|
|
32
|
1
|
36003
|
my ($class, $SHA, $BIT) = @_; |
10
|
|
|
|
|
|
|
|
11
|
32
|
|
|
|
|
93
|
my $self = {}; |
12
|
32
|
|
|
|
|
116
|
$self->{SHA} = $SHA; |
13
|
32
|
|
|
|
|
93
|
$self->{BIT} = $BIT; |
14
|
32
|
|
|
|
|
265
|
bless($self, $class); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _SHA { |
18
|
40088
|
|
|
40088
|
|
49188
|
my $self = shift; |
19
|
|
|
|
|
|
|
|
20
|
40088
|
100
|
|
|
|
92208
|
pop unless $self->{BIT}; |
21
|
40088
|
|
|
|
|
48164
|
&{$self->{SHA}}(@_); |
|
40088
|
|
|
|
|
211771
|
|
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _computeMsg { |
25
|
88
|
|
|
88
|
|
185
|
my ($self, $values) = @_; |
26
|
|
|
|
|
|
|
|
27
|
88
|
|
|
|
|
607
|
my $Msg2bin = pack("H*", $values->{Msg}); |
28
|
88
|
|
|
|
|
176
|
my $nbits = $values->{Len}; |
29
|
88
|
|
|
|
|
184
|
my $nbytes = $nbits >> 3; |
30
|
88
|
100
|
|
|
|
249
|
if ($nbits % 8) { $nbytes++ } |
|
39
|
|
|
|
|
53
|
|
31
|
88
|
100
|
|
|
|
246
|
$Msg2bin = substr($Msg2bin, 0, $nbytes) |
32
|
|
|
|
|
|
|
if $nbytes < length($Msg2bin); |
33
|
|
|
|
|
|
|
|
34
|
88
|
|
|
|
|
244
|
unpack("H*", $self->_SHA($Msg2bin, $nbits)); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _computeMonte { |
38
|
40
|
|
|
40
|
|
93
|
my ($self, $values) = @_; |
39
|
|
|
|
|
|
|
|
40
|
40
|
50
|
|
|
|
232
|
die "COUNT value out of sequence: $values->{COUNT}\n" |
41
|
|
|
|
|
|
|
if $values->{count}++ != $values->{COUNT}; |
42
|
40
|
|
|
|
|
341
|
my ($MD0, $MD1, $MD2, $MDi) = (pack("H*", $values->{Seed})) x 3; |
43
|
40
|
|
|
|
|
115
|
for (1..1000) { |
44
|
40000
|
|
|
|
|
210374
|
my $M = $MD0 . $MD1 . $MD2; |
45
|
40000
|
|
|
|
|
81971
|
$MDi = $self->_SHA($M, length($M)*8); |
46
|
40000
|
|
|
|
|
535861
|
($MD0, $MD1, $MD2) = ($MD1, $MD2, $MDi); |
47
|
|
|
|
|
|
|
} |
48
|
40
|
|
|
|
|
678
|
$values->{Seed} = unpack("H*", $MDi); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $TAGS = join('|', qw(Len Msg MD Seed COUNT)); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub check { |
54
|
32
|
|
|
32
|
1
|
89
|
my ($self, $file) = @_; |
55
|
|
|
|
|
|
|
|
56
|
32
|
|
|
|
|
77
|
local $_; |
57
|
32
|
|
|
|
|
101
|
local *F; |
58
|
32
|
50
|
|
|
|
1193
|
open(F, $file) or die $!; |
59
|
|
|
|
|
|
|
|
60
|
32
|
|
|
|
|
151
|
my $values = { 'count' => 0 }; |
61
|
32
|
|
|
|
|
441
|
while () { |
62
|
686
|
100
|
|
|
|
6031
|
next unless /^\s*($TAGS)\s*=\s*([\da-f]+)/o; |
63
|
354
|
|
|
|
|
1127
|
$values->{$1} = $2; |
64
|
354
|
100
|
|
|
|
1461
|
next unless $1 eq 'MD'; |
65
|
128
|
100
|
|
|
|
7062
|
my $computed = defined $values->{Msg} |
66
|
|
|
|
|
|
|
? $self->_computeMsg($values) |
67
|
|
|
|
|
|
|
: $self->_computeMonte($values); |
68
|
128
|
|
|
|
|
2182
|
my $ok = $computed eq $values->{MD}; |
69
|
128
|
100
|
|
|
|
2247
|
print "$computed ", $ok ? "OK" : "FAILED", "\n"; |
70
|
|
|
|
|
|
|
} |
71
|
32
|
|
|
|
|
805
|
close(F); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
__END__ |