Crypt::Argon2(3pm)
πΈ Crypt::Argon2 β the Perl interface to the Argon2 KDFs π
okay so this page is Crypt::Argon2(3pm), part of the User Contributed Perl Documentation, and it's literally your new bestie for turning passwords into cryptographic keys. buckle up π
β¨ VERSION β¨
version 0.031 β yes queen, we're on 0.031 π
π¦ SYNOPSIS π¦
here's the vibe, copy-paste style:
use Crypt::Argon2 qw/argon2id_pass argon2_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 argon2_verify($encoded, $password);
}
like, that's the whole loop: make a salt, hash the password, store it, then verify later. iconic β¨
π DESCRIPTION π
This module implements the Argon2 key derivation function, which is suitable to convert any password into a cryptographic key. most often it's used for secure storage of passwords, but ngl it can also derive an encryption key from a password. it offers variable time and memory costs as well as output size β so you get to tune it, main character energy fr fr.
To find appropriate parameters, the bundled program argon2-calibrate can be used. bestie, please use it, don't just guess π
π FUNCTIONS π
β argon2_pass($type, $password, $salt, $t_cost, $m_factor, $parallelism, $tag_size)
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").
okay so here's what each arg does π
$typeβ the argon2 type that is used. This must be one of'argon2id','argon2i'or'argon2d'.$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. (no cap, uniqueness is the whole point π§)$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 are16or32.
π argon2_verify($encoded, $password)
This verifies that the $password matches $encoded. All parameters and the tag value are extracted from $encoded, so no further arguments are necessary. slay, zero extra work π«Ά
π§ argon2_raw($type, $password, $salt, $t_cost, $m_factor, $parallelism, $tag_size)
This function processes the $password with the given $salt and parameters much like "argon2_pass", but returns the binary tag instead of a formatted string. raw bytes, no dress-up π
π argon2id_pass($password, $salt, $t_cost, $m_factor, $parallelism, $tag_size)
π argon2i_pass($password, $salt, $t_cost, $m_factor, $parallelism, $tag_size)
π argon2d_pass($password, $salt, $t_cost, $m_factor, $parallelism, $tag_size)
This function processes the $password much like "argon2_pass" does, but the $type argument is set like the function name. so like, the type is already baked in β no $type arg for you β¨
π argon2id_verify($encoded, $password)
π argon2i_verify($encoded, $password)
π argon2d_verify($encoded, $password)
This verifies that the $password matches $encoded and the given type. All parameters and the tag value are extracted from $encoded, so no further arguments are necessary.
π argon2id_raw($password, $salt, $t_cost, $m_factor, $parallelism, $tag_size)
π argon2i_raw($password, $salt, $t_cost, $m_factor, $parallelism, $tag_size)
π argon2d_raw($password, $salt, $t_cost, $m_factor, $parallelism, $tag_size)
This function processes the $password much like "argon2_raw" does, but the $type argument is set like the function name.
π¦ argon2_needs_rehash($encoded, $type, $t_cost, $m_cost, $parallelism, $output_length, $salt_length)
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"), $t_cost, $m_cost, $parallelism, $output_length or $salt_length arguments mismatches any of the parameters of the password-encoded hash.
lowkey the glow-up detector: if your stored hash's params don't match the ones you're passing in, it says "bestie, rehash time" π
πΈ argon2_types
This returns all supported argon2 subtypes. Currently that's 'argon2id', 'argon2i' and 'argon2d'.
β‘ argon2_implementation
This returns the implementation that is used. Possible values include "avx512", "avx2", "sse3", and "reference". it's giving "which CPU flex did we get" π₯
π ACKNOWLEDGEMENTS π
This module is based on the reference implementation as can be found at <https://github.com/P-H-C/phc-winner-argon2>. credit where credit is due, periodt π
π SEE ALSO π
You will also need a good source of randomness to generate good salts. Some possible solutions include:
- Net::SSLeay β its
RAND_bytesfunction 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::Bcrypt β an implementation of bcrypt, a battle-tested algorithm that tries to be CPU but not particularly memory intensive.
- Crypt::ScryptKDF β an implementation of scrypt, a older scheme that also tries to be memory hard.
π AUTHOR π
Leon Timmermans <fawaka@gmail.com>
π COPYRIGHT AND LICENSE π
This software is Copyright (c) 2013 by Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, Samuel Neves, Thomas Pornin and Leon Timmermans.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
and that's the whole page bestie π«Ά written for perl v5.42.3, dated 2026-08-19, Crypt::Argon2(3pm) β go forth and hash responsibly, mwah ππΈ
π¦ where this page comes from
- ubuntu stonking: libcrypt-argon2-perl 0.031-1build1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms