GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Crypt::Argon2(3) User Contributed Perl Documentation Crypt::Argon2(3)

Crypt::Argon2 - Perl interface to the Argon2 key derivation functions

version 0.011

 use Crypt::Argon2 qw/argon2id_pass argon2id_verify/;

 sub add_pass {
   my ($user, $password) = @_;
   my $salt = get_random(16);
   my $encoded = argon2id_pass($password, $salt, 3, '32M', 1, 16);
   store_password($user, $encoded);
 }

 sub check_password {
   my ($user, $password) = @_;
   my $encoded = fetch_encoded($user);
   return argon2id_verify($encoded, $password);
 }

This module implements the Argon2 key derivation function, which is suitable to convert any password into a cryptographic key. This is most often used to for secure storage of passwords but can also be used to derive a encryption key from a password. It offers variable time and memory costs as well as output size.

To find appropriate parameters, the bundled program "argon2-calibrate" can be used.

This function processes the $password with the given $salt and parameters. It encodes the resulting tag and the parameters as a password string (e.g. "$argon2id$v=19$m=65536,t=2,p=1$c29tZXNhbHQ$wWKIMhR9lyDFvRz9YTZweHKfbftvj+qf+YFY4NeBbtA").
  • $password

    This is the password that is to be turned into a cryptographic key.

  • $salt

    This is the salt that is used. It must be long enough to be unique.

  • $t_cost

    This is the time-cost factor, typically a small integer that can be derived as explained above.

  • $m_factor

    This is the memory costs factor. This must be given as a integer followed by an order of magnitude ("k", "M" or "G" for kilobytes, megabytes or gigabytes respectively), e.g. '64M'.

  • $parallelism

    This is the number of threads that are used in computing it.

  • $tag_size

    This is the size of the raw result in bytes. Typical values are 16 or 32.

This verifies that the $password matches $encoded. All parameters and the tag value are extracted from $encoded, so no further arguments are necessary.

This function processes the $password with the given $salt and parameters much like "argon2i_pass", but returns the binary tag instead of a formatted string.

This function processes the $password with the given $salt and parameters much like argon2id_pass, but uses the argon2i variant instead.

This verifies that the $password matches $encoded. All parameters and the tag value are extracted from $encoded, so no further arguments are necessary.

This function processes the $password with the given $salt and parameters much like "argon2i_pass", but returns the binary tag instead of a formatted string.

This function processes the $password with the given $salt and parameters much like argon2id_pass, but uses the argon2d variant instead.

This verifies that the $password matches $encoded. All parameters and the tag value are extracted from $encoded, so no further arguments are necessary.

This function processes the $password with the given $salt and parameters much like "argon2i_pass", but returns a binary tag for argon2d instead of a formatted string for argon2i.

This function checks if a password-encoded string needs a rehash. It will return true if the $type (valid values are "argon2i", "argon2id" or "argon2d") mismatches or any of the $t_cost, $m_cost, $parallelism, $salt_length or $output_length arguments are higher than in the password-encoded hash.

This module is based on the reference implementation as can be found at <https://github.com/P-H-C/phc-winner-argon2>.

You will also need a good source of randomness to generate good salts. Some possible solutions include:
  • Net::SSLeay

    Its RAND_bytes function is OpenSSL's pseudo-randomness source.

  • Crypt::URandom

    A minimalistic abstraction around OS-provided non-blocking (pseudo-)randomness.

  • "/dev/random" / "/dev/urandom"

    A Linux/BSD specific pseudo-file that will allow you to read random bytes.

Implementations of other similar algorithms include:

  • Crypt::ScryptKDF

    An implementation of scrypt, a older scheme that also tries to be memory hard.

  • Crypt::Eksblowfish::Bcrypt

    An implementation of bcrypt, a battle-tested algorithm that tries to be CPU but not particularly memory intensive.

Leon Timmermans <leont@cpan.org>

Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, Samuel Neves, Thomas Pornin and Leon Timmermans has dedicated the work to the Commons by waiving all of his or her rights to the work worldwide under copyright law and all related or neighboring legal rights he or she had in the work, to the extent allowable by law.

Works under CC0 do not require attribution. When citing the work, you should not imply endorsement by the author.

2022-04-08 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.