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?

• I can't think of anything else it would add to the security properties. Of course, there ought to be easier ways to do a constant time equality comparison; perhaps they are extremely paranoid about how "helpful" optimizing compilers can be. – poncho Jan 17 '15 at 19:37
• @poncho I think it could be simpler than that; if there is no time constant comparison and there is a HMAC function it may be easier to use the latter. I'm not sure if the PHP type system would be a burden, but personally I don't see why a time constant compare wouldn't work. – Maarten Bodewes Jan 17 '15 at 19:43
• I think symfony.com/blog/new-in-symfony-2-2-security-utilities implies that StringUtils::equals is already supposed to include protection against timing attacks. So there should be some other explanation for the additional HMAC layer? – Neil Slater Jan 17 '15 at 23:36
• I've seen suggestions to use this as constant time comparison by people who're afraid that the compiler will optimize the usual constant time comparison code into variable time code. – CodesInChaos Jan 18 '15 at 12:48