Improve algorithm steps for Modern Algorithms' supports() method - #558
Merged
Conversation
Move parameter-only checks ahead of plaintext and ciphertext checks so
support queries can observe them.
For example, this now returns false:
SubtleCrypto.supports("encrypt", {
name: "AES-GCM",
iv: new Uint8Array(12),
tagLength: 31,
})
A 31-bit AES-GCM tag is never valid, regardless of key or plaintext.
This was referenced Aug 7, 2026
twiss
reviewed
Aug 7, 2026
Member
Author
|
@twiss to confirm then
The rest is fine from your POV? |
Member
|
Yeah, I'll do one more pass afterwards but I think the rest looks good 👍 Thanks! |
panva
force-pushed
the
supports-improvements
branch
from
August 7, 2026 15:25
1583eb8 to
c635495
Compare
Member
Author
|
@twiss done |
Check HKDF's 255-block output limit before the operation reaches
unavailable key material.
For example, this now returns false:
SubtleCrypto.supports("deriveBits", {
name: "HKDF",
hash: "SHA-256",
salt: new Uint8Array(),
info: new Uint8Array(),
}, 65288)
With SHA-256 the maximum is 65280 bits, so 65288 bits can never be
derived.
Expose the unconditional zero-length failure before import reaches unavailable key data.
For example, this now returns false:
SubtleCrypto.supports("importKey", {
name: "HMAC",
hash: "SHA-256",
length: 0,
})
No HMAC key data can satisfy an explicitly requested length of zero.
Expose universally invalid modulus lengths and public exponents before
the operation reaches key generation.
For example, this now returns false:
SubtleCrypto.supports("generateKey", {
name: "RSA-PSS",
modulusLength: 2048,
publicExponent: new Uint8Array([2]),
hash: "SHA-256",
})
No RSA key can use an even public exponent.
Expose impossible public-key inputs and overlong derivations before the
operation reaches unavailable base key material.
For example, this now returns false:
SubtleCrypto.supports("deriveBits", {
name: "X25519",
public: publicKey,
}, 257)
X25519 produces at most 256 bits, so 257 bits can never be derived.
Expose impossible public-key inputs and overlong derivations before the
operation reaches unavailable base key material.
For example, with a P-256 public key, this now returns false:
SubtleCrypto.supports("deriveBits", {
name: "ECDH",
public: publicKey,
}, 257)
A P-256 field element encodes to 256 bits. The output limit is derived
from the public key's EC domain parameters, so extended named curves are
handled without enumeration.
Expose unsupported ECDSA and ECDH named curves before import reaches unavailable key data.
For example, this now returns false:
SubtleCrypto.supports("importKey", {
name: "ECDSA",
namedCurve: "not-a-curve",
})
NamedCurve remains a DOMString so applicable specifications can define additional curves.
panva
force-pushed
the
supports-improvements
branch
from
August 11, 2026 13:12
c635495 to
b16487f
Compare
twiss
approved these changes
Aug 11, 2026
github-actions Bot
added a commit
that referenced
this pull request
Aug 11, 2026
SHA: 811c24c Reason: push, by twiss Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Modern Algorithms specification defines
SubtleCrypto.supports()by normalizing an algorithm and executing its operation steps until it encounters unavailable key or data, key generation, a return, or an exception.This makes the ordering and explicitness of validation in the core Web Cryptography specification observable. Some core operations currently reach one of those stopping points before checking parameters that
supports()does have. This can makesupports()returntruefor an interaction that:This PR makes those outcomes observable before
supports()reaches its stopping point.Changes
NamedCurveas an enum so names not defined by the core or an applicable specification fail during normalization.The XOF checks establish an intentionally unsupported boundary rather than claiming every such composition is cryptographically impossible/undefined. Selecting an output length for an XOF does not turn it into the fixed-output hash expected by these traditional algorithms. In particular, implementations already reject RSA and ECDSA combinations with XOF digests using
NotSupportedError. This just sets it as baseline.Successful operations are unchanged.
Examples
Each of the following now returns
false.AES-GCM parameters
A 31-bit AES-GCM tag is never valid, regardless of key or plaintext.
HKDF output length
With SHA-256 the maximum is 65280 bits, so 65288 bits can never be derived.
XOFs in traditional algorithms
Modern Algorithms implementations deliberately exclude XOF digests from these traditional algorithms. Selecting an output length does not turn cSHAKE into a fixed-output hash.
Undefined named curves
No import using an undefined curve could ever succeed.
Zero-length HMAC imports
No HMAC key data can satisfy an explicitly requested length of zero.
RSA key generation parameters
No RSA key can use an even public exponent.
X25519 derivation length
X25519 produces at most 256 bits, so 257 bits can never be derived. Refs: WICG/webcrypto-modern-algos#74
ECDH derivation length
With a P-256 public key, the field element encodes to 256 bits. The output limit is derived from the public key’s EC domain parameters, so extended named curves are handled without enumeration. Refs: WICG/webcrypto-modern-algos#74
Preview | Diff