Botan 3.11.0
Crypto and TLS for C&
ffi_xof.cpp
Go to the documentation of this file.
1/*
2* (C) 2025 Jack Lloyd
3* 2025 René Meusel, Rohde & Schwarz Cybersecurity
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/ffi.h>
9
10#include <botan/xof.h>
11#include <botan/internal/ffi_util.h>
12
13extern "C" {
14
15using namespace Botan_FFI;
16
17BOTAN_FFI_DECLARE_STRUCT(botan_xof_struct, Botan::XOF, 0x0f1303a0);
18
19int botan_xof_init(botan_xof_t* this_xof, const char* xof_name, uint32_t flags) {
20 return ffi_guard_thunk(__func__, [=]() -> int {
21 if(Botan::any_null_pointers(this_xof, xof_name) || *xof_name == 0) {
23 }
24 if(flags != 0) {
26 }
27
28 auto xof = Botan::XOF::create(xof_name);
29 if(xof == nullptr) {
31 }
32
33 ffi_new_object(this_xof, std::move(xof));
34 return BOTAN_FFI_SUCCESS;
35 });
36}
37
38// NOLINTNEXTLINE(misc-misplaced-const)
39int botan_xof_copy_state(botan_xof_t* dest, const botan_xof_t this_xof) {
40 return BOTAN_FFI_VISIT(this_xof, [=](const auto& src) { return ffi_new_object(dest, src.copy_state()); });
41}
42
43int botan_xof_block_size(botan_xof_t this_xof, size_t* out) {
46 }
47 return BOTAN_FFI_VISIT(this_xof, [=](const auto& xof) { *out = xof.block_size(); });
48}
49
50int botan_xof_name(botan_xof_t this_xof, char* name, size_t* name_len) {
51 if(Botan::any_null_pointers(name_len)) {
53 }
54
55 return BOTAN_FFI_VISIT(this_xof, [=](const auto& xof) { return write_str_output(name, name_len, xof.name()); });
56}
57
59 return BOTAN_FFI_VISIT(this_xof, [=](const auto& xof) { return xof.accepts_input() ? 1 : 0; });
60}
61
63 return BOTAN_FFI_VISIT(this_xof, [](auto& xof) { xof.clear(); });
64}
65
66int botan_xof_update(botan_xof_t this_xof, const uint8_t* in, size_t in_len) {
67 if(in_len == 0) {
68 return 0;
69 }
70
73 }
74
75 return BOTAN_FFI_VISIT(this_xof, [=](auto& xof) { xof.update({in, in_len}); });
76}
77
78int botan_xof_output(botan_xof_t this_xof, uint8_t* out, size_t out_len) {
79 if(out_len == 0) {
80 return 0;
81 }
82
85 }
86
87 return BOTAN_FFI_VISIT(this_xof, [=](auto& xof) { xof.output({out, out_len}); });
88}
89
93}
static std::unique_ptr< XOF > create(std::string_view algo_spec, std::string_view provider="")
Definition xof.cpp:28
struct botan_xof_struct * botan_xof_t
Definition ffi.h:383
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:140
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition ffi.h:132
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:133
@ BOTAN_FFI_SUCCESS
Definition ffi.h:116
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:158
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:185
#define BOTAN_FFI_DECLARE_STRUCT(NAME, TYPE, MAGIC)
Definition ffi_util.h:61
int botan_xof_output(botan_xof_t this_xof, uint8_t *out, size_t out_len)
Definition ffi_xof.cpp:78
int botan_xof_name(botan_xof_t this_xof, char *name, size_t *name_len)
Definition ffi_xof.cpp:50
int botan_xof_copy_state(botan_xof_t *dest, const botan_xof_t this_xof)
Definition ffi_xof.cpp:39
int botan_xof_clear(botan_xof_t this_xof)
Definition ffi_xof.cpp:62
int botan_xof_init(botan_xof_t *this_xof, const char *xof_name, uint32_t flags)
Definition ffi_xof.cpp:19
int botan_xof_destroy(botan_xof_t xof)
Definition ffi_xof.cpp:90
int botan_xof_update(botan_xof_t this_xof, const uint8_t *in, size_t in_len)
Definition ffi_xof.cpp:66
int botan_xof_accepts_input(botan_xof_t this_xof)
Definition ffi_xof.cpp:58
int botan_xof_block_size(botan_xof_t this_xof, size_t *out)
Definition ffi_xof.cpp:43
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
int write_str_output(char out[], size_t *out_len, const std::string &str)
Definition ffi_util.h:265
bool any_null_pointers(Ptrs... ptr)
Definition mem_utils.h:54