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

Patch bip39 to use native crypto lib pbkdf2 #1769

Merged
merged 4 commits into from
Aug 13, 2020

Conversation

andrepimenta
Copy link
Member

@andrepimenta andrepimenta commented Aug 13, 2020

Description

This PR improves/fixes the android startup time by making bip39 use a native version of pbkdf2.

First it was needed to add a synchronous pbkdf2 function on the library react native aes crypto. Not doing so would make us have to change a lot of logic that uses bip39. So this was introduced on react-native-aes-crypto-lib:
Android side:

@ReactMethod(isBlockingSynchronousMethod = true)
	public String pbkdf2Sync(String pwd, String salt, Integer cost, Integer length)
	throws NoSuchAlgorithmException, InvalidKeySpecException, UnsupportedEncodingException
	{
        	String strs = pbkdf2(pwd, salt, cost, length);
			return strs;
    }

iOS side:

RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(pbkdf2Sync:(NSString *)password salt:(NSString *)salt
                  cost:(NSInteger)cost length:(NSInteger)length){
	
	return [AesCrypt pbkdf2:password salt:salt cost:cost length:length];
}

And then on bip39:

  // Bellow is the native equivalent of pbkdf2(mnemonicBuffer, saltBuffer, 2048, 64, 'sha512')

  const seed = Aes.pbkdf2Sync(mnemonicBuffer.toString('utf8'), saltBuffer.toString('utf8'), 2048, 512);
  const seedBuffer = global.Buffer.from(seed, "hex")

@andrepimenta andrepimenta requested a review from a team as a code owner August 13, 2020 16:44
@andrepimenta andrepimenta added the needs-qa Any New Features that needs a full manual QA prior to being added to a release. label Aug 13, 2020
Copy link
Contributor

@estebanmino estebanmino left a comment

Choose a reason for hiding this comment

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

👏 👏 👏

@andrepimenta andrepimenta merged commit 6384433 into develop Aug 13, 2020
@andrepimenta andrepimenta deleted the improvement/android-startup-time branch August 13, 2020 18:17
@andrepimenta andrepimenta added No QA Needed Apply this label when your PR does not need any QA effort. and removed needs-qa Any New Features that needs a full manual QA prior to being added to a release. labels Aug 13, 2020
rickycodes pushed a commit that referenced this pull request Jan 31, 2022
* Patch bip39 to use native crypto lib pbkdf2

* Typo

* Fix for tests
nop33 added a commit to alephium/mobile-wallet that referenced this pull request Aug 5, 2022
mvaivre pushed a commit to alephium/mobile-wallet that referenced this pull request Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next release No QA Needed Apply this label when your PR does not need any QA effort.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants