line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*-cperl-*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Crypt::FDH - Full Domain Hash |
4
|
|
|
|
|
|
|
# Copyright (c) 2016-2017 Ashish Gulhati |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# $Id: lib/Crypt/FDH.pm v1.009 Sat Jun 10 00:08:07 PDT 2017 $ |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
27270
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
62
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package Crypt::FDH; |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
40
|
|
13
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
31
|
|
14
|
2
|
|
|
2
|
|
847
|
use Digest::SHA; |
|
2
|
|
|
|
|
4753
|
|
|
2
|
|
|
|
|
83
|
|
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
13
|
use vars qw( @ISA $VERSION $AUTOLOAD ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
186
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
BEGIN { |
19
|
2
|
|
|
2
|
|
11
|
require Exporter; |
20
|
2
|
|
|
|
|
10
|
our ( $VERSION ) = '$Revision: 1.009 $' =~ /\s+([\d\.]+)/; |
21
|
2
|
|
|
|
|
21
|
our @ISA = qw(Exporter); |
22
|
2
|
|
|
|
|
440
|
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
|
22
|
my %args = @_; |
30
|
4
|
|
50
|
|
|
16
|
my ($size, $m, $algo) = ($args{Size},$args{Message},$args{Algorithm}||'sha256'); |
31
|
4
|
50
|
|
|
|
39
|
die "Invalid hash algorithm: $algo" unless $algo =~ /$VALGOS/; |
32
|
4
|
|
|
|
|
17
|
my $ctx = Digest::SHA->new($algo); |
33
|
4
|
|
|
|
|
67
|
my $hash; my $n = int($size / $hashsz{$algo}); |
|
4
|
|
|
|
|
12
|
|
34
|
|
|
|
|
|
|
die "Hash size does not fit into target size\n" |
35
|
4
|
50
|
|
|
|
10
|
unless $n * $hashsz{$algo} == $size; my $hexlen = $size / 4; |
|
4
|
|
|
|
|
8
|
|
36
|
4
|
|
|
|
|
12
|
for (0..$n-1) { |
37
|
15
|
|
|
|
|
46
|
$ctx->add($m.$_); |
38
|
15
|
|
|
|
|
78
|
$hash .= $ctx->hexdigest; |
39
|
|
|
|
|
|
|
} |
40
|
4
|
|
|
|
|
29
|
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.009 $ |
64
|
|
|
|
|
|
|
$Date: Sat Jun 10 00:08:07 PDT 2017 $ |
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) 2016-2017 Ashish Gulhati. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
124
|
|
|
|
|
|
|
under the terms of the Artistic License 2.0. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
See http://www.perlfoundation.org/artistic_license_2_0 for the full |
127
|
|
|
|
|
|
|
license terms. |