Package Exports
- blake2b
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (blake2b) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
blake2b
Blake2b (64-bit version) in pure Javascript
This module is based on @dcposch implementation of BLAKE2b, with some changes:
- This module requires you to pass in a
out
buffer, saving an allocation - This module allows you to set the
salt
andpersonal
parameters - This module exports constants for the parameters in libsodium style
All credit goes to @dcposch for doing the hard work of porting the implementation from C to Javascript.
Usage
var blake2b = require('blake2b')
var output = new Uint8Array(64)
var input = Buffer.from('hello world')
blake2b(output, input)
API
blake2b(out, input, [key], [salt], [personal], [noAssert = false])
Hash input
and write result to out
, optionally with key
, salt
and
personal
. Bypass input assertions by setting noAssert
to true
.
All parameters must be Uint8Array
, Buffer
or another object with a compatible
API. All parameters must also fulfill the following constraints, or an
AssertionError
will be thrown (unless noAssert = true
):
out
must within the byte ranges defined by the constants below.input
can be any length, including0
key
is optional, but must within the byte ranges defined by the constants below, if given. This value must be kept secret, and can be used to create prefix-MACs.salt
is optional, but must be exactlySALTBYTES
, if given. You can use this parameter as a kind of per user id, or local versioning scheme. This value is not required to be secret.personal
is optional, but must be exactlyPERSONALBYTES
, if given. You can use this parameter as a kind of app id, or global versioning scheme. This value is not required to be secret.
Constants
blake2b.BYTES_MIN
Minimum length ofout
blake2b.BYTES_MAX
Maximum length ofout
blake2b.BYTES
Recommended default length ofout
blake2b.KEYBYTES_MIN
Minimum length ofkey
blake2b.KEYBYTES_MAX
Maximum length ofkey
blake2b.KEYBYTES
Recommended default length ofkey
blake2b.SALTBYTES
Required length ofsalt
blake2b.PERSONALBYTES
Required length ofpersonal
Install
npm install blake2b
Test vectors
This repository includes test vectors with
{outlen, out, input, key, salt, personal}
objects for testing conformance
against the spec and other implementations:
- Lines 2 - 257 are tests for hashing with no key, taken from BLAKE2 test vectors
- Lines 258 - 513 are tests for hashing with keys, taken from BLAKE2 test vectors
- Lines 514- 577 are tests for hashing with key, salt and personalisation, derived from the libsodium tests