Editing PBKDF2 This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) # PBKDF2 (hmacSHA1) for JavaScript Compares the PBKDF2 methods of the [Stanford Javascript Crypto Library](http://bitwiseshiftleft.github.com/sjcl/) with the ones from [CryptoJS](http://code.google.com/p/crypto-js/) and [Anandam](http://anandam.name/pbkdf2/). Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script src="http://anandam.name/pbkdf2/sha1.js"> </script> <script src="http://anandam.name/pbkdf2/pbkdf2.js"> </script> <script src="//raw.github.com/bitwiseshiftleft/sjcl/version-0.8/sjcl.js"> </script> <script src="//raw.github.com/bitwiseshiftleft/sjcl/master/core/sha1.js"> </script> <script src="//crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/pbkdf2.js"> </script> <script> var hmacSHA1 = function(key) { var hasher = new sjcl.misc.hmac(key, sjcl.hash.sha1); this.encrypt = function() { return hasher.encrypt.apply(hasher, arguments); }; }; // from http://stackoverflow.com/questions/3745666/ function hex2a(hex) { var str = ''; for (var i = 0; i < hex.length; i += 2) str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); return str; } var iterations = 500; var password = 'password'; var hexSalt = '29EEE7AA9C0E9315'; var keySizeBits = 256; var sjclSalt = sjcl.codec.hex.toBits(hexSalt); var cryptoSalt = CryptoJS.enc.Hex.parse(hexSalt); var anandamSalt = hex2a(hexSalt); </script> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code sjcl.misc.pbkdf2(password, sjclSalt, iterations, keySizeBits, hmacSHA1); Test 2 Title Async (check if this is an asynchronous test) Code CryptoJS.PBKDF2(password, cryptoSalt, { keySize: keySizeBits / 32, iterations: iterations }); Test 3 Title Async (check if this is an asynchronous test) Code var pbkdf2 = new PBKDF2(password, anandamSalt, iterations, keySizeBits / 8); pbkdf2.deriveKey(function() {}, function() { deferred.resolve() });