Comparing version 0.5.1 to 0.5.2
{ | ||
"name": "js-sha3", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"main": ["src/sha3.js"], | ||
@@ -5,0 +5,0 @@ "ignore": [ |
@@ -0,1 +1,5 @@ | ||
# v0.5.2 / 2016-06-06 | ||
* Fixed shake output incorrect in the special length. | ||
# v0.5.1 / 2015-10-27 | ||
@@ -2,0 +6,0 @@ |
@@ -1,5 +0,3 @@ | ||
Copyright (c) 2015 Chen Yi-Cyuan | ||
Copyright 2015-2016 Chen, Yi-Cyuan | ||
MIT License | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
@@ -6,0 +4,0 @@ a copy of this software and associated documentation files (the |
{ | ||
"name": "js-sha3", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.", | ||
@@ -22,2 +22,3 @@ "main": "src/sha3.js", | ||
"keccak", | ||
"shake", | ||
"hash", | ||
@@ -29,3 +30,3 @@ "encryption", | ||
"license": "MIT", | ||
"author": "emn178 <emn178@gmail.com>", | ||
"author": "Chen, Yi-Cyuan <emn178@gmail.com>", | ||
"homepage": "https://github.com/emn178/js-sha3", | ||
@@ -32,0 +33,0 @@ "bugs": { |
@@ -284,2 +284,2 @@ # js-sha3 | ||
The project's website is located at https://github.com/emn178/js-sha3 | ||
Author: emn178@gmail.com | ||
Author: Chen, Yi-Cyuan (emn178@gmail.com) |
129
src/sha3.js
@@ -1,19 +0,15 @@ | ||
/* | ||
* js-sha3 v0.5.1 | ||
* https://github.com/emn178/js-sha3 | ||
/** | ||
* [js-sha3]{@link https://github.com/emn178/js-sha3} | ||
* | ||
* Copyright 2015, emn178@gmail.com | ||
* | ||
* Licensed under the MIT license: | ||
* http://www.opensource.org/licenses/MIT | ||
* @version 0.5.2 | ||
* @author Chen, Yi-Cyuan [emn178@gmail.com] | ||
* @copyright Chen, Yi-Cyuan 2015-2016 | ||
* @license MIT | ||
*/ | ||
;(function(root, undefined) { | ||
(function (root) { | ||
'use strict'; | ||
var NODE_JS = typeof(module) != 'undefined'; | ||
if(NODE_JS) { | ||
if (NODE_JS) { | ||
root = global; | ||
if(root.JS_SHA3_TEST) { | ||
root.navigator = { userAgent: 'Chrome'}; | ||
} | ||
} | ||
@@ -34,4 +30,4 @@ var HEX_CHARS = '0123456789abcdef'.split(''); | ||
var createOutputMethod = function(bits, padding, outputType) { | ||
return function(message) { | ||
var createOutputMethod = function (bits, padding, outputType) { | ||
return function (message) { | ||
return new Keccak(bits, padding, bits).update(message)[outputType](); | ||
@@ -41,4 +37,4 @@ } | ||
var createShakeOutputMethod = function(bits, padding, outputType) { | ||
return function(message, outputBits) { | ||
var createShakeOutputMethod = function (bits, padding, outputType) { | ||
return function (message, outputBits) { | ||
return new Keccak(bits, padding, outputBits).update(message)[outputType](); | ||
@@ -48,11 +44,11 @@ } | ||
var createMethod = function(bits, padding) { | ||
var createMethod = function (bits, padding) { | ||
var method = createOutputMethod(bits, padding, 'hex'); | ||
method.create = function() { | ||
method.create = function () { | ||
return new Keccak(bits, padding, bits); | ||
}; | ||
method.update = function(message) { | ||
method.update = function (message) { | ||
return method.create().update(message); | ||
}; | ||
for(var i = 0;i < OUTPUT_TYPES.length;++i) { | ||
for (var i = 0;i < OUTPUT_TYPES.length;++i) { | ||
var type = OUTPUT_TYPES[i]; | ||
@@ -64,11 +60,11 @@ method[type] = createOutputMethod(bits, padding, type); | ||
var createShakeMethod = function(bits, padding) { | ||
var createShakeMethod = function (bits, padding) { | ||
var method = createShakeOutputMethod(bits, padding, 'hex'); | ||
method.create = function(outputBits) { | ||
method.create = function (outputBits) { | ||
return new Keccak(bits, padding, outputBits); | ||
}; | ||
method.update = function(message, outputBits) { | ||
method.update = function (message, outputBits) { | ||
return method.create(outputBits).update(message); | ||
}; | ||
for(var i = 0;i < OUTPUT_TYPES.length;++i) { | ||
for (var i = 0;i < OUTPUT_TYPES.length;++i) { | ||
var type = OUTPUT_TYPES[i]; | ||
@@ -88,7 +84,7 @@ method[type] = createShakeOutputMethod(bits, padding, type); | ||
for(var i = 0;i < algorithms.length;++i) { | ||
for (var i = 0;i < algorithms.length;++i) { | ||
var algorithm = algorithms[i]; | ||
var bits = algorithm.bits; | ||
var createMethod = algorithm.createMethod; | ||
for(var j = 0;j < bits.length;++j) { | ||
for (var j = 0;j < bits.length;++j) { | ||
var method = algorithm.createMethod(bits[j], algorithm.padding); | ||
@@ -112,3 +108,3 @@ methods[algorithm.name +'_' + bits[j]] = method; | ||
for(var i = 0;i < 50;++i) { | ||
for (var i = 0;i < 50;++i) { | ||
this.s[i] = 0; | ||
@@ -118,5 +114,5 @@ } | ||
Keccak.prototype.update = function(message) { | ||
Keccak.prototype.update = function (message) { | ||
var notString = typeof(message) != 'string'; | ||
if(notString && message.constructor == root.ArrayBuffer) { | ||
if (notString && message.constructor == root.ArrayBuffer) { | ||
message = new Uint8Array(message); | ||
@@ -127,11 +123,11 @@ } | ||
while(index < length) { | ||
if(this.reset) { | ||
while (index < length) { | ||
if (this.reset) { | ||
this.reset = false; | ||
blocks[0] = this.block; | ||
for(i = 1;i < blockCount + 1;++i) { | ||
for (i = 1;i < blockCount + 1;++i) { | ||
blocks[i] = 0; | ||
} | ||
} | ||
if(notString) { | ||
if (notString) { | ||
for (i = this.start;index < length && i < byteCount; ++index) { | ||
@@ -162,6 +158,6 @@ blocks[i >> 2] |= message[index] << SHIFT[i++ & 3]; | ||
this.lastByteIndex = i; | ||
if(i >= byteCount) { | ||
if (i >= byteCount) { | ||
this.start = i - byteCount; | ||
this.block = blocks[blockCount]; | ||
for(i = 0;i < blockCount;++i) { | ||
for (i = 0;i < blockCount;++i) { | ||
s[i] ^= blocks[i]; | ||
@@ -178,8 +174,8 @@ } | ||
Keccak.prototype.finalize = function() { | ||
Keccak.prototype.finalize = function () { | ||
var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s; | ||
blocks[i >> 2] |= this.padding[i & 3]; | ||
if(this.lastByteIndex == this.byteCount) { | ||
if (this.lastByteIndex == this.byteCount) { | ||
blocks[0] = blocks[blockCount]; | ||
for(i = 1;i < blockCount + 1;++i) { | ||
for (i = 1;i < blockCount + 1;++i) { | ||
blocks[i] = 0; | ||
@@ -189,3 +185,3 @@ } | ||
blocks[blockCount - 1] |= 0x80000000; | ||
for(i = 0;i < blockCount;++i) { | ||
for (i = 0;i < blockCount;++i) { | ||
s[i] ^= blocks[i]; | ||
@@ -196,3 +192,3 @@ } | ||
Keccak.prototype.toString = Keccak.prototype.hex = function() { | ||
Keccak.prototype.toString = Keccak.prototype.hex = function () { | ||
this.finalize(); | ||
@@ -203,4 +199,4 @@ | ||
var hex = '', block; | ||
while(j < outputBlocks) { | ||
for(i = 0;i < blockCount && j < outputBlocks;++i, ++j) { | ||
while (j < outputBlocks) { | ||
for (i = 0;i < blockCount && j < outputBlocks;++i, ++j) { | ||
block = s[i]; | ||
@@ -212,15 +208,16 @@ hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] + | ||
} | ||
if(j % blockCount == 0) { | ||
if (j % blockCount == 0) { | ||
f(s); | ||
i = 0; | ||
} | ||
} | ||
if(extraBytes) { | ||
if (extraBytes) { | ||
block = s[i]; | ||
if(extraBytes > 0) { | ||
if (extraBytes > 0) { | ||
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F]; | ||
} | ||
if(extraBytes > 1) { | ||
if (extraBytes > 1) { | ||
hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F]; | ||
} | ||
if(extraBytes > 2) { | ||
if (extraBytes > 2) { | ||
hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F]; | ||
@@ -232,3 +229,3 @@ } | ||
Keccak.prototype.buffer = function() { | ||
Keccak.prototype.buffer = function () { | ||
this.finalize(); | ||
@@ -240,3 +237,3 @@ | ||
var buffer; | ||
if(extraBytes) { | ||
if (extraBytes) { | ||
buffer = new ArrayBuffer((outputBlocks + 1) << 2); | ||
@@ -247,11 +244,11 @@ } else { | ||
var array = new Uint32Array(buffer); | ||
while(j < outputBlocks) { | ||
for(i = 0;i < blockCount && j < outputBlocks;++i, ++j) { | ||
while (j < outputBlocks) { | ||
for (i = 0;i < blockCount && j < outputBlocks;++i, ++j) { | ||
array[j] = s[i]; | ||
} | ||
if(j % blockCount == 0) { | ||
if (j % blockCount == 0) { | ||
f(s); | ||
} | ||
} | ||
if(extraBytes) { | ||
if (extraBytes) { | ||
array[i] = s[i]; | ||
@@ -263,3 +260,3 @@ buffer = buffer.slice(0, bytes); | ||
Keccak.prototype.digest = Keccak.prototype.array = function() { | ||
Keccak.prototype.digest = Keccak.prototype.array = function () { | ||
this.finalize(); | ||
@@ -270,4 +267,4 @@ | ||
var array = [], offset, block; | ||
while(j < outputBlocks) { | ||
for(i = 0;i < blockCount && j < outputBlocks;++i, ++j) { | ||
while (j < outputBlocks) { | ||
for (i = 0;i < blockCount && j < outputBlocks;++i, ++j) { | ||
offset = j << 2; | ||
@@ -280,16 +277,16 @@ block = s[i]; | ||
} | ||
if(j % blockCount == 0) { | ||
if (j % blockCount == 0) { | ||
f(s); | ||
} | ||
} | ||
if(extraBytes) { | ||
if (extraBytes) { | ||
offset = j << 2; | ||
block = s[i]; | ||
if(extraBytes > 0) { | ||
if (extraBytes > 0) { | ||
array[offset] = block & 0xFF; | ||
} | ||
if(extraBytes > 1) { | ||
if (extraBytes > 1) { | ||
array[offset + 1] = (block >> 8) & 0xFF; | ||
} | ||
if(extraBytes > 2) { | ||
if (extraBytes > 2) { | ||
array[offset + 2] = (block >> 16) & 0xFF; | ||
@@ -301,3 +298,3 @@ } | ||
var f = function(s) { | ||
var f = function (s) { | ||
var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, | ||
@@ -307,3 +304,3 @@ b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, | ||
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]; | ||
@@ -488,6 +485,6 @@ c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41]; | ||
if(!root.JS_SHA3_TEST && NODE_JS) { | ||
if (!root.JS_SHA3_TEST && NODE_JS) { | ||
module.exports = methods; | ||
} else if(root) { | ||
for(var key in methods) { | ||
} else if (root) { | ||
for (var key in methods) { | ||
root[key] = methods[key]; | ||
@@ -494,0 +491,0 @@ } |
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
28873
454