Botan 3.12.0
Crypto and TLS for C&
ffi_zfec.cpp
Go to the documentation of this file.
1/*
2* (C) 2023 Least Authority TFA GmbH
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#include <botan/ffi.h>
8
9#include <botan/assert.h>
10#include <botan/internal/ffi_util.h>
11
12#if defined(BOTAN_HAS_ZFEC)
13 #include <botan/zfec.h>
14#endif
15
16extern "C" {
17
18int botan_zfec_encode(size_t K, size_t N, const uint8_t* input, size_t size, uint8_t** outputs) {
19 if(Botan::any_null_pointers(input, outputs)) {
21 }
22#if defined(BOTAN_HAS_ZFEC)
23 return Botan_FFI::ffi_guard_thunk(__func__, [=]() -> int {
24 Botan::ZFEC(K, N).encode(input, size, [=](size_t index, const uint8_t block[], size_t blockSize) -> void {
25 std::copy(block, block + blockSize, outputs[index]);
26 });
27 return BOTAN_FFI_SUCCESS;
28 });
29#else
30 BOTAN_UNUSED(K, N, input, size, outputs);
32#endif
33}
34
36 size_t K, size_t N, const size_t* indexes, uint8_t* const* const inputs, size_t shareSize, uint8_t** outputs) {
37 if(Botan::any_null_pointers(indexes, inputs, outputs)) {
39 }
40#if defined(BOTAN_HAS_ZFEC)
41 return Botan_FFI::ffi_guard_thunk(__func__, [=]() -> int {
42 std::map<size_t, const uint8_t*> shares;
43 for(size_t k = 0; k < K; ++k) {
44 shares.insert(std::pair<size_t, const uint8_t*>(indexes[k], inputs[k]));
45 }
47 shares, shareSize, [=](size_t index, const uint8_t block[], size_t blockSize) -> void {
48 std::copy(block, block + blockSize, outputs[index]);
49 });
50 return BOTAN_FFI_SUCCESS;
51 });
52#else
53 BOTAN_UNUSED(K, N, indexes, inputs, shareSize, outputs);
55#endif
56}
57}
#define BOTAN_UNUSED
Definition assert.h:144
void encode(const uint8_t input[], size_t size, const output_cb_t &output_cb) const
Definition zfec.cpp:393
void decode_shares(const std::map< size_t, const uint8_t * > &shares, size_t share_size, const output_cb_t &output_cb) const
Definition zfec.cpp:436
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:140
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:133
@ BOTAN_FFI_SUCCESS
Definition ffi.h:116
int botan_zfec_decode(size_t K, size_t N, const size_t *indexes, uint8_t *const *const inputs, size_t shareSize, uint8_t **outputs)
Definition ffi_zfec.cpp:35
int botan_zfec_encode(size_t K, size_t N, const uint8_t *input, size_t size, uint8_t **outputs)
Definition ffi_zfec.cpp:18
int ffi_guard_thunk(const char *func_name, T thunk)
Definition ffi_util.h:95
bool any_null_pointers(Ptrs... ptr)
Definition mem_utils.h:54