libsodium_crypto_stream_salsa2012 (libsodium v3.0.1)
View SourceThe reduced-round Salsa20/12 stream cipher with a 64-bit nonce, faster than Salsa20/20 with a smaller security margin.
crypto_stream_salsa2012/3 returns raw keystream and 'xor'/3 encrypts
or decrypts by combining a message with it. The 8 byte nonce is too short
to be chosen at random safely.
This is not authenticated encryption: ciphertexts can be modified without
detection, so pair it with a MAC or use libsodium_crypto_secretbox
instead. A nonce must never be reused with the same key.
K = libsodium_crypto_stream_salsa2012:keygen(),
N = libsodium_randombytes:buf(libsodium_crypto_stream_salsa2012:noncebytes()),
C = libsodium_crypto_stream_salsa2012:'xor'(<<"message">>, N, K),
<<"message">> = libsodium_crypto_stream_salsa2012:'xor'(C, N, K).
Summary
Types
A crypto_stream_salsa2012_KEYBYTES (32-byte) binary.
A crypto_stream_salsa2012_NONCEBYTES (8-byte) binary.
Functions
Return CLen bytes of keystream for the noncebytes/0 byte nonce N and the keybytes/0 byte key K.
Return crypto_stream_salsa2012_keybytes(), in bytes.
Generate a random keybytes/0 byte key.
Return crypto_stream_salsa2012_messagebytes_max(), in bytes.
Return crypto_stream_salsa2012_noncebytes(), in bytes.
Encrypt or decrypt M by combining it with the keystream for the nonce
N and key K.
Types
Functions
-spec crypto_stream_salsa2012(CLen, N, K) -> Result when CLen :: non_neg_integer(), N :: n(), K :: k(), Result :: binary().
Return CLen bytes of keystream for the noncebytes/0 byte nonce N and the keybytes/0 byte key K.
-spec keybytes() -> Result when Result :: 32.
Return crypto_stream_salsa2012_keybytes(), in bytes.
-spec keygen() -> Result when Result :: k().
Generate a random keybytes/0 byte key.
-spec messagebytes_max() -> Result when Result :: non_neg_integer().
Return crypto_stream_salsa2012_messagebytes_max(), in bytes.
-spec noncebytes() -> Result when Result :: 8.
Return crypto_stream_salsa2012_noncebytes(), in bytes.
Encrypt or decrypt M by combining it with the keystream for the nonce
N and key K.