Salsa20 eStream cipher in Lua.
The Salsa20 stream cipher was published by Daniel J. Bernstein of the University of Illinois at Chicago in 2005 and submitted to the eSTREAM project.
The algorithm is an efficient and well-designed cipher. As of 2015, there are no effective attacks on this cipher.
All byte sequences are implemented as strings, which are 8-bit clean in Lua.
salsa20.generate(k, v, i, rounds)
- k
- A 16-byte or 32-byte sequence representing the secret key.
- v
- An 8-byte sequence representing the nonce.
- i
- An 8-byte sequence representing the stream position of the 64-byte block.
- rounds (optional)
- May be 20 (default), 12, or 8.
A 64-byte output block.
salsa20.encrypt(key, nonce, plaintext, rounds)
- key
- A 16-byte or 32-byte sequence representing the secret key.
- nonce
- An 8-byte sequence representing the nonce.
- plaintext
- The unencrypted message.
- rounds (optional)
- May be 20 (default), 12, or 8.
The encrypted message.
salsa20.encrypt_table(key, nonce, plaintab, rounds)
This is a convenience function for encrypting multiple strings while maintaining state.
- key
- A 16-byte or 32-byte sequence representing the secret key.
- nonce
- An 8-byte sequence representing the nonce.
- plaintab
- A table containing unencrypted messages.
- rounds (optional)
- May be 20 (default), 12, or 8.
A table containing encrypted messages.
salsa20.decrypt(key, nonce, ciphertext, rounds)
- key
- A 16-byte or 32-byte sequence representing the secret key.
- nonce
- An 8-byte sequence representing the nonce.
- ciphertext
- The encrypted message.
- rounds (optional)
- May be 20 (default), 12, or 8.
The unencrypted message.
salsa20.decrypt_table(key, nonce, ciphertab, rounds)
This is a convenience function for decrypting multiple strings while maintaining state.
- key
- A 16-byte or 32-byte sequence representing the secret key.
- nonce
- An 8-byte sequence representing the nonce.
- ciphertab
- A table containing encrypted messages.
- rounds (optional)
- May be 20 (default), 12, or 8.
A table containing unencrypted messages.