manpagez: man pages & more
man Crypt::Stream::Salsa20(3)
Home | html | info | man
Crypt::Stream::Salsa20(3)                  User Contributed Perl Documentation



NAME

       Crypt::Stream::Salsa20 - Stream cipher Salsa20


SYNOPSIS

          use Crypt::Stream::Salsa20;

          # encrypt
          my $key = "1234567890123456";
          my $nonce  = "12345678";
          my $enc_stream = Crypt::Stream::Salsa20->new($key, $nonce);
          my $ct = $enc_stream->crypt("plain message");

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


DESCRIPTION

       Provides an interface to the Salsa20 stream cipher.


METHODS

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

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

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

        # $key     .. [binary string] 32 or 16 bytes
        # $nonce   .. [binary string] 8 bytes
        # $counter .. [integer] initial counter value (DEFAULT: 0)
        # $rounds  .. [integer] rounds (DEFAULT: 20)

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

       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.

        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.

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

   clone
       Returns a copy of the stream cipher object in its current state.

        my $stream2 = $stream->clone();


SEE ALSO

       o   Crypt::Stream::ChaCha(3), Crypt::Stream::RC4(3),
           Crypt::Stream::Sober128(3), Crypt::Stream::Sosemanuk(3)

       o   <https://cr.yp.to/snuffle/spec.pdf>

perl v5.34.3                      2026-05-11         Crypt::Stream::Salsa20(3)

cryptx 0.89.0 - Generated Tue May 12 11:28:46 CDT 2026
© manpagez.com 2000-2026
Individual documents may contain additional copyright information.