Visual RFC.
ALL RFCs / RFC 4226
Read the RFC ↗
RFC 4226 / Counter-based one-time passwords

Encode the counter before HMAC

02

HOTP uses HMAC-SHA-1 over an eight-byte counter. Hexadecimal text is a readable notation for those bytes.

RFC 4226 · § 5.2EXAMPLE
4 / 4
Encode the counter before HMACCounter2 changes the message and all20displayed output bytes; resulting code359152.Counter bytes enter HMAC-SHA-1C=2 → 20 different HMAC bytes00b1ac2b73fa40852f6ef73087892210111193128b13c114c515e71604171618ff1944Dynamic truncation followsResulting HOTP: 359152Same key; changed counter messagePublished vectors · secret generation and storage outside model
04
Change only the counter

Counter2 uses the same test key but a new eight-byte message. The output grid and final code both change.

Source for this drawing: RFC 4226 · Read RFC section 5.2 ↗

Protocol participantThreat or exceptionProtocol controlSimplified drawings · precise section references
New to this? Start hereA quick picture + helpful background

A seal answers a specific question.

A certificate or signature supports particular checks about a key or message. It does not automatically prove that every claim or sender is trustworthy.

Helpful first, if these ideas are unfamiliar

These pictures are analogies to help you learn. The linked RFC explains the actual rules.

Related RFCs and changes

“Updates” changes part of an earlier RFC. “Obsoletes” replaces it. This list shows selected related documents.

KEY POINT

Hash the eight counter bytes; do not hash the decimal characters of the counter.

  • The base HOTP algorithm uses HMAC-SHA-1 with secret K and an increasing counter C. The output HS is 160 bits, or 20 bytes. SHA-1 here is used inside HMAC; this does not endorse SHA-1 signatures, ordinary hash passwords or a current security assessment (§§5.2–5.3).
  • The counter is represented in eight bytes, high-order byte first (big endian). Counter1 becomes00 00 00 00 00 00 00 01. Decimal character "1" would instead be the single ASCII byte 31; that is not this input (§5.2; Appendix C).
  • Appendix D supplies the public20-byte ASCII test key 12345678901234567890. Counter1 yields HMAC75a48a19d4cbe100644e8ac1397eea747a2d33ab. The key bytes are kept in their supplied order, not reversed. Reported/unverified erratum 6702 is not an accepted change to the algorithm.
  • Changing C to 2 changes the last counter byte to02 and yields HMAC0bacb7fa082fef30782211938bc1c5e70416ff44, then code 359152. Code generation is deterministic for the same K,C; this illustration is not random-number generation.
  • Shared keys MUST be strong and at least 128 bits;160 bits is RECOMMENDED (§4 R6). Each generator has a different unique K (§5.1). These published test vectors demonstrate arithmetic, not secure provisioning or storage.
DETAILS

Offline public test values and selected rules; not a login service, secure token implementation or deployment recommendation.

Read the RFC section ↗

All chapters in RFC 4226

Drawing view

Scroll the drawing to see every part. Playback controls stay above it.

RFC 9700 / CHAPTERS

Chapters

For full details, tables, algorithms, and exceptions, read the original RFC.

RFC status and corrections ↗