Botan 3.11.0
Crypto and TLS for C&
ffi_xof.cpp File Reference
#include <botan/ffi.h>
#include <botan/xof.h>
#include <botan/internal/ffi_util.h>

Go to the source code of this file.

Functions

 BOTAN_FFI_DECLARE_STRUCT (botan_xof_struct, Botan::XOF, 0x0f1303a0)
int botan_xof_accepts_input (botan_xof_t this_xof)
int botan_xof_block_size (botan_xof_t this_xof, size_t *out)
int botan_xof_clear (botan_xof_t this_xof)
int botan_xof_copy_state (botan_xof_t *dest, const botan_xof_t this_xof)
int botan_xof_destroy (botan_xof_t xof)
int botan_xof_init (botan_xof_t *this_xof, const char *xof_name, uint32_t flags)
int botan_xof_name (botan_xof_t this_xof, char *name, size_t *name_len)
int botan_xof_output (botan_xof_t this_xof, uint8_t *out, size_t out_len)
int botan_xof_update (botan_xof_t this_xof, const uint8_t *in, size_t in_len)

Function Documentation

◆ BOTAN_FFI_DECLARE_STRUCT()

BOTAN_FFI_DECLARE_STRUCT ( botan_xof_struct ,
Botan::XOF ,
0x0f1303a0  )

◆ botan_xof_accepts_input()

int botan_xof_accepts_input ( botan_xof_t xof)

Get the input/output state of this eXtendable Output Function Typically, XOFs don't accept input as soon as the first output bytes were requested.

Parameters
xofthe object to read
Returns
1 iff the XOF is still accepting input bytes

Definition at line 58 of file ffi_xof.cpp.

58 {
59 return BOTAN_FFI_VISIT(this_xof, [=](const auto& xof) { return xof.accepts_input() ? 1 : 0; });
60}
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:158

References BOTAN_FFI_VISIT.

◆ botan_xof_block_size()

int botan_xof_block_size ( botan_xof_t xof,
size_t * block_size )

Writes the block size of the eXtendable Output Function to *block_size

Parameters
xofXOF object
block_sizevariable to hold the XOF's block size
Returns
0 on success, a negative value on failure

Definition at line 43 of file ffi_xof.cpp.

43 {
46 }
47 return BOTAN_FFI_VISIT(this_xof, [=](const auto& xof) { *out = xof.block_size(); });
48}
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:133
bool any_null_pointers(Ptrs... ptr)
Definition mem_utils.h:54

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_xof_clear()

int botan_xof_clear ( botan_xof_t xof)

Reinitializes the state of the eXtendable Output Function.

Parameters
xofXOF object
Returns
0 on success, a negative value on failure

Definition at line 62 of file ffi_xof.cpp.

62 {
63 return BOTAN_FFI_VISIT(this_xof, [](auto& xof) { xof.clear(); });
64}

References BOTAN_FFI_VISIT.

◆ botan_xof_copy_state()

int botan_xof_copy_state ( botan_xof_t * dest,
botan_xof_t source )

Copy the state of an eXtendable Output Function

Parameters
destdestination XOF object
sourcesource XOF object
Returns
0 on success, a negative value on failure

Definition at line 39 of file ffi_xof.cpp.

39 {
40 return BOTAN_FFI_VISIT(this_xof, [=](const auto& src) { return ffi_new_object(dest, src.copy_state()); });
41}
BOTAN_FFI_ERROR ffi_new_object(T *obj, Args &&... args)
Definition ffi_util.h:178

References BOTAN_FFI_VISIT, and Botan_FFI::ffi_new_object().

◆ botan_xof_destroy()

int botan_xof_destroy ( botan_xof_t xof)

Frees all resources of the eXtendable Output Function object

Parameters
xofxof object
Returns
0 if success, error if invalid object handle

Definition at line 90 of file ffi_xof.cpp.

90 {
91 return BOTAN_FFI_CHECKED_DELETE(xof);
92}
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:185

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_xof_init()

int botan_xof_init ( botan_xof_t * xof,
const char * xof_name,
uint32_t flags )

Initialize an eXtendable Output Function

Parameters
xofXOF object
xof_namename of the XOF, e.g., "SHAKE-128"
flagsshould be 0 in current API revision, all other uses are reserved and return BOTAN_FFI_ERROR_BAD_FLAG

Definition at line 19 of file ffi_xof.cpp.

19 {
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}
static std::unique_ptr< XOF > create(std::string_view algo_spec, std::string_view provider="")
Definition xof.cpp:28
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:140
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition ffi.h:132
@ BOTAN_FFI_SUCCESS
Definition ffi.h:116
int ffi_guard_thunk(const char *func_name, T thunk)
Definition ffi_util.h:95

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan::XOF::create(), Botan_FFI::ffi_guard_thunk(), and Botan_FFI::ffi_new_object().

◆ botan_xof_name()

int botan_xof_name ( botan_xof_t xof,
char * name,
size_t * name_len )

Get the name of this eXtendable Output Function

Parameters
xofthe object to read
nameoutput buffer
name_lenon input, the length of buffer, on success the number of bytes written

Definition at line 50 of file ffi_xof.cpp.

50 {
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}
int write_str_output(char out[], size_t *out_len, const std::string &str)
Definition ffi_util.h:265

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and Botan_FFI::write_str_output().

◆ botan_xof_output()

int botan_xof_output ( botan_xof_t xof,
uint8_t * out,
size_t out_len )

Generate output bytes from the eXtendable Output Function

Parameters
xofXOF object
outoutput buffer
out_lennumber of bytes to write into the output buffer
Returns
0 on success, a negative value on failure

Definition at line 78 of file ffi_xof.cpp.

78 {
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}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_xof_update()

int botan_xof_update ( botan_xof_t xof,
const uint8_t * in,
size_t in_len )

Send more input to the eXtendable Output Function

Parameters
xofXOF object
ininput buffer
in_lennumber of bytes to read from the input buffer
Returns
0 on success, a negative value on failure

Definition at line 66 of file ffi_xof.cpp.

66 {
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}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.