react-native-openpgp icon indicating copy to clipboard operation
react-native-openpgp copied to clipboard

new BigInteger() very slow during generation of rsa key

Open akyGit opened this issue 7 years ago • 4 comments

I have a trouble with performance during generation of key 2048 bit. This process can spend from 3 minutes to 14-15. Therefore I would like to know, what exactly spend time. It was BigInteger constructors in rsa generate method. (src/crypto/public_key/rsa.js) call of new BigInteger() can spend from 2 to 5 minutes.

Smartphone:

  • Android 6.0.1;
  • ASUS Zenfone (ZD551KL);
  • processor Qualcomm MSM8939 Snapdragon 615 + Adreno 405;
  • RAM 3072MB.

Project dependencies:

  • "react": "15.4.2"
  • "react-native": "0.42.3"
  • "react-native-openpgp": "^1.0.3"

Code snippet:

      const optionsGenerateKey = {
        userIds: [{ name:'FirstName LastName', email:'[email protected]' }],
        numBits: 2048,
        passphrase: 'password',
      };

      console.warn('prepare random values...');
      await openpgp.prepareRandomValues();

      console.warn('keys generation...');
      const start = Date.now();
      const key = await this.generateKey(optionsGenerateKey);
      const end = Date.now();
      console.warn((end - start) / 1000);``` 

akyGit avatar Mar 21 '17 12:03 akyGit

Who had such a problem? Maybe I do something wrong? Keys generation is very slow. Grateful for help

akyGit avatar Apr 04 '17 19:04 akyGit

Having same issue, key generation takes too long. 2048 bit key takes 6s on ios simulator, and multiple minute on android device and sim @akyGit did you somehow fix this?

amitaymolko avatar May 06 '17 10:05 amitaymolko

@akyGit https://stackoverflow.com/questions/43229527/react-native-openpgp-very-slow-generation-keys-on-devices How did you fix this issue?

raza-basit avatar Aug 31 '17 13:08 raza-basit

Hey everyone,

the assumption in the StackOverflow post is correct, keys generation is very low (especially for everything over 1024 bit keys), because it uses React-Native's JavascriptCore to generate the keys instead of delegating the task to native libraries.

I want to port all crypto stuff to use native libraries sometime in the future, but haven't found the time yet (and for the apps I've built with this, 1024 was totally ok).

In the meantime, PRs are very welcome and sorry for not responding guys! :)

orhan avatar Aug 31 '17 13:08 orhan