Side-channel attacks: timing, cache, power, and why constant-time code matters
Side channels leak secrets through how long, how loudly, or how much power a computation takes. Timing leaks in string comparison, cache attacks such as Spectre and Meltdown, power analysis on devices, and the coding and patching habits that defend.
Diagram
A timing leak in a token check
Step 1 of 4
Compare
A naive check stops at the first mismatched byte.
def check(token, expected):
return token == expected # may return earlyThe example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
Timing in application code
- What fails
- Early-exit comparisons and secret-dependent branches leak timing.
- Who is affected
- Tokens, MACs, and passwords compared in code.
- What you would notice
- Use of == on secrets in review.
- What you change
- Use constant-time comparison functions.
CPU side channels
- What fails
- Spectre and Meltdown (2018) read memory through speculative execution and cache timing.
- Who is affected
- Shared hosts and browsers.
- What you would notice
- Missing microcode or OS mitigations.
- What you change
- Patch OS, firmware, and browsers; isolate sensitive workloads.
Hardware devices
- What fails
- Power and electromagnetic analysis read keys from smart cards and embedded chips.
- Who is affected
- Device makers and users.
- What you would notice
- Embedded crypto without countermeasures.
- What you change
- Use certified secure elements for keys.
Use libraries that already care
Well-maintained crypto libraries (libsodium, BoringSSL, Go’s crypto packages) are written to avoid secret-dependent timing. Writing your own primitives almost always reintroduces leaks.
Check yourself
Recognition and the fix. Nothing here is a procedure.
Why can token == expected leak information?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.