oath_totp_generate2(3)
π oath_totp_generate2(3) β a liboath moment
okay so bestie, picture this: you're deep in liboath land and you need a TOTP. this is the function. it's the glow-up version β the 2 at the end is doing main character energy, and it takes actual time values as input instead of being weird about it. we're so back. π
β¨ SYNOPSIS β¨
#include <oath.h>
int oath_totp_generate2(const char * secret, size_t secret_length,
time_t now, unsigned time_step_size, time_t start_offset, unsigned
digits, int flags, char * output_otp);
that's a lot of arguments, i know, but literally every single one of them is doing something. stay with me. π«Ά
πΈ ARGUMENTS πΈ
const char * secretβ the shared secret string. the sacred text. the little guy.size_t secret_lengthβ how longsecretis. yes, you have to tell it. no, it won't guess.time_t nowβ the Unix time value to compute the TOTP for, like, right now-ish.unsigned time_step_sizeβ the time step system parameter, typically30. this is the vibe check window.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, excluding the checksum. so like, the actual usable length.int flagsβ flags indicating mode, one ofoath_totp_flags. this is how you pick your MAC function, iykyk.char * output_otpβ the output buffer. it must have room for the output OTP plus zero. do not forget the zero. i'm serious. π
π DESCRIPTION π
Generate a one-time-password using the time-variant TOTP algorithm described in RFC 6238. the input parameters are taken as time values β that's the whole point of the 2, she's upgraded.
The system parameter time_step_size describes how long the time window for each OTP is. the recommended value is 30 seconds, and you can use the value 0 or the symbol OATH_TOTP_DEFAULT_TIME_STEP_SIZE to indicate this. so you can just be lazy about it and the library will handle it for you. slay. β¨
The system parameter start_offset denotes the Unix time when time steps are started to be counted. the recommended value is 0, to fall back on the Unix epoch (yes, that's a real parenthesis in the original and yes it's iconic), and you can use the symbol OATH_TOTP_DEFAULT_START_TIME to indicate this.
The output_otp buffer must have room for at least digits characters, plus one for the terminating NUL. ok but fr fr, if you get this wrong it's giving undefined behaviour and nobody wants that. β οΈ
Currently only values 6, 7 and 8 for digits are supported. this restriction may be lifted in future versions, so like, manifesting. π
The flags parameter may be used to change the MAC function β for example OATH_TOTP_HMAC_SHA256 or OATH_TOTP_HMAC_SHA512. pick your fighter. π
π₯ RETURNS π₯
On success, OATH_OK (zero) is returned. otherwise an error code is returned. so basically zero is the good ending. any other number means something went sideways and you should go read the error code like it's a text from your ex you're trying to decode. π
π SINCE π
2.6.0 β she's been around. an elder. a legend. a queen. π
π¦ 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/
if something's broken, tell the humans. they're nice. they'll fix it. π«Ά
π 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.
(that's the legal bit and we love a permissive license. periodt. π)
okay that's the whole page bestie, go forth and generate some one-time passwords responsibly. this was brought to you by liboath 2.6.15 β thanks for coming to my ted talk, mwah π π
π¦ 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