oath_totp_validate4(3)

๐Ÿ’… oath_totp_validate4(3) โ€” the liboath glow-up ๐ŸŽ€

okay so bestie, welcome to oath_totp_validate4 ๐Ÿ’– this one lives in liboath (that's the manual we're in, iykyk) and it's the function that checks whether somebody's TOTP code is actually valid. no cap, it's giving "bouncer at the club checking IDs" energy. let's get into it โœจ


๐ŸŒธ SYNOPSIS ๐ŸŒธ

#include <oath.h>

int oath_totp_validate4(const char * secret, size_t secret_length,
time_t now, unsigned time_step_size, time_t start_offset, size_t window,
int * otp_pos, uint64_t * otp_counter, int flags, const char * otp);

literally that whole signature. yes it's a lot of arguments. she's high-maintenance and we love her for it ๐Ÿ’…


๐Ÿฆ‹ ARGUMENTS ๐Ÿฆ‹

okay so here's the roster, everyone gets their moment:

  • const char * secret โ€” the shared secret string. the sacred text. the little password-in-a-string that both sides know ๐Ÿคซ
  • size_t secret_length โ€” length of secret. yeah, she needs to be told explicitly, no guessing โœจ
  • time_t now โ€” Unix time value to validate TOTP for. like, what time even is it โฐ
  • unsigned time_step_size โ€” time step system parameter (typically 30). so like, how many seconds per step, and 30 is the vibe ๐ŸŒˆ
  • time_t start_offset โ€” Unix time of when to start counting time steps (typically 0). where the clock-steps begin counting from ๐Ÿ•ฐ๏ธ
  • size_t window โ€” how many OTPs after/before start OTP to test. the search radius, bestie ๐Ÿ”
  • int * otp_pos โ€” output search position in search window (may be NULL). where in the window it hit ๐ŸŽฏ
  • uint64_t * otp_counter โ€” counter value used to calculate OTP value (may be NULL). the counter that did the math ๐Ÿงฎ
  • int flags โ€” flags indicating mode, one of oath_totp_flags. the settings dropdown ๐ŸŽ›๏ธ
  • const char * otp โ€” the OTP to validate. the code being judged ๐Ÿ‘‘

โœจ DESCRIPTION โœจ

So what does she do? She validates an OTP according to the OATH TOTP algorithm per RFC 6238 ๐Ÿ’– iconic spec, no notes.

Currently only OTP lengths of 6, 7 or 8 digits are supported. and like, that's a restriction โ€” she's saying "this may be lifted in future versions", although some limitations are inherent in the protocol. so don't come for her, it's a protocol thing ๐Ÿ˜ญ

The flags parameter may be used to change the MAC function, for example OATH_TOTP_HMAC_SHA256 or OATH_TOTP_HMAC_SHA512. so you can swap the whole MAC vibe, slay ๐Ÿ”ฅ


๐Ÿ‘‘ RETURNS ๐Ÿ‘‘

Returns absolute value of position in OTP window (zero is first position) โ€” or OATH_INVALID_OTP if no OTP was found in the OTP window โ€” or an error code. so: a position, a rejection, or a problem. three moods ๐Ÿ’€


โญ SINCE โญ

2.6.0 โ€” she's been here a minute, respect the veteran ๐Ÿซถ


๐Ÿ› REPORTING BUGS ๐Ÿ›

Found a bug? Report bugs to <oath-toolkit-help@nongnu.org> ๐Ÿ’Œ. liboath home page: https://oath-toolkit.codeberg.page/ and general help using GNU software: http://www.gnu.org/gethelp/. go off, they wanna hear it โœจ


Copyright ยฉ 2009-2026 Simon Josefsson.

Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. fr fr, that's the license, be cool about it ๐Ÿ’œ


k bye bestie, go validate some OTPs and stan RFC 6238 for me ๐ŸŒธ๐Ÿฆ‹๐ŸŽ€ โ€” this has been liboath 2.6.15, signing off, oath_totp_validate4(3) style ๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from