oath_hotp_generate(3)

✨ oath_hotp_generate β€” like, the HOTP generator ✨

okay bestie, so this one lives in the liboath manual, section 3 (the library functions girlies), and it's genuinely iconic β€” it's the function that makes one-time passwords out of thin air. let's get into it πŸ’…


🌸 SYNOPSIS 🌸

#include <oath.h>

int oath_hotp_generate(const char * secret, size_t secret_length,
uint64_t moving_factor, unsigned digits, bool add_checksum, size_t
truncation_offset, char * output_otp);

like yes she's got a lot of arguments but she's worth it, trust 🫢


πŸŽ€ ARGUMENTS πŸŽ€

  • const char * secret β€” the shared secret string, the lil bestie everything's built on πŸ”
  • size_t secret_length β€” how long that secret is, obviously
  • uint64_t moving_factor β€” a counter showing which OTP you're on rn (this is the whole "moving" part of moving factor, iykyk)
  • unsigned digits β€” how many digits you want in your OTP, and this does not count the checksum
  • bool add_checksum β€” do you want a checksum digit tacked on or not
  • size_t truncation_offset β€” use a specific truncation offset, fancy
  • char * output_otp β€” the output buffer πŸ’– and it must have room for the output OTP plus zero

🌈 DESCRIPTION 🌈

so the whole vibe: she generates a one-time-password using the HOTP algorithm, exactly like RFC 4226 describes. no cap, that's the entire job and she does it flawlessly ✨

now, listen β€” use the value OATH_HOTP_DYNAMIC_TRUNCATION for truncation_offset unless you really need a specific truncation offset. like, genuinely really. main character energy is trusting the dynamic truncation πŸ™ˆ

to find out how big your OTP is gonna be, hit up the OATH_HOTP_LENGTH() macro. and remember: your output_otp buffer has to have room for that length plus one for the terminating NUL. that NUL is not optional, she's the plus-one of this whole operation πŸŽ€

πŸ’€ heads up fr fr: right now only the values 6, 7 and 8 are supported for digits, and the add_checksum value just gets ignored. yes, ignored. she's not even looking at it. these restrictions may get lifted in future versions, although ngl some limitations are baked into the protocol itself and are here to stay.

⭐ RETURNS ⭐

on success you get OATH_OK (which is zero, cute right?) and otherwise you get an error code. no in-between, periodt 🫢


πŸ¦‹ REPORTING BUGS πŸ¦‹

found a bug? spill it 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. slay, genuinely 🌸


okay that's the whole page bestie, you're officially an HOTP expert now 🧚

signing off with love from the liboath manual, version 2.6.15 β€” oath_hotp_generate(3), written and dated with the manual πŸ’œ

πŸ“¦ where this page comes from