crypto.hkdf #
Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved. Use of this source code is governed by an MIT license that can be found in the LICENSE file. Package hkdf implements the HMAC-based Extract-and-Expand Key Derivation Function (HKDF) as defined in RFC 5869.
HKDF is a cryptographic key derivation function (KDF) with the goal of expanding limited input keying material into one or more cryptographically strong secret keys. Based off: https://github.com/golang/go/tree/master/src/crypto/hkdf
fn expand #
fn expand[H](h fn () H, pseudorandom_key []u8, info string, key_length int) ![]u8
expand derives a key from the given hash, key, and optional context info, returning a []u8 of length key_length that can be used as cryptographic key. The extraction step is skipped.
The key should have been generated by extract, or be a uniformly random or pseudorandom cryptographically strong key. See RFC 5869, Section 3.3. Most common scenarios will want to use key instead.
fn extract #
fn extract[H](h fn () H, secret []u8, salt []u8) ![]u8
extract generates a pseudorandom key for use with expand from an input secret and an optional independent salt.
Only use this function if you need to reuse the extracted key with multiple expand invocations and different context values. Most common scenarios, including the generation of multiple keys, should use key instead.
fn key #
fn key[H](h fn () H, secret []u8, salt []u8, info string, key_length int) ![]u8
key derives a key from the given hash, secret, salt and context info, returning a []u8 of length key_length that can be used as cryptographic key. Salt and info can be empty.