-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Description
Is your feature request related to a problem? Please describe.
The Ethereum community includes a sizable community of developers and users who make heavy use of Node and the npm ecosystem. The scrypt key derivation function is a core component of Ethereum's cryptopgraphy. Within that community there is presently interest in moving as much as possible to Node's crypto built-ins (and so to more recent versions of Node) and away from 3rd party modules, e.g. the deprecated scrypt package.
However, the way that Node's built-in crypto.scrypt currently implements its memory limit is incompatible with options N, r, p value-combinations that are commonly seen in sample/test data for Ethereum and real-world usage as well. Examples:
https://github.com/ethereum/go-ethereum/blob/master/accounts/keystore/testdata/v3_test_vector.json
https://github.com/ethereumjs/ethereumjs-wallet/blob/master/src/test/index.js
Even if the maxmem option for Node's crypto.scrypt is set to the max value allowed (4294967295), there will be an exception such as:
Error: error:060B50AC:digital envelope routines:EVP_PBE_scrypt:memory limit exceeded
at handleError (internal/crypto/scrypt.js:62:14)
at Object.scrypt (internal/crypto/scrypt.js:47:3)
...
Describe the solution you'd like
Node's crypto.scrypt and crypto.scryptSync are revised to allow for a maxmem value corresponding to options N, r, p value-combinations that are in wide use with other scrypt implementations, i.e. in JS but also other programming languages (golang example, pure-JS example, another pure-JS example). Alternatively, the way that Node checks for too large N, r, p value-combinations is revised to the same end.
Describe alternatives you've considered
(a) A solution exists for Node >=10.5.0 <12.0.0 whereby, via an scrypt function shim that has fallback logic for memory limit exceptions (example), it's suggested to users that the scrypt package be installed in their own projects. This has obvious downsides:
- It's a deprecated package.
- That deprecated package is a 3rd party package vs. a Node built-in.
- That deprecated package isn't compatible with Node
>=12.0.0. - If the deprecated package isn't installed then the shim must fall back to a pure-JS implementation, see downsides of (b) below.
(b) For Node >=12.0.0 the only solution presently is to implement an scrypt function shim with automatic fallback to a pure-JS implementation. Downsides:
- Performance will greatly suffer for widely used
N,r,pvalue-combinations. - The pure-JS implementation will come from a 3rd party package vs. a Node built-in.