oath_totp_validate2_callback(3)

πŸ’… oath_totp_validate2_callback(3) β€” the liboath glow-up

okay so bestie, welcome to the manual page for oath_totp_validate2_callback(3). it lives in liboath, it's the fancy callback-flavored version of TOTP validation, and honestly? it's giving main character energy for anyone who can't just strcmp two strings like a normie. let's get into it ✨


🌸 NAME 🌸

oath_totp_validate2_callback β€” an API function. that's it, that's the name, she's an API function and she's iconic πŸ’–


πŸŽ€ SYNOPSIS πŸŽ€

#include <oath.h>

int oath_totp_validate2_callback(const char * secret, size_t
secret_length, time_t now, unsigned time_step_size, time_t start_offset,
unsigned digits, size_t window, int * otp_pos,
oath_validate_strcmp_function strcmp_otp, void * strcmp_handle);

like, look at all those parameters. she has range. πŸ¦‹


✨ ARGUMENTS ✨

okay so here's the whole cast, in order, no skips, no cuts 🫢

  • const char * secret β€” the shared secret string. the actual tea. πŸ“
  • size_t secret_length β€” how long that secret is, in all its glory.
  • time_t now β€” the Unix time value we're computing TOTP for. basically "what time do we think it is".
  • unsigned time_step_size β€” the time step system parameter. typically 30. classic. ⏰
  • time_t start_offset β€” the Unix time of when to start counting time steps. typically 0.
  • unsigned digits β€” how many digits you want in the OTP. (more on the valid numbers below, bestie πŸ‘€)
  • size_t window β€” how many OTPs after the start counter to test. your search zone πŸ’…
  • int * otp_pos β€” output search position in the search window. may be NULL. yes, NULL is allowed, she's flexible.
  • oath_validate_strcmp_function strcmp_otp β€” a function pointer to a strcmp-like function. we love a pluggable vibe.
  • void * strcmp_handle β€” caller handle that gets passed on through to strcmp_otp. it's the little bag you hand over. πŸŽ€

πŸ’œ DESCRIPTION πŸ’œ

so what does she do? she validates an OTP according to the OATH TOTP algorithm, per RFC 6238. periodt. πŸ”₯

the way validation works: she generates a whole bunch of potential OTPs and then calls your strcmp_otp function to compare each potential OTP against the given otp. it's like a lineup but for codes. πŸ•΅οΈβ€β™€οΈ

that callback has the following prototype:

int (*oath_validate_strcmp_function) (void *handle, const char
*test_otp);

here's the vibe check on the return value: your function should be similar to strcmp in that it returns 0 only on matches. but it differs β€” and this is the important part, ngl β€” by permitting use of negative return codes as an indication of internal failures in the callback. positive values mean the OTP didn't match. so like: 0 = slay, negative = something broke on your end 😭, positive = nope, not it πŸ’€

lowkey the whole reason this callback interface exists: you might not be able to compare OTPs directly using normal strcmp. maybe you only have a hashed OTP, for example. in that case you'd typically pass the hashed OTP in the strcmp_handle, let your implementation of strcmp_otp hash the test_otp OTP using that same hash, and then compare the results. matching hashes, matching vibes. ✨

also, real talk: currently only OTP lengths of 6, 7 or 8 digits are supported. those restrictions may be lifted in future versions, although β€” and this is the caveat, bestie β€” some limitations are inherent in the protocol. so don't come for her, it's the protocol's fault πŸ™ˆ


πŸ‘‘ RETURNS πŸ‘‘

she returns the absolute value of the position in the OTP window (zero is the first position), or OATH_INVALID_OTP if no OTP was found in the OTP window, or an error code. that's the whole menu. πŸ“


⭐ SINCE ⭐

1.10.0 β€” she's been around, she's got history, she's a legacy icon. πŸ’…


πŸ¦‹ REPORTING BUGS πŸ¦‹

found something cursed? report bugs to <oath-toolkit-help@nongnu.org>.


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. so like, go off, just keep the receipts 🧚


okay that's the whole page, no notes, you ate that πŸ’– this was the oath_totp_validate2_callback(3) page from liboath, version 2.6.15 β€” mwah, go validate some OTPs bestie, ily πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from