Security Advisories (2)
CVE-2026-41564 (2026-04-23)

CryptX versions before 0.088 for Perl do not reseed the Crypt::PK PRNG state after forking. The Crypt::PK::RSA, Crypt::PK::DSA, Crypt::PK::DH, Crypt::PK::ECC, Crypt::PK::Ed25519 and Crypt::PK::X25519 modules seed a per-object PRNG state in their constructors and reuse it without fork detection. A Crypt::PK::* object created before `fork()` shares byte-identical PRNG state with every child process, and any randomized operation they perform can produce identical output, including key generation. Two ECDSA or DSA signatures from different processes are enough to recover the signing private key through nonce-reuse key recovery. This affects preforking services such as the Starman web server, where a Crypt::PK::* object loaded at startup is inherited by every worker process.

CVE-2026-41565 (2026-05-28)

CryptX versions before 0.088_001 for Perl have a stack buffer overflow in four AEAD decrypt_verify helpers. The gcm_decrypt_verify, ccm_decrypt_verify, chacha20poly1305_decrypt_verify and eax_decrypt_verify XS routines copied the caller-supplied authentication tag into a fixed 144-byte stack buffer (MAXBLOCKSIZE) without checking the supplied length. A longer tag overwrites the stack past the buffer. Version 0.088 added the clamp to gcm_decrypt_verify, and 0.088_001 added it to the other three. Any caller of an affected helper that forwards an attacker-controlled tag longer than the buffer can trigger the overflow.

NAME

Crypt::PRNG - Cryptographically secure random number generator

SYNOPSIS

### Functional interface:
use Crypt::PRNG qw(random_bytes random_bytes_hex random_bytes_b64 random_bytes_b64u
                   random_string random_string_from rand irand);

$octets = random_bytes(45);
$hex_string = random_bytes_hex(45);
$base64_string = random_bytes_b64(45);
$base64url_string = random_bytes_b64u(45);
$alphanumeric_string = random_string(30);
$string = random_string_from('ACGT', 64);
$floating_point_number_0_to_1 = rand;
$floating_point_number_0_to_88 = rand(88);
$unsigned_32bit_int = irand;

### OO interface:
use Crypt::PRNG;

$prng = Crypt::PRNG->new;  # defaults to ChaCha20
#or
$prng = Crypt::PRNG->new("RC4");
#or
$prng = Crypt::PRNG->new("RC4", "some data used for seeding PRNG");

$octets = $prng->bytes(45);
$hex_string = $prng->bytes_hex(45);
$base64_string = $prng->bytes_b64(45);
$base64url_string = $prng->bytes_b64u(45);
$alphanumeric_string = $prng->string(30);
$string = $prng->string_from('ACGT', 64);
$floating_point_number_0_to_1 = $prng->double;
$floating_point_number_0_to_88 = $prng->double(88);
$unsigned_32bit_int = $prng->int32;

DESCRIPTION

Provides an interface to the ChaCha20 based pseudo random number generator (thread-safe and fork-safe).

FUNCTIONS

random_bytes

$octets = random_bytes($length);

Returns $length random octects.

random_bytes_hex

$hex_string = random_bytes_hex($length);

Returns $length random octects encoded as hexadecimal string.

random_bytes_b64

$base64_string = random_bytes_b64($length);

Returns $length random octects Base64 encoded.

random_bytes_b64u

$base64url_string = random_bytes_b64u($length);

Returns $length random octects Base64 URL Safe (RFC 4648 section 5) encoded.

random_string_from

$string = random_string_from($range, $length);
#e.g.
$string = random_string_from("ABCD", 10);

Returns a random string made of $length chars randomly chosen from $range string.

random_string

$alphanumeric_string = random_string($length);
#or
$alphanumeric_string = random_string;  # default length = 20

Similar to random_string_from, only $range is fixed to 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'.

rand

$n = rand;
#or
$n = rand($limit);

Returns a random floating point number from range [0,1) (if called without parameter) or [0,$limit).

irand

$i = irand;

Returns a random unsigned 32bit integer - range 0 .. 0xFFFFFFFF.

METHODS

new

$prng = Crypt::PRNG->new;  # defaults to ChaCha20
#or
$prng = Crypt::PRNG->new($alg);
#or
$prng = Crypt::PRNG->new($alg, $seed);

# $alg  ... algorithm name 'ChaCha20' (DEFAULT), 'Fortuna', 'RC4', 'Sober128' or 'Yarrow'
# $seed ... will be used as an initial entropy for seeding PRNG

If $seed is not specified the PRNG is automatically seeded with 32bytes random data taken from /dev/random (UNIX) or CryptGenRandom (Win32)

add_entropy

$prng->add_entropy($random_data);
#or
$prng->add_entropy();

If called without parameter it uses 32bytes random data taken from /dev/random (UNIX) or CryptGenRandom (Win32).

BEWARE: you probably do not need this function at all as the module does automatic seeding on initialization as well as reseeding after fork and thread creation.

bytes

$octets = $prng->bytes($length);

See random_bytes

bytes_hex

$hex_string = $prng->bytes_hex($length);

See random_bytes_hex

bytes_b64

$base64_string = $prng->bytes_b64($length);

See random_bytes_b64

bytes_b64u

$base64url_string = $prng->bytes_b64u($length);

See random_bytes_b64u

string

$alphanumeric_string = $prng->string($length);
#or
$alphanumeric_string = $prng->string;

See random_string

string_from

$string = $prng->string_from($range, $length);

See random_string_from

double

$n = $prng->double;
#or
$n = $prng->double($limit);

See rand

int32

$i = $prng->int32;

See irand

SEE ALSO

Crypt::PRNG::Fortuna, Crypt::PRNG::RC4, Crypt::PRNG::Sober128, Crypt::PRNG::Yarrow