From 19fb4637219b908673d8fe863ed660217d2b04c3 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Thu, 5 Jul 2018 04:45:48 -0700 Subject: [PATCH] Use MD4 instead of SHA1 for filename hashes We don't need the cryptographic strength of SHA-1 for this purpose, so we may as well use a faster hashing algorithm. While I was at it, I also sapped out the use of hash.end + hash.read combo for the faster and more conventional hash.update + hash.digest. In my local testing, this also seems to offer a nice speed boost. --- src/fs-cache.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fs-cache.js b/src/fs-cache.js index 07c66a1a..1894af73 100644 --- a/src/fs-cache.js +++ b/src/fs-cache.js @@ -71,16 +71,16 @@ const write = function(filename, result, callback) { * @return {String} */ const filename = function(source, identifier, options) { - const hash = crypto.createHash("SHA1"); + const hash = crypto.createHash("md4"); const contents = JSON.stringify({ source: source, options: options, identifier: identifier, }); - hash.end(contents); + hash.update(contents); - return hash.read().toString("hex") + ".json.gz"; + return hash.digest("hex") + ".json.gz"; }; /**