---
name: "oath_totp_generate"
section: "3"
platform: "linux"
package: "oath-toolkit"
version: "2.6.15-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/oath_totp_generate"
---

# oath\_totp\_generate(3)

API function

## NAME

oath\_totp\_generate - API function

## SYNOPSIS

**#include \<oath.h\>**

**int oath\_totp\_generate(const char \*** *secret***, size\_t** *secret\_length***, time\_t** *now***, unsigned** *time\_step\_size***, time\_t** *start\_offset***, unsigned** *digits***, char \*** *output\_otp***);**

## ARGUMENTS

- const char \* secret

  the shared secret string

- size\_t secret\_length

  length of *secret*

- time\_t now

  Unix time value to compute TOTP for

- unsigned time\_step\_size

  time step system parameter (typically 30)

- time\_t start\_offset

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

- unsigned digits

  number of requested digits in the OTP, excluding checksum

- char \* output\_otp

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

## 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.

## RETURNS

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

## SINCE

1\.4.0

## 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.
