Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

blakejs

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blakejs - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

16

blake2b.js

@@ -161,4 +161,5 @@ // Blake2B in pure Javascript

// Initialize the hashing context with optional key 'key'
// Returns a newly created context
// Creates a BLAKE2b hashing context
// Requires an output length between 1 and 64 bytes
// Takes an optional Uint8Array key
function blake2b_init (outlen, key) {

@@ -198,3 +199,4 @@ if (outlen === 0 || outlen > 64) {

// Add 'in' into the hash. Expects a Uint8Array
// Updates a BLAKE2b streaming hash
// Requires hash context and Uint8Array (byte array)
function blake2b_update (ctx, input) {

@@ -211,4 +213,4 @@ for (var i = 0; i < input.length; i++) {

// Generate the message digest.
// Returns a Uint8Array
// Completes a BLAKE2b streaming hash
// Returns a Uint8Array containing the message digest
function blake2b_final (ctx) {

@@ -236,3 +238,3 @@ ctx.t += ctx.c // mark last block offset

// - input - the input bytes, as a Uint8Array or ASCII string
// - key - optional key, either a 32 or 64-byte Uint8Array
// - key - optional key Uint8Array, up to 64 bytes
// - outlen - optional output length in bytes, default 64

@@ -256,3 +258,3 @@ function blake2b (input, key, outlen) {

// - input - the input bytes, as a Uint8Array or ASCII string
// - key - optional key, either a 32 or 64-byte Uint8Array
// - key - optional key Uint8Array, up to 64 bytes
// - outlen - optional output length in bytes, default 64

@@ -259,0 +261,0 @@ function blake2bHex (input, key, outlen) {

@@ -53,3 +53,2 @@ // BLAKE2s hash function in pure Javascript

var m = new Uint32Array(16)
function blake2s_compress (ctx, last) {

@@ -95,5 +94,5 @@ var i = 0

// Initialize the hashing context "ctx" with optional key "key".
// 1 <= outlen <= 32 gives the digest size in bytes.
// Secret key (also <= 32 bytes) is optional (keylen = 0).
// Creates a BLAKE2s hashing context
// Requires an output length between 1 and 32 bytes
// Takes an optional Uint8Array key
function blake2s_init (outlen, key) {

@@ -125,2 +124,4 @@ if (!(outlen > 0 && outlen <= 32)) {

// Updates a BLAKE2s streaming hash
// Requires hash context and Uint8Array (byte array)
function blake2s_update (ctx, input) {

@@ -137,2 +138,4 @@ for (var i = 0; i < input.length; i++) {

// Completes a BLAKE2s streaming hash
// Returns a Uint8Array containing the message digest
function blake2s_final (ctx) {

@@ -159,3 +162,3 @@ ctx.t += ctx.c // mark last block offset

// - input - the input bytes, as a Uint8Array or ASCII string
// - key - optional key, either a 32 or 64-byte Uint8Array
// - key - optional key Uint8Array, up to 32 bytes
// - outlen - optional output length in bytes, default 64

@@ -179,3 +182,3 @@ function blake2s (input, key, outlen) {

// - input - the input bytes, as a Uint8Array or ASCII string
// - key - optional key, either a 32 or 64-byte Uint8Array
// - key - optional key Uint8Array, up to 32 bytes
// - outlen - optional output length in bytes, default 64

@@ -182,0 +185,0 @@ function blake2sHex (input, key, outlen) {

{
"name": "blakejs",
"version": "0.4.1",
"version": "0.4.2",
"description": "Pure Javascript implementation of the BLAKE2b and BLAKE2s hash functions",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -6,5 +6,9 @@ BLAKE.js

BLAKE is the default hash function in the venerable `NaCl` cryptography library. Like SHA2 and SHA3 but unlike MD5 and SHA1, it's believed to be secure. With an optimized assembly implementation, it's faster than all of those.
Of course, this one is Javascript, so it won't be winning any speed records. More on Performance below. It'll be totally fine for most applications though, and it's the only way to compute BLAKE in a browser.
```js
var blake = require('blakejs')
console.log(blake.blake2bHex('hello world'))
console.log(blake.blake2bHex('abc'))
// prints ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923

@@ -18,4 +22,6 @@

---
Exports two functions:
First, `blake2b` computes a BLAKE2b hash.
Pass it a `Uint8Array` containing bytes to hash, and it will return a `Uint8Array` containing the hash.
```js

@@ -28,3 +34,3 @@ // Computes the BLAKE2B hash of a string or byte array, and returns a Uint8Array

// - input - the input bytes, as a Uint8Array or ASCII string
// - key - optional key, either a 32 or 64-byte Uint8Array
// - key - optional key Uint8Array, up to 64 bytes
// - outlen - optional output length in bytes, default 64

@@ -34,15 +40,23 @@ function blake2b(input, key, outlen) {

}
```
// Computes the BLAKE2B hash of a string or byte array
//
// Returns an n-byte hash in hex, all lowercase
//
// Parameters:
// - input - the input bytes, as a Uint8Array or ASCII string
// - outlen - optional output length in bytes, default 64
function blake2bHex(input, outlen) {
[...]
}
For convenience, `blake2bHex` takes the same arguments and works the same way, but returns a hex string.
Second, you can use the `blake2b_init`, `blake2bupdate`, and `blake2b_final` functions to compute the hash of a stream of bytes.
```js
var KEY = null // optional key
var OUTPUT_LENGTH = 64 // bytes
var context = blake2b_init(OUTPUT_LENGTH, KEY)
...
// each time you get a byte array from the stream:
blake2b_update(context, bytes)
...
// finally, once the stream has been exhausted
var hash = blake2b_final(context)
// returns a 64-byte hash, as a Uint8Array
```
Finally, all five of these functions (`blake2b`, `blake2bHex`, `blake2b_init`, `blake2b_update`, and `blake2b_final`) have `blake2s` equivalents. The inputs are identical except that maximum key size and maximum output size are 32 bytes instead of 64.
Limitations

@@ -70,3 +84,3 @@ ---

Javascript doesn't have 64-bit integers, and BLAKE2b is a 64-bit integer algorithm. Writing it with`Uint32Array` is not that fast.
Javascript doesn't have 64-bit integers, and BLAKE2b is a 64-bit integer algorithm. Writing it with`Uint32Array` is not that fast. BLAKE2s is a 32-bit algorithm, so it's a bit faster.

@@ -73,0 +87,0 @@ If we want better machine code at the expense of gross looking JS code, we could use asm.js

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