| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Crypt::PBKDF2::Hash::HMACSHA2; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: HMAC-SHA2 support for Crypt::PBKDF2 using Digest::SHA |
|
3
|
|
|
|
|
|
|
our $VERSION = '0.160410'; # VERSION |
|
4
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:ARODLAND'; # AUTHORITY |
|
5
|
3
|
|
|
3
|
|
1945
|
use Moo 2; |
|
|
3
|
|
|
|
|
68
|
|
|
|
3
|
|
|
|
|
16
|
|
|
6
|
3
|
|
|
3
|
|
632
|
use strictures 2; |
|
|
3
|
|
|
|
|
18
|
|
|
|
3
|
|
|
|
|
94
|
|
|
7
|
3
|
|
|
3
|
|
497
|
use namespace::autoclean; |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
19
|
|
|
8
|
3
|
|
|
3
|
|
1082
|
use Digest::SHA (); |
|
|
3
|
|
|
|
|
4996
|
|
|
|
3
|
|
|
|
|
76
|
|
|
9
|
3
|
|
|
3
|
|
14
|
use Type::Tiny; |
|
|
3
|
|
|
|
|
19
|
|
|
|
3
|
|
|
|
|
72
|
|
|
10
|
3
|
|
|
3
|
|
11
|
use Types::Standard qw(Enum); |
|
|
3
|
|
|
|
|
1
|
|
|
|
3
|
|
|
|
|
36
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Crypt::PBKDF2::Hash'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'sha_size' => ( |
|
15
|
|
|
|
|
|
|
is => 'ro', |
|
16
|
|
|
|
|
|
|
isa => Type::Tiny->new( |
|
17
|
|
|
|
|
|
|
name => 'SHASize', |
|
18
|
|
|
|
|
|
|
parent => Enum[qw( 224 256 384 512 )], |
|
19
|
|
|
|
|
|
|
display_name => 'valid number of bits for SHA-2', |
|
20
|
|
|
|
|
|
|
), |
|
21
|
|
|
|
|
|
|
default => 256, |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has '_hasher' => ( |
|
25
|
|
|
|
|
|
|
is => 'lazy', |
|
26
|
|
|
|
|
|
|
init_arg => undef, |
|
27
|
|
|
|
|
|
|
); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _build__hasher { |
|
30
|
24
|
|
|
24
|
|
728
|
my $self = shift; |
|
31
|
24
|
|
|
|
|
43
|
my $shasize = $self->sha_size; |
|
32
|
|
|
|
|
|
|
|
|
33
|
24
|
|
|
|
|
360
|
return Digest::SHA->can("hmac_sha$shasize"); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub hash_len { |
|
37
|
63
|
|
|
63
|
0
|
62
|
my $self = shift; |
|
38
|
63
|
|
|
|
|
179
|
return $self->sha_size() / 8; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub generate { |
|
42
|
4200
|
|
|
4200
|
0
|
2777
|
my $self = shift; # ($data, $key) |
|
43
|
4200
|
|
|
|
|
48851
|
return $self->_hasher->(@_); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub to_algo_string { |
|
47
|
21
|
|
|
21
|
0
|
23
|
my $self = shift; |
|
48
|
|
|
|
|
|
|
|
|
49
|
21
|
|
|
|
|
50
|
return $self->sha_size; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub from_algo_string { |
|
53
|
21
|
|
|
21
|
0
|
30
|
my ($class, $str) = @_; |
|
54
|
|
|
|
|
|
|
|
|
55
|
21
|
|
|
|
|
377
|
return $class->new( sha_size => $str ); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=pod |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=encoding UTF-8 |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 NAME |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Crypt::PBKDF2::Hash::HMACSHA2 - HMAC-SHA2 support for Crypt::PBKDF2 using Digest::SHA |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 VERSION |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
version 0.160410 |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Uses L<Digest::SHA> C<hmac_sha256>/C<hmac_sha384>/C<hmac_sha512> to provide |
|
77
|
|
|
|
|
|
|
the HMAC-SHA2 family of hashes for L<Crypt::PBKDF2>. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 AUTHOR |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Andrew Rodland <arodland@cpan.org> |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Andrew Rodland. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
88
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |