Created
August 8, 2012 17:48
-
-
Save cbiffle/3297028 to your computer and use it in GitHub Desktop.
Multiple round hash benchmark (CoffeeScript/node.js)
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
#!/usr/bin/env coffee | |
# | |
# This simulates a common pattern for deriving encryption keys | |
# from passwords. It's somewhat alarming how fast computers | |
# have become. You may have to try round counts over 100k to | |
# get a useful measurement! | |
# | |
# To use: | |
# coffee hash-benchmark.coffee <algo> <rounds> | |
# | |
# Algo name options are in the node.js crypto docs, try sha256. | |
crypto = require 'crypto' | |
[ coffee, prog, algo, rounds ] = process.argv | |
data = new Buffer("seed!") | |
before = new Date | |
for i in [rounds..1] | |
hash = crypto.createHash(algo) | |
hash.update(data) | |
data = hash.digest() | |
after = new Date | |
console.log "Took #{after - before} milliseconds" | |
console.log "Final content: #{new Buffer(data).toString('hex')}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment