Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upcrypto: add better scrypt option aliases #21525
Conversation
addaleax
added
crypto
semver-minor
labels
Jun 25, 2018
This comment has been minimized.
This comment has been minimized.
nodejs-github-bot
added
the
crypto
label
Jun 25, 2018
cjihrig
reviewed
Jun 25, 2018
| @@ -82,10 +82,16 @@ function check(password, salt, keylen, options, callback) { | |||
| if (options && options !== defaults) { | |||
| if (options.hasOwnProperty('N')) | |||
| N = validateInt32(options.N, 'N', 0, INT_MAX); | |||
| if (options.hasOwnProperty('cost')) | |||
This comment has been minimized.
This comment has been minimized.
cjihrig
Jun 25, 2018
Contributor
If we do go the route of adding these aliases, I'd prefer if these were else ifs, and the priority were documented and tested. Otherwise, the priority becomes an implementation detail that could subtly break in the future. Throwing is another option if someone were to provide N and cost, but that might be overkill.
This comment has been minimized.
This comment has been minimized.
jasnell
Jun 29, 2018
Member
Perhaps process.emitWarning() if both are provided would be a softer nudge?
This comment has been minimized.
This comment has been minimized.
jasnell
Jun 29, 2018
Member
I agree that a test for the priority would be a good addition here. Will sign off with that added.
This comment has been minimized.
This comment has been minimized.
vsemozhetbyt
reviewed
Jun 25, 2018
| - `r` {number} Block size parameter. **Default:** `8`. | ||
| - `p` {number} Parallelization parameter. **Default:** `1`. | ||
| - `cost` {number} CPU/memory cost parameter. Must be a power of two greater | ||
| than one. **Default:** `16384`. |
This comment has been minimized.
This comment has been minimized.
vsemozhetbyt
Jun 25, 2018
Member
Such indentation produces false code blocks in HTML version.
maxmem case below will be fixed in #21500, cost case seems to need fixing here.
This comment has been minimized.
This comment has been minimized.
vsemozhetbyt
reviewed
Jun 25, 2018
| - `r` {number} Block size parameter. **Default:** `8`. | ||
| - `p` {number} Parallelization parameter. **Default:** `1`. | ||
| - `cost` {number} CPU/memory cost parameter. Must be a power of two greater | ||
| than one. **Default:** `16384`. |
This comment has been minimized.
This comment has been minimized.
jasnell
requested changes
Jun 29, 2018
| @@ -82,10 +82,16 @@ function check(password, salt, keylen, options, callback) { | |||
| if (options && options !== defaults) { | |||
| if (options.hasOwnProperty('N')) | |||
| N = validateInt32(options.N, 'N', 0, INT_MAX); | |||
| if (options.hasOwnProperty('cost')) | |||
This comment has been minimized.
This comment has been minimized.
jasnell
Jun 29, 2018
Member
I agree that a test for the priority would be a good addition here. Will sign off with that added.
addaleax
force-pushed the
addaleax:crypto-scrypt-aliases
branch
from
d11c385
to
f4f7d6b
Jun 29, 2018
This comment has been minimized.
This comment has been minimized.
|
Thanks for the PR: it would help me. I always had trouble with these non-readable option names (already with |
This comment has been minimized.
This comment has been minimized.
|
ping @jasnell :) |
TimothyGu
reviewed
Jul 9, 2018
|
Have you considered something like this instead: const { kCost, kBlockSize, kParallelization } = crypto.constants;
// …
scrypt(..., {
[kCost]: 16,
[kParallelization]: 1,
[kBlockSize]: 1
});This is similarly readable but avoids the maneuver we have to do with regards to option handling. |
| @@ -80,12 +80,25 @@ function check(password, salt, keylen, options, callback) { | |||
|
|
|||
| let { N, r, p, maxmem } = defaults; | |||
| if (options && options !== defaults) { | |||
| if (options.hasOwnProperty('N')) | |||
| let has_N, has_r, has_p; | |||
| if (has_N = options.hasOwnProperty('N')) | |||
This comment has been minimized.
This comment has been minimized.
TimothyGu
Jul 9, 2018
•
Member
I know the hasOwnProperty has already been there, but we should really use undefined as a measure of if an option was set, to be consistent with the rest of the API surface and to prevent Object.create(null) from breaking this.
This comment has been minimized.
This comment has been minimized.
addaleax
force-pushed the
addaleax:crypto-scrypt-aliases
branch
from
f4f7d6b
to
fad284e
Jul 9, 2018
This comment has been minimized.
This comment has been minimized.
Can you explain how your suggestion would work? |
jasnell
approved these changes
Jul 10, 2018
|
sorry for the delay, was on vacation :-) |
addaleax
added some commits
Jun 25, 2018
addaleax
force-pushed the
addaleax:crypto-scrypt-aliases
branch
from
fad284e
to
83800fa
Jul 16, 2018
This comment has been minimized.
This comment has been minimized.
addaleax
added
the
author ready
label
Jul 16, 2018
This comment has been minimized.
This comment has been minimized.
|
AIX benchmark failures seem inexplicable. Maybe something's up on the host such that it can't launch subprocesses at the moment? Anyway, here's a Resume Build: https://ci.nodejs.org/job/node-test-pull-request/15899/ UPDATE: It's green. |
This comment has been minimized.
This comment has been minimized.
|
We have a green CI and one approval. This can technically land, but would be great if someone from @nodejs/crypto could give it a quick look. |
This comment has been minimized.
This comment has been minimized.
|
@addaleax Sorry I missed the notification on this thread. My proposal was to export three string-valued constants from |
This comment has been minimized.
This comment has been minimized.
|
@TimothyGu How strongly do you feel about that? It seems like that would feel a bit less natural here… |
tniessen
approved these changes
Jul 17, 2018
This comment has been minimized.
This comment has been minimized.
|
@addaleax Not very, just trying to offer an alternative here. |
This comment has been minimized.
This comment has been minimized.
|
Landed in e9b22e9 |
addaleax
closed this
Jul 18, 2018
addaleax
deleted the
addaleax:crypto-scrypt-aliases
branch
Jul 18, 2018
addaleax
added a commit
that referenced
this pull request
Jul 18, 2018
This comment has been minimized.
This comment has been minimized.
|
Depends on #21782 to land on |
addaleax commentedJun 25, 2018
Make parameter names available in a human-readable way, for
more accessible/self-documenting usage of the
scryptfunctions.This implements a review comment from the original PR that has
not been addressed.
Refs: #20816 (comment)
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes