1 PBKDF2 versus many decrypts

JavaScript performance comparison

Test case created by Eyal

Info

I can use PBKDF2 to authentication a password before I try using it or just decrypt and see if the reuslt is valid. So either I PBKDF2 once or do a lot of possibly failing decryptions. I want to see where the break-even is.

Preparation code

<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/core.js">
</script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/cipher-core.js">
</script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/sha1.js">
</script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/hmac.js">
</script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/pbkdf2.js">
</script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/aes.js">
</script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/mode-ecb.js">
</script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/pad-nopadding.js">
</script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/enc-base64.js">
</script>
<script>
Benchmark.prototype.setup = function() {
    var salt = CryptoJS.lib.WordArray.random(32 / 8);
   
    function randomString() {
      var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
      var string_length = 8;
      var randomstring = '';
      for (var i = 0; i < string_length; i++) {
        var rnum = Math.floor(Math.random() * chars.length);
        randomstring += chars.substring(rnum, rnum + 1);
      }
      return (randomstring);
    }
    var key = randomString();
    var keyWordArray = CryptoJS.lib.WordArray.random(128 / 8); //128bytes
    var toDecryptIv = [];
    var toDecryptCipher = [];
    while (toDecryptIv.length < 1500) {
      toDecryptIv.push(CryptoJS.lib.WordArray.random(128 / 8));
      toDecryptCipher.push(CryptoJS.lib.WordArray.random(128 / 8));
    }
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
1 PBKDF2-256 run
var authAndKey = CryptoJS.PBKDF2(key, salt, {
  keySize: 256 / 32,
  iterations: 1000
});
pending…
1PBKDF2-128 + many decryptions
var authAndKey = CryptoJS.PBKDF2(key, salt, {
  keySize: 128 / 32,
  iterations: 1000
});
for (var i = 0; i < toDecryptIv.length; i++) {
  var aesEncryptor = CryptoJS.algo.AES.createDecryptor(keyWordArray, {
    iv: toDecryptIv[i]
  });
  var ciphertext0 = aesEncryptor.process(toDecryptCipher[i]);
  var ciphertext1 = aesEncryptor.finalize();
  ciphertext0.concat(ciphertext1);
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment