Socket
Socket
Sign inDemoInstall

js-sha3

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-sha3 - npm Package Compare versions

Comparing version 0.5.5 to 0.5.6

2

bower.json
{
"name": "js-sha3",
"version": "0.5.5",
"version": "0.5.6",
"main": ["src/sha3.js"],

@@ -5,0 +5,0 @@ "ignore": [

# Change Log
## v0.5.6 / 2016-12-29
### Fixed
- ArrayBuffer dosen't work in Webpack.
## v0.5.5 / 2016-09-26

@@ -4,0 +8,0 @@ ### Added

{
"name": "js-sha3",
"version": "0.5.5",
"version": "0.5.6",
"description": "A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.",

@@ -5,0 +5,0 @@ "main": "src/sha3.js",

@@ -88,2 +88,6 @@ # js-sha3

```
If you use TypeScript, you can import like this:
```TypeScript
import { sha3_512 } from 'js-sha3';
```

@@ -90,0 +94,0 @@ ## Example

/**
* [js-sha3]{@link https://github.com/emn178/js-sha3}
*
* @version 0.5.5
* @version 0.5.6
* @author Chen, Yi-Cyuan [emn178@gmail.com]

@@ -9,10 +9,12 @@ * @copyright Chen, Yi-Cyuan 2015-2016

*/
(function (root) {
/*jslint bitwise: true */
(function () {
'use strict';
var NODE_JS = typeof process == 'object' && process.versions && process.versions.node;
var root = typeof window === 'object' ? window : {};
var NODE_JS = !root.JS_SHA3_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
if (NODE_JS) {
root = global;
}
var COMMON_JS = !root.JS_SHA3_TEST && typeof module == 'object' && module.exports;
var COMMON_JS = !root.JS_SHA3_NO_COMMON_JS && typeof module === 'object' && module.exports;
var HEX_CHARS = '0123456789abcdef'.split('');

@@ -24,4 +26,4 @@ var SHAKE_PADDING = [31, 7936, 2031616, 520093696];

var RC = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649,
0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0,
2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771,
0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0,
2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771,
2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648,

@@ -36,3 +38,3 @@ 2147516545, 2147483648, 32896, 2147483648, 2147483649, 0, 2147516424, 2147483648];

return new Keccak(bits, padding, bits).update(message)[outputType]();
}
};
};

@@ -43,3 +45,3 @@

return new Keccak(bits, padding, outputBits).update(message)[outputType]();
}
};
};

@@ -55,3 +57,3 @@

};
for (var i = 0;i < OUTPUT_TYPES.length;++i) {
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
var type = OUTPUT_TYPES[i];

@@ -71,3 +73,3 @@ method[type] = createOutputMethod(bits, padding, type);

};
for (var i = 0;i < OUTPUT_TYPES.length;++i) {
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
var type = OUTPUT_TYPES[i];

@@ -85,9 +87,11 @@ method[type] = createShakeOutputMethod(bits, padding, type);

var methods = {};
var methods = {}, methodNames = [];
for (var i = 0;i < algorithms.length;++i) {
for (var i = 0; i < algorithms.length; ++i) {
var algorithm = algorithms[i];
var bits = algorithm.bits;
for (var j = 0;j < bits.length;++j) {
methods[algorithm.name +'_' + bits[j]] = algorithm.createMethod(bits[j], algorithm.padding);
for (var j = 0; j < bits.length; ++j) {
var methodName = algorithm.name +'_' + bits[j];
methodNames.push(methodName);
methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding);
}

@@ -109,15 +113,15 @@ }

for (var i = 0;i < 50;++i) {
for (var i = 0; i < 50; ++i) {
this.s[i] = 0;
}
};
}
Keccak.prototype.update = function (message) {
var notString = typeof message != 'string';
if (notString && message.constructor == root.ArrayBuffer) {
if (notString && message instanceof ArrayBuffer) {
message = new Uint8Array(message);
}
var length = message.length, blocks = this.blocks, byteCount = this.byteCount,
blockCount = this.blockCount, index = 0, s = this.s, i, code;
var length = message.length, blocks = this.blocks, byteCount = this.byteCount,
blockCount = this.blockCount, index = 0, s = this.s, i, code;
while (index < length) {

@@ -127,3 +131,3 @@ if (this.reset) {

blocks[0] = this.block;
for (i = 1;i < blockCount + 1;++i) {
for (i = 1; i < blockCount + 1; ++i) {
blocks[i] = 0;

@@ -133,7 +137,7 @@ }

if (notString) {
for (i = this.start;index < length && i < byteCount;++index) {
for (i = this.start; index < length && i < byteCount; ++index) {
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
}
} else {
for (i = this.start;index < length && i < byteCount;++index) {
for (i = this.start; index < length && i < byteCount; ++index) {
code = message.charCodeAt(index);

@@ -162,3 +166,3 @@ if (code < 0x80) {

this.block = blocks[blockCount];
for (i = 0;i < blockCount;++i) {
for (i = 0; i < blockCount; ++i) {
s[i] ^= blocks[i];

@@ -180,3 +184,3 @@ }

blocks[0] = blocks[blockCount];
for (i = 1;i < blockCount + 1;++i) {
for (i = 1; i < blockCount + 1; ++i) {
blocks[i] = 0;

@@ -186,3 +190,3 @@ }

blocks[blockCount - 1] |= 0x80000000;
for (i = 0;i < blockCount;++i) {
for (i = 0; i < blockCount; ++i) {
s[i] ^= blocks[i];

@@ -196,7 +200,7 @@ }

var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
extraBytes = this.extraBytes, i = 0, j = 0;
var hex = '', block;
while (j < outputBlocks) {
for (i = 0;i < blockCount && j < outputBlocks;++i, ++j) {
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
block = s[i];

@@ -208,3 +212,3 @@ hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] +

}
if (j % blockCount == 0) {
if (j % blockCount === 0) {
f(s);

@@ -232,3 +236,3 @@ i = 0;

var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
extraBytes = this.extraBytes, i = 0, j = 0;

@@ -244,6 +248,6 @@ var bytes = this.outputBits >> 3;

while (j < outputBlocks) {
for (i = 0;i < blockCount && j < outputBlocks;++i, ++j) {
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
array[j] = s[i];
}
if (j % blockCount == 0) {
if (j % blockCount === 0) {
f(s);

@@ -264,7 +268,7 @@ }

var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
extraBytes = this.extraBytes, i = 0, j = 0;
var array = [], offset, block;
while (j < outputBlocks) {
for (i = 0;i < blockCount && j < outputBlocks;++i, ++j) {
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
offset = j << 2;

@@ -277,3 +281,3 @@ block = s[i];

}
if (j % blockCount == 0) {
if (j % blockCount === 0) {
f(s);

@@ -299,7 +303,7 @@ }

var f = function (s) {
var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33,
var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33,
b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49;
for (n = 0;n < 48;n += 2) {
for (n = 0; n < 48; n += 2) {
c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];

@@ -482,11 +486,11 @@ c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];

}
}
};
if (COMMON_JS) {
module.exports = methods;
} else if (root) {
for (var key in methods) {
root[key] = methods[key];
} else {
for (var i = 0; i < methodNames.length; ++i) {
root[methodNames[i]] = methods[methodNames[i]];
}
}
}(this));
})();

@@ -0,1 +1,2 @@

// Node.js env
expect = require('expect.js');

@@ -19,2 +20,24 @@ var sha3 = require('../src/sha3.js');

delete require.cache[require.resolve('./test-shake.js')];
// Webpack browser env
JS_SHA3_NO_NODE_JS = true;
window = global;
expect = require('expect.js');
var sha3 = require('../src/sha3.js');
keccak_512 = sha3.keccak_512;
keccak_384 = sha3.keccak_384;
keccak_256 = sha3.keccak_256;
keccak_224 = sha3.keccak_224;
sha3_512 = sha3.sha3_512;
sha3_384 = sha3.sha3_384;
sha3_256 = sha3.sha3_256;
sha3_224 = sha3.sha3_224;
shake_128 = sha3.shake_128;
shake_256 = sha3.shake_256;
require('./test.js');
require('./test-shake.js');
delete require.cache[require.resolve('../src/sha3.js')];
delete require.cache[require.resolve('./test.js')];
delete require.cache[require.resolve('./test-shake.js')];
sha3_512 = null;

@@ -31,5 +54,8 @@ sha3_384 = null;

JS_SHA3_TEST = true;
// browser env
JS_SHA3_NO_NODE_JS = true;
JS_SHA3_NO_COMMON_JS = true;
window = global;
require('../src/sha3.js');
require('./test.js');
require('./test-shake.js');

@@ -101,3 +101,4 @@ (function (sha3_512, sha3_384, sha3_256, sha3_224, keccak_512, keccak_384, keccak_256, keccak_224) {

'ArrayBuffer': {
'a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26': new ArrayBuffer(0)
'a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26': new ArrayBuffer(0),
'01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450': new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]).buffer
}

@@ -104,0 +105,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