[Pkg-javascript-commits] [node-sha.js] 138/237: hash: adhere to NIST paper properly
Bastien Roucariès
rouca at moszumanska.debian.org
Fri May 5 09:03:47 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-sha.js.
commit fb2e39f86ce80948b697ac7d0d5f9b7f99c0672c
Author: Daniel Cousens <github at dcousens.com>
Date: Thu Sep 4 16:39:28 2014 +1000
hash: adhere to NIST paper properly
---
hash.js | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/hash.js b/hash.js
index 8a5e995..c7f690c 100644
--- a/hash.js
+++ b/hash.js
@@ -48,31 +48,28 @@ module.exports = function (Buffer) {
return this
}
-
Hash.prototype.digest = function (enc) {
- var bl = this._blockSize
- var fl = this._finalSize
- var len = this._len*8
+ // Suppose the length of the message M, in bits, is l
+ var l = this._len * 8
- var x = this._block
+ // Append the bit 1 to the end of the message
+ this._block[this._len % this._blockSize] = 0x80
- var bits = len % (bl*8)
+ // and then k zero bits, where k is the smallest non-negative solution to the equation (l + 1 + k) === finalSize mod blockSize
+ this._block.fill(0, this._len % this._blockSize + 1)
- // add end marker, so that appending 0's creates a different hash.
- x[this._len % bl] = 0x80
- x.fill(0, this._len % this._blockSize + 1)
-
- if (bits >= fl*8) {
+ if (l % (this._blockSize * 8) >= this._finalSize * 8) {
this._update(this._block)
this._block.fill(0)
}
- //TODO: handle case where the bit length is > Math.pow(2, 29)
- x.writeInt32BE(len, fl + 4) //big endian
+ // to this append the block which is equal to the number l written in binary
+ // TODO: handle case where l is > Math.pow(2, 29)
+ this._block.writeInt32BE(l, this._blockSize - 4)
var hash = this._update(this._block) || this._hash()
- if(enc == null) return hash
- return hash.toString(enc)
+
+ return enc ? hash.toString(enc) : hash
}
Hash.prototype._update = function () {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-sha.js.git
More information about the Pkg-javascript-commits
mailing list