memcmp compares two memory regions byte by byte, returning zero when they match and a nonzero value based on the first differing byte. Its early exit is dangerous for cryptographic values: the elapsed time reveals how many leading bytes matched. section 10.4.1
Early-exit comparison
A glibc implementation repeatedly loads corresponding bytes, advances both pointers, and continues only while they are equal. The first mismatch exits the loop and returns a0 - b0, so longer matching prefixes take longer to compare. section 10.4.1
Use constant-time comparison for secrets instead: scan every byte, accumulate differences with XOR, and decide equality only after the scan. Go's crypto/subtle implementation returns 1 for equal-length equal slices and 0 otherwise. section 10.4.1
