Skip to content

Commit 11f58ba

Browse files
committed
docs(readme): clarify HOTP/TOTP parameters
1 parent e11be12 commit 11f58ba

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

README-RU.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ auto key = hmac::pbkdf2_hmac_sha256(password, salt, iters, 32);
195195
### 🕓 HOTP и TOTP токены
196196

197197
Библиотека поддерживает генерацию одноразовых паролей по RFC 4226 и RFC 6238.
198+
Секрет передаётся в виде сырых байт. Если он задан в Base32 (часто в OTP URI),
199+
сначала декодируйте его.
200+
201+
- **HOTP** — 6 цифр, SHA-1.
202+
- **TOTP** — период 30 с, 6 цифр, SHA-1. `is_totp_token_valid` допускает окно ±1 интервал.
198203

199204
#### HOTP (HMAC-based One-Time Password)
200205

@@ -205,6 +210,7 @@ std::string key = "12345678901234567890"; // raw key
205210
uint64_t counter = 0;
206211
int otp = get_hotp_code(key, counter); // по умолчанию: 6 цифр, SHA1
207212
std::cout << "HOTP: " << otp << std::endl;
213+
bool ok = (otp == 755224); // тестовый вектор RFC 4226
208214
```
209215

210216
#### TOTP (Time-based One-Time Password)
@@ -224,6 +230,14 @@ uint64_t time_at = 1700000000;
224230
int otp = get_totp_code_at(key, time_at);
225231
```
226232

233+
Для проверки кода:
234+
235+
```cpp
236+
bool valid = hmac::is_totp_token_valid(94287082, key, 59, 30, 8, hmac::TypeHash::SHA1); // тестовый вектор RFC 6238
237+
```
238+
239+
Известные тестовые векторы: [RFC 4226, приложение D](https://www.rfc-editor.org/rfc/rfc4226#appendix-D) и [RFC 6238, приложение B](https://www.rfc-editor.org/rfc/rfc6238#appendix-B).
240+
227241
### 🕓 Временные токены на основе HMAC (Custom HMAC Time Tokens)
228242

229243
Библиотека также включает **облегчённую реализацию временных HMAC-токенов**, не связанную напрямую с RFC 4226/6238 (HOTP/TOTP). Эти токены:

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ auto okm = hmac::hkdf_expand_sha256(prk, {}, 32); // derive 32 bytes
236236
### 🕓 HOTP and TOTP Tokens
237237
238238
The library supports generating one-time passwords based on RFC 4226 and RFC 6238.
239+
Secrets are supplied as raw bytes. If you receive a Base32 string (common in OTP
240+
URIs), decode it before calling the functions.
241+
242+
- **HOTP** — 6 digits, SHA-1.
243+
- **TOTP** — 30 s period, 6 digits, SHA-1. `is_totp_token_valid` accepts tokens
244+
from the previous and next interval (±1).
239245
240246
#### HOTP (HMAC-based One-Time Password)
241247
@@ -246,6 +252,7 @@ std::string key = "12345678901234567890"; // raw key
246252
uint64_t counter = 0;
247253
int otp = get_hotp_code(key, counter); // defaults: 6 digits, SHA1
248254
std::cout << "HOTP: " << otp << std::endl;
255+
bool ok = (otp == 755224); // RFC 4226 test vector
249256
```
250257

251258
#### TOTP (Time-based One-Time Password)
@@ -265,6 +272,14 @@ uint64_t time_at = 1700000000;
265272
int otp = get_totp_code_at(key, time_at);
266273
```
267274

275+
To verify a received code:
276+
277+
```cpp
278+
bool valid = hmac::is_totp_token_valid(94287082, key, 59, 30, 8, hmac::TypeHash::SHA1); // RFC 6238 test vector
279+
```
280+
281+
Known test vectors: [RFC 4226 Appendix D](https://www.rfc-editor.org/rfc/rfc4226#appendix-D) and [RFC 6238 Appendix B](https://www.rfc-editor.org/rfc/rfc6238#appendix-B).
282+
268283
### 🕓 Time-Based HMAC Tokens (Custom HMAC Time Tokens)
269284

270285
The library also includes a **lightweight implementation of time-based HMAC tokens**, which are not directly based on RFC 4226/6238 (HOTP/TOTP). These tokens:

0 commit comments

Comments
 (0)