Define the ECDH length limit for supports("deriveBits") - #74
Conversation
SubtleCrypto.supports("deriveBits", algorithm, length) needs an explicit ECDH length rule.
For P-521, WebCrypto ECDH returns the x-coordinate. That is 66 bytes (ceil(521 / 8)), so deriveBits(..., 528) succeeds and returns a 66-byte buffer. 529 should fail.
The spec should say whether supports("deriveBits", { name: "ECDH", public }, length) uses that same byte-rounded maximum. Without that, implementations may treat P-521 as capped at 521 bits, even though deriveBits(..., 528) is valid.
|
I think this length check is already covered by Step 8 of the check support for an algorithm algorithm, and we don't need an extra step for it, assuming my interpretation of specification is correct. (That said, I find the description of Step 8 is a little unclear, so please feel free to correct me if I'm misunderstanding it.) My interpretation of Step 8 is that the implementation executes the target operation in a kind of "dry-run" mode, where it:
In the other words, the implementation would still perform all the validation on length, usages and parameters in normalizedAlgorithm, specified by the target operation. Combining with the Step 8 of the ECDH deriveBits operation (https://w3c.github.io/webcrypto/#ecdh-operations-derive-bits), the implementation would already check the length here. |
|
The unclear part for me is that Step 8 says the implementation skips a step that relies on an unavailable parameter, and the ECDH For ECDH, though, the length in bits of Maybe Step 8 should say that a step is skipped only when the parameter or value it relies on cannot be determined during the dry run. |
|
I see your point. The length of That said, the whole "dry-run" interpretation is just my own guess. Indeed, it doesn't seems to be fully compatible with the current wording of step 8. For example, since step 1 of the ECDH deriveBits operation relies on the unavailable parameter It would probably be best to wait a response from the editors explaining the original intention behind step 8. |
|
Hi 👋 Thanks for flagging this, and sorry for the delayed response. The original intention behind Step 8 was to run the initial validation steps in the operations, and then stop. This is particularly relevant for the operations that check some field(s) of the algorithm struct, such as the PBKDF2 derive bits operation. This is a bit hacky but allows us not to copy those steps into this spec. However, if the operation does some checks at the end, it indeed doesn't work. Perhaps, rather than adding some ECDH-specific text to Because the text there is quite general, we could similarly write something quite general and e.g. say something like:
That should not be observably different (other than performance) from the current spec text, I think. If that seems reasonable I can also make a PR due to the IPR issue, otherwise if someone else wants to do so go for it :) |
|
|
the change in w3c/webcrypto#558 would address the issue indeed. happy to close this PR. thanks |
SubtleCrypto.supports("deriveBits", algorithm, length) needs an clearer ECDH length rule.
For
P-521, WebCrypto ECDH returns the x-coordinate. That is 66 bytes (ceil(521 / 8)), soderiveBits(..., 528)succeeds and returns a 66-byte buffer.529should fail.The spec should say whether
supports("deriveBits", { name: "ECDH", public }, length)uses that same byte-rounded maximum. Without that, implementations may treat P-521 as capped at 521 bits, even thoughderiveBits(..., 528)is valid.This PR proposes text, but happy to convert to an issue for discussion
Preview | Diff