line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
12
|
use v5.26; |
|
1
|
|
|
|
|
3
|
|
2
|
1
|
|
|
1
|
|
6
|
use Object::Pad; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Blockchain::Ethereum::Keystore::Keyfile::KDF; |
5
|
|
|
|
|
|
|
class Blockchain::Ethereum::Keystore::Keyfile::KDF; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:REFECO'; # AUTHORITY |
8
|
|
|
|
|
|
|
our $VERSION = '0.007'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
849
|
use Crypt::KeyDerivation qw(pbkdf2); |
|
1
|
|
|
|
|
357
|
|
|
1
|
|
|
|
|
65
|
|
11
|
1
|
|
|
1
|
|
467
|
use Crypt::ScryptKDF qw(scrypt_raw); |
|
1
|
|
|
|
|
2993
|
|
|
1
|
|
|
|
|
1530
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
0
|
5
|
field $algorithm :reader :writer :param; |
|
2
|
|
|
2
|
0
|
7
|
|
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
11
|
|
14
|
2
|
|
|
2
|
0
|
7
|
field $dklen :reader :writer :param; |
|
2
|
|
|
2
|
0
|
825441
|
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
8
|
|
15
|
|
|
|
|
|
|
field $n :reader :writer :param //= undef; |
16
|
1
|
|
|
1
|
0
|
3
|
field $p :reader :writer :param //= undef; |
|
1
|
|
|
2
|
0
|
7
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
7
|
|
17
|
1
|
|
|
1
|
0
|
3
|
field $r :reader :writer :param //= undef; |
|
1
|
|
|
2
|
0
|
5
|
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
7
|
|
18
|
1
|
|
|
1
|
0
|
4
|
field $prf :reader :writer :param //= undef; |
|
1
|
|
|
2
|
0
|
6
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
7
|
|
19
|
0
|
|
|
0
|
0
|
0
|
field $c :reader :writer :param //= undef; |
|
0
|
|
|
0
|
0
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
20
|
1
|
|
|
1
|
0
|
4
|
field $salt :reader :writer :param; |
|
1
|
|
|
2
|
0
|
5
|
|
|
2
|
|
|
0
|
0
|
7
|
|
|
2
|
|
|
2
|
0
|
22
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
8
|
|
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
0
|
5
|
method decode ($password) { |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
2
|
|
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
|
|
11
|
my $kdf_function = '_decode_kdf_' . $self->algorithm; |
25
|
2
|
|
|
|
|
9
|
return $self->$kdf_function($password); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
|
3
|
method _decode_kdf_pbkdf2 ($password) { |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
3
|
my $derived_key = pbkdf2($password, pack("H*", $self->salt), $self->c, 'SHA256', $self->dklen); |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
25
|
return $derived_key; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
1
|
|
3
|
method _decode_kdf_scrypt ($password) { |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
6
|
my $derived_key = scrypt_raw( |
38
|
|
|
|
|
|
|
$password, # |
39
|
|
|
|
|
|
|
pack("H*", $self->salt), |
40
|
|
|
|
|
|
|
$self->n, |
41
|
|
|
|
|
|
|
$self->r, |
42
|
|
|
|
|
|
|
$self->p, |
43
|
|
|
|
|
|
|
$self->dklen |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
1813680
|
return $derived_key; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=pod |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=encoding UTF-8 |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 NAME |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Blockchain::Ethereum::Keystore::Keyfile::KDF |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 VERSION |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
version 0.007 |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 AUTHOR |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Reginaldo Costa <refeco@cpan.org> |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
This software is Copyright (c) 2023 by REFECO. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
This is free software, licensed under: |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
The MIT (X11) License |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |