Closed guidovranken closed 3 years ago
This behavior is not only known, but also documented:
nb_blocks
The number of blocks for the work area. Must be at least 8. A value of 100000 (one hundred megabytes) is a good starting point. If the computation takes too long, reduce this number. If it is too fast, increase this number. If it is still too fast with all available memory, increase nb_iterations.nb_iterations
The number of iterations. It must be at least 1. A value of 3 is strongly recommended; any value lower than 3 enables significantly more efficient attacks.[...]
CAVEATS
Any deviation from the specified input and output length ranges results in undefined behaviour. Make sure your inputs are correct.
There are multiple facets as to what led to this decision (without wanting to say whether they are good or bad reasons right now):
The above rationale applies for the crypto_blake2b*()
family as well, which will do silly things if you break the documented rules for key and output sizes.
@guidovranken, thanks for the report.
@fscoto, thanks for your spot-on reply.
This is indeed "not a bug". In general, Monocypher does not check trusted input. When you give a pointer no NULL check is performed. When you give a size, it is assumed valid. Monocypher is neither foolproof nor misuse resistant —it doesn't even aim to be.
That said, your bug report suggests you may disagree with those design choices. If so, I would be very interested to know why. You might have arguments we haven't thought of yet.
Ok
I'm fuzzing Monocypher using https://github.com/guidovranken/cryptofuzz
The following examples may be using invalid parameters, but that shouldn't lead to memory issues IMO.
Segfault if blocks < 8
Outputs uninitialized memory if iterations is 0
Use valgrind to verify this.