lua-salsa20
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.
Resources
Usage
All byte sequences are implemented as strings, which are 8-bit clean in Lua.
generate
salsa20.generate(k, v, i, rounds)
Arguments
- 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.
Return Value
A 64-byte output block.
encrypt
salsa20.encrypt(key, nonce, plaintext, rounds)
Arguments
- 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.
Return Value
The encrypted message.
encrypt_table
salsa20.encrypt_table(key, nonce, plaintab, rounds)
This is a convenience function for encrypting multiple strings while maintaining state.
Arguments
- 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.
Return Value
A table containing encrypted messages.
decrypt
salsa20.decrypt(key, nonce, ciphertext, rounds)
Arguments
- 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.
Return Value
The unencrypted message.
decrypt_table
salsa20.decrypt_table(key, nonce, ciphertab, rounds)
This is a convenience function for decrypting multiple strings while maintaining state.
Arguments
- 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.
Return Value
A table containing unencrypted messages.