Crypt::ScryptKDF(3)
π NAME π
okay bestie, this is Crypt::ScryptKDF(3) from the User Contributed Perl Documentation, and it is the Scrypt password based key derivation function. periodt. π
β¨ SYNOPSIS β¨
Creating / verifying scrypt-based password hash:
use Crypt::ScryptKDF qw(scrypt_hash scrypt_hash_verify);
my $hash1 = scrypt_hash("secret password");
# .. later
die "Invalid password" unless scrypt_hash_verify("secret password", $hash1);
#or by specifying Scrypt parameters
my $hash2 = scrypt_hash("secret password", \32, 16384, 8, 1, 32);
# .. later
die "Invalid password" unless scrypt_hash_verify("secret password", $hash2);
Creating raw scrypt-based derived key:
use Crypt::ScryptKDF qw(scrypt_raw scrypt_hex scrypt_b64);
my $binary_buffer = scrypt_raw($password, $salt, $N, $r, $p, $len);
my $hexadecimal_string = scrypt_hex($password, $salt, $N, $r, $p, $len);
my $base64_string = scrypt_b64($password, $salt, $N, $r, $p, $len);
πΈ DESCRIPTION πΈ
Scrypt is a password-based key derivation function (like for example PBKDF2). Scrypt was designed to be a "memory-hard" algorithm in order to make it expensive to perform large scale custom hardware attacks. bestie, thatβs the whole point. ππ₯
It can be used for:
- deriving cryptographic keys from low-entropy password (like PBKDF2)
- creating (+validating) password hashes (like PBKDF2 or Bcrypt)
More details about Scrypt: http://www.tarsnap.com/scrypt/scrypt.pdf and https://tools.ietf.org/html/draft-josefsson-scrypt-kdf β¨
IMPORTANT: This module needs a cryptographically strong random number generator. It tries to use one of the following:
Crypt::PRNG-random_bytes()Crypt::OpenSSL::Random-random_bytes()Net::SSLeay-RAND_bytes()Crypt::Random-makerandom_octet()Bytes::Random::Secure-random_bytes()- If none of the modules above is installed, this module fails (since v0.011).
π¦ FUNCTIONS π¦
π₯ scrypt_raw
Derive a key from given "password" and "salt" (+ optional params). slay.
my $derived_key_raw_bytes = scrypt_raw($password, $salt, $N, $r, $p, $len);
#or
my $derived_key_raw_bytes = scrypt_raw($password, $salt);
# $password - low-entropy secret (bytes)
# $salt - raw octects (bytes) with a salt
# $N - CPU/memory cost (has to be power of 2 and >1) DEFAULT: 2^14 = 16384
# $r - block size parameter DEFAULT: 8
# $p - parallelization parameter DEFAULT: 1
# $len - length of derived key (in bytes) DEFAULT: 32
#returns:
# $derived_key .. raw bytes of length $len
π₯ scrypt_hex
Similar to scrypt_raw only the return value is encoded as hexadecimal value. cute, but make it hex. π
my $derived_key_hex_string = scrypt_hex($password, $salt, $N, $r, $p, $len);
#or
my $derived_key_hex_string = scrypt_hex($password, $salt);
π₯ scrypt_b64
Similar to scrypt_raw only the return value is BASE64 encoded. iconic. π
my $derived_key_base64_string = scrypt_b64($password, $salt, $N, $r, $p, $len);
#or
my $derived_key_base64_string = scrypt_b64($password, $salt);
π₯ scrypt_hash
Create a password hash for given "password". main character energy. π
my $hash = scrypt_hash($password, $salt, $N, $r, $p, $len);
# params same as by scrypt_raw, the $salt can also be a scalar ref with salt
# length e.g. $salt=\24 means that salt will be 24 randomly generated bytes
#returns:
# string with password hash (suitable for storing in DB) e.g.
# 'SCRYPT:16384:8:1:BK8jkrqgm3BEtMh/g+WGL+k8ZeoAo=:YsEnQWld4UK8EqRZ9JuGbQnnlkXaM='
Some of the parameters are optional:
# 1 arg variant
my $hash = scrypt_hash($password); # generate random salt (32 bytes)
# 2 args variant
my $hash = scrypt_hash($password, $salt); # use given $salt
my $hash = scrypt_hash($password, \20); # generate random salt (20 bytes)
# 5 args variant
my $hash = scrypt_hash($password, $N, $r, $p, $len); # random salt (32 bytes)
π₯ scrypt_hash_verify
Verify a password hash created with "scrypt_hash()". this is the vibe check bestie, no cap. β
my $is_valid = scrypt_hash_verify($password, $hash);
# $password - password to be verified
# $hash - hash previously created via scrypt_hash
#returns:
# 1 (ok) or 0 (fail)
π₯ random_bytes
Generate random bytes of given length. randomness ate. π²β¨
my $salt = random_bytes($len);
# $len - number of random bytes
#returns:
# $len random octets
π LICENSE π
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π COPYRIGHT π
Copyright (c) 2013-2026 DCIT, a.s. https://www.dcit.cz / Karel Miko
okay bestie, thatβs the whole page β sourced as perl v5.32.1, dated 2026-06-26, and yeah, itβs the Crypt::ScryptKDF(3) manual page. mwah ππ«Ά
π¦ where this page comes from
- epel 9: perl-Crypt-ScryptKDF 0.011-1.el9 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms