Skip to content

deanlin0/totp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

TOTP Implementation

A practice of simple implementation of TOTP.

Description

TOTP is an algorithm to generate one-time password based on HOTP.

HOTP is an algorithm based on HMAC. It generates a password with a key and moving factor.
In TOTP, the moving factor is defined as the current time steps.

The following is a brief description of the algorithm from RFC6238 and RFC4226:

TOTP = HOTP(K, T)
HOTP(K, C) = Truncate(HMAC-SHA-1(K, C))
// Please refer to RFC4226 for the definition of Truncate.

K = secret key
C = moving factor
T = (Current Unix time - T0) / X
T0 = the Unix time to start counting time steps (default: 0)
X = time step in seconds (default: 30)

Usage

To run the program:

go run .

and the output:

2022/11/15 18:36:34 Start generating TOTP.
2022/11/15 18:36:39 Your OTP: 751798
2022/11/15 18:36:44 Your OTP: 751798
2022/11/15 18:36:49 Your OTP: 751798
2022/11/15 18:36:54 Your OTP: 751798
2022/11/15 18:36:59 Your OTP: 751798
2022/11/15 18:37:04 Your OTP: 949926
^C2022/11/15 18:37:05 Interrupt received.

To change key, digits, and step size, go to main.go:

totp.GenerateTOTP(key, hash, digits, step)

About

TOTP implementation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages