The current interface description of ChaCha20::SetKey
suggests that literally any key-length is supported (comment set key with flexible keylength; 256bit recommended
), while passing in a key with a length less than 16 bytes would lead to a buffer overread:
This PR adds an assert to only allowing sizes of 16 or 32 bytes (i.e. 128 and 256 bits, respectively) which seem what was intended originally, looking at the following piece of code:
The fuzz tests are adopted accordingly to pick either 16 or 32 rather than a length in the range of 16 to 32. An alternative would be to just assert for the minimum size of 16 (and a maximum size of 32), if for some reason supporting keys with a length between 17 and 31 bytes is important; I guess it isn’t though, it would also be confusing as the extra bytes wouldn’t be used.