Prevent timing attacks en cryptographic operations
Timing attacks exploit ejecución time variations a leak secrets. Aprender constant-time comparación, uniform processing, y blinding techniques.
- 1
A timing attack measures how long an operation takes to infer information about the secret. For example, a string comparison that returns early on the first mismatch leaks how many characters match. Defense: all operations on secret data must take time independent of the data value.
- 2 Comparador de hashes →
Comparar hashes in constant time. This tool performs a byte-by-byte comparison that always processes all bytes, regardless of where the first mismatch occurs. Never use === to compare hashes or HMACs — it short-circuits and leaks timing information.
- 3 Generador de HMAC →
Generar an HMAC for authentication. When verifying, use a constant-time comparison function (crypto.timingSafeEqual in Node.js). The comparison must touch every byte regardless of match position.
- 4
For RSA, use blinding: multiply the message by a random value r^e before signing, then divide the result by r. This randomizes the computation time and prevents timing-based key recovery. Modern crypto libraries (OpenSSL, Web Crypto) do this internally — always use library functions, never implement crypto from scratch.
Preguntas frecuentes
- How does a timing attack work?
- The attacker sends many requests and measures response time. If the first byte of the secret matches, the comparison takes slightly longer. By trying all values for each byte and observing timing, the attacker recovers the secret one byte at a time. This has been demonstrated over network (within ~15ms precision).
- Is === safe for comparing non-secret data?
- Yes. Timing attacks only matter when the compared value is secret (passwords, hashes, tokens). For non-sensitive comparisons (e.g., checking if a user role is "admin"), === is fine. The rule: use constant-time comparison only for secrets.