This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 27331 - deriveBits() has a non-nullable length
Summary: deriveBits() has a non-nullable length
Status: RESOLVED INVALID
Alias: None
Product: Web Cryptography
Classification: Unclassified
Component: Web Cryptography API Document (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Ryan Sleevi
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-15 00:22 UTC by Eric Roman
Modified: 2014-11-20 00:44 UTC (History)
2 users (show)

See Also:


Attachments

Description Eric Roman 2014-11-15 00:22:11 UTC
The WebIDL for deriveBits reads as:

  Promise<any> deriveBits(AlgorithmIdentifier algorithm,
                          CryptoKey baseKey,
                          unsigned long length);

The "length" argument is not defined as nullable.

However there are several of the algorithm's "Derive Bits" reference the possibility of "length" being null. For instance:

ECDH:
 
If length is null:
  Return secret

HKDF-CTR:

If length is null, then throw a TypeError.

PBKDF2:

If length is null or is not a multiple of 8, then throw an OperationError.



It sounds like the intent was for deriveBits's length to be nullable, in which case it should probably be marked as "unsigned long?"

Otherwise as written ECMAScript's ToNumber() will eat the null and spit out a 0, meaning it is only possible for length to be 0 and never null in those sections.
Comment 1 Mark Watson 2014-11-17 16:03:14 UTC
The deriveBits *operation* is also used by the deriveKey method, in which case the length supplied is the output of the 'get length' operation of the target key algorithm. The value null is used for the case where (i) the target key algorithm can import any number of bits and (ii) the derivation algorithm has a default number of bits to output.

(i) includes the key derivation algorithms
(ii) includes the DH algorithms, where the derived bits are the DH shared secret which has a defined length

So, whether the deriveBits *method* supports nullable length is an API design decision. Technically, both options would make sense.

[It's still possible there are spec errors - the inconsistency between the returned error types when checking the length value seems wrong].
Comment 2 Eric Roman 2014-11-20 00:44:45 UTC
Thanks for the explanation Mark!

Given that when called by derive key it can be null, my bug report is invalid.