| Internet-Draft | Update to RFC 6238 (TOTP) | December 2026 |
| Rigopoulos | Expires 9 June 2027 | [Page] |
Section 5.2 of RFC 6238 requires that the verifier not accept the second attempt of an OTP after a successful validation, and leaves the method to the implementer. This document updates and extends RFC 6238 with a stored last accepted time step and a single atomic check-and-store step, so that each OTP is accepted at most once. It adds one recommendation on when an OTP is produced. Nothing else changes. Reference code and test results are included.¶
This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.¶
Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at https://datatracker.ietf.org/drafts/current/.¶
Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."¶
This Internet-Draft will expire on 9 June 2027.¶
Copyright (c) 2026 IETF Trust and the persons identified as the document authors. All rights reserved.¶
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Revised BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Revised BSD License.¶
Section 5.2 of [RFC6238] states that the verifier MUST NOT accept the second attempt of an OTP after the successful validation of the first, and leaves the method to the implementer. This document updates and extends [RFC6238] with that method. The transmission delay window, the time step size, and the OTP values do not change. An OTP inside the window is accepted at most once.¶
For each point, the following lists what [RFC6238] says, the piece it does not specify, and the answer given here.¶
RFC 6238 says Not specified This document
------------------ --------------------- ----------------------
R1: know Unix time How exact it must be Accurate source (Sec. 3)
No second attempt What is kept Last accepted time step
(Sec. 5.2)
Same Simultaneous attempts One atomic step (Sec. 5.2)
Same Several instances One durable store
(Sec. 5.2)
Resynchronization Use with the rule Advance the time step
(Sec. 6)
The OTP value When it is produced Only on request (Sec. 4)
¶
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.¶
The terms of Section 2 of [RFC6238] apply. This document names the symbols of [RFC6238] once, here, and then uses words: the shared secret (K), the time step size (X), the Unix time to start counting time steps (T0), and the number of time steps (T) since that start time.¶
This section updates Section 3 of [RFC6238].¶
Requirement R1 says that the prover and the verifier MUST know or be able to derive the current Unix time. Unix time counts whole seconds since midnight UTC of January 1, 1970. It is the same everywhere, has no time zones, and gives an exact number of time steps. The verifier MUST obtain the current Unix time from an accurate time source, for example a network time source.¶
This section updates Section 4 of [RFC6238].¶
The algorithm, which uses HOTP [RFC4226], and the OTP values are unchanged. The prover and the verifier stay in step offline: each works out the same OTP from the shared secret and the current time step, with no contact between them. Section 6 of [RFC6238] covers clock drift.¶
An application that displays an OTP SHOULD produce it only when the user asks for it, and SHOULD make it no longer available once it has been used or has expired.¶
This document updates Section 5.2 of [RFC6238] as follows.¶
=== OLD ===
Note that a prover may send the same OTP inside a given time-step
window multiple times to a verifier. The verifier MUST NOT accept
the second attempt of the OTP after the successful validation has
been issued for the first OTP, which ensures one-time only use of an
OTP.
=== NEW ===
Note that a prover may send the same OTP inside a given time-step
window multiple times to a verifier. The verifier MUST NOT accept
the second attempt of the OTP after the successful validation has
been issued for the first OTP, which ensures one-time only use of an
OTP.
To meet this requirement, the verifier MUST keep, for each prover,
the time step of the last OTP it accepted (the "last accepted time
step"), and MUST handle each received OTP as follows:
1. Accept the OTP only if its time step is inside the transmission
delay window and later than the last accepted time step. If no
time step has been accepted yet, any time step inside the window
qualifies.
2. Check and store in one atomic step: a single operation of the
store that reports whether the value changed (for example a
compare-and-swap). If another attempt has already stored that
time step or a later one, reject the OTP.
3. Reject the OTP if the store cannot be reached.
4. Keep the stored value across restarts and failover, and use the
same store in every verifier instance for that prover.
The transmission delay window and the recommended time-step size of
30 seconds are unchanged.
=== END ===
¶
Rationale: [RFC6238] allows a window for transmission delay. With the last accepted time step, an OTP inside that window is accepted at most once, including when two verifier instances receive it at the same moment. A database update such as "UPDATE totp_state SET last_time_step = :time_step WHERE prover_id = :prover_id AND last_time_step < :time_step" is a single operation of the kind that rule 2 describes.¶
Compatibility: a prover built to [RFC6238] works unchanged with a verifier built to this document. Cost: one stored number for each prover, and one store operation for each accepted OTP.¶
An OTP that is produced but not sent leaves the stored time step unchanged (Appendix A, case 8). Only the verifier's acceptance confirms authentication, and beyond that single acceptance nothing about the OTP stays valid.¶
This document updates Section 6 of [RFC6238] as follows.¶
=== ADD AT THE END OF SECTION 6 === Accepting an OTP found by resynchronization also advances the last accepted time step. The drift found by resynchronization does not allow an OTP whose time step is not later than the last accepted time step. === END ===¶
[RFC Editor: please remove this section and the reference to RFC 7942 before publication.]¶
This section reports the status of known implementations of this update at the time of posting of this Internet-Draft, and is based on a proposal described in [RFC7942]. Listing an implementation here does not imply endorsement by the IETF, and other implementations may exist.¶
Test results, using SHA-1 and the secret and time steps of Appendix B of [RFC6238]:¶
This document has no IANA actions.¶
The values are from Appendix B of [RFC6238]: shared secret "12345678901234567890", SHA-1, 8 digits, time step size 30 seconds, start time 0. Unix time 1111111109 is time step 37037036 with OTP 07081804, and Unix time 1111111111 is time step 37037037 with OTP 14050471. The verifier clock reads 1111111111, and the window is the current time step and the one before it. Cases 1 to 3 use one prover, cases 4 to 6 a second, case 7 a third, and case 8 a fourth. "none" means no time step has been accepted yet. A conforming verifier gives these results.¶
Case Before OTP (time step) Decision After 1 none 14050471 (37037037) ACCEPT 37037037 2 37037037 14050471 (37037037) REJECT 37037037 3 37037037 07081804 (37037036) REJECT 37037037 4 none 07081804 (37037036) ACCEPT 37037036 5 37037036 14050471 (37037037) ACCEPT 37037037 6 37037037 07081804 (37037036) REJECT 37037037 7 none 14050471 x32 at once 1 ACCEPT, 31 REJECT 37037037 8 none (none sent) NO CHANGE none Time step size: 30 seconds Verifier clock: Unix time 1111111111 = time step 37037037 Window: time steps 37037036 to 37037037¶
This class implements Section 5.2 and produced the results in Appendix A.¶
<CODE BEGINS> file "TOTPVerifier.java"
/**
* Copyright (c) 2026 IETF Trust and the persons identified as
* authors of the code. All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, is permitted pursuant to, and subject
* to the license terms contained in, the Revised BSD License
* set forth in Section 4.e of the IETF Trust's Legal Provisions
* Relating to IETF Documents
* (https://trustee.ietf.org/license-info).
*/
import java.nio.ByteBuffer;
import java.security.GeneralSecurityException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
/**
* TOTP verifier with the rule of Section 5.2 of this update. The
* store holds the last accepted time step for each prover (-1 if
* none).
*/
public class TOTPVerifier {
private final int digits;
private final String crypto; // HmacSHA1, HmacSHA256, ...
final ConcurrentHashMap<String, AtomicLong> store =
new ConcurrentHashMap<String, AtomicLong>();
public TOTPVerifier(int digits, String crypto) {
this.digits = digits;
this.crypto = crypto;
}
/** The TOTP value for a shared secret and a time step. */
public static String otp(byte[] sharedSecret, long timeStep,
int digits, String crypto) {
try {
Mac hmac = Mac.getInstance(crypto);
hmac.init(new SecretKeySpec(sharedSecret, "RAW"));
byte[] hash = hmac.doFinal(
ByteBuffer.allocate(8).putLong(timeStep).array());
long binary = ByteBuffer.wrap(
hash, hash[hash.length - 1] & 0xf, 4).getInt()
& 0x7fffffffL;
return String.format("%0" + digits + "d",
binary % (long) Math.pow(10, digits));
} catch (GeneralSecurityException e) {
throw new IllegalStateException(e);
}
}
/**
* Returns true (accept) or false (reject). firstTimeStep to
* lastTimeStep is the transmission delay window.
*/
public boolean validate(String prover, byte[] sharedSecret,
String otp, long firstTimeStep, long lastTimeStep) {
AtomicLong last = store.computeIfAbsent(prover,
x -> new AtomicLong(-1L));
for (long step = Math.max(firstTimeStep, last.get() + 1);
step <= lastTimeStep; step++) {
if (otp(sharedSecret, step, digits, crypto)
.equals(otp)) {
// Check and store in one atomic step.
long prev = last.get();
while (prev < step) {
if (last.compareAndSet(prev, step)) {
return true;
}
prev = last.get();
}
return false;
}
}
return false;
}
}
<CODE ENDS>¶
The author thanks the authors of RFC 6238 and RFC 4226, who did not write, check, or endorse this document.¶