Skip to content

Latest commit

 

History

History
38 lines (29 loc) · 1.17 KB

salsa20.rst

File metadata and controls

38 lines (29 loc) · 1.17 KB

Salsa20

Salsa20 is a stream cipher designed by Daniel J. Bernstein. The secret key is by preference 256 bits long, but it can also work with 128 bit keys.

This is an example of how Salsa20 can encrypt data:

>>> from Crypto.Cipher import Salsa20 >>> >>> plaintext = b'Attack at dawn' >>> secret = b'Thirty-two byte (256 bits) key' >>> cipher = Salsa20.new(key=secret) >>> msg = cipher.nonce + cipher.encrypt(plaintext)

And this is how you would decrypt it:

>>> from Crypto.Cipher import Salsa20 >>> >>> secret = b'Thirty-two byte (256 bits) key' >>> msg_nonce = msg[:8] >>> ciphertext = msg[8:] >>> cipher = Salsa20.new(key=secret, nonce=msg_nonce) >>> plaintext = cipher.decrypt(ciphertext)

Warning

Salsa20 does not guarantee authenticity of the data you decrypt! In other words, an attacker may manipulate the data in transit. In order to prevent that, you must also use a Message Authentication Code (such as HMAC <../hash/hmac>) to authenticate the ciphertext (encrypt-then-mac).

Crypto.Cipher.Salsa20