Time-based One-time Password algorithm
The Time-based One-time Password algorithm (TOTP) is an extension of the HMAC-based One-time Password algorithm (HOTP) generating a one-time password (OTP) by instead taking uniqueness from the current time. It has been adopted as Internet Engineering Task Force (IETF) standard RFC 6238, is the cornerstone of Initiative for Open Authentication (OATH), and is used in a number of two-factor authentication (2FA) systems.
Because of latency, both network and human, and unsynchronised clocks, the one-time password must validate over a range of times between the authenticator and the authenticated. Here, time is downsampled into larger durations (e.g., 30 seconds) to allow for validity between the parties. However, as with HOTP the decreased uniqueness requires additional countermeasures, such as rate limiting.
To establish TOTP authentication, the authenticated and authenticator must pre-establish both the HOTP parameters and the following TOTP parameters:
- T0, the Unix time from which to start counting time steps (default is 0)
- TX, an interval which will be used to calculate the value of the counter CT (default is 30 seconds)
Both the authenticator and the authenticatee compute the TOTP value, then the authenticator checks if the TOTP value supplied by the authenticated matches the locally generated TOTP value. Some authenticators allow values that should have been generated before or after the current time in order to account for slight clock skews, network latency and user delays.
TOTP uses the HOTP algorithm, substituting the counter with a non-decreasing value based on the current time.
- TOTP value(K) = HOTP value(K, CT)
The time counter, CT, is an integer counting the number of durations, TX, in the difference between the current Unix time, T, and some epoch (T0; cf. Unix epoch); the latter values all being in integer seconds.
Note that Unix time is not strictly increasing. When a leap second is inserted into UTC, Unix time repeats one second. But a single leap second does not cause the integer part of Unix time to decrease, and CT is non-decreasing as well so long as TX is a multiple of one second.
For subsequent authentications to work, the clocks of the authenticated and the authenticator need to be roughly synchronized (the authenticator will typically accept one-time passwords generated from timestamps that differ by ±1 time interval from the authenticated's timestamp).
Weaknesses and vulnerabilitiesEdit
TOTP values can be phished like passwords, though this requires attackers to proxy the credentials in real time.
Implementations that don't limit login attempts are vulnerable to brute forcing of values.
An attacker who steals the shared secret can generate new, valid TOTP values at will. This can be a particular problem if the attacker breaches a large authentication database.
Because TOTP devices have consumable batteries and clocks that can de-synchronize, and can be lost and/or stolen, all real-world implementations have backup methods to bypass the protection (e.g.: printed recovery codes, SMS/email/phone call delivered recovery code or link), etc.). This can create significant support costs for services with large user-bases, and also provide weak points for attackers to try first.
TOTP values are valid for longer than the amount of time they show on the screen (typically twice as long). This is a concession that the authenticating and authenticated sides' clocks can be skewed by a large margin.
A TOTP draft was developed through the collaboration of several OATH members in order to create an industry-backed standard. It complements the event-based one-time standard HOTP and offers end user organizations and enterprises more choice in selecting technologies that best fit their application requirements and security guidelines. In 2008, OATH submitted a draft version of the specification to the IETF. This version incorporates all the feedback and commentary that the authors received from the technical community based on the prior versions submitted to the IETF. In May, 2011, TOTP officially became RFC 6238.
- Botan, C++ cryptography library with HOTP/TOTP support
- "RFC 6238 – TOTP: Time-Based One-Time Password Algorithm". Retrieved July 13, 2011.
- Zetter, Kim. "RSA Agrees to Replace Security Tokens After Admitting Compromise". WIRED. Retrieved 2017-02-17.
- Alexander, Madison. "OATH Submits TOTP: Time-Based One Time Password Specification to IETF". Open Authentication. Retrieved 22 February 2010.
- Step by step Python implementation in a Jupyter Notebook
- Designing Docker Hub Two-Factor Authentication, (section "Using Time-Based One-Time Password (TOTP) Authentication").