line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Passphrase::Argon2; |
2
|
|
|
|
|
|
|
$Crypt::Passphrase::Argon2::VERSION = '0.009'; |
3
|
2
|
|
|
2
|
|
69093
|
use strict; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
58
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
72
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
449
|
use Crypt::Passphrase 0.010 -encoder; |
|
2
|
|
|
|
|
14699
|
|
|
2
|
|
|
|
|
13
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
8024
|
use Carp 'croak'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
135
|
|
9
|
2
|
|
|
2
|
|
463
|
use Crypt::Argon2 0.017 qw/argon2_pass argon2_needs_rehash argon2_verify argon2_types/; |
|
2
|
|
|
|
|
907
|
|
|
2
|
|
|
|
|
984
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %settings_for = ( |
12
|
|
|
|
|
|
|
interactive => { |
13
|
|
|
|
|
|
|
time_cost => 2, |
14
|
|
|
|
|
|
|
memory_cost => '64M', |
15
|
|
|
|
|
|
|
}, |
16
|
|
|
|
|
|
|
moderate => { |
17
|
|
|
|
|
|
|
time_cost => 3, |
18
|
|
|
|
|
|
|
memory_cost => '256M', |
19
|
|
|
|
|
|
|
}, |
20
|
|
|
|
|
|
|
sensitive => { |
21
|
|
|
|
|
|
|
time_cost => 4, |
22
|
|
|
|
|
|
|
memory_cost => '1G', |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my %valid_types = map { ($_ => 1) } argon2_types; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _settings_for { |
29
|
5
|
|
|
5
|
|
17
|
my %args = @_; |
30
|
5
|
|
50
|
|
|
30
|
my $subtype = $args{subtype} // 'argon2id'; |
31
|
5
|
50
|
|
|
|
21
|
croak "Unknown subtype $subtype" unless $valid_types{$subtype}; |
32
|
5
|
|
100
|
|
|
20
|
my $profile = $args{profile} // 'moderate'; |
33
|
5
|
50
|
|
|
|
18
|
croak "Unknown profile $profile" unless $settings_for{$profile}; |
34
|
|
|
|
|
|
|
return { |
35
|
|
|
|
|
|
|
memory_cost => $args{memory_cost} // $settings_for{$profile}{memory_cost}, |
36
|
|
|
|
|
|
|
time_cost => $args{time_cost} // $settings_for{$profile}{time_cost}, |
37
|
|
|
|
|
|
|
parallelism => $args{parallelism} // 1, |
38
|
|
|
|
|
|
|
output_size => $args{output_size} // 32, |
39
|
5
|
|
66
|
|
|
133
|
salt_size => $args{salt_size} // 16, |
|
|
|
66
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
40
|
|
|
|
|
|
|
subtype => $subtype, |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub new { |
45
|
3
|
|
|
3
|
1
|
413
|
my ($class, %args) = @_; |
46
|
3
|
|
|
|
|
13
|
return bless _settings_for(%args), $class; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub hash_password { |
50
|
2
|
|
|
2
|
1
|
18
|
my ($self, $password) = @_; |
51
|
2
|
|
|
|
|
19
|
my $salt = $self->random_bytes($self->{salt_size}); |
52
|
2
|
|
|
|
|
10289
|
return argon2_pass($self->{subtype}, $password, $salt, @{$self}{qw/time_cost memory_cost parallelism output_size/}); |
|
2
|
|
|
|
|
336020
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub needs_rehash { |
56
|
5
|
|
|
5
|
1
|
35
|
my ($self, $hash) = @_; |
57
|
5
|
|
|
|
|
16
|
return argon2_needs_rehash($hash, @{$self}{qw/subtype time_cost memory_cost parallelism output_size salt_size/}); |
|
5
|
|
|
|
|
39
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub crypt_subtypes { |
61
|
0
|
|
|
0
|
1
|
0
|
return argon2_types; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub verify_password { |
65
|
5
|
|
|
5
|
1
|
112018
|
my ($class, $password, $hash) = @_; |
66
|
5
|
|
|
|
|
443915
|
return argon2_verify($hash, $password); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
#ABSTRACT: An Argon2 encoder for Crypt::Passphrase |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |