orhan / react-native-openpgp

OpenPGP.js adaptation for React-Native
http://openpgpjs.org
39 stars 13 forks source link

new BigInteger() very slow during generation of rsa key #7

Open akyGit opened 7 years ago

akyGit commented 7 years ago

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:

Project dependencies:

Code snippet:


      const optionsGenerateKey = {
        userIds: [{ name:'FirstName LastName', email:'first.last@gmail.com' }],
        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 commented 7 years ago

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

amitaymolko commented 7 years ago

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?

raza-basit commented 7 years ago

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

orhan commented 7 years ago

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! :)