Skip to content

Commit

Permalink
Merge pull request #9 from crypto-browserify/cleanup
Browse files Browse the repository at this point in the history
clean up/rename the md5 stuff
  • Loading branch information
dcousens committed Oct 13, 2015
2 parents c713c6a + 5a52062 commit 0c6bf84
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 43 deletions.
41 changes: 0 additions & 41 deletions helpers.js

This file was deleted.

30 changes: 30 additions & 0 deletions make-hash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict'
var intSize = 4
var zeroBuffer = new Buffer(intSize)
zeroBuffer.fill(0)

var charSize = 8
var hashSize = 16

function toArray (buf) {
if ((buf.length % intSize) !== 0) {
var len = buf.length + (intSize - (buf.length % intSize))
buf = Buffer.concat([buf, zeroBuffer], len)
}

var arr = new Array(buf.length >>> 2)
for (var i = 0, j = 0; i < buf.length; i += intSize, j++) {
arr[j] = buf.readInt32LE(i)
}

return arr
}

module.exports = function hash (buf, fn) {
var arr = fn(toArray(buf), buf.length * charSize)
buf = new Buffer(hashSize)
for (var i = 0; i < arr.length; i++) {
buf.writeInt32LE(arr[i], i << 2, true)
}
return buf
}
4 changes: 2 additions & 2 deletions md5.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* See http://pajhome.org.uk/crypt/md5 for more info.
*/

var helpers = require('./helpers')
var makeHash = require('./make-hash')

/*
* Calculate the MD5 of an array of little-endian words, and a bit length
Expand Down Expand Up @@ -147,5 +147,5 @@ function bit_rol (num, cnt) {
}

module.exports = function md5 (buf) {
return helpers.hash(buf, core_md5, 16)
return makeHash(buf, core_md5)
}

0 comments on commit 0c6bf84

Please sign in to comment.