blake2b-wasm
Advanced tools
Comparing version 0.0.0 to 1.0.0
var sigma = [ | ||
[ 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] | ||
] | ||
@@ -20,4 +20,4 @@ | ||
;; ${a} = ${a} + ${b} + $m${sigma[r][2*i+0]} | ||
(set_local ${a} (i64.add (get_local ${a}) (i64.add (get_local ${b}) (get_local $m${sigma[r][2*i+0]})))) | ||
;; ${a} = ${a} + ${b} + $m${sigma[r][2 * i + 0]} | ||
(set_local ${a} (i64.add (get_local ${a}) (i64.add (get_local ${b}) (get_local $m${sigma[r][2 * i + 0]})))) | ||
@@ -33,4 +33,4 @@ ;; ${d} = rotr64(${d} ^ ${a}, 32) | ||
;; ${a} = ${a} + ${b} + $m${sigma[r][2*i+1]} | ||
(set_local ${a} (i64.add (get_local ${a}) (i64.add (get_local ${b}) (get_local $m${sigma[r][2*i+1]})))) | ||
;; ${a} = ${a} + ${b} + $m${sigma[r][2 * i + 1]} | ||
(set_local ${a} (i64.add (get_local ${a}) (i64.add (get_local ${b}) (get_local $m${sigma[r][2 * i + 1]})))) | ||
@@ -50,31 +50,26 @@ ;; ${d} = rotr64(${d} ^ ${a}, 16) | ||
;; ROUND(${r}) | ||
${G(r,0, '$v0', '$v4', '$v8', '$v12')} | ||
${G(r,1, '$v1', '$v5', '$v9', '$v13')} | ||
${G(r,2, '$v2', '$v6', '$v10', '$v14')} | ||
${G(r,3, '$v3', '$v7', '$v11', '$v15')} | ||
${G(r,4, '$v0', '$v5', '$v10', '$v15')} | ||
${G(r,5, '$v1', '$v6', '$v11', '$v12')} | ||
${G(r,6, '$v2', '$v7', '$v8', '$v13')} | ||
${G(r,7, '$v3', '$v4', '$v9', '$v14')} | ||
${G(r, 0, '$v0', '$v4', '$v8', '$v12')} | ||
${G(r, 1, '$v1', '$v5', '$v9', '$v13')} | ||
${G(r, 2, '$v2', '$v6', '$v10', '$v14')} | ||
${G(r, 3, '$v3', '$v7', '$v11', '$v15')} | ||
${G(r, 4, '$v0', '$v5', '$v10', '$v15')} | ||
${G(r, 5, '$v1', '$v6', '$v11', '$v12')} | ||
${G(r, 6, '$v2', '$v7', '$v8', '$v13')} | ||
${G(r, 7, '$v3', '$v4', '$v9', '$v14')} | ||
` | ||
} | ||
// function rotr64 (w, c) { | ||
// i64 | ||
// // ( w >> c ) | ( w << ( 64 - c ) ) | ||
// rotr64 | ||
// } | ||
console.log( | ||
ROUND( 0 ), | ||
ROUND( 1 ), | ||
ROUND( 2 ), | ||
ROUND( 3 ), | ||
ROUND( 4 ), | ||
ROUND( 5 ), | ||
ROUND( 6 ), | ||
ROUND( 7 ), | ||
ROUND( 8 ), | ||
ROUND( 9 ), | ||
ROUND( 10 ), | ||
ROUND( 11 ) | ||
ROUND(0), | ||
ROUND(1), | ||
ROUND(2), | ||
ROUND(3), | ||
ROUND(4), | ||
ROUND(5), | ||
ROUND(6), | ||
ROUND(7), | ||
ROUND(8), | ||
ROUND(9), | ||
ROUND(10), | ||
ROUND(11) | ||
) |
39
index.js
@@ -12,4 +12,4 @@ var fs = require('fs') | ||
function Blake2b () { | ||
if (!(this instanceof Blake2b)) return new Blake2b() | ||
function Blake2b (digestLength, key, salt, personal) { | ||
if (!(this instanceof Blake2b)) return new Blake2b(digestLength, key, salt, personal) | ||
if (!mod) throw new Error('WASM not loaded. Wait for Blake2b.ready(cb)') | ||
@@ -22,5 +22,22 @@ | ||
this.digestLength = digestLength || 32 | ||
this.finalized = false | ||
this.pointer = freeList.pop() | ||
mod.blake2b_init(this.pointer, 32) | ||
memory.fill(0, 0, 64) | ||
memory[0] = this.digestLength | ||
memory[1] = key ? key.length : 0 | ||
memory[2] = 1 // fanout | ||
memory[3] = 1 // depth | ||
if (salt) memory.set(salt, 32) | ||
if (personal) memory.set(personal, 48) | ||
mod.blake2b_init(this.pointer, this.digestLength) | ||
if (key) { | ||
this.update(key) | ||
memory.fill(0, head, head + key.length) // whiteout key | ||
memory[this.pointer + 200] = 128 | ||
} | ||
} | ||
@@ -45,6 +62,14 @@ | ||
if (!enc || enc === 'binary') return memory.slice(this.pointer + 128, this.pointer + 128 + 32) | ||
if (enc === 'hex') return hexSlice(memory, this.pointer + 128, 32) | ||
if (!enc || enc === 'binary') { | ||
return memory.slice(this.pointer + 128, this.pointer + 128 + this.digestLength) | ||
} | ||
for (var i = 0; i < 32; i++) enc[i] = memory[this.pointer + 128 + i] | ||
if (enc === 'hex') { | ||
return hexSlice(memory, this.pointer + 128, this.digestLength) | ||
} | ||
for (var i = 0; i < this.digestLength; i++) { | ||
enc[i] = memory[this.pointer + 128 + i] | ||
} | ||
return enc | ||
@@ -96,3 +121,1 @@ } | ||
} | ||
window.Blake2b = module.exports |
{ | ||
"name": "blake2b-wasm", | ||
"version": "0.0.0", | ||
"version": "1.0.0", | ||
"description": "Blake2b implemented in WASM", | ||
@@ -10,3 +10,5 @@ "main": "index.js", | ||
"devDependencies": { | ||
"browserify": "^14.4.0" | ||
"blake2b": "^1.2.0", | ||
"browserify": "^14.4.0", | ||
"tape": "^4.6.3" | ||
}, | ||
@@ -20,3 +22,4 @@ "browserify": { | ||
"compile": "wast2wasm blake2b.wat -o blake2b.wasm", | ||
"demo": "browserify example.js > bundle.js" | ||
"demo": "browserify example.js > bundle.js", | ||
"test": "tape test.js" | ||
}, | ||
@@ -23,0 +26,0 @@ "repository": { |
@@ -24,5 +24,5 @@ # blake2b-wasm | ||
var hash = blake2b() | ||
.update(new Buffer('hello')) // pass in a buffer or uint8array | ||
.update(new Buffer(' ')) | ||
.update(new Buffer('world')) | ||
.update(Buffer.from('hello')) // pass in a buffer or uint8array | ||
.update(Buffer.from(' ')) | ||
.update(Buffer.from('world')) | ||
.digest('hex') | ||
@@ -29,0 +29,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
119843
12
211
0
3