libsodium_crypto_kdf_blake2b (libsodium v3.0.1)
View SourceDerive many subkeys from a single keybytes/0 byte master key with
BLAKE2b; the construction behind libsodium_crypto_kdf.
Each subkey is identified by a 64-bit integer SubkeyId and a
contextbytes/0 byte context, which separates keys derived for different
purposes. Subkeys are between bytes_min/0 and bytes_max/0 bytes long.
Master keys can be generated with libsodium_crypto_kdf:keygen/0.
Key = libsodium_randombytes:buf(libsodium_crypto_kdf_blake2b:keybytes()),
Subkey1 = libsodium_crypto_kdf_blake2b:derive_from_key(32, 1, <<"Examples">>, Key),
Subkey2 = libsodium_crypto_kdf_blake2b:derive_from_key(32, 2, <<"Examples">>, Key),
32 = byte_size(Subkey1),
true = Subkey1 =/= Subkey2.
Summary
Types
A crypto_kdf_blake2b_CONTEXTBYTES (8-byte) binary.
A crypto_kdf_blake2b_KEYBYTES (32-byte) binary.
Functions
Return crypto_kdf_blake2b_bytes_max(), in bytes.
Return crypto_kdf_blake2b_bytes_min(), in bytes.
Return crypto_kdf_blake2b_contextbytes(), in bytes.
Derive the SubkeyLen byte subkey number SubkeyId for the
contextbytes/0 byte context Ctx from the keybytes/0 byte master
key Key.
Return crypto_kdf_blake2b_keybytes(), in bytes.
Types
Functions
-spec bytes_max() -> Result when Result :: 64.
Return crypto_kdf_blake2b_bytes_max(), in bytes.
-spec bytes_min() -> Result when Result :: 16.
Return crypto_kdf_blake2b_bytes_min(), in bytes.
-spec contextbytes() -> Result when Result :: 8.
Return crypto_kdf_blake2b_contextbytes(), in bytes.
-spec derive_from_key(SubkeyLen, SubkeyId, Ctx, Key) -> Result when SubkeyLen :: non_neg_integer(), SubkeyId :: non_neg_integer(), Ctx :: ctx(), Key :: key(), Result :: binary() | -1.
Derive the SubkeyLen byte subkey number SubkeyId for the
contextbytes/0 byte context Ctx from the keybytes/0 byte master
key Key.
Returns -1 when SubkeyLen is outside bytes_min/0 to bytes_max/0.
-spec keybytes() -> Result when Result :: 32.
Return crypto_kdf_blake2b_keybytes(), in bytes.