Digest comparison
This is probably quite surprising, but within secrets, you can find the compare_digest(a, b) function, which is the equivalent of comparing two digests by simply doing a == b. So, why do we need that function? It's because it has been designed to prevent timing attacks. These kind of attacks can infer information about where the two digests start being different, according to the time it takes for the comparison to fail. So, compare_digest prevents this attack by removing the correlation between time and failures. I think this is a brilliant example of how sophisticated attacking methods can be. If you raised your eyebrows in astonishment, maybe now it's clearer why I said to never implement cryptography functions by yourself. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access