Timing Attack

Cybersecurity Glossary Cryptography & Passwords

Timing Attack

A side-channel attack that extracts secrets by measuring data-dependent execution time, such as string or HMAC comparisons that return early, or responses that reveal whether a user exists.

Timing Attack is a side-channel attack that extracts sensitive information by precisely measuring how long operations take. When execution time depends on secret data, attackers can infer the secret through statistical analysis of timing differences.

Common Vulnerable Patterns

Cryptographic Operations

// RSA decryption time varies with bit values
// AES cache timing reveals key bits
// ECDSA nonce bias from timing

Prevention

// Use constant-time comparison
import hmac
def safe_compare(a, b):
    return hmac.compare_digest(a, b)

// Python
from secrets import compare_digest

// Ruby
require 'rack/utils'
Rack::Utils.secure_compare(a, b)

// Always takes same time regardless of match position

Mitigation Strategies

  • Use constant-time comparison functions
  • Add random delays (weak, can be averaged out)
  • Use cryptographic libraries with timing-safe implementations
  • Consider hardware-based timing protections

See Also