Fixed incorrect result when file size >= 512M.

pull/22/head v0.6.0
Yi-Cyuan Chen 8 years ago
parent 05de50a022
commit a35fd5a343

@ -1,5 +1,9 @@
# Change Log # Change Log
## v0.6.0 / 2017-10-31
### Fixed
- incorrect result when file size >= 512M.
## v0.5.0 / 2017-10-07 ## v0.5.0 / 2017-10-07
### Added ### Added
- support for web worker. #5 - support for web worker. #5

@ -1,6 +1,6 @@
{ {
"name": "js-sha512", "name": "js-sha512",
"version": "0.5.0", "version": "0.6.0",
"main": ["src/sha512.js"], "main": ["src/sha512.js"],
"ignore": [ "ignore": [
"samples", "samples",

File diff suppressed because one or more lines are too long

@ -1,6 +1,6 @@
{ {
"name": "js-sha512", "name": "js-sha512",
"version": "0.5.0", "version": "0.6.0",
"description": "This is a simple SHA-512, SHA-384, SHA-512/224, SHA-512/256 hash functions for JavaScript supports UTF-8 encoding.", "description": "This is a simple SHA-512, SHA-384, SHA-512/224, SHA-512/256 hash functions for JavaScript supports UTF-8 encoding.",
"main": "src/sha512.js", "main": "src/sha512.js",
"devDependencies": { "devDependencies": {

@ -1,7 +1,7 @@
/* /*
* [js-sha512]{@link https://github.com/emn178/js-sha512} * [js-sha512]{@link https://github.com/emn178/js-sha512}
* *
* @version 0.5.0 * @version 0.6.0
* @author Chen, Yi-Cyuan [emn178@gmail.com] * @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2014-2017 * @copyright Chen, Yi-Cyuan 2014-2017
* @license MIT * @license MIT
@ -195,7 +195,7 @@
} }
this.bits = bits; this.bits = bits;
this.block = this.start = this.bytes = 0; this.block = this.start = this.bytes = this.hBytes = 0;
this.finalized = this.hashed = false; this.finalized = this.hashed = false;
} }
@ -274,6 +274,10 @@
this.start = i; this.start = i;
} }
} }
if (this.bytes > 4294967295) {
this.hBytes += this.bytes / 4294967296 << 0;
this.bytes = this.bytes % 4294967296;
}
return this; return this;
}; };
@ -300,6 +304,7 @@
blocks[25] = blocks[26] = blocks[27] = blocks[28] = blocks[25] = blocks[26] = blocks[27] = blocks[28] =
blocks[29] = blocks[30] = blocks[31] = blocks[32] = 0; blocks[29] = blocks[30] = blocks[31] = blocks[32] = 0;
} }
blocks[30] = this.hBytes << 3 | this.bytes >> 29;
blocks[31] = this.bytes << 3; blocks[31] = this.bytes << 3;
this.hash(); this.hash();
}; };

@ -316,6 +316,13 @@
}); });
}); });
}); });
context('when large size', function () {
var hash = algorithm.create();
hash.bytes = 4294967295;
hash.update('any');
expect(hash.hBytes).to.be(1);
});
}); });
} }

Loading…
Cancel
Save