HMAC-based Extract-and-Expand Key Derivation Function (HKDF) as defined in RFC 5869. The HMAC is provided by libsodium which uses the HMAC-SHA-512/256 algorithm.
$ npm i --save sodium-hkdf
or
$ yarn add sodium-hkdf
For deriving a new key of length 32 bytes from some input keying material ikm
:
const hkdfKey = deriveHKDFKey(ikm, 32);
A salt
and some application specific info string (which is hashed into the HMAC) can additionally be provided:
const salt = new Uint8Array(32).fill(0);
const hkdfKey = deriveHKDFKey(input, 32, salt, "info");