-
Notifications
You must be signed in to change notification settings - Fork 2
/
OTP.h
44 lines (26 loc) · 1.35 KB
/
OTP.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
Copyright (c) 2015 Colum Paget <[email protected]>
* SPDX-License-Identifier: GPL-3.0
*/
#ifndef LIBUSEFUL_OTP_H
#define LIBUSEFUL_OTP_H
/* Generate a Time based One Time Password.
For compatiblity with Google authenticator you should use:
HashType=sha1
Digits=6
Interval=30
SecretEncoding=ENCODE_BASE32
This function does not parse totp urls, you will have to extract the secret from those yourself.
*/
//Calculate TOTP at a given time, returns number of seconds the code is valid from that time
int TOTPAtTime(char **RetStr, const char *HashType, const char *EncodedSecret, int SecretEncoding, time_t When, int Digits, int Interval);
//Calculate TOTP at the current moment
char *TOTP(char *RetStr, const char *HashType, const char *EncodedSecret, int SecretEncoding, int Digits, int Interval);
//Calculate TOTP at Current time, at CurrTime - (Interval / 2 +5) and at CurrTime + (Interval / 2 +5)
//returns number of seconds the 'Curr' code is valid from CurrTime
int TOTPPrevCurrNext(char **Prev, char **Curr, char **Next, const char *HashType, const char *EncodedSecret, int SecretEncoding, int Digits, int Interval);
//Calculate GoogleAutenticator code for the current moment
char *GoogleTOTP(char *RetStr, const char *EncodedSecret);
//Google authenticator compatible TOTP
char *GoogleTOTP(char *RetStr, const char *EncodedSecret);
#endif