liveBook · Manning

Constant-time comparison

A constant-time comparison is an equality-checking technique whose execution pattern does not reveal information through the position or content of mismatches.

How 2 Manning books explain it

Hacking Cryptography

A constant-time comparison compares values without execution time depending on the position or content of mismatches, aside from permitted length handling.

How it is used
Protects secret comparisons from timing leakage during cryptographic implementation.
How deep it goes
Explains short-circuit leakage and a Go implementation, including accumulator behavior, but does not develop timing-measurement methodology.
Examples
Uses decimal-guessing intuition, glibc memcmp, and Go's crypto/subtle ConstantTimeCompare.
What you can do after
Apply Go's crypto/subtle.ConstantTimeCompare or an equivalent full-scan comparison for equal-length secret values.

Read how Hacking Cryptography explains constant-time comparison →

Real-World Cryptography

A constant-time comparison compares two values in an execution pattern whose duration does not depend on the location of their first difference.

How it is used
Protects authentication-tag verification from timing attacks caused by early comparison exits.
How deep it goes
Explains branch avoidance and XOR-OR accumulation, while leaving the exact trick as an exercise.
Examples
Uses MAC tag verification and Go byte-array comparison with XOR and OR accumulation.
What you can do after
Apply it via cryptographic library verification functions when comparing received and computed authentication tags.

Read how Real-World Cryptography explains constant-time comparison →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.