Skip to content

Commit

Permalink
Scrypt Difficulty - reduce encrypt/decrypt time (#456)
Browse files Browse the repository at this point in the history
* tuned scrypt difficulty, to be test with built

* test another config

* reduce difficulty

* update difficulty

Co-authored-by: thedoublejay <[email protected]>
  • Loading branch information
ivan-zynesis and thedoublejay authored Aug 6, 2021
1 parent f54fff6 commit 1247387
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion app/api/wallet/provider/mnemonic_encrypted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,31 @@ import { EnvironmentNetwork } from '../../../environment'
import { getBip32Option } from '../network'
import { WalletPersistenceData, WalletType } from '../persistence'

const encryption = new PrivateKeyEncryption(new Scrypt(), numOfBytes => {
// BIP38 default, 16k, 8, 8
const DEFAULT_SCRYPT_N_R_P = [
Math.pow(2, 9),
8, // decide stress on ram, not to reduce, to remained strong POW
2 // iteration, directly stack up time (if only purely single thread)
]

/**
* Benchmarked using samsung s8 (adb linked, which is really slow)
* -----|---|---|---------|--------
* N | r | p | encrypt | sign tx
* -----|---|---|---------|--------
* 2^14 | 8 | 8 | 199433 | 218643
* 2^11 | 8 | 8 | 17086 | 23299
* 2^11 | 8 | 1 | 3692 | 9137
* 2^11 | 1 | 8 | 3694 | 8603
* 2^11 | 1 | 1 | 2001 | 7231
* 2^11 | 4 | 1 | 2949 | 7624
* 2^12 | 4 | 4 | 2962 | 8277
*
* 2^11 | 8 | 8 | 19491 | 29512
* 2^14 | 8 | 1 | 26615 | 30331
* 2^11 | 4 | 8 | 8926 | 14117
*/
const encryption = new PrivateKeyEncryption(new Scrypt(...DEFAULT_SCRYPT_N_R_P), numOfBytes => {
const bytes = Random.getRandomBytes(numOfBytes)
return Buffer.from(bytes)
})
Expand Down

0 comments on commit 1247387

Please sign in to comment.