line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Passphrase::Argon2; |
2
|
|
|
|
|
|
|
$Crypt::Passphrase::Argon2::VERSION = '0.008'; |
3
|
2
|
|
|
2
|
|
67936
|
use strict; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
57
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
68
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
449
|
use Crypt::Passphrase 0.010 -encoder; |
|
2
|
|
|
|
|
15626
|
|
|
2
|
|
|
|
|
13
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
8108
|
use Carp 'croak'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
138
|
|
9
|
2
|
|
|
2
|
|
473
|
use Crypt::Argon2 0.017 qw/argon2_pass argon2_needs_rehash argon2_verify argon2_types/; |
|
2
|
|
|
|
|
879
|
|
|
2
|
|
|
|
|
954
|
|
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
|
|
50
|
my %args = @_; |
30
|
5
|
|
50
|
|
|
48
|
my $subtype = $args{subtype} // 'argon2id'; |
31
|
5
|
50
|
|
|
|
22
|
croak "Unknown subtype $subtype" unless $valid_types{$subtype}; |
32
|
5
|
|
100
|
|
|
17
|
my $profile = $args{profile} // 'moderate'; |
33
|
5
|
50
|
|
|
|
23
|
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} // 16, |
39
|
5
|
|
66
|
|
|
101
|
salt_size => $args{salt_size} // 16, |
|
|
|
66
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
40
|
|
|
|
|
|
|
subtype => $subtype, |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub new { |
45
|
3
|
|
|
3
|
1
|
496
|
my ($class, %args) = @_; |
46
|
3
|
|
|
|
|
14
|
return bless _settings_for(%args), $class; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub hash_password { |
50
|
2
|
|
|
2
|
1
|
16
|
my ($self, $password) = @_; |
51
|
2
|
|
|
|
|
24
|
my $salt = $self->random_bytes($self->{salt_size}); |
52
|
2
|
|
|
|
|
10427
|
return argon2_pass($self->{subtype}, $password, $salt, @{$self}{qw/time_cost memory_cost parallelism output_size/}); |
|
2
|
|
|
|
|
328744
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub needs_rehash { |
56
|
5
|
|
|
5
|
1
|
36
|
my ($self, $hash) = @_; |
57
|
5
|
|
|
|
|
12
|
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
|
117079
|
my ($class, $password, $hash) = @_; |
66
|
5
|
|
|
|
|
440759
|
return argon2_verify($hash, $password); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
#ABSTRACT: An Argon2 encoder for Crypt::Passphrase |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |