Early exit is a leak
A byte-by-byte compare that stops at the first mismatch tells an attacker, by timing, how many leading bytes they got right. For a secret, that turns a guess into a search. Use a constant-time compare.
Length still leaks
Constant-time compare hides the position of the first difference, not the length. For a secret, hash to a fixed length first so even the length is not a signal. compare_digest on digests is the safe form.