What is blakejs?
The blakejs npm package provides JavaScript implementations of the BLAKE2b and BLAKE2s cryptographic hash functions. These hash functions are designed to be faster than MD5, SHA-1, and SHA-2, while providing a higher level of security. The package is useful for generating cryptographic hashes for data integrity, digital signatures, and other security-related applications.
What are blakejs's main functionalities?
BLAKE2b Hashing
This feature allows you to generate a BLAKE2b hash of a given input string. The example code demonstrates how to hash the string 'Hello, world!' and output the resulting hash in hexadecimal format.
const blake = require('blakejs');
const hash = blake.blake2bHex('Hello, world!');
console.log(hash);
BLAKE2s Hashing
This feature allows you to generate a BLAKE2s hash of a given input string. The example code demonstrates how to hash the string 'Hello, world!' and output the resulting hash in hexadecimal format.
const blake = require('blakejs');
const hash = blake.blake2sHex('Hello, world!');
console.log(hash);
Keyed Hashing
This feature allows you to generate a keyed BLAKE2b hash, which can be used for message authentication. The example code demonstrates how to hash the string 'Hello, world!' with a given key and output the resulting hash in hexadecimal format.
const blake = require('blakejs');
const key = new Uint8Array(32); // Example key
const hash = blake.blake2bHex('Hello, world!', key);
console.log(hash);
Other packages similar to blakejs
crypto-js
crypto-js is a widely-used library that provides a variety of cryptographic algorithms, including MD5, SHA-1, SHA-256, and more. While it does not include BLAKE2b or BLAKE2s, it offers a broader range of cryptographic functions compared to blakejs.
hash.js
hash.js is a library that provides various hash functions, including SHA family algorithms. It does not support BLAKE2b or BLAKE2s, but it is known for its performance and ease of use in hashing operations.
blake2
blake2 is another npm package that provides implementations of the BLAKE2b and BLAKE2s hash functions. It is similar to blakejs but may have different performance characteristics and API design.
BLAKE.js
Pure Javascript implementation of the BLAKE2B hash function.
var Blake = require('blake')
console.log(Blake.blake2bHex('hello world'))
API
Exports two functions:
function blake2b(input, key, outlen) {
[...]
}
function blake2bHex(input, outlen) {
[...]
}
Limitations
- Can only handle up to 2**53 bytes of input
Testing
Performance
15.2 MB / second on a 2.2GHz i7-4770HQ
¯\_(ツ)_/¯
If you're using BLAKE2b in server side code, you probably want the native wrapper which should be able to do several hundred MB / second on the same processor.
If you're using BLAKE2b in a web app, 15 MB/sec is probably fine.
Javascript doesn't have 64-bit integers, and BLAKE2b is a 64-bit integer algorithm. Writing it withUint32Array
is not that fast.
If we want better machine code at the expense of gross looking JS code, we could use asm.js
License
Creative Commons CC0. Ported from the reference C implementation in
RFC 7693.