Repository: deno
Issue: SubtleCrypto.verify() only supports specific combinations of ECDSA key curves and hash algorithms
Labels: crypto

Deno's `SubtleCrypto.verify()` currently only supports the following combinations of ECDSA key curves and hash algorithms:

1. `P-256` and `SHA-256`
2. `P-384` and `SHA-384`

https://deno.land/x/deno@v1.36.1/ext/crypto/00_crypto.js?source#L1338

This method should be able to verify signatures when the signing key's curve and the signature's hash algorithm are not one of these two supported combinations. In my case I'm trying to verify a signature using a signing key that uses the `P-384` curve while the signature's hash algorithm is `SHA-256`.

## Reproduction

1. Save the following to a file **deno_bug.ts**
1. Run the file with `deno run deno_bug.ts`
1. Observe the `NotSupportedError: Not implemented` exception

```ts
const crypto = globalThis.crypto;

const verified = await crypto.subtle.verify(
  // algorithm
  { "name": "ECDSA", "hash": { "name": "SHA-256" } },
  // key
  await crypto.subtle.importKey(
    // format
    "jwk",
    // keyData
    {
      kty: "EC",
      crv: "P-384",
      x: "gy6HLyYUkYECJbn1_Na7Y3i19V8_ywRbxzWZNHX9VJBE35v-GSEXZcaaHdoFCzjU",
      y: "UINAGkNPsk0RLVbD4c-_y5iR_sBpYIG--Wy8d8iN3a9Gpa7h3VFbWvqrk76cCyaR",
      ext: false,
    },
    // algorithm
    { name: "ECDSA", namedCurve: "P-384" },
    // extractable
    false,
    // keyUsages
    ["verify"],
  ),
  // signature
  // deno-fmt-ignore
  new Uint8Array([
    58, 68, 190, 223, 226, 125, 90, 252, 186, 237, 107, 156, 188, 164, 123, 55,
    235, 28, 21, 240, 44, 191, 131, 232, 51, 187, 222, 95, 236, 95, 240, 203,
    71, 5, 195, 154, 164, 226, 61, 44, 116, 88, 120, 129, 231, 158, 38, 228,
    128, 23, 32, 135, 119, 89, 212, 130, 216, 29, 179, 96, 89, 184, 102, 194,
    79, 254, 48, 32, 141, 50, 245, 26, 11, 153, 248, 7, 187, 240, 3, 118, 1,
    200, 202, 110, 81, 26, 108, 231, 100, 108, 170, 244, 104, 191, 204, 244,
  ]),
  // data
  // deno-fmt-ignore
  new Uint8Array([
    48, 130, 1, 201, 160, 3, 2, 1, 2, 2, 6, 1, 116, 133, 103, 13, 117, 48, 10,
    6, 8, 42, 134, 72, 206, 61, 4, 3, 2, 48, 72, 49, 28, 48, 26, 6, 3, 85, 4,
    3, 12, 19, 65, 112, 112, 108, 101, 32, 87, 101, 98, 65, 117, 116, 104, 110,
    32, 67, 65, 32, 49, 49, 19, 48, 17, 6, 3, 85, 4, 10, 12, 10, 65, 112, 112,
    108, 101, 32, 73, 110, 99, 46, 49, 19, 48, 17, 6, 3, 85, 4, 8, 12, 10, 67,
    97, 108, 105, 102, 111, 114, 110, 105, 97, 48, 30, 23, 13, 50, 48, 48, 57,
    49, 51, 48, 50, 52, 57, 49, 55, 90, 23, 13, 50, 48, 48, 57, 49, 52, 48, 50,
    53, 57, 49, 55, 90, 48, 129, 145, 49, 73, 48, 71, 6, 3, 85, 4, 3, 12, 64,
    51, 50, 55, 101, 98, 53, 56, 56, 102, 49, 53, 55, 100, 54, 98, 98, 54, 52,
    53, 52, 102, 57, 55, 102, 53, 101, 53, 54, 99, 56, 54, 102, 52, 52, 98, 53,
    48, 55, 99, 56, 56, 49, 56, 102, 102, 50, 51, 48, 98, 100, 48, 102, 54, 50,
    53, 98, 100, 98, 54, 53, 98, 99, 98, 54, 49, 26, 48, 24, 6, 3, 85, 4, 11,
    12, 17, 65, 65, 65, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105,
    111, 110, 49, 19, 48, 17, 6, 3, 85, 4, 10, 12, 10, 65, 112, 112, 108, 101,
    32, 73, 110, 99, 46, 49, 19, 48, 17, 6, 3, 85, 4, 8, 12, 10, 67, 97, 108,
    105, 102, 111, 114, 110, 105, 97, 48, 89, 48, 19, 6, 7, 42, 134, 72, 206,
    61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 98, 2, 84, 53,
    213, 131, 219, 114, 152, 230, 192, 207, 119, 136, 231, 159, 202, 237, 52,
    135, 207, 184, 4, 2, 205, 42, 112, 67, 7, 146, 61, 159, 94, 240, 15, 156,
    13, 168, 253, 33, 98, 230, 183, 227, 71, 129, 239, 150, 117, 47, 245, 122,
    35, 180, 120, 170, 182, 170, 239, 190, 183, 206, 63, 102, 163, 85, 48, 83,
    48, 12, 6, 3, 85, 29, 19, 1, 1, 255, 4, 2, 48, 0, 48, 14, 6, 3, 85, 29,
    15, 1, 1, 255, 4, 4, 3, 2, 4, 240, 48, 51, 6, 9, 42, 134, 72, 134, 247, 99,
    100, 8, 2, 4, 38, 48, 36, 161, 34, 4, 32, 251, 176, 71, 81, 16, 189, 192,
    173, 96, 36, 90, 134, 114, 86, 138, 202, 179, 233, 134, 11, 16, 5, 199,
    215, 170, 116, 89, 118, 203, 125, 142, 173,
  ]),
);

console.log({ verified });
```

```sh
$> deno run deno_bug.ts 
error: Uncaught NotSupportedError: Not implemented
const verified = await crypto.subtle.verify(
                                     ^
    at SubtleCrypto.verify (ext:deno_crypto/00_crypto.js:1342:17)
    at file:///...snip.../deno_bug.ts:3:38
```