Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/crypto/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ function bigIntArrayToUnsignedInt(input) {
result |= input[n] << 8 * n_reversed;
}

return result;
return result >>> 0;
}

function bigIntArrayToUnsignedBigInt(input) {
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-webcrypto-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,28 @@ if (!common.hasCrypto)
const assert = require('assert');

const {
bigIntArrayToUnsignedInt,
normalizeAlgorithm,
} = require('internal/crypto/util');

// bigIntArrayToUnsignedInt must return an unsigned 32-bit value even when
// the most significant byte has its top bit set. Otherwise the signed `<<`
// operator yields a negative Int32 for inputs like [0x80, 0x00, 0x00, 0x01].
{
assert.strictEqual(
bigIntArrayToUnsignedInt(new Uint8Array([0x80, 0x00, 0x00, 0x01])),
0x80000001);
assert.strictEqual(
bigIntArrayToUnsignedInt(new Uint8Array([0xff, 0xff, 0xff, 0xff])),
0xffffffff);
assert.strictEqual(
bigIntArrayToUnsignedInt(new Uint8Array([1, 0, 1])),
65537);
assert.strictEqual(
bigIntArrayToUnsignedInt(new Uint8Array([1, 0, 0, 0, 0])),
undefined);
}

{
// Check that normalizeAlgorithm does not mutate object inputs.
const algorithm = { name: 'ECDSA', hash: 'SHA-256' };
Expand Down
Loading