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 1.1.2 to 1.2.0

329

blake2b.js

@@ -86,213 +86,17 @@ // Blake2B in pure Javascript

const BLAKE2B_IV32 = new Uint32Array([
0xf3bcc908,
0x6a09e667,
0x84caa73b,
0xbb67ae85,
0xfe94f82b,
0x3c6ef372,
0x5f1d36f1,
0xa54ff53a,
0xade682d1,
0x510e527f,
0x2b3e6c1f,
0x9b05688c,
0xfb41bd6b,
0x1f83d9ab,
0x137e2179,
0x5be0cd19
0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372,
0x5f1d36f1, 0xa54ff53a, 0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c,
0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19
])
const SIGMA8 = [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
14,
10,
4,
8,
9,
15,
13,
6,
1,
12,
0,
2,
11,
7,
5,
3,
11,
8,
12,
0,
5,
2,
15,
13,
10,
14,
3,
6,
7,
1,
9,
4,
7,
9,
3,
1,
13,
12,
11,
14,
2,
6,
5,
10,
4,
0,
15,
8,
9,
0,
5,
7,
2,
4,
10,
15,
14,
1,
11,
12,
6,
8,
3,
13,
2,
12,
6,
10,
0,
11,
8,
3,
4,
13,
7,
5,
15,
14,
1,
9,
12,
5,
1,
15,
14,
13,
4,
10,
0,
7,
6,
3,
9,
2,
8,
11,
13,
11,
7,
14,
12,
1,
3,
9,
5,
0,
15,
4,
8,
6,
2,
10,
6,
15,
14,
9,
11,
3,
0,
8,
12,
2,
13,
7,
1,
4,
10,
5,
10,
2,
8,
4,
7,
6,
1,
5,
15,
11,
9,
14,
3,
12,
13,
0,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
14,
10,
4,
8,
9,
15,
13,
6,
1,
12,
0,
2,
11,
7,
5,
3
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 10, 4, 8, 9, 15, 13,
6, 1, 12, 0, 2, 11, 7, 5, 3, 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1,
9, 4, 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8, 9, 0, 5, 7, 2, 4,
10, 15, 14, 1, 11, 12, 6, 8, 3, 13, 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5,
15, 14, 1, 9, 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11, 13, 11, 7,
14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10, 6, 15, 14, 9, 11, 3, 0, 8, 12, 2,
13, 7, 1, 4, 10, 5, 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0, 0,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 10, 4, 8, 9, 15, 13, 6,
1, 12, 0, 2, 11, 7, 5, 3
]

@@ -361,6 +165,76 @@

// reusable parameterBlock
const parameterBlock = new Uint8Array([
0,
0,
0,
0, // 0: outlen, keylen, fanout, depth
0,
0,
0,
0, // 4: leaf length, sequential mode
0,
0,
0,
0, // 8: node offset
0,
0,
0,
0, // 12: node offset
0,
0,
0,
0, // 16: node depth, inner length, rfu
0,
0,
0,
0, // 20: rfu
0,
0,
0,
0, // 24: rfu
0,
0,
0,
0, // 28: rfu
0,
0,
0,
0, // 32: salt
0,
0,
0,
0, // 36: salt
0,
0,
0,
0, // 40: salt
0,
0,
0,
0, // 44: salt
0,
0,
0,
0, // 48: personal
0,
0,
0,
0, // 52: personal
0,
0,
0,
0, // 56: personal
0,
0,
0,
0 // 60: personal
])
// Creates a BLAKE2b hashing context
// Requires an output length between 1 and 64 bytes
// Takes an optional Uint8Array key
function blake2bInit (outlen, key) {
// Takes an optinal Uint8Array salt
// Takes an optinal Uint8Array personal
function blake2bInit (outlen, key, salt, personal) {
if (outlen === 0 || outlen > 64) {

@@ -372,2 +246,8 @@ throw new Error('Illegal output length, expected 0 < length <= 64')

}
if (salt && salt.length !== 16) {
throw new Error('Illegal salt, expected Uint8Array with length is 16')
}
if (personal && personal.length !== 16) {
throw new Error('Illegal personal, expected Uint8Array with length is 16')
}

@@ -383,8 +263,15 @@ // state, 'param block'

// initialize parameterBlock before usage
parameterBlock.fill(0)
parameterBlock[0] = outlen
if (key) parameterBlock[1] = key.length
parameterBlock[2] = 1 // fanout
parameterBlock[3] = 1 // depth
if (salt) parameterBlock.set(salt, 32)
if (personal) parameterBlock.set(personal, 48)
// initialize hash state
for (let i = 0; i < 16; i++) {
ctx.h[i] = BLAKE2B_IV32[i]
ctx.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameterBlock, i * 4)
}
const keylen = key ? key.length : 0
ctx.h[0] ^= 0x01010000 ^ (keylen << 8) ^ outlen

@@ -442,9 +329,17 @@ // key the hash, if applicable

// - outlen - optional output length in bytes, default 64
function blake2b (input, key, outlen) {
// - salt - optional salt bytes, string, Buffer or Uint8Array
// - personal - optional personal bytes, string, Buffer or Uint8Array
function blake2b (input, key, outlen, salt, personal) {
// preprocess inputs
outlen = outlen || 64
input = util.normalizeInput(input)
if (salt) {
salt = util.normalizeInput(salt)
}
if (personal) {
personal = util.normalizeInput(personal)
}
// do the math
const ctx = blake2bInit(outlen, key)
const ctx = blake2bInit(outlen, key, salt, personal)
blake2bUpdate(ctx, input)

@@ -462,4 +357,6 @@ return blake2bFinal(ctx)

// - outlen - optional output length in bytes, default 64
function blake2bHex (input, key, outlen) {
const output = blake2b(input, key, outlen)
// - salt - optional salt bytes, string, Buffer or Uint8Array
// - personal - optional personal bytes, string, Buffer or Uint8Array
function blake2bHex (input, key, outlen, salt, personal) {
const output = blake2b(input, key, outlen, salt, personal)
return util.toHex(output)

@@ -466,0 +363,0 @@ }

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

@@ -18,3 +18,3 @@ "main": "index.js",

"author": "",
"license": "CC0-1.0",
"license": "MIT",
"bugs": {

@@ -21,0 +21,0 @@ "url": "https://github.com/dcposch/blakejs/issues"

@@ -22,2 +22,7 @@ const test = require('tape')

// with personal
t.equal(blake2bHex('abc', null, null, 'salt123456789012', 'personal12345678'),
'f6860a4cb1baadf6e3cc36c81b974d1167fbcd36dfbe55f3c2a561ab1863fb3d' +
'2afc40ea9a95c3ad46f100e2a65c3a3b841d616fda1ea45b47074baccfe3b644')
t.end()

@@ -24,0 +29,0 @@ })

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