HMAC based on BLAKE2b
Even though BLAKE2b is designed to also work as a MAC, specifications like Noise call for a HMAC.
const { randombytes_buf } = require('sodium-universal/randombytes')
const hmac = require('.')
const mac = Buffer.alloc(hmac.BYTES)
const key = Buffer.alloc(hmac.KEYBYTES)
randombytes_buf(key)
const data = Buffer.from('some data')
hmac(mac, data, key)
Size of the output MAC in bytes
RFC2104 recommended size of the key in bytes.
Computes a HMAC from data
with key
and writes it into out
.
out
must be aBuffer
orUint8Array
of lengthhmac.BYTES
data
must be aBuffer
,Uint8Array
orArray
ofBuffer
s orUint8Array
s.key
must be aBuffer
orUint8Array
. Per the HMAC speckey
can be as small as 1 byte, in which case it is right-padded withNUL
bytes, or any size larger thanhmac.KEYBYTES
in which case it is hashed down to fit. The recommended size by the spec ishmac.KEYBYTES
npm install hmac-blake2b