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. typically30. classic. β°time_t start_offsetβ the Unix time of when to start counting time steps. typically0.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 beNULL. yes,NULLis allowed, she's flexible.oath_validate_strcmp_function strcmp_otpβ a function pointer to astrcmp-like function. we love a pluggable vibe.void * strcmp_handleβ caller handle that gets passed on through tostrcmp_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 normalstrcmp. maybe you only have a hashed OTP, for example. in that case you'd typically pass the hashed OTP in thestrcmp_handle, let your implementation ofstrcmp_otphash thetest_otpOTP 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>.
- liboath home page: https://oath-toolkit.codeberg.page/
- general help using GNU software: http://www.gnu.org/gethelp/
π COPYRIGHT π
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
- arch rolling: oath-toolkit 2.6.15-1 Β· GPL-3.0-or-later
- nixpkgs unstable: oath-toolkit 2.6.15
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms