Cryptography guides

Check a TOTP generator against a published time vector

·

A time-based one-time password is determined by the shared secret, HMAC algorithm, digit count and time step. Check those inputs against a published example before comparing two implementations.

TOTP Generator

Reproduce the SHA-1 code at Unix second 59

Choose SHA-1 and Load RFC example. The Base32 key represents the public, 20-byte ASCII value 12345678901234567890. The example sets eight digits, a 30-second period and reference Unix second 59.

Generate code. The counter is 1 and the window runs from 30 to 59. The eight-digit code is 94287082. Change the reference to 60 and generate again. Counter 2 starts a new window.

Public SHA-1 vector at reference Unix second 59
GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ

RFC 6238, TOTP reference implementation and test vectors

Load the matching published key when you change hash

Choose SHA-256, then Load RFC example again. At second 59 the code is 46119246. Repeat with SHA-512 and expect 90693936. The RFC reference implementation uses separate 32-byte and 64-byte keys for these examples.

The moving counter is the Unix time divided by the period and rounded down. The implementation HMACs its eight-byte big-endian representation and uses HOTP dynamic truncation before formatting the requested number of digits.

RFC 6238, TOTP reference implementation and test vectorsRFC 4226, HOTP algorithm and dynamic truncation

Compare a live clock with a frozen reference

Choose Current device clock and generate with known settings. The workspace replaces the code at the next window boundary and counts the remaining whole seconds. Use Reference Unix timestamp to keep the test on a fixed second.

For your own verifier, both sides need the same secret, algorithm, digit count, period and time step. Preserve leading zeroes when comparing codes. The published example secrets are for interoperability testing.

RFC 6238, TOTP reference implementation and test vectorsRFC 4648, Base32 encoding

Common questions

Can I use a formatted Base32 key?

ASCII spaces, tabs and line breaks are allowed between symbols, and lowercase is accepted. RFC 4648 padding is optional and checked when present.

Does copying a code copy the secret?

Copy code writes only the generated digits to the clipboard. Reset clears the active workspace and stops the live timer.

Sources

Put it into practice.

Related guides