Botan 2.19.3
Crypto and TLS for C&
Functions
ffi_hotp.cpp File Reference
#include <botan/ffi.h>
#include <botan/internal/ffi_util.h>

Go to the source code of this file.

Functions

int botan_hotp_check (botan_hotp_t hotp, uint64_t *next_hotp_counter, uint32_t hotp_code, uint64_t hotp_counter, size_t resync_range)
 
int botan_hotp_destroy (botan_hotp_t hotp)
 
int botan_hotp_generate (botan_hotp_t hotp, uint32_t *hotp_code, uint64_t hotp_counter)
 
int botan_hotp_init (botan_hotp_t *hotp, const uint8_t key[], size_t key_len, const char *hash_algo, size_t digits)
 

Function Documentation

◆ botan_hotp_check()

int botan_hotp_check ( botan_hotp_t  hotp,
uint64_t *  next_hotp_counter,
uint32_t  hotp_code,
uint64_t  hotp_counter,
size_t  resync_range 
)

Verify a HOTP code

Definition at line 76 of file ffi_hotp.cpp.

81 {
82#if defined(BOTAN_HAS_HOTP)
83 return BOTAN_FFI_RETURNING(Botan::HOTP, hotp, h, {
84
85 auto resp = h.verify_hotp(hotp_code, hotp_counter, resync_range);
86
87 if(next_hotp_counter)
88 *next_hotp_counter = resp.second;
89
90 return (resp.first == true) ? BOTAN_FFI_SUCCESS : BOTAN_FFI_INVALID_VERIFIER;
91 });
92
93#else
94 BOTAN_UNUSED(hotp, next_hotp_counter, hotp_code, hotp_counter, resync_range);
96#endif
97 }
#define BOTAN_UNUSED(...)
Definition assert.h:142
std::pair< bool, uint64_t > verify_hotp(uint32_t otp, uint64_t starting_counter, size_t resync_range=0)
Definition hotp.cpp:52
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:83
@ BOTAN_FFI_INVALID_VERIFIER
Definition ffi.h:64
@ BOTAN_FFI_SUCCESS
Definition ffi.h:63
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition ffi_util.h:101

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_INVALID_VERIFIER, BOTAN_FFI_RETURNING, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan::HOTP::verify_hotp().

◆ botan_hotp_destroy()

int botan_hotp_destroy ( botan_hotp_t  hotp)

Destroy a HOTP instance

Returns
0 if success, error if invalid object handle

Definition at line 48 of file ffi_hotp.cpp.

49 {
50#if defined(BOTAN_HAS_HOTP)
51 return BOTAN_FFI_CHECKED_DELETE(hotp);
52#else
53 BOTAN_UNUSED(hotp);
55#endif
56 }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:129

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_hotp_generate()

int botan_hotp_generate ( botan_hotp_t  hotp,
uint32_t *  hotp_code,
uint64_t  hotp_counter 
)

Generate a HOTP code for the provided counter

Definition at line 58 of file ffi_hotp.cpp.

61 {
62#if defined(BOTAN_HAS_HOTP)
63 if(hotp == nullptr || hotp_code == nullptr)
65
66 return BOTAN_FFI_DO(Botan::HOTP, hotp, h, {
67 *hotp_code = h.generate_hotp(hotp_counter);
68 });
69
70#else
71 BOTAN_UNUSED(hotp, hotp_code, hotp_counter);
73#endif
74 }
uint32_t generate_hotp(uint64_t counter)
Definition hotp.cpp:42
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:77
#define BOTAN_FFI_DO(T, obj, param, block)
Definition ffi_util.h:92

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, and Botan::HOTP::generate_hotp().

◆ botan_hotp_init()

int botan_hotp_init ( botan_hotp_t hotp,
const uint8_t  key[],
size_t  key_len,
const char *  hash_algo,
size_t  digits 
)

Initialize a HOTP instance

Definition at line 24 of file ffi_hotp.cpp.

28 {
29 if(hotp == nullptr || key == nullptr || hash_algo == nullptr)
31
32 *hotp = nullptr;
33
34#if defined(BOTAN_HAS_HOTP)
35 return ffi_guard_thunk(__func__, [=]() -> int {
36
37 *hotp = new botan_hotp_struct(
38 new Botan::HOTP(key, key_len, hash_algo, digits));
39
40 return BOTAN_FFI_SUCCESS;
41 });
42#else
43 BOTAN_UNUSED(hotp, key, key_len, hash_algo, digits);
45#endif
46 }
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition ffi.cpp:89
AlgorithmIdentifier hash_algo
Definition x509_obj.cpp:22

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and hash_algo.