libsodium_crypto_core_hsalsa20 (libsodium v3.0.1)

View Source

The HSalsa20 core function, which derives a outputbytes/0 byte subkey from a keybytes/0 byte key and a inputbytes/0 byte input. It is the building block of XSalsa20 and of the crypto_box key derivation.

The constbytes/0 byte constant C is normally the 16-byte string <<"expand 32-byte k">>. This is a low-level primitive: it is not a general-purpose key derivation function, and the key must be secret and uniformly random.

Key = libsodium_randombytes:buf(libsodium_crypto_core_hsalsa20:keybytes()),
In = libsodium_randombytes:buf(libsodium_crypto_core_hsalsa20:inputbytes()),
Out = libsodium_crypto_core_hsalsa20:crypto_core_hsalsa20(In, Key, <<"expand 32-byte k">>),
32 = byte_size(Out),
Out = libsodium_crypto_core_hsalsa20:crypto_core_hsalsa20(In, Key, <<"expand 32-byte k">>).

Summary

Types

c()

A crypto_core_hsalsa20_CONSTBYTES (16-byte) binary.

A crypto_core_hsalsa20_INPUTBYTES (16-byte) binary.

k()

A crypto_core_hsalsa20_KEYBYTES (32-byte) binary.

A crypto_core_hsalsa20_OUTPUTBYTES (32-byte) binary.

Functions

Return crypto_core_hsalsa20_constbytes(), in bytes.

Compute the HSalsa20 core of the inputbytes/0 byte input In with the keybytes/0 byte key K and the constbytes/0 byte constant C, returning outputbytes/0 bytes.

Return crypto_core_hsalsa20_inputbytes(), in bytes.

Return crypto_core_hsalsa20_keybytes(), in bytes.

Return crypto_core_hsalsa20_outputbytes(), in bytes.

Types

c()

-type c() :: <<_:128>>.

A crypto_core_hsalsa20_CONSTBYTES (16-byte) binary.

in()

-type in() :: <<_:128>>.

A crypto_core_hsalsa20_INPUTBYTES (16-byte) binary.

k()

-type k() :: <<_:256>>.

A crypto_core_hsalsa20_KEYBYTES (32-byte) binary.

out()

-type out() :: <<_:256>>.

A crypto_core_hsalsa20_OUTPUTBYTES (32-byte) binary.

Functions

constbytes()

-spec constbytes() -> Result when Result :: 16.

Return crypto_core_hsalsa20_constbytes(), in bytes.

crypto_core_hsalsa20(In, K, C)

-spec crypto_core_hsalsa20(In, K, C) -> Result when In :: in(), K :: k(), C :: c(), Result :: out().

Compute the HSalsa20 core of the inputbytes/0 byte input In with the keybytes/0 byte key K and the constbytes/0 byte constant C, returning outputbytes/0 bytes.

inputbytes()

-spec inputbytes() -> Result when Result :: 16.

Return crypto_core_hsalsa20_inputbytes(), in bytes.

keybytes()

-spec keybytes() -> Result when Result :: 32.

Return crypto_core_hsalsa20_keybytes(), in bytes.

outputbytes()

-spec outputbytes() -> Result when Result :: 32.

Return crypto_core_hsalsa20_outputbytes(), in bytes.