-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Labels
Description
The crypto_sign_signature function takes a pointer that it will set to the length of the output buffer. This is less than ideal for good ergonomics:
- The parameter makes it appear as if the length of the signature is dynamic, but it is not, it is always
MLDSA_CRYPTO_BYTES. - The shape of the parameter pair (buffer followed by length) is sufficiently close to other uses where it is an input parameter that callers may expect it to be set on input.
- It isn't checked internally, so if a caller does set it and it has the wrong value, then this is ignored.
- A check of the size after the call is almost never useful. There are two cases:
- The caller provided a buffer that is too large. The check may enable a call to
reallocor some other approach to trim the buffer (though given that the size is invariant, this is almost always an error). - The caller provided a buffer that is too small. In this case, the check of the returned size happens after the library has written past the end of a buffer and therefore the state of the value is undefined.
- The caller provided a buffer that is too large. The check may enable a call to
All of this adds up to a dangerous API pattern, where people write code that appears defensive but will actually corrupt memory.