Botan 3.11.0
Crypto and TLS for C&
ffi_hotp.cpp File Reference
#include <botan/ffi.h>
#include <botan/assert.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 67 of file ffi_hotp.cpp.

68 {
69#if defined(BOTAN_HAS_HOTP)
70 return BOTAN_FFI_VISIT(hotp, [=](auto& h) {
71 auto resp = h.verify_hotp(hotp_code, hotp_counter, resync_range);
72
73 if(next_hotp_counter) {
74 *next_hotp_counter = resp.second;
75 }
76
77 return (resp.first == true) ? BOTAN_FFI_SUCCESS : BOTAN_FFI_INVALID_VERIFIER;
78 });
79
80#else
81 BOTAN_UNUSED(hotp, next_hotp_counter, hotp_code, hotp_counter, resync_range);
83#endif
84}
#define BOTAN_UNUSED
Definition assert.h:144
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:140
@ BOTAN_FFI_INVALID_VERIFIER
Definition ffi.h:118
@ BOTAN_FFI_SUCCESS
Definition ffi.h:116
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:158

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_INVALID_VERIFIER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ 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 44 of file ffi_hotp.cpp.

44 {
45#if defined(BOTAN_HAS_HOTP)
46 return BOTAN_FFI_CHECKED_DELETE(hotp);
47#else
48 BOTAN_UNUSED(hotp);
50#endif
51}
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:185

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 53 of file ffi_hotp.cpp.

53 {
54#if defined(BOTAN_HAS_HOTP)
55 if(hotp == nullptr || hotp_code == nullptr) {
57 }
58
59 return BOTAN_FFI_VISIT(hotp, [=](auto& h) { *hotp_code = h.generate_hotp(hotp_counter); });
60
61#else
62 BOTAN_UNUSED(hotp, hotp_code, hotp_counter);
64#endif
65}
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:133

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ 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 26 of file ffi_hotp.cpp.

26 {
27 if(hotp == nullptr || key == nullptr || hash_algo == nullptr) {
29 }
30
31 *hotp = nullptr;
32
33#if defined(BOTAN_HAS_HOTP)
34 return ffi_guard_thunk(__func__, [=]() -> int {
35 auto otp = std::make_unique<Botan::HOTP>(key, key_len, hash_algo, digits);
36 return ffi_new_object(hotp, std::move(otp));
37 });
38#else
39 BOTAN_UNUSED(hotp, key, key_len, hash_algo, digits);
41#endif
42}
BOTAN_FFI_ERROR ffi_new_object(T *obj, Args &&... args)
Definition ffi_util.h:178
int ffi_guard_thunk(const char *func_name, T thunk)
Definition ffi_util.h:95

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