-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto: use byteLength in timingSafeEqual #23341
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b07480a
crypto: use byteLength in timingSafeEqual
ZaneHannanAU e5ddde8
Update test-crypto-timing-safe-equal.js
ZaneHannanAU 976b4ca
Input buffers byteLenght
ZaneHannanAU 24f01c8
Update test-crypto-timing-safe-equal.js
ZaneHannanAU e032fcf
Update test-crypto-timing-safe-equal.js
ZaneHannanAU 9902544
semicolon
ZaneHannanAU 70febc0
spelling
ZaneHannanAU File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,114 @@ assert.strictEqual( | |
false | ||
); | ||
|
||
{ | ||
const ab32 = new ArrayBuffer(32); | ||
const dv32 = new DataView(ab32); | ||
dv32.setUint32(0, 1); | ||
dv32.setUint32(4, 1, true); | ||
dv32.setBigUint64(8, 1n); | ||
dv32.setBigUint64(16, 1n, true); | ||
dv32.setUint16(24, 1); | ||
dv32.setUint16(26, 1, true); | ||
dv32.setUint8(28, 1); | ||
dv32.setUint8(29, 1); | ||
|
||
// 'should consider equal buffers to be equal' | ||
assert.strictEqual( | ||
crypto.timingSafeEqual(Buffer.from(ab32), dv32), | ||
true | ||
); | ||
assert.strictEqual( | ||
crypto.timingSafeEqual(new Uint32Array(ab32), dv32), | ||
true | ||
); | ||
assert.strictEqual( | ||
crypto.timingSafeEqual( | ||
new Uint8Array(ab32, 0, 16), | ||
Buffer.from(ab32, 0, 16) | ||
), | ||
true | ||
); | ||
assert.strictEqual( | ||
crypto.timingSafeEqual( | ||
new Uint32Array(ab32, 0, 8), | ||
Buffer.of(0, 0, 0, 1, // 4 | ||
1, 0, 0, 0, // 8 | ||
0, 0, 0, 0, 0, 0, 0, 1, // 16 | ||
1, 0, 0, 0, 0, 0, 0, 0, // 24 | ||
0, 1, // 26 | ||
1, 0, // 28 | ||
1, 1, // 30 | ||
0, 0) // 32 | ||
), | ||
true | ||
); | ||
|
||
// 'should consider unequal buffer views to be unequal' | ||
assert.strictEqual( | ||
crypto.timingSafeEqual( | ||
new Uint32Array(ab32, 16, 4), | ||
Buffer.from(ab32, 0, 16) | ||
), | ||
false | ||
); | ||
assert.strictEqual( | ||
crypto.timingSafeEqual( | ||
new Uint8Array(ab32, 0, 16), | ||
Buffer.from(ab32, 16, 16) | ||
), | ||
false | ||
); | ||
assert.strictEqual( | ||
crypto.timingSafeEqual( | ||
new Uint32Array(ab32, 0, 8), | ||
Buffer.of(0, 0, 0, 1, // 4 | ||
1, 0, 0, 0, // 8 | ||
0, 0, 0, 0, 0, 0, 0, 1, // 16 | ||
1, 0, 0, 0, 0, 0, 0, 0, // 24 | ||
0, 1, // 26 | ||
1, 0, // 28 | ||
1, 1, // 30 | ||
0, 1) // 32 | ||
), | ||
false | ||
); | ||
// 'buffers with differing byteLength must throw an equal length error' | ||
common.expectsError( | ||
() => crypto.timingSafeEqual(Buffer.from(ab32, 0, 8), | ||
Buffer.from(ab32, 0, 9)), | ||
{ | ||
code: 'ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH', | ||
type: RangeError, | ||
message: 'Input buffers must have the same byteLength' | ||
} | ||
); | ||
common.expectsError( | ||
() => crypto.timingSafeEqual( | ||
new Uint32Array(ab32, 0, 8), // 32 | ||
Buffer.of(0, 0, 0, 1, // 4 | ||
1, 0, 0, 0, // 8 | ||
0, 0, 0, 0, 0, 0, 0, 1, // 16 | ||
1, 0, 0, 0, 0, 0, 0, 0, // 24 | ||
0, 1, // 26 | ||
1, 0, // 28 | ||
1, 1, // 30 | ||
0) // 31 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you factor out these |
||
), | ||
{ | ||
code: 'ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH', | ||
type: RangeError, | ||
message: 'Input buffers must have the same byteLength' | ||
} | ||
); | ||
} | ||
|
||
common.expectsError( | ||
() => crypto.timingSafeEqual(Buffer.from([1, 2, 3]), Buffer.from([1, 2])), | ||
{ | ||
code: 'ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH', | ||
type: RangeError, | ||
message: 'Input buffers must have the same length' | ||
message: 'Input buffers must have the same byteLength' | ||
} | ||
); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to consider undoing this change. Error message changes are considered semver-major, meaning this couldn't be released until Node.js 12.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure, are we still doing that? I was under the impression that we don’t necessarily consider it semver-major when there’s an associated message code…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that error message changes shouldn't be semver major if there is an error code, since that was (one of) the advertised advantage in migrating to them. That said, I'm not sure there is much benefit to changing this. IMO, the error message was better before, even if it didn't completely reflect the implementation details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps,
Input buffers must have the same number of bytes
? Same idea, a bit more human readable?