I've been looking at the s2n implementation of HMAC, and in the `update' function (line 175), it says
/* Keep track of how much of the current hash block is full * * Why the 4294949760 constant in this code? 4294949760 is the highest 32-bit * value that is congruent to 0 modulo all of our HMAC block sizes, that is also * at least 16k smaller than 2^32. It therefore has no effect on the mathematical * result, and no valid record size can cause it to overflow. * * The value was found with the following python code; * * x = (2 ** 32) - (2 ** 14) * while True: * if x % 40 | x % 48 | x % 64 | x % 128 == 0: * break * x -= 1 * print x * * What it does do however is ensure that the mod operation takes a * constant number of instruction cycles, regardless of the size of the * input. On some platforms, including Intel, the operation can take a * smaller number of cycles if the input is "small". */
It then goes on to do
state->currently_in_hash_block += (4294949760 + size) % state->hash_block_size; state->currently_in_hash_block %= state->block_size;
I don't understand why you would want to add a number that's congruent to zero modulo
state->hash_block_size - what does it achieve? How does it guarantee a constant number of instruction cycles?