CryptX

 view release on metacpan or  search on metacpan

lib/Crypt/KeyDerivation.pm  view on Meta::CPAN


  my $derived_key = bcrypt_pbkdf($password, $salt, $rounds, $hash_name, $len);
  #or
  my $derived_key = bcrypt_pbkdf($password, $salt, $rounds, $hash_name);
  #or
  my $derived_key = bcrypt_pbkdf($password, $salt, $rounds);
  #or
  my $derived_key = bcrypt_pbkdf($password, $salt);

  # $password ... [binary string] input keying material (password)
  # $salt ....... [binary string] salt/nonce
  # $rounds ..... [integer] optional, number of rounds, DEFAULT: 16
  # $hash_name .. [string]  optional, DEFAULT: 'SHA512'
  # $len ........ [integer] optional, derived key len in bytes, DEFAULT: 32

Larger C<$rounds> values increase CPU cost linearly.

=head2 scrypt_pbkdf

scrypt key derivation according to L<https://www.rfc-editor.org/rfc/rfc7914>.

I<Since: CryptX-0.088>


  my $derived_key = scrypt_pbkdf($password, $salt, $N, $r, $p, $len);
  #or
  my $derived_key = scrypt_pbkdf($password, $salt, $N, $r, $p);
  #or
  my $derived_key = scrypt_pbkdf($password, $salt, $N);
  #or
  my $derived_key = scrypt_pbkdf($password, $salt);

  # $password ... [binary string] input keying material (password)
  # $salt ....... [binary string] salt/nonce
  # $N .......... [integer] optional, CPU/memory cost (must be power of 2), DEFAULT: 1024
  # $r .......... [integer] optional, block size, DEFAULT: 8
  # $p .......... [integer] optional, parallelization parameter, DEFAULT: 1
  # $len ........ [integer] optional, derived key len in bytes, DEFAULT: 32

Use only power-of-two values for C<$N>. Larger C<$N>, C<$r>, and C<$p>
increase resource usage substantially; invalid combinations croak.

=head2 argon2_pbkdf

Argon2 key derivation according to L<https://www.rfc-editor.org/rfc/rfc9106>.

I<Since: CryptX-0.088>


  my $derived_key = argon2_pbkdf($type, $password, $salt, $t_cost, $m_factor, $parallelism, $len, $secret, $ad);
  #or
  my $derived_key = argon2_pbkdf($type, $password, $salt, $t_cost, $m_factor, $parallelism, $len);
  #or
  my $derived_key = argon2_pbkdf($type, $password, $salt, $t_cost, $m_factor, $parallelism);
  #or
  my $derived_key = argon2_pbkdf($type, $password, $salt);

  # $type        ... [string]  one of 'argon2d', 'argon2i', 'argon2id'
  # $password    ... [binary string] input keying material (password)
  # $salt        ... [binary string] salt/nonce (recommended: at least 16 bytes)
  # $t_cost      ... [integer] optional, time cost (number of iterations), DEFAULT: 3
  # $m_factor    ... [integer] optional, memory cost in kibibytes (1 KiB = 1024 B), DEFAULT: 65536 (= 64 MiB)
  # $parallelism ... [integer] optional, degree of parallelism, DEFAULT: 1
  # $len         ... [integer] optional, derived key len in bytes, DEFAULT: 32
  # $secret      ... [binary string] optional, secret value, DEFAULT: ''
  # $ad          ... [binary string] optional, associated data, DEFAULT: ''

Increasing C<$t_cost>, C<$m_factor>, or C<$parallelism> increases work and
memory requirements. Invalid combinations croak. Optional C<$secret> and
C<$ad> may be C<undef>; otherwise they must be string or stringifiable scalars.

=head1 SEE ALSO

=over

=item * L<CryptX>

=item * L<Crypt::Digest>, L<Crypt::Mac>, L<Crypt::PRNG>

=item * L<https://www.rfc-editor.org/rfc/rfc2898>

=item * L<https://www.rfc-editor.org/rfc/rfc5869>

=item * L<https://www.rfc-editor.org/rfc/rfc7914>

=item * L<https://www.rfc-editor.org/rfc/rfc9106>

=back

=cut



( run in 1.632 second using v1.01-cache-2.11-cpan-71847e10f99 )