line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*-cperl-*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Crypt::FDH - Full Domain Hash |
4
|
|
|
|
|
|
|
# Copyright (c) Ashish Gulhati |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# $Id: lib/Crypt/FDH.pm v1.010 Sat Oct 27 21:26:17 PDT 2018 $ |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
129369
|
use strict; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
75
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package Crypt::FDH; |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
49
|
|
13
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
31
|
|
14
|
2
|
|
|
2
|
|
1127
|
use Digest::SHA; |
|
2
|
|
|
|
|
5831
|
|
|
2
|
|
|
|
|
120
|
|
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
14
|
use vars qw( @ISA $VERSION $AUTOLOAD ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
247
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
BEGIN { |
19
|
2
|
|
|
2
|
|
14
|
require Exporter; |
20
|
2
|
|
|
|
|
12
|
our ( $VERSION ) = '$Revision: 1.010 $' =~ /\s+([\d\.]+)/; |
21
|
2
|
|
|
|
|
31
|
our @ISA = qw(Exporter); |
22
|
2
|
|
|
|
|
577
|
our @EXPORT_OK = qw(hash hexhash hexdigest fdh); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $VALGOS = 'sha1|sha256'; |
26
|
|
|
|
|
|
|
my %hashsz = ('sha256' => 256, 'sha1' => 160); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub hash { |
29
|
4
|
|
|
4
|
1
|
99
|
my %args = @_; |
30
|
4
|
|
50
|
|
|
16
|
my ($size, $m, $algo) = ($args{Size},$args{Message},$args{Algorithm}||'sha256'); |
31
|
4
|
50
|
|
|
|
65
|
die "Invalid hash algorithm: $algo" unless $algo =~ /$VALGOS/; |
32
|
4
|
|
|
|
|
19
|
my $ctx = Digest::SHA->new($algo); |
33
|
4
|
|
|
|
|
68
|
my $hash; my $n = int($size / $hashsz{$algo}); |
|
4
|
|
|
|
|
13
|
|
34
|
|
|
|
|
|
|
die "Hash size does not fit into target size\n" |
35
|
4
|
50
|
|
|
|
11
|
unless $n * $hashsz{$algo} == $size; my $hexlen = $size / 4; |
|
4
|
|
|
|
|
5
|
|
36
|
4
|
|
|
|
|
13
|
for (0..$n-1) { |
37
|
15
|
|
|
|
|
54
|
$ctx->add($m.$_); |
38
|
15
|
|
|
|
|
81
|
$hash .= $ctx->hexdigest; |
39
|
|
|
|
|
|
|
} |
40
|
4
|
|
|
|
|
30
|
return $hash; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub fdh { |
44
|
0
|
|
|
0
|
1
|
|
hash @_ |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub hexhash { |
48
|
0
|
|
|
0
|
1
|
|
hash @_ |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub hexdigest { |
52
|
0
|
|
|
0
|
1
|
|
hash @_ |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; # End of Crypt::FDH |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 NAME |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Crypt::FDH - Full Domain Hash |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 VERSION |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$Revision: 1.010 $ |
64
|
|
|
|
|
|
|
$Date: Sat Oct 27 21:26:17 PDT 2018 $ |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 SYNOPSIS |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Provides a Full Domain Hash of the input for cryptograhic uses. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
use Crypt::FDH qw (hash); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $fdh = hash(Size => 2048, Message => "Hello world!\n", Algorithm => 'SHA256'); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 SUBROUTINES |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 hash / hexhash / hexdigest / fdh |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
All of these names are aliases for one subroutine which returns a Full |
79
|
|
|
|
|
|
|
Domain Hash of the input message, as a hex number. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 AUTHOR |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Ashish Gulhati, C<< >> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 BUGS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
88
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
89
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SUPPORT |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
perldoc Crypt::FDH |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
You can also look for information at: |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=over 4 |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
L |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
L |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item * CPAN Ratings |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
L |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item * Search CPAN |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
L |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=back |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Copyright (c) Ashish Gulhati. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This software package is Open Software; you can use, redistribute, |
124
|
|
|
|
|
|
|
and/or modify it under the terms of the Open Artistic License 2.0. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Please see L for the full license |
127
|
|
|
|
|
|
|
terms, and ensure that the license grant applies to you before using |
128
|
|
|
|
|
|
|
or modifying this software. By using or modifying this software, you |
129
|
|
|
|
|
|
|
indicate your agreement with the license terms. |