oath_totp_validate3_callback(3)
β¨ oath_totp_validate3_callback(3) β¨
okay so bestie, welcome to the oath_totp_validate3_callback page π
this lil icon lives in the liboath manual, section 3, and she's here to let you validate a TOTP without ever comparing the OTPs directly. yes, that's the whole vibe. let's get into it π«Ά
πΈ NAME πΈ
oath_totp_validate3_callback β the API function π (yes literally that's her whole job description, she's booked and busy)
π SYNOPSIS π
#include <oath.h>
int oath_totp_validate3_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, uint64_t * otp_counter,
oath_validate_strcmp_function strcmp_otp, void * strcmp_handle);
not me counting the arguments... there's eleven of them bestie, ELEVEN, she is not subtle π
π¦ ARGUMENTS π¦
const char * secretβ the shared secret string, the whole reason we're here β¨size_t secret_lengthβ how long that secret is, in case she's shy about her length πtime_t nowβ the Unix time value you wanna compute the TOTP for π°οΈunsigned time_step_sizeβ the time step system parameter (typically30, like, the standard one bestie)time_t start_offsetβ Unix time of when to start counting time steps (typically0, so like, the beginning of time fr)unsigned digitsβ how many digits you want in the OTP π’size_t windowβ how many OTPs after the start counter to test β that's your search window πint * otp_posβ output search position in the search window (may beNULL). lowkey optional, highkey useful πuint64_t * otp_counterβ the counter value used to calculate the OTP value (may beNULLtoo, no pressure)oath_validate_strcmp_function strcmp_otpβ a function pointer to astrcmp-like function π§void * strcmp_handleβ the caller handle that gets passed on tostrcmp_otp, hand it over bestie π«±
π DESCRIPTION π
So what she actually does: she validates an OTP according to the OATH TOTP algorithm per RFC 6238 πβ¨ periodt, that's the spec.
Validation is implemented by generating a number of potential OTPs and performing a call to the strcmp_otp function, to compare the potential OTP against the given otp. It has the following prototype:
int (*oath_validate_strcmp_function) (void *handle, const char *test_otp);
The way that function should behave: it should be similar to strcmp in that it returns 0 only on matches π―. But she differs β she also permits use of negative return codes as an indication of internal failures in the callback π. And positive values indicate OTP mismatch. so like:
0β slay, it matched π- negative β something broke inside the callback, that's a her-problem not a you-problem π
- positive β nope, mismatch π
This callback interface is useful when you cannot compare OTPs directly using normal strcmp, but instead for example only have a hashed OTP π. You would then typically pass in the hashed OTP in the strcmp_handle and let your implementation of strcmp_otp hash the test_otp OTP using the same hash, and then compare the results. it's giving "compare the hashes, not the secrets" energy and honestly? iconic.
Currently only OTP lengths of6,7or8digits are supported. This restrictions may be lifted in future versions, although some limitations are inherent in the protocol. so no, you cannot do 4 digits, do not come for her π
β RETURNS β
Returns the 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 π«Ά
π SINCE π
2.4.0 β she's been here a minute, respect the resume π
π REPORTING BUGS π
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. no cap, that's the actual license text, keep it intact bestie π
so yeah, that's her π eleven arguments, one callback, zero direct OTP comparisons β main character energy fr fr. go validate some TOTPs, iykyk π¦β¨
β with love from liboath, version 2.6.15 πΈ (that's the source and version, noted with a cute lil sign-off instead of a boring footer line, you're welcome π
)
π¦ 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