fix(ext/crypto): ChaCha20-Poly1305 uses raw-secret format and iv param (#34915)
## Summary
The `ChaCha20-Poly1305` WebCrypto support added in #34417 did not follow
the
[WICG modern WebCrypto algorithms
spec](https://wicg.github.io/webcrypto-modern-algos/#chacha20-poly1305),
as reported in #34904 by @panva. Two issues:
1. **Key format** — import/export only recognized the legacy `"raw"`
`KeyFormat`.
The modern spec introduces `"raw-secret"` for all symmetric keys; for
the
pre-existing symmetric algorithms `"raw"` is an alias of `"raw-secret"`,
and
new algorithms (ChaCha20-Poly1305) recognize **only** `"raw-secret"`.
2. **AEAD parameters** — encrypt/decrypt required a `nonce` member
instead of the
`AeadParams` `iv` member.
```js
const alg = 'ChaCha20-Poly1305'
const key = await crypto.subtle.importKey('raw-secret', new Uint8Array(32), alg, false, ['encrypt', 'decrypt'])
await crypto.subtle.encrypt({ name: alg, iv: new Uint8Array(12), additionalData: new Uint8Array() }, key, new Uint8Array([1, 2, 3]))
```
## Changes
- Add the `"raw-secret"` `KeyFormat`.
- Treat `"raw"` as an alias of `"raw-secret"` for the existing symmetric
algorithms (AES-CBC/CTR/GCM/KW, HMAC, HKDF, PBKDF2).
- ChaCha20-Poly1305 now recognizes only `"raw-secret"` for raw
import/export,
and additionally supports `jwk` (`kty: "oct"`, `alg: "C20P"`).
- Rename the ChaCha20-Poly1305 encrypt/decrypt AEAD parameter `nonce` →
`iv`.
- Regenerate the ChaCha20-Poly1305 WPT expectations (encrypt_decrypt,
import_export,
generateKey successes, and serialization now pass).
### Note on AES-OCB
AES-OCB is a newer (tentative) algorithm that shares the AES
import/export path and
also uses `"raw-secret"` in the spec. It is **intentionally excluded**
from the
`"raw-secret"` alias here: enabling it would surface a separate,
pre-existing
AES-OCB encrypt panic with non-12-byte IVs (`ocb3` fixes the nonce size
at 12 bytes;
the WPT vectors use 120-bit IVs). Its behaviour and WPT expectations are
left
unchanged and that crash is left for a dedicated fix.
## Test
- New `tests/unit/webcrypto_test.ts` coverage: `raw-secret`/`iv`
round-trip, `jwk`
round-trip, `raw` rejection for ChaCha20-Poly1305, and `raw-secret`
alias for the
existing symmetric algorithms.
- WPT ChaCha20-Poly1305 encrypt_decrypt / import_export / generateKey /
serialization
tests pass.
Closes #34904
Closes denoland/divybot#494
---------
Co-authored-by: divybot <divybot@users.noreply.github.com>
Co-authored-by: Divy Srivastava <me@littledivy.com>