libsodium_crypto_core_hchacha20 (libsodium v3.0.1)
View SourceThe HChaCha20 core function, which derives a outputbytes/0 byte subkey
from a keybytes/0 byte key and a inputbytes/0 byte input (typically
the first 16 bytes of an extended nonce). It is the building block of
XChaCha20.
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_hchacha20:keybytes()),
In = libsodium_randombytes:buf(libsodium_crypto_core_hchacha20:inputbytes()),
Out = libsodium_crypto_core_hchacha20:crypto_core_hchacha20(In, Key, <<"expand 32-byte k">>),
32 = byte_size(Out),
Out = libsodium_crypto_core_hchacha20:crypto_core_hchacha20(In, Key, <<"expand 32-byte k">>).
Summary
Types
A crypto_core_hchacha20_CONSTBYTES (16-byte) binary.
A crypto_core_hchacha20_INPUTBYTES (16-byte) binary.
A crypto_core_hchacha20_KEYBYTES (32-byte) binary.
A crypto_core_hchacha20_OUTPUTBYTES (32-byte) binary.
Functions
Return crypto_core_hchacha20_constbytes(), in bytes.
Compute the HChaCha20 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_hchacha20_inputbytes(), in bytes.
Return crypto_core_hchacha20_keybytes(), in bytes.
Return crypto_core_hchacha20_outputbytes(), in bytes.
Types
-type c() :: <<_:128>>.
A crypto_core_hchacha20_CONSTBYTES (16-byte) binary.
-type in() :: <<_:128>>.
A crypto_core_hchacha20_INPUTBYTES (16-byte) binary.
-type k() :: <<_:256>>.
A crypto_core_hchacha20_KEYBYTES (32-byte) binary.
-type out() :: <<_:256>>.
A crypto_core_hchacha20_OUTPUTBYTES (32-byte) binary.
Functions
-spec constbytes() -> Result when Result :: 16.
Return crypto_core_hchacha20_constbytes(), in bytes.
-spec crypto_core_hchacha20(In, K, C) -> Result when In :: in(), K :: k(), C :: c(), Result :: out().
Compute the HChaCha20 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.
-spec inputbytes() -> Result when Result :: 16.
Return crypto_core_hchacha20_inputbytes(), in bytes.
-spec keybytes() -> Result when Result :: 32.
Return crypto_core_hchacha20_keybytes(), in bytes.
-spec outputbytes() -> Result when Result :: 32.
Return crypto_core_hchacha20_outputbytes(), in bytes.