Botan 3.5.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/internal/ffi_util.h>
10
11#if defined(BOTAN_HAS_ZFEC)
12 #include <botan/zfec.h>
13#endif
14
15extern "C" {
16
17int botan_zfec_encode(size_t K, size_t N, const uint8_t* input, size_t size, uint8_t** outputs) {
18#if defined(BOTAN_HAS_ZFEC)
19 return Botan_FFI::ffi_guard_thunk(__func__, [=]() -> int {
20 Botan::ZFEC(K, N).encode(input, size, [=](size_t index, const uint8_t block[], size_t blockSize) -> void {
21 std::copy(block, block + blockSize, outputs[index]);
22 });
23 return BOTAN_FFI_SUCCESS;
24 });
25#else
26 BOTAN_UNUSED(K, N, input, size, outputs);
28#endif
29}
30
32 size_t K, size_t N, const size_t* indexes, uint8_t* const* const inputs, size_t shareSize, uint8_t** outputs) {
33#if defined(BOTAN_HAS_ZFEC)
34 return Botan_FFI::ffi_guard_thunk(__func__, [=]() -> int {
35 std::map<size_t, const uint8_t*> shares;
36 for(size_t k = 0; k < K; ++k) {
37 shares.insert(std::pair<size_t, const uint8_t*>(indexes[k], inputs[k]));
38 }
40 shares, shareSize, [=](size_t index, const uint8_t block[], size_t blockSize) -> void {
41 std::copy(block, block + blockSize, outputs[index]);
42 });
43 return BOTAN_FFI_SUCCESS;
44 });
45#else
46 BOTAN_UNUSED(K, N, indexes, inputs, shareSize, outputs);
48#endif
49}
50}
#define BOTAN_UNUSED
Definition assert.h:118
void encode(const uint8_t input[], size_t size, const output_cb_t &output_cb) const
Definition zfec.cpp:399
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:442
size_t blockSize
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:124
@ BOTAN_FFI_SUCCESS
Definition ffi.h:103
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:31
int botan_zfec_encode(size_t K, size_t N, const uint8_t *input, size_t size, uint8_t **outputs)
Definition ffi_zfec.cpp:17
int ffi_guard_thunk(const char *func_name, const std::function< int()> &thunk)
Definition ffi.cpp:116