Skip to content

Commit aee24f1

Browse files
Fix digesting of large data
Based on #39 by @samKamerer.
1 parent e963695 commit aee24f1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

hash.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ Hash.prototype.digest = function (enc) {
5454
}
5555

5656
// to this append the block which is equal to the number l written in binary
57-
// TODO: handle case where l is > Math.pow(2, 29)
58-
this._block.writeInt32BE(l, this._blockSize - 4)
57+
if (l <= 0xffffffff) {
58+
this._block.writeUInt32BE(l, this._blockSize - 4)
59+
} else {
60+
var ll = l & 0xffffffff
61+
this._block.writeUInt32BE((l - ll) / 0x100000000, this._blockSize - 8)
62+
this._block.writeUInt32BE(ll, this._blockSize - 4)
63+
}
5964

6065
var hash = this._update(this._block) || this._hash()
6166

0 commit comments

Comments
 (0)