Skip to content

All four BLAKE2 variants (blake2b, blake2bp, blake2s, blake2sp) for io.js with stream support

License

Notifications You must be signed in to change notification settings

reqshark/node-blake2

 
 

Repository files navigation

node-blake2

NPM version Build status

Why BLAKE2 for hashing? Because "BLAKE2 outperforms MD5, SHA-1, SHA-2, and SHA-3 on recent Intel CPUs" and has "no known security issues, whereas SHA-1, MD5, and SHA-512 are susceptible to length-extension". https://blake2.net/

node-blake2 provides a stream-compatible blake2b, blake2bp, blake2s, and blake2sp Hash and KeyedHash for io.js.

node-blake2 was tested to work on

  • Ubuntu 14.04 (g++ 4.8.2)
  • Ubuntu 14.04 (clang++ 3.6.2-svn238746-1~exp1)
  • Ubuntu 15.04 (g++ 4.9.2)
  • Windows 8.1 x64 (VS2013)
  • OS X 10.10 (Apple LLVM 6.1.0)

Install

On Windows, first install Python 2.7.9 so that node-gyp works.

In your project, run:

npm install blake2 --save

or install from the GitHub repo:

npm install ludios/node-blake2 --save

Examples

Unkeyed BLAKE2b

var blake2 = require('blake2');
var h = blake2.createHash('blake2b');
h.update(new Buffer("test"));
console.log(h.digest("hex"));

blake2.createHash works like node's crypto.createHash.

Keyed BLAKE2b

var blake2 = require('blake2');
var h = blake2.createKeyedHash('blake2b', new Buffer('key - up to 64 bytes for blake2b, 32 for blake2s'));
h.update(new Buffer("test"));
console.log(h.digest("hex"));

blake2.createKeyedHash takes a key argument like crypto.createHmac. Although it is not an HMAC, a keyed hash serves the same purpose.

Important notes

  • blake2.create{Hash,KeyedHash} support algorithms blake2b, blake2bp, blake2s, and blake2sp.
  • Data passed to .update on blake2.{Hash,KeyedHash} must be a Buffer.
  • Keys passed to blake2.createKeyedHash(algo, key) must be a Buffer.
  • Just as with crypto.Hash, .digest() can only be called once.

With streams

This works exactly like it does with crypto.Hash. See b2sum.js.

Copying a hash object

You can call .copy() on a Hash or KeyedHash, which will return a new object with all of the internal BLAKE2 state copied from the source object.

var blake2 = require('blake2');
var h = blake2.createHash('blake2b');
h.update(new Buffer("test"));

// Call .copy() before .digest(), because .digest() finalizes internal state
var j = h.copy();

// h is unaffected by updates to j
j.update(new Buffer("more"));

console.log(h.digest());
console.log(j.digest());

Known issues

  • On Windows, node-blake2 requires AVX instructions due to some SSE2 build problems. This shouldn't be too hard to fix.

About

All four BLAKE2 variants (blake2b, blake2bp, blake2s, blake2sp) for io.js with stream support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 89.6%
  • C# 8.9%
  • Other 1.5%