Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pbkdf2 performance vs sjcl #21

Closed
rubensayshi opened this issue Jul 31, 2015 · 9 comments
Closed

pbkdf2 performance vs sjcl #21

rubensayshi opened this issue Jul 31, 2015 · 9 comments

Comments

@rubensayshi
Copy link
Contributor

I was trying to figure out how to optimize bip39 a bit for mobile (cordova), the sjcl package is about 10x faster for me than the pbkdf package, could be interesting to switch?

  • note you have to ./configure --with-sha512 --with-hmac --with-pbkdf2 --with-bitArray && make the sjcl, the default npm package does not contain sha512.... *
var sjcl = require('sjcl');
var pbkdf = require('pbkdf');

var mnemonic = "later arrest fit foil goat excess online question trumpet grape license term bounce job nominee nuclear credit artefact measure record buyer service husband april tower average athlete pole alpha law picnic tail prepare satisfy dizzy hire illness legal forum rain sniff ask asthma pond present beach either minimum";
var salt = "roooooooobs";
var mnemonicBuffer = new Buffer(mnemonic, 'utf8');
var saltBuffer = new Buffer(password, 'utf8');

t = (new Date).getTime();

console.log(typeof sjcl.hash.sha512);

var hmacSHA512 = function (key) {
    var hasher = new sjcl.misc.hmac( key, sjcl.hash.sha512 );
    this.encrypt = function () {
        return hasher.encrypt.apply( hasher, arguments );
    };
};

var sjclResult = sjcl.misc.pbkdf2(sjcl.codec.utf8String.toBits(mnemonic), sjcl.codec.utf8String.toBits(salt), 2048, 64 * 8, hmacSHA512);
console.log("sjcl.misc.pbkdf2 " + ((new Date).getTime() - t));
console.log(sjcl.codec.hex.fromBits(sjclResult));

t = (new Date).getTime();

var pbkdf2Result = pbkdf2.pbkdf2Sync(mnemonicBuffer, saltBuffer, 2048, 64, 'sha512');
console.log("pbkdf2.pbkdf2Sync " + ((new Date).getTime() - t));
console.log(pbkdf2Result.toString('hex'));
@rubensayshi
Copy link
Contributor Author

small repo to test with: https://github.com/rubensayshi/pbkdf2-benchmark

@dcousens said he was experiencing sjcl to be slower, maybe something different about his test case

@rubensayshi
Copy link
Contributor Author

ios is also factor 10x and is by far the worst, pdkdf2 takes 23s, sjcl 2.8s

@rubensayshi
Copy link
Contributor Author

maybe something along the lines of; blocktrail@a49b3d7

always seems hard to swap out certain parts for browserify...

@dcousens
Copy link
Contributor

dcousens commented Aug 1, 2015

@rubensayshi what version of browserify are you using? My iOS mobile takes exactly 2.2s in a cordova build ...

@rubensayshi
Copy link
Contributor Author

crypto-browserify@3.9.13

@rubensayshi
Copy link
Contributor Author

did you try that benchmark repo I made @dcousens, are you getting different results than me? because desktop chrome and android also are a lot slower ....

@rubensayshi
Copy link
Contributor Author

also, if I try my small benchmark repo I'm getting a lot better results for ios than in the app I was initially testing it in, still sjcl is faster though.

so I gotta go investigate ...

@dcousens
Copy link
Contributor

@rubensayshi might close this here in favour of browserify/pbkdf2#18?

@rubensayshi
Copy link
Contributor Author

aye

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants