Encode the counter before HMAC
02HOTP uses HMAC-SHA-1 over an eight-byte counter. Hexadecimal text is a readable notation for those bytes.
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 ↗
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.
Terms in this drawing
Related RFCs and changes
“Updates” changes part of an earlier RFC. “Obsoletes” replaces it. This list shows selected related documents.
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.
Offline public test values and selected rules; not a login service, secure token implementation or deployment recommendation.
Read the RFC section ↗