A constant-time comparison is supposed to contain no branch that depends on its input. The span form of ctsafe::equals opens with exactly one: if the two sizes differ, it returns false before a single byte gets read. That looks like a hole in the discipline, and it isn't one. Constant-time code protects the contents of a buffer, so a comparison routine has to decide whether the length counts as contents. Call it public and you buy the one early return worth having, and you close an overread that is a far more realistic bug than the leak it admits.
What the timing channel actually carries
The bug the routine exists for is older than most of the code that still contains it:
if ( memcmp ( mac , expected , 16 ) == 0 ) { . . . } // CWE-208
Enter fullscreen mode
Exit fullscreen mode
memcmp returns as soon as two bytes differ. Someone who can time the call learns how many leading bytes they guessed correctly, and walks the tag out one byte at a time.…