oath\_totp\_generate2(3) liboath oath\_totp\_generate2(3)

# [NAME](#NAME)

oath\_totp\_generate2 - API function

# [SYNOPSIS](#SYNOPSIS)

**#include &lt;oath.h&gt;**

**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);**

# [ARGUMENTS](#ARGUMENTS)

[const char * secret](#const)

the shared secret string

[size\_t secret\_length](#size_t)

length of *secret*

[time\_t now](#time_t)

Unix time value to compute TOTP for

[unsigned time\_step\_size](#unsigned)

time step system parameter (typically 30)

[time\_t start\_offset](#time_t~2)

Unix time of when to start counting time steps (typically 0)

[unsigned digits](#unsigned~2)

number of requested digits in the OTP, excluding checksum

[int flags](#int)

flags indicating mode, one of **oath\_totp\_flags**

[char * output\_otp](#char)

output buffer, must have room for the output OTP plus zero

# [DESCRIPTION](#DESCRIPTION)

Generate a one-time-password using the time-variant TOTP algorithm described in RFC 6238. The input parameters are taken as time values.

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.

The system parameter *start\_offset* denote the Unix time when time steps are started to be counted. The recommended value is 0, to fall back on the Unix epoch) 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.

Currently only values 6, 7 and 8 for *digits* are supported. This restriction may be lifted in future versions.

The *flags* parameter may be used to change the MAC function, for example **OATH\_TOTP\_HMAC\_SHA256** or **OATH\_TOTP\_HMAC\_SHA512**.

# [RETURNS](#RETURNS)

On success, **OATH\_OK** (zero) is returned, otherwise an error code is returned.

# [SINCE](#SINCE)

2.6.0

# [REPORTING BUGS](#REPORTING_BUGS)

Report bugs to &lt;oath-toolkit-help@nongnu.org&gt;. liboath home page: https://www.nongnu.org/oath-toolkit/ General help using GNU software: http://www.gnu.org/gethelp/

# [COPYRIGHT](#COPYRIGHT)

Copyright © 2009-2020 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.

2.6.12-dirty liboath

---

Document: oath_totp_generate2(3) from oath-toolkit 2.6.12-r12 (Chainguard OS)
Source: https://gitlab.com/oath-toolkit/oath-toolkit.git
