Package Cryptodome :: Package Cipher :: Module Salsa20

Module Salsa20

Salsa20 stream cipher

Salsa20 is a stream cipher designed by Daniel J. Bernstein.

Its key is by preference 256 bits long, but it can also work with 128 bit keys.

As an example, encryption can be done as follows:

>>> from Cryptodome.Cipher import Salsa20
>>>
>>> key = b'*Thirty-two byte (256 bits) key*'
>>> cipher = Salsa20.new(key)
>>> msg = cipher.nonce + cipher.encrypt(b'Attack at dawn')
Classes
  Salsa20Cipher
Salsa20 cipher object
Functions
 
new(key, nonce=None)
Create a new Salsa20 cipher
Variables
  block_size = 1
Size of a data block (in bytes)
  key_size = (16, 32)
Size of a key (in bytes)
Function Details

new(key, nonce=None)

 
Create a new Salsa20 cipher
Parameters:
  • key (byte string) - The secret key to use in the symmetric cipher. It must be 16 or 32 bytes long.
  • nonce (byte string) - A value that must never be reused for any other encryption. It must be 8 bytes long.

    If not provided, a random byte string will be generated (you can read it back via the nonce attribute).

Returns:
an Salsa20Cipher object