]> Dogcows Code - chaz/p5-File-KDBX/blob - lib/File/KDBX/KDF/Argon2.pm
Version 0.906
[chaz/p5-File-KDBX] / lib / File / KDBX / KDF / Argon2.pm
1 package File::KDBX::KDF::Argon2;
2 # ABSTRACT: The Argon2 family of key derivation functions
3
4 use warnings;
5 use strict;
6
7 use Crypt::Argon2 qw(argon2d_raw argon2id_raw);
8 use File::KDBX::Constants qw(:kdf);
9 use File::KDBX::Error;
10 use File::KDBX::Util qw(:class);
11 use namespace::clean;
12
13 extends 'File::KDBX::KDF';
14
15 our $VERSION = '0.906'; # VERSION
16
17
18 sub salt { $_[0]->{+KDF_PARAM_ARGON2_SALT} or throw 'Salt is not set' }
19 sub seed { $_[0]->salt }
20 sub parallelism { $_[0]->{+KDF_PARAM_ARGON2_PARALLELISM} //= KDF_DEFAULT_ARGON2_PARALLELISM }
21 sub memory { $_[0]->{+KDF_PARAM_ARGON2_MEMORY} //= KDF_DEFAULT_ARGON2_MEMORY }
22 sub iterations { $_[0]->{+KDF_PARAM_ARGON2_ITERATIONS} //= KDF_DEFAULT_ARGON2_ITERATIONS }
23 sub version { $_[0]->{+KDF_PARAM_ARGON2_VERSION} //= KDF_DEFAULT_ARGON2_VERSION }
24 sub secret { $_[0]->{+KDF_PARAM_ARGON2_SECRET} }
25 sub assocdata { $_[0]->{+KDF_PARAM_ARGON2_ASSOCDATA} }
26
27 sub init {
28 my $self = shift;
29 my %args = @_;
30 return $self->SUPER::init(
31 KDF_PARAM_ARGON2_SALT() => $args{+KDF_PARAM_ARGON2_SALT} // $args{salt},
32 KDF_PARAM_ARGON2_PARALLELISM() => $args{+KDF_PARAM_ARGON2_PARALLELISM} // $args{parallelism},
33 KDF_PARAM_ARGON2_MEMORY() => $args{+KDF_PARAM_ARGON2_MEMORY} // $args{memory},
34 KDF_PARAM_ARGON2_ITERATIONS() => $args{+KDF_PARAM_ARGON2_ITERATIONS} // $args{iterations},
35 KDF_PARAM_ARGON2_VERSION() => $args{+KDF_PARAM_ARGON2_VERSION} // $args{version},
36 KDF_PARAM_ARGON2_SECRET() => $args{+KDF_PARAM_ARGON2_SECRET} // $args{secret},
37 KDF_PARAM_ARGON2_ASSOCDATA() => $args{+KDF_PARAM_ARGON2_ASSOCDATA} // $args{assocdata},
38 );
39 }
40
41 sub _transform {
42 my $self = shift;
43 my $key = shift;
44
45 my ($uuid, $salt, $iterations, $memory, $parallelism)
46 = ($self->uuid, $self->salt, $self->iterations, $self->memory, $self->parallelism);
47
48 if ($uuid eq KDF_UUID_ARGON2D) {
49 return argon2d_raw($key, $salt, $iterations, $memory, $parallelism, length($salt));
50 }
51 elsif ($uuid eq KDF_UUID_ARGON2ID) {
52 return argon2id_raw($key, $salt, $iterations, $memory, $parallelism, length($salt));
53 }
54
55 throw 'Unknown Argon2 type', uuid => $uuid;
56 }
57
58 1;
59
60 __END__
61
62 =pod
63
64 =encoding UTF-8
65
66 =head1 NAME
67
68 File::KDBX::KDF::Argon2 - The Argon2 family of key derivation functions
69
70 =head1 VERSION
71
72 version 0.906
73
74 =head1 DESCRIPTION
75
76 An Argon2 key derivation function. This is a L<File::KDBX::KDF> subclass.
77
78 This KDF allows for excellent resistance to ASIC password cracking. It's a solid choice but doesn't have the
79 track record of L<File::KDBX::KDF::AES> and requires using the KDBX4+ file format.
80
81 =head1 ATTRIBUTES
82
83 =head2 salt
84
85 =head2 parallelism
86
87 =head2 memory
88
89 =head2 iterations
90
91 =head2 version
92
93 =head2 secret
94
95 =head2 assocdata
96
97 Get various KDF parameters.
98
99 C<version>, C<secret> and C<assocdata> are currently unused.
100
101 =head1 BUGS
102
103 Please report any bugs or feature requests on the bugtracker website
104 L<https://github.com/chazmcgarvey/File-KDBX/issues>
105
106 When submitting a bug or request, please include a test-file or a
107 patch to an existing test-file that illustrates the bug or desired
108 feature.
109
110 =head1 AUTHOR
111
112 Charles McGarvey <ccm@cpan.org>
113
114 =head1 COPYRIGHT AND LICENSE
115
116 This software is copyright (c) 2022 by Charles McGarvey.
117
118 This is free software; you can redistribute it and/or modify it under
119 the same terms as the Perl 5 programming language system itself.
120
121 =cut
This page took 0.038739 seconds and 4 git commands to generate.