Created
June 27, 2013 20:34
-
-
Save quezo/5880148 to your computer and use it in GitHub Desktop.
This was a small test I created to determine the fastest Cipher (an algorithm used for encryption/decryption) available in NodeJS. There was a huge variation between the best (aes-128-ofb at 305.6934) and the worst (bf-ecb at 1024.3660).
This file contains hidden or 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
var crypto = require('crypto'); | |
var _ = require('underscore')._; | |
// Returns elapsed time in milliseconds | |
function get_elapsed_time(startTime) { | |
var diff = process.hrtime(startTime); | |
// (seconds to milliseconds) + (nanoseconds to milliseconds) | |
return (diff[0] * 1000) + (diff[1] / 1000000); | |
} | |
// Simple sorting function for cipher objects | |
function compareTimes(cipherNTimeA, cipherNTimeB) { | |
if (cipherNTimeA.time < cipherNTimeB.time) return -1; | |
else if (cipherNTimeA.time > cipherNTimeB.time) return 1; | |
else return 0; | |
} | |
var key = 'boxerpuppies'; | |
var text = 'Puppies > Kittens'; | |
// Get all the ciphers stored in Node.js | |
var ciphers = crypto.getCiphers(); | |
var ciphersAndTimes = []; | |
for (var i = 0; i < ciphers.length; i++) { | |
var cipher_algoritm = ciphers[i]; | |
var loops = 10000; | |
var j = 0; | |
var startTime = process.hrtime(); | |
try { | |
for (; j < loops; j++) { | |
var cipher = crypto.createCipher(cipher_algoritm, key); | |
var encrypted = cipher.update(text, 'utf8', 'hex') + cipher.final('hex'); | |
var decipher = crypto.createDecipher(cipher_algoritm, key); | |
var decrypted = decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8'); | |
} | |
ciphersAndTimes.push({'name': cipher_algoritm, 'time': get_elapsed_time(startTime)}); | |
} | |
catch(e) { | |
// Some ciphers can't run on my machine. Dunno why | |
} | |
} | |
ciphersAndTimes.sort(compareTimes); | |
for (var i = 0; i < ciphersAndTimes.length; i++) { | |
console.log(ciphersAndTimes[i].time.toFixed(4) + ' ms to complete with Cipher ' + ciphersAndTimes[i].name); | |
} |
This file contains hidden or 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
305.6934 ms to complete with Cipher aes-128-ofb | |
306.0972 ms to complete with Cipher aes-256-ctr | |
306.9010 ms to complete with Cipher rc4 | |
308.5980 ms to complete with Cipher rc4-hmac-md5 | |
308.7294 ms to complete with Cipher aes-256-cfb | |
308.8647 ms to complete with Cipher aes-192-ctr | |
309.2756 ms to complete with Cipher idea-cfb | |
310.3835 ms to complete with Cipher aes-192-cfb | |
311.3220 ms to complete with Cipher des-ofb | |
312.9775 ms to complete with Cipher aes-128-cfb8 | |
314.2114 ms to complete with Cipher camellia-128-cfb | |
314.8514 ms to complete with Cipher camellia-256-cfb | |
315.9214 ms to complete with Cipher camellia-256-ofb | |
317.2570 ms to complete with Cipher aes-128-ecb | |
318.0120 ms to complete with Cipher aes-256-xts | |
320.6958 ms to complete with Cipher cast5-cfb | |
321.8985 ms to complete with Cipher aes-128-cfb | |
322.0991 ms to complete with Cipher seed-ofb | |
322.1443 ms to complete with Cipher aes-256-ecb | |
322.1829 ms to complete with Cipher aes-256-cfb8 | |
322.9140 ms to complete with Cipher seed-cfb | |
323.1760 ms to complete with Cipher rc2-ofb | |
323.4281 ms to complete with Cipher rc2-cfb | |
324.9066 ms to complete with Cipher aes-256-cbc | |
325.8192 ms to complete with Cipher aes-192-ecb | |
326.2461 ms to complete with Cipher aes128 | |
326.3878 ms to complete with Cipher camellia-128-ofb | |
326.9485 ms to complete with Cipher aes-192-ofb | |
327.9205 ms to complete with Cipher aes-192-cbc | |
328.0412 ms to complete with Cipher aes-128-cbc | |
330.2278 ms to complete with Cipher aes-256-ofb | |
330.6721 ms to complete with Cipher idea-ofb | |
331.4438 ms to complete with Cipher camellia-256-ecb | |
332.2577 ms to complete with Cipher rc4-40 | |
332.4009 ms to complete with Cipher des-cbc | |
333.2247 ms to complete with Cipher des-cfb | |
333.8402 ms to complete with Cipher des | |
334.0151 ms to complete with Cipher cast5-ecb | |
334.9739 ms to complete with Cipher aes-128-xts | |
336.3573 ms to complete with Cipher camellia-192-ecb | |
337.3718 ms to complete with Cipher desx-cbc | |
337.4112 ms to complete with Cipher aes-128-ctr | |
338.0858 ms to complete with Cipher camellia-256-cbc | |
338.2789 ms to complete with Cipher cast-cbc | |
339.3415 ms to complete with Cipher des-ede3-cfb | |
340.1954 ms to complete with Cipher camellia-192-ofb | |
340.9094 ms to complete with Cipher cast | |
340.9842 ms to complete with Cipher camellia192 | |
341.5286 ms to complete with Cipher cast5-ofb | |
342.0115 ms to complete with Cipher rc2-cbc | |
342.4925 ms to complete with Cipher rc2 | |
343.8533 ms to complete with Cipher aes-192-cfb8 | |
344.1049 ms to complete with Cipher rc2-40-cbc | |
344.1054 ms to complete with Cipher des-ede-ofb | |
345.2359 ms to complete with Cipher seed | |
346.0038 ms to complete with Cipher camellia-192-cbc | |
346.1149 ms to complete with Cipher camellia-128-cfb8 | |
346.2682 ms to complete with Cipher aes256 | |
346.5707 ms to complete with Cipher des-cfb8 | |
347.8600 ms to complete with Cipher seed-ecb | |
350.7369 ms to complete with Cipher des-ede | |
351.2504 ms to complete with Cipher camellia-128-ecb | |
354.7003 ms to complete with Cipher des-ecb | |
356.5764 ms to complete with Cipher aes192 | |
356.9626 ms to complete with Cipher idea-ecb | |
357.2245 ms to complete with Cipher camellia-256-cfb8 | |
358.1344 ms to complete with Cipher rc2-ecb | |
359.3361 ms to complete with Cipher camellia-128-cbc | |
359.8418 ms to complete with Cipher camellia-192-cfb8 | |
361.0383 ms to complete with Cipher camellia256 | |
361.1736 ms to complete with Cipher des-ede-cbc | |
361.3440 ms to complete with Cipher cast5-cbc | |
361.7156 ms to complete with Cipher desx | |
361.8896 ms to complete with Cipher rc2-64-cbc | |
361.9439 ms to complete with Cipher des-ede3 | |
363.1647 ms to complete with Cipher des-ede3-ofb | |
363.6036 ms to complete with Cipher des3 | |
364.1484 ms to complete with Cipher des-ede-cfb | |
364.1746 ms to complete with Cipher idea | |
364.4851 ms to complete with Cipher camellia128 | |
364.6573 ms to complete with Cipher CAST-cbc | |
366.8511 ms to complete with Cipher camellia-192-cfb | |
370.6481 ms to complete with Cipher seed-cbc | |
383.5571 ms to complete with Cipher des-ede3-cbc | |
387.0772 ms to complete with Cipher idea-cbc | |
427.6058 ms to complete with Cipher des-ede3-cfb8 | |
436.6427 ms to complete with Cipher des-ede3-cfb1 | |
447.0983 ms to complete with Cipher aes-128-cfb1 | |
467.0500 ms to complete with Cipher aes-192-cfb1 | |
500.1223 ms to complete with Cipher aes-256-cfb1 | |
655.9387 ms to complete with Cipher camellia-128-cfb1 | |
670.9988 ms to complete with Cipher des-cfb1 | |
756.9891 ms to complete with Cipher camellia-192-cfb1 | |
761.0961 ms to complete with Cipher camellia-256-cfb1 | |
977.7205 ms to complete with Cipher bf-cfb | |
1003.6622 ms to complete with Cipher blowfish | |
1003.8480 ms to complete with Cipher bf | |
1015.1084 ms to complete with Cipher bf-ofb | |
1016.6883 ms to complete with Cipher bf-cbc | |
1024.3660 ms to complete with Cipher bf-ecb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
kittens better 👎