Time-based one-time password

Time-based one-time password (TOTP) is a computer algorithm that generates a one-time password (OTP) that uses the current time as a source of uniqueness. As an extension of the HMAC-based one-time password algorithm (HOTP), it has been adopted as Internet Engineering Task Force (IETF) standard .
TOTP is the cornerstone of Initiative for Open Authentication (OATH), and is used in a number of two-factor authentication (2FA) systems.
History
Through the collaboration of several OATH members, a TOTP draft was developed in order to create an industry-backed standard. It complements the event-based one-time standard HOTP, and it 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.
Algorithm
To establish TOTP authentication, the authenticatee and authenticator must pre-establish both the HOTP parameters and the following TOTP parameters:
T, the Unix time from which to start counting time steps (default is 0),
T, an interval which will be used to calculate the value of the counter C (default is 30 seconds).
Both the authenticator and the authenticatee compute the TOTP value, then the authenticator checks whether the TOTP value supplied by the authenticatee 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, replacing the counter with a non-decreasing value based on the current time:
TOTP value(K) = HOTP value(K, C),
calculating counter value
where
C is the count of the number of durations T between T and T,
T is the current time in seconds since a particular epoch,
T is the epoch as specified in seconds since the Unix epoch (e.g. if using Unix time, then T is 0),
T is the length of one time duration (e.g. 30 seconds).
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 C is non-decreasing as well so long as T is a multiple of one second.
Security
Unlike passwords, TOTP codes are single-use, so a compromised credential is only valid for a limited time. However, users must enter TOTP codes into an authentication page, which creates the potential for phishing attacks. Due to the short window in which TOTP codes are valid, attackers must proxy the credentials in real time.
TOTP credentials are also based on a shared secret known to both the client and the server, creating multiple locations from which a secret can be stolen. An attacker with access to this shared secret could generate new, valid TOTP codes at will. This can be a particular problem if the attacker breaches a large authentication database.
See also
Botan (programming library)
FreeOTP
Google Authenticator
multiOTP
Comparison of TOTP applications
References
External links
Internet protocols
Computer access control
Cryptographic algorithms