Konstas.Engineering Notes
Networking · Cybersecurity · Infrastructure
Cryptography

Side-Channel and Timing Attacks

Articles · July 2026 · Ioannis (John) Konstas

You can have a mathematically perfect cipher and still leak the key — not through the algorithm, but through the machine running it. Side-channel attacks exploit the physical shadow a computation casts: how long it takes, how much power it draws, what sound or electromagnetic emission it makes, what it leaves in the cache. The algorithm is sound; the implementation talks. This is one of the most counterintuitive and important ideas in applied security.

The classic: timing attacks

A timing attack infers secret data from how long an operation takes. The canonical example is decades old and still instructive: RSA and similar implementations can leak private keys because the time to perform a modular exponentiation depends on the bits of the secret. Feed the device many chosen inputs, measure the tiny timing differences, and statistics recovers the key one bit at a time — no need to break the math at all.

Smartcards were an early victim: an attacker with physical access sends byte patterns to be signed, times each operation, and correlates the durations (and even the number of set bits in the input) with the internal key-dependent branches. Enough measurements, and the private key falls out.

The everyday version: string comparison

You don't need a smartcard to be vulnerable. The most common timing bug in ordinary software is comparing secrets with a normal equality check, which returns the instant it finds a mismatch:

# VULNERABLE: returns early on first differing byte.
# An attacker measures response time to learn the token prefix-by-prefix.
def check_token(supplied, real):
    return supplied == real          # short-circuits -> leaks how much matched

# SAFE: constant-time comparison, always examines every byte.
import hmac
def check_token_safe(supplied, real):
    return hmac.compare_digest(supplied, real)

Every language ships a constant-time comparator (hmac.compare_digest in Python, crypto.timingSafeEqual in Node, subtle.ConstantTimeCompare in Go). Use it for tokens, MACs, and password hashes — anywhere a mismatch is a secret.

The broader family

Defenses: make the shadow constant

The unifying principle is eliminate the correlation between secret data and observable behavior:

Why it matters even if you're not writing crypto

Two reasons. First, the string-comparison bug is common, easy to introduce, and easy to fix — and it's real: token and signature verification are exactly where it bites. Second, side channels reframe how you think about security: correctness of the algorithm is necessary but not sufficient; the implementation and the hardware are part of the attack surface. A perfect lock on a door with a glass panel is not a secure door.

A flawless cipher can still betray its key through timing, power, or cache. The defense is to make the observable behavior independent of the secret — constant-time code and battle-tested libraries — because the machine, not just the math, is part of your threat model.

← All articles

Research and direction by Ioannis (John) Konstas; compiled and finalized with AI assistance.

👁· views