From bfd5f1598cc462b460791fdfca9bb6c2c69fec9b Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Sat, 6 Jan 2024 16:48:31 +0530 Subject: feat(ext/crypto): initial support for p521 in `generateKey` and `importKey` (#21815) Part 1 of a potential 3 part series. Ref #13449 The current implementation passes key material back and forth RustCrypto group of crates and ring. ring does not implement p521 yet. This PR adds support for P521 named curve in `generateKey` and `importKey` where we use RustCrypto. Other parts should be moved over to the RustGroup group of crates for consistency. --- cli/tests/unit/webcrypto_test.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'cli') diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index 4e1a31eaa..829330eba 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -2006,3 +2006,42 @@ Deno.test(async function testHmacJwkImport() { ["sign", "verify"], ); }); + +Deno.test(async function p521Import() { + const jwk = { + "crv": "P-521", + "ext": true, + "key_ops": [ + "verify", + ], + "kty": "EC", + "x": + "AXkSI8nfkc6bu3fifXGuKKbu08g5LKPfxUNQJJYzzPgmN8XLDzx0C9Sdeejl1XoWGrheKPHl0k4tUmHw0cdInpfj", + "y": + "AT4vjsO0bzVRlN3Wthv9DewncDXS2tlTob5QojV8WX1GzOAikRfWFEP3nspoSv88U447acZAsk5IvgGJuVjgMDlx", + }; + const algorithm = { name: "ECDSA", namedCurve: "P-521" }; + + const key = await crypto.subtle.importKey( + "jwk", + jwk, + algorithm, + true, + ["verify"], + ); + + assert(key instanceof CryptoKey); +}); + +Deno.test(async function p521Generate() { + const algorithm = { name: "ECDSA", namedCurve: "P-521" }; + + const key = await crypto.subtle.generateKey( + algorithm, + true, + ["sign", "verify"], + ); + + assert(key.privateKey instanceof CryptoKey); + assert(key.publicKey instanceof CryptoKey); +}); -- cgit v1.2.3