Closed SethArchambault closed 1 year ago
Good catch, but I think we’ll need to change it a little.
In Argon2, all user provided sizes are u32 (from the specs). Monocypher’s API matches this. So the index
, lane
, lane_size
, and ref
should all be u32 … lemme check… OK, got it. Line 866, I’m defining lane
as a u64:
u64 lane =
pass == 0 && slice == 0
? segment
: (index_seed >> 32) % config.nb_lanes;
I believe this was a mistake:
segment
is a u32, so no overflow could happen there.config.nb_lanes
is a u32, so no overflow there either. index_seed
must definitely be a u64, but with the right shift it goes right back to 32 significant bits. Maybe we need an explicit cast there.When we compute the index however the multiplication of lane
and lane_size
could overflow… except (i) they cannot, because nb_lanes * lane_size <= nb_blocks
to begin with, and nb_blocks
is a u32. And (ii) even if it did I think we’d get the same result after truncation. Oh, and the reference set stays in one lane, so the entire operation cannot possibly overflow.
To be tested, but I’m pretty sure the proper fix here is to:
lane
should be a u32 (may require a cast or two)ref
should be a u32 (definitely requires a cast, possibly of the whole expression).Could you try and change your PR to make that fix? You found the warning, you should take credit for the fix. If it passes the tests that will likely be good to merge.
Cool - just changing the types works, and tests pass!
Perfect, thank you! I’ll need to pay special attention to line 880 (u32 ref = (window_start + z) % lane_size;
), but if the test pass that’s probably correct. Merging right away.
This came out of adding these compile options:
-Werror -Wall -Wextra -Wshadow -Wconversion -Wno-deprecated-declarations -Wno-unused-parameter
And finding this one error:
Easy fix:
Though - I guess there's now the question - does this loss of precision matter under any circumstances?