HOTP and Counter-Based OTP
What you'll learn: How HOTP generates one-time passwords using a counter instead of time, and why counter synchronization matters.
What is HOTP?
HOTP (HMAC-based One-Time Password) is an authentication mechanism that generates unique passwords based on a counter value rather than the current time. Each time you request a new password, the counter increments by one on both the client device and the server. The password is computed using HMAC (a cryptographic hash function) with two inputs: a shared secret key and the current counter value.
Think of it like a numbered ticket dispenser: both you and the security guard have identical dispensers starting at ticket #1. Each time you need access, you both pull the next ticket. As long as your ticket numbers match, you're authenticated.
HOTP vs TOTP
While TOTP (from the previous lesson) uses time windows to generate codes that expire every 30-60 seconds, HOTP uses a counter that only increments when you explicitly generate a new password. This means:
- HOTP codes don't expire based on time—they remain valid until used
- No clock synchronization issues between client and server
- Requires explicit user action to generate each new code
The Counter Synchronization Challenge
The biggest weakness of HOTP is counter desynchronization. If a user generates several codes without using them (perhaps hitting "refresh" multiple times), their counter advances but the server's doesn't. Now they're out of sync.
Most implementations solve this with a look-ahead window: the server checks not just the expected counter value, but also the next 5-10 values ahead. If a match is found, the server jumps its counter forward to match.
Key Takeaway: HOTP uses an incrementing counter instead of time to generate one-time passwords, avoiding clock sync issues but requiring careful counter synchronization management between client and server.