Crypt::...XSalsa20(3)

πŸ’– NAME πŸ’–

Crypt::Stream::XSalsa20 β€” Stream cipher XSalsa20. This is the Crypt::...XSalsa20(3) page from the User Contributed Perl Documentation shelf, and it's literally all about the XSalsa20 stream cipher, bestie. ✨

🌈 SYNOPSIS 🌈

Okay so here's the whole flow, no cap:

use Crypt::Stream::XSalsa20;

# encrypt
my $key    = "12345678901234567890123456789012";  # 32 bytes
my $nonce  = "123456789012345678901234";          # 24 bytes
my $enc_stream = Crypt::Stream::XSalsa20->new($key, $nonce);
my $ct = $enc_stream->crypt("plain message");

# decrypt
my $dec_stream = Crypt::Stream::XSalsa20->new($key, $nonce);
my $pt = $dec_stream->crypt($ct);

πŸ¦‹ DESCRIPTION πŸ¦‹

Since: CryptX-0.089 ✨

Provides an interface to the XSalsa20 stream cipher, an extended-nonce variant of Salsa20 with a 192-bit (24-byte) nonce. The larger nonce makes random nonce generation safe in practice. Highkey, the way that larger nonce makes random nonce generation safe in practice? Obsessed. It ate, honestly. πŸ’…

πŸ’… METHODS πŸ’…

Unless noted otherwise, assume $stream is an existing stream object created via new, for example:

my $stream = Crypt::Stream::XSalsa20->new($key, $nonce);

🌸 new 🌸

my $stream = Crypt::Stream::XSalsa20->new($key, $nonce);
#or
my $stream = Crypt::Stream::XSalsa20->new($key, $nonce, $rounds);

# $key    .. [binary string] 32 bytes
# $nonce  .. [binary string] 24 bytes
# $rounds .. [integer] optional, rounds (DEFAULT: 20)

So $key is a [binary string] of 32 bytes, $nonce is a [binary string] of 24 bytes, and $rounds is an optional [integer] for rounds with DEFAULT: 20. Slay.

πŸ”₯ crypt πŸ”₯

Encrypts or decrypts data. The output has the same length as the input. Returns a binary string (raw bytes). Lowkey giving raw bytes, periodt.

The input is converted using Perl's usual scalar stringification. Passing undef is treated as an empty string with the usual warning, and numeric scalars are stringified before processing. Not me passing undef and getting the usual warning β€” it's still treated as an empty string, fr fr.

my $ciphertext = $stream->crypt($plaintext);
#or
my $plaintext = $stream->crypt($ciphertext);

πŸŽ€ keystream πŸŽ€

Returns $length bytes of raw keystream as a binary string.

The length is taken using Perl's usual numeric coercion. Values that coerce to an oversized unsigned length are rejected as too large. Vibe check: rejected as too large, bestie. πŸ’€ Ngl, the oversized unsigned length does not get to sneak through.

my $random_bytes = $stream->keystream($length);

πŸ‘‘ clone πŸ‘‘

Returns a copy of the stream cipher object in its current state. Main character energy, but make it a copy β€” iykyk.

my $stream2 = $stream->clone;

🌟 SEE ALSO 🌟


🫢 Okay that's the whole page! Cute sign-off: this Crypt::...XSalsa20(3) manual is from perl v5.42.0, dated 2026-05-11, and it's giving User Contributed Perl Documentation energy. Mwah πŸ’‹βœ¨
πŸ“¦ where this page comes from