Skip to Content
oxcrypto

Salsa20

Encrypt with Salsa20, its reduced-round variants or XSalsa20.

from oxcrypto.stream.salsa20 import SALSA

key = bytes(32)
nonce = bytes(24)
ciphertext = SALSA.XSALSA20.apply_keystream(key, nonce, b"hello")
assert SALSA.XSALSA20.apply_keystream(key, nonce, ciphertext) == b"hello"

cipher = SALSA.XSALSA20.new(key, nonce, counter=2)
assert cipher.position == 128
VariantKeyNonce
SALSA8, SALSA12, SALSA2032 bytes8 bytes
XSALSA8, XSALSA12, XSALSA2032 bytes24 bytes

Salsa20 is in the eSTREAM software portfolio. Salsa20/12 is the variant the portfolio recommends; Salsa20/8 is a faster reduced-round variant. XSalsa20 extends the nonce to 192 bits. Only 256-bit keys are supported. The 64-bit counter gives 2⁶⁴ − 1 usable 64-byte blocks.