TFAC
tfac.h
Go to the documentation of this file.
1/*
2 Copyright 2020 Raphael Beck
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
23#ifndef TFAC_H
24#define TFAC_H
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#if defined(_WIN32) && defined(TFAC_DLL)
31#ifdef TFAC_BUILD_DLL
32#define TFAC_API __declspec(dllexport)
33#else
34#define TFAC_API __declspec(dllimport)
35#endif
36#else
37#define TFAC_API
38#endif
39
40#include <time.h>
41#include <stdint.h>
42#include <stddef.h>
43
48#define TFAC_MAX_DIGITS 18
49
53#define TFAC_MAX_SECRET_KEY_SIZE 256
54
58#define TFAC_DEFAULT_HASH_ALGO 0
59
63#define TFAC_DEFAULT_DIGITS 6
64
68#define TFAC_DEFAULT_STEPS 30
69
74{
75 TFAC_SHA1 = 0,
76 TFAC_SHA224 = 1,
77 TFAC_SHA256 = 2,
78};
79
84{
88 char string[32];
89
96 uint64_t number;
97};
98
104{
109 char secret_key_base32[48 + 1];
110
114 uint8_t secret_key[30];
115};
116
121{
125 uint32_t major;
126
130 uint32_t minor;
131
135 uint32_t patch;
136
140 char string[32];
141};
142
147TFAC_API struct tfac_secret tfac_generate_secret();
148
157TFAC_API struct tfac_token tfac_totp(const char* secret_key_base32, uint8_t digits, uint8_t steps, enum tfac_hash_algo hash_algo);
158
170TFAC_API uint64_t tfac_totp_raw(const uint8_t* secret_key, size_t secret_key_length, uint8_t digits, uint8_t steps, enum tfac_hash_algo hash_algo, time_t utc);
171
181TFAC_API uint8_t tfac_verify_totp(const char* secret_key_base32, const char* totp, uint8_t digits, uint8_t steps, enum tfac_hash_algo hash_algo);
182
191TFAC_API struct tfac_token tfac_hotp(const char* secret_key_base32, uint8_t digits, uint64_t counter, enum tfac_hash_algo hash_algo);
192
203TFAC_API uint64_t tfac_hotp_raw(const uint8_t* secret_key, size_t secret_key_length, uint8_t digits, uint64_t counter, enum tfac_hash_algo hash_algo);
204
210
211#ifdef __cplusplus
212} // extern "C"
213#endif
214
215#endif // TFAC_H
Definition: tfac.h:104
char secret_key_base32[48+1]
Definition: tfac.h:109
uint8_t secret_key[30]
Definition: tfac.h:114
Definition: tfac.h:84
uint64_t number
Definition: tfac.h:96
Definition: tfac.h:121
uint32_t minor
Definition: tfac.h:130
uint32_t major
Definition: tfac.h:125
uint32_t patch
Definition: tfac.h:135
tfac_hash_algo
Definition: tfac.h:74
TFAC_API struct tfac_version_number tfac_get_version_number()
Definition: tfac.c:221
TFAC_API uint64_t tfac_hotp_raw(const uint8_t *secret_key, size_t secret_key_length, uint8_t digits, uint64_t counter, enum tfac_hash_algo hash_algo)
Definition: tfac.c:80
TFAC_API uint8_t tfac_verify_totp(const char *secret_key_base32, const char *totp, uint8_t digits, uint8_t steps, enum tfac_hash_algo hash_algo)
Definition: tfac.c:133
TFAC_API uint64_t tfac_totp_raw(const uint8_t *secret_key, size_t secret_key_length, uint8_t digits, uint8_t steps, enum tfac_hash_algo hash_algo, time_t utc)
Definition: tfac.c:114
TFAC_API struct tfac_token tfac_totp(const char *secret_key_base32, uint8_t digits, uint8_t steps, enum tfac_hash_algo hash_algo)
Definition: tfac.c:119
TFAC_API struct tfac_secret tfac_generate_secret()
Definition: tfac.c:210
TFAC_API struct tfac_token tfac_hotp(const char *secret_key_base32, uint8_t digits, uint64_t counter, enum tfac_hash_algo hash_algo)
Definition: tfac.c:100