Out of curiosity I'm looking for and slowing down many things about cryptography and also looking for some pure PHP libraries, such as Sodium_Compat , for the sole reason that I understand a lot more of PHP compared to C, which is ideal for encryption, as far as I know.
However, something caught my eye in the following following :
/**
* Use pack() and binary operators to turn the two integers
* into hexadecimal characters. We don't use chr() here, because
* it uses a lookup table internally and we want to avoid
* cache-timing side-channels.
*/
$hex .= pack(
'CC',
(55 + $b + ((($b - 10) >> 8) & ~6)),
(55 + $c + ((($c - 10) >> 8) & ~6))
);
I just did not find much information about cache-timing
, remembering that there is cache-timing attack
and timing attack
, which are different things (or not?), the second has more information.
I found this information here , which is the most summarized and there is another reply and comment that seems to be almost the answer of this question , but I'm not sure. Even based on the comment of the code I assume that the problem is that chr()
uses some type of array (would that be lookup table internally
?) While pack()
not, but how then pack()
is able to convert the integer to hexadecimal?
The issue is, pack()
is not supposed to be vulnerable while chr()
has such a problem, this is not even mentioned in PHP documentation, perhaps because it is very specific . What functions, on the inside, have different? How do they convert integers and why can one convert "more securely than the other"? Why are they both not vulnerable?