Botan 3.4.0
Crypto and TLS for C&
Functions
ffi_zfec.cpp File Reference
#include <botan/ffi.h>
#include <botan/internal/ffi_util.h>

Go to the source code of this file.

Functions

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)
 
int botan_zfec_encode (size_t K, size_t N, const uint8_t *input, size_t size, uint8_t **outputs)
 

Function Documentation

◆ botan_zfec_decode()

int botan_zfec_decode ( size_t K,
size_t N,
const size_t * indexes,
uint8_t *const * inputs,
size_t shareSize,
uint8_t ** outputs )

Decode some previously encoded shares using certain ZFEC parameters.

Parameters
Kthe number of shares needed for recovery
Nthe total number of shares
indexesThe index into the encoder's outputs for the corresponding element of the inputs array. Must be of length K.
inputsK previously encoded shares to decode
shareSizethe length in bytes of each input
outputsAn out parameter pointing to a fully allocated array of size [K][shareSize]. For all k in range, a decoded block will written to the memory starting at outputs[k][0].
Returns
0 on success, negative on failure

Definition at line 31 of file ffi_zfec.cpp.

32 {
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}
#define BOTAN_UNUSED
Definition assert.h:118
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 ffi_guard_thunk(const char *func_name, const std::function< int()> &thunk)
Definition ffi.cpp:116

References blockSize, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan::ZFEC::decode_shares(), and Botan_FFI::ffi_guard_thunk().

◆ botan_zfec_encode()

int botan_zfec_encode ( size_t K,
size_t N,
const uint8_t * input,
size_t size,
uint8_t ** outputs )

ZFEC Encode some bytes with certain ZFEC parameters.

Parameters
Kthe number of shares needed for recovery
Nthe number of shares generated
inputthe data to FEC
sizethe length in bytes of input, which must be a multiple of K
outputsAn out parameter pointing to a fully allocated array of size [N][size / K]. For all n in range, an encoded block will be written to the memory starting at outputs[n][0].
Returns
0 on success, negative on failure

Definition at line 17 of file ffi_zfec.cpp.

17 {
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}
void encode(const uint8_t input[], size_t size, const output_cb_t &output_cb) const
Definition zfec.cpp:399

References blockSize, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan::ZFEC::encode(), and Botan_FFI::ffi_guard_thunk().