Generic Hashing
Bindings for the crypto_generichash API. See the libsodium crypto_generichash docs for more information.
Constants
Buffer lengths (integer)
crypto_generichash_BYTEScrypto_generichash_BYTES_MINcrypto_generichash_BYTES_MAXcrypto_generichash_KEYBYTEScrypto_generichash_KEYBYTES_MINcrypto_generichash_KEYBYTES_MAXcrypto_generichash_STATEBYTES
String constants (string)
crypto_generichash_PRIMITIVE
crypto_generichash
sodium.crypto_generichash(out, in, [key])
Hashes a value with an optional key using the generichash method.
outshould be abufferof length withincrypto_generichash_BYTES_MIN-crypto_generichash_BYTES_MAXinshould be abufferof any lengthkeyis an optionalbufferof length withincrypto_generichash_KEYBYTES_MIN-crypto_generichash_KEYBYTES_MAX
The generated hash is stored in out.
Also exposes crypto_generichash_BYTES and crypto_generichash_KEYBYTES that can be used as "default" buffer sizes.
crypto_generichash_batch
sodium.crypto_generichash_batch(out, inArray, [key])
Same as crypto_generichash, except that this hashes an array of buffer's instead of a single one.
Instance API
crypto_generichash_instance
var instance = sodium.crypto_generichash_instance([key], [outlen])
Creates a generichash instance that can hash a stream of input buffer's.
keyis an optionalbufferas aboveoutlenis thebuffersize of your output
instance.update
instance.update(in)
Updates the instance with a new piece of data.
inshould be abufferof any size
instance.final
instance.final(out)
Finalizes the instance.
outshould be abufferas above with the same length you gave when creating the instance
The generated hash is stored in out.
Stateful API
Replaces the above instance implementation in the N-API release
crypto_generichash_init
var state = Buffer.alloc(crypto_generichash_STATEBYTES)
sodium.crypto_generichash_init(state, [key], outlen)
Initialise a new hash state with an optional key and the desired output length.
statemust be a buffer of lengthcrypto_generichash_STATEBYTESbyteskeyis an optional buffer as above
crypto_generichash_update
sodium.crypto_generichash_update(state, in)
Update a hash state with a given input.
statemust be a buffer of lengthcrypto_generichash_STATEBYTESbytesinshould be a abufferof any length
crypto_generichash_final(state, out)
sodium.crypto_generichash_final(state, out)
Finalize a given hash state and write the digest to output buffer
statemust be a buffer of lengthcrypto_generichash_STATEBYTESbytesoutmust be abufferwithcrypto_generichash_BYTES_MIN <= out.byteLength <= crypto_generichash_BYTES_MAXout.byteLengthshould equaloutlenspecified whencrypto_generichash_initwas called
