Skip to content

Commit

Permalink
Merge pull request #302 from ph4r05/bigHashException
Browse files Browse the repository at this point in the history
If hashing more than 2^53-1 bits, throw exception, #299
  • Loading branch information
Nilos committed Jun 10, 2016
2 parents 1439fb2 + e2b3925 commit a1d5c46
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/sha1.js
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions core/sha256.js
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions core/sha512.js
Expand Up @@ -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;
Expand Down

0 comments on commit a1d5c46

Please sign in to comment.