opyeb totplab

Validating an implementation with the RFC 6238 and 4226 test vectors

The fastest way to know an implementation is right is to reproduce the values the standard published. RFC 6238 and RFC 4226 put them in a table.

2026-11-29 · about 7 min

Why test vectors matter

TOTP implementations fail quietly. Decode the secret wrongly, reverse the counter bytes, or shift the truncation offset by one, and you still get plausible six-digit numbers that never match.

Reproducing published input/output pairs catches all of those at once. Section 05 of this page runs that comparison for you.

The premises of RFC 6238

RFC 6238 publishes its table with T0 = 0, a time step X of 30 seconds and 8-digit codes. Times are Unix seconds since 1970-01-01 00:00:00 UTC.

The table uses 59, 1111111109, 1111111111, 1234567890, 2000000000 and 20000000000 seconds. The last one is in the year 2603 and exists to exercise a 64-bit counter.

The three seeds

RFC 6238 uses a different seed per algorithm: SHA-1 takes '12345678901234567890' (20 bytes), SHA-256 the same string stretched to 32 bytes, SHA-512 to 64 bytes.

In Base32 those are GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ, GEZ…GEZA and GEZ…GNA. The vector table on this page uses exactly those seeds.

How to read the table

Each row is 'time → expected code'. At 59 seconds the SHA-1 value is 94287082, SHA-256 gives 46119246 and SHA-512 gives 90693936.

Three algorithms differ at the same moment because both the seed and the hash differ. If any one of them mismatches, that combination is wrong.

Boundary times

59 seconds falls in the second step, not the first, because 59 ÷ 30 has a quotient of 1. Getting this value right proves the step calculation.

1111111109 and 1111111111 are two seconds apart but land in different steps (37,037,036 and 37,037,037). Matching both proves the boundary handling.

Notes for SHA-256 and SHA-512

Many implementations feed the 20-byte SHA-1 seed straight into SHA-256, which will not match the RFC. The seed must be extended to 32 bytes and 64 bytes respectively.

In real services the secret length is decided by the server, so never change the length yourself — use the secret exactly as issued.

The RFC 4226 HOTP vectors

RFC 4226 publishes 6-digit values for the seed '12345678901234567890' at counters 0 through 9: 755224, 287082, 359152, 969429, 338314, 254676, 287922, 162583, 399871, 520489.

These validate the core arithmetic under TOTP. If they fail, TOTP will fail as well.

Recomputing them here

Press 'Run all 28' in section 05. The page computes 18 TOTP and 10 HOTP values, compares them with the published ones and reports how many match.

You can repeat the check in Python: pack the counter as 8 bytes with struct and use hmac and hashlib. When two independent implementations agree, the arithmetic can be trusted.

Questions in this article

One vector fails — what is wrong?

A wrong secret decode, counter byte order, hash algorithm, truncation offset or digit count. Start from the HOTP vectors with the same seed to narrow it down.

Why is 20000000000 seconds included?

It does not fit in a 32-bit integer. It is a boundary value that proves the counter is handled as 64 bits.

Can a 6-digit service be checked with 8-digit vectors?

Not by direct comparison. Do not take the last six digits of an 8-digit value; recompute the same step with 6 digits. Set the digit count to 6 here and fix the time.

An example secret is already loaded. Replace it with yours and the code changes on the spot.

Open the workbench
← All guides