Socket
Socket
Sign inDemoInstall

blake2b

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blake2b

Blake2b (64-bit version) in pure Javascript


Version published
Weekly downloads
50K
increased by17.24%
Maintainers
1
Weekly downloads
 
Created
Source

blake2b

Build Status

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 and personal 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

var out = 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, including 0
  • 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 exactly SALTBYTES, 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 exactly PERSONALBYTES, 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.

var instance = blake2b.instance(outlen, [key], [salt], [personal], [noAssert = false])

Like the above method, but allows your to update the hash as you can access more data. noAssert will also disable asserts in .update and .final methods. Note that outlen should be a number, and that you pass the Buffer in the .final method

var instance = instance.update(input)

Update the hash with new input. Calling this method after .final will throw an error.

var out = instance.final(out)

Finalise the the hash and write the digest to out. out must be exactly equal to outlen given in the .instance method.

Constants

  • blake2b.BYTES_MIN Minimum length of out
  • blake2b.BYTES_MAX Maximum length of out
  • blake2b.BYTES Recommended default length of out
  • blake2b.KEYBYTES_MIN Minimum length of key
  • blake2b.KEYBYTES_MAX Maximum length of key
  • blake2b.KEYBYTES Recommended default length of key
  • blake2b.SALTBYTES Required length of salt
  • blake2b.PERSONALBYTES Required length of personal

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:

License

ISC

FAQs

Package last updated on 06 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc