liveBook · Manning

One-time code

As explained in Real-World Cryptography

A one-time password is an authentication code intended to be accepted for only one authentication attempt or a narrowly defined validity period.

A one-time code replaces a long-term password during authentication. It is derived from a uniformly random symmetric key and additional data, then accepted only once or within a narrow validity period. Reusing it would defeat its purpose: exposure should not grant unlimited account access. section 11.2.3

Two common schemes differ in the extra value combined with the shared key:

  • HOTP uses a counter, requiring client and server state to remain synchronized. section 11.2.3
  • TOTP uses the current time and is widely used because it avoids maintaining a shared counter state. section 11.2.3
  • Mobile authenticator applications and security keys commonly generate these codes. section 11.2.3

TOTP sign-in

During registration, a service shares a symmetric key with an authenticator application, often through a QR code. Later, the application generates a six-digit code; the service independently computes the expected value with HMAC and the current time, then compares the values in constant time. section 11.2.3

How Real-World Cryptography covers it

How deep it goes
Explains symmetric-key derivation, HOTP counters, TOTP time values, registration, generation, and constant-time validation.
Examples
Uses Google Authenticator, six-digit 30-second codes, QR-code registration, and an example.com TOTP login flow.
What it assumes
Introduces symmetric-key authentication and OTP mechanisms while assuming familiarity with basic cryptographic keys.
What you can do after
Apply it via HOTP or TOTP to authenticate users without exposing their long-term symmetric keys.
How it connects
Connects symmetric keys, HMAC, passwordless authentication, HOTP, TOTP, security keys, and authenticator applications.

Also explained in

Compare how 3 books explain one-time code →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Real-World Cryptography. The section links point to the parts of the book it draws on.