Skip to content

Commit ca2bb43

Browse files
committed
crypto: reject duplicate ML-KEM JWK key_ops
Signed-off-by: Filip Skokan <[email protected]>
1 parent acb1bd7 commit ca2bb43

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

lib/internal/crypto/util.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,10 @@ const kKeyOps = {
772772
unwrapKey: 6,
773773
deriveKey: 7,
774774
deriveBits: 8,
775+
encapsulateKey: 9,
776+
encapsulateBits: 10,
777+
decapsulateKey: 11,
778+
decapsulateBits: 12,
775779
};
776780

777781
function validateKeyOps(keyOps, usagesSet) {

test/parallel/test-webcrypto-export-import-ml-kem.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,16 @@ async function testImportJwk({ name, publicUsages, privateUsages }, extractable)
491491
});
492492
}
493493
})().then(common.mustCall());
494+
495+
// Regression test: JWK `key_ops` validation must recognize ML-KEM operations
496+
// (encapsulateKey, encapsulateBits, decapsulateKey, decapsulateBits) so that
497+
// duplicate entries are rejected
498+
(async function() {
499+
for (const op of ['encapsulateKey', 'encapsulateBits',
500+
'decapsulateKey', 'decapsulateBits']) {
501+
const jwk = { ...keyData['ML-KEM-768'].jwk, key_ops: [op, op] };
502+
await assert.rejects(
503+
subtle.importKey('jwk', jwk, { name: 'ML-KEM-768' }, true, [op]),
504+
{ name: 'DataError', message: /Duplicate key operation/ });
505+
}
506+
})().then(common.mustCall());

0 commit comments

Comments
 (0)