summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNils Kenneweg <github@ovt.me>2016-06-10 11:27:41 +0200
committerGitHub <noreply@github.com>2016-06-10 11:27:41 +0200
commita1d5c461a480f4caa46d305816e2a6d3b3157801 (patch)
tree6d192c06b388523b69887c6f3736b98944f182d2
parent1439fb2458d5ea4eeecce5cb5c52981f1d99e35d (diff)
parente2b3925ac4fee9301d29220d6b7a38cea53c9c55 (diff)
downloadsjcl-a1d5c461a480f4caa46d305816e2a6d3b3157801.zip
sjcl-a1d5c461a480f4caa46d305816e2a6d3b3157801.tar.gz
sjcl-a1d5c461a480f4caa46d305816e2a6d3b3157801.tar.bz2
Merge pull request #302 from ph4r05/bigHashException
If hashing more than 2^53-1 bits, throw exception, #299
-rw-r--r--core/sha1.js4
-rw-r--r--core/sha256.js3
-rw-r--r--core/sha512.js4
3 files changed, 11 insertions, 0 deletions
diff --git a/core/sha1.js b/core/sha1.js
index 806baf1..b56d749 100644
--- a/core/sha1.js
+++ b/core/sha1.js
@@ -60,6 +60,10 @@ sjcl.hash.sha1.prototype = {
var i, b = this._buffer = sjcl.bitArray.concat(this._buffer, data),
ol = this._length,
nl = this._length = ol + sjcl.bitArray.bitLength(data);
+ if (nl > 9007199254740991){
+ throw new sjcl.exception.invalid("Cannot hash more than 2^53 - 1 bits");
+ }
+
if (typeof Uint32Array !== 'undefined') {
var c = new Uint32Array(b);
var j = 0;
diff --git a/core/sha256.js b/core/sha256.js
index c058538..22ff4d8 100644
--- a/core/sha256.js
+++ b/core/sha256.js
@@ -68,6 +68,9 @@ sjcl.hash.sha256.prototype = {
var i, b = this._buffer = sjcl.bitArray.concat(this._buffer, data),
ol = this._length,
nl = this._length = ol + sjcl.bitArray.bitLength(data);
+ if (nl > 9007199254740991){
+ throw new sjcl.exception.invalid("Cannot hash more than 2^53 - 1 bits");
+ }
if (typeof Uint32Array !== 'undefined') {
var c = new Uint32Array(b);
diff --git a/core/sha512.js b/core/sha512.js
index 4b4e7a6..32da101 100644
--- a/core/sha512.js
+++ b/core/sha512.js
@@ -68,6 +68,10 @@ sjcl.hash.sha512.prototype = {
var i, b = this._buffer = sjcl.bitArray.concat(this._buffer, data),
ol = this._length,
nl = this._length = ol + sjcl.bitArray.bitLength(data);
+ if (nl > 9007199254740991){
+ throw new sjcl.exception.invalid("Cannot hash more than 2^53 - 1 bits");
+ }
+
if (typeof Uint32Array !== 'undefined') {
var c = new Uint32Array(b);
var j = 0;