Performing HMAC with random key before MAC comparison In Laravel (a PHP framework) I can see that they calculate a HMAC with a random key over the final HMAC before comparison. This additional HMAC calculation is of course performed for both the calculated MAC and the received MAC value, using this randomized key.

Does this just supply a method of performing a "constant time" compare? Or does it add other security properties to the MAC calculation. I presume the former, but I want to be sure. Is this a known technique for performing MAC comparisons?
The commit that added this double HMAC only says it improves &quot;valid MAC detection&quot;, but it simultaneously adds the constant-time comparison, so likely the reason is indeed defense against timing attacks:

Improve valid MAC detection
Implement constant time string comparison as well as double HMAC
verification for encryption MACs.

Double HMAC is a known technique to avoid the side channel attack, and has been recommended as a more reliable (and &quot;simpler&quot;) alternative to constant time comparisons. I am not aware of anyone recommending both, which is pointless (they prevent the same attack) and costs even more than double HMAC - its main downside compared to constant time comparisons. On the other hand, it should not hurt, so perhaps it is done out of an abundance of caution.