Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Remove SJCL #388

Merged
merged 5 commits into from
May 31, 2017
Merged

Remove SJCL #388

merged 5 commits into from
May 31, 2017

Conversation

jtormey
Copy link
Contributor

@jtormey jtormey commented May 30, 2017

This removes SJCL by replacing it with the latest version of crypto-browserify's pbkdf2 implementation. It's ~1.4x slower, but that's acceptable.

I'd like to add the option to encrypt / decrypt asynchronously as well, since that will be ~10x faster than SJCL was and not block the UI. But with the async approach there's more that could potentially go wrong, so will leave that out for now.

Copy link
Contributor

@Sjors Sjors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK.
Tested login, 2nd pwd, wallet creation and BIP 38.

Copy link
Contributor

@mpfluger mpfluger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️


salt = sjcl.codec.hex.toBits(salt.toString('hex'));
var stretched = sjcl.misc.pbkdf2(password, salt, iterations, keylen || 256, hmacSHA1);
assert(typeof password === 'string', 'password string required');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not important, but the previous assert failed on empty string while the new one doesn't

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, will check for that. Thanks!

var stretched = sjcl.misc.pbkdf2(password, salt, iterations, keylen || 256, hmacSHA1);
assert(typeof password === 'string', 'password string required');
assert(typeof iterations === 'number' && !isNaN(iterations), 'iterations number required');
assert(keyLenBits == null || keyLenBits % 8 === 0, 'key length must be evenly divisible into bytes');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

successfully fails on keyLenBits === Infinity and -Infinity :)

Copy link
Contributor

@kristovatlas kristovatlas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

untested but looks good to me. nice improvement on stricter asserts and better var naming. would be nice one day to add a unit test or two more for stretchPassword using more typical values for the wallet to ensure consistency between sjcl and crypto-browserify, but I bet all sorts of obvious stuff would break in the wallet if they weren't the same.

@Sjors Sjors merged commit 8b026b8 into v3.32-release May 31, 2017
@Sjors Sjors deleted the crypto-pbkdf2 branch May 31, 2017 11:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants