Possible Left Over Bytes Issues
alexander-pick opened this issue · 1 comments
I was looking at the Android version of this hash algorithm here while looking at a kernel module using siphash:
https://android.googlesource.com/kernel/common/+/3af7a2f61023/lib/siphash.c
And compared it to your reference implementation. The references uses ni
, a moving pointer from the for loop for the left over parts while the Android code uses end
.
Now I am a bit confused since using ni
will still point to the last block already processed if entering the switch statement. ni
and end
will never be equal as the for loop terminates on !=
.
Unless I am not mistaken if using ni
instead of end in the switch would make the code re-read the number of bytes to process in the last run, from the previously already read block, instead the real bytes which remain after end
?
From my understanding you are calculating end
to be 64 bit aligned by subtracting len modulo 8
from it. So the bytes should be read from end + x
not from the final ni + x
(ni
being end - 8
after the loop).
Found my issues, ni is still bumped even if not processed.