oath_totp_validate_callback(3)
π oath_totp_validate_callback(3) β the liboath era
okay so bestie, you found the page for oath_totp_validate_callback, and honestly? it's giving "the smartest function in the group chat." it lives in liboath, and it's the one you call when you need to check whether somebody's TOTP code is actually correct. let's get into it β¨
πΈ NAME πΈ
oath_totp_validate_callback β an API function. that's it, that's the name. it validates TOTP OTPs, but with a callback twist. π
β¨ SYNOPSIS β¨
#include <oath.h>
int oath_totp_validate_callback(const char * secret, size_t
secret_length, time_t now, unsigned time_step_size, time_t start_offset,
unsigned digits, size_t window, oath_validate_strcmp_function
strcmp_otp, void * strcmp_handle);
like, look at all those parameters. she's thorough. π
π¦ ARGUMENTS π¦
every single one, bestie, no skipping:
const char * secretβ the shared secret string. the actual secret-secret. π€«size_t secret_lengthβ how long thatsecretis, obviously.time_t nowβ the Unix time value to compute the TOTP for.unsigned time_step_sizeβ the time step system parameter. typically30. that's the classic. β°time_t start_offsetβ the Unix time of when to start counting time steps. typically0.unsigned digitsβ the number of requested digits in the OTP.size_t windowβ how many OTPs after the start counter to test. so like, how far forward we're willing to look. πoath_validate_strcmp_function strcmp_otpβ a function pointer to a strcmp-like function. yes, a callback. we love a callback. π«Άvoid * strcmp_handleβ the caller handle that gets passed on tostrcmp_otp. hand it over, girl.
π DESCRIPTION π
so what does she actually do? she validates an OTP according to the OATH TOTP algorithm, per RFC 6238. periodt.
here's the vibe: validation happens by generating a bunch of potential OTPs and then calling your strcmp_otp function to compare each potential OTP against the given otp. so it's like a little lineup of candidates and your callback does the judging. π
the callback has this prototype, exactly:
int (*oath_validate_strcmp_function) (void *handle, const char
*test_otp);
your function should be similar to strcmp in that it returns 0 only on a match. but here's where she's different, and this is important, ngl: negative return codes are permitted as an indication of internal failures in the callback. positive values indicate OTP mismatch. so like, 0 = slay, negative = something broke inside you, positive = nope, wrong code. π
this callback interface is genuinely iconic when you cannot compare OTPs directly using a normal strcmp. like, say you only have a hashed OTP. in that case you'd typically pass in the hashed OTP inside strcmp_handle, and let your implementation of strcmp_otp hash the test_otp OTP using the same hash, and then compare the results. hashing both sides, comparing hashes, chef's kiss. π§
β οΈ heads up: currently only OTP lengths of 6, 7 or 8 digits are supported. these restrictions may be lifted in future versions, although some limitations are inherent in the protocol. so don't come for her about 9 digits, it's a protocol thing. π
β RETURNS β
she returns 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 deal. π
π SINCE π
1.6.0. she's been around. a real veteran. π
π REPORTING BUGS π
found a bug? don't suffer in silence, bestie β 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 yes, share it, just keep the receipts. π§Ύ
okay and one last cute little sign-off: this adorable page comes to you from liboath, version 2.6.15 β the oath_totp_validate_callback(3) manual page itself. go forth and validate those OTPs, bestie, you're gonna ate. ππ
β¨
π¦ 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