-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hash: switch from MD5 to murmur hash
MD5 doesn't work in FIPS mode, and there's no particular reason to use a cryptographically secure hash. Also shrink size of slug output from 32 to 8 characters.
- Loading branch information
Showing
4 changed files
with
19 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
'use strict' | ||
var crypto = require('crypto') | ||
var MurmurHash3 = require('imurmurhash') | ||
|
||
module.exports = function (uniq) { | ||
if (uniq) { | ||
var hash = crypto.createHash('md5') | ||
hash.update(uniq) | ||
return hash.digest('hex') | ||
var hash = new MurmurHash3(uniq) | ||
return ('00000000' + hash.result().toString(16)).substr(-8) | ||
} else { | ||
// Safe because w/o a callback because this interface can | ||
// neither block nor error (by contrast with randomBytes | ||
// which will throw an exception without enough entropy) | ||
return crypto.pseudoRandomBytes(16).toString('hex') | ||
// Called without a callback, because this interface should neither block | ||
// nor error (by contrast with randomBytes which will throw an exception | ||
// without enough entropy). | ||
// | ||
// However, due to a change in Node 0.10.27+, pseudoRandomBytes is now the | ||
// same as randomBytes, and may in fact block in situations where | ||
// insufficent entropy is available. | ||
return crypto.pseudoRandomBytes(4).toString('hex') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters