Botan 3.4.0
Crypto and TLS for C&
zfec.h
Go to the documentation of this file.
1/*
2 * Forward error correction based on Vandermonde matrices
3 *
4 * (C) 1997-1998 Luigi Rizzo (luigi@iet.unipi.it)
5 * (C) 2009,2017,2021 Jack Lloyd
6 *
7 * Distributed under the terms given in license.txt
8 */
9
10#ifndef BOTAN_ZFEC_H_
11#define BOTAN_ZFEC_H_
12
13#include <botan/types.h>
14#include <functional>
15#include <map>
16#include <string>
17#include <vector>
18
19namespace Botan {
20
21/**
22* A forward error correction code compatible with the zfec
23* library (https://github.com/tahoe-lafs/zfec)
24*
25* This algorithm is *not constant time* and is likely succeptible to
26* side channels. Do not use this class to encode information that
27* should be kept secret. (If nothing else, because the first K shares
28* are simply the original input!)
29*/
31 public:
32 typedef std::function<void(size_t, const uint8_t[], size_t)> output_cb_t;
33
34 /**
35 * FEC constructor
36 * @param K the number of shares needed for recovery
37 * @param N the number of shares generated
38 */
39 ZFEC(size_t K, size_t N);
40
41 size_t recovery_threshold() const { return m_K; }
42
43 size_t generated_shares() const { return m_N; }
44
45 std::string provider() const;
46
47 /**
48 * @param input the data to FEC
49 * @param size the length in bytes of input
50 * @param output_cb the output callback
51 */
52 void encode(const uint8_t input[], size_t size, const output_cb_t& output_cb) const;
53
54 /**
55 * @param shares exactly K shares of data to FEC
56 * @param share_size the length in bytes of each share
57 * @param output_cb the output callback
58 */
59 void encode_shares(const std::vector<const uint8_t*>& shares,
60 size_t share_size,
61 const output_cb_t& output_cb) const;
62
63 /**
64 * @param shares map of share id to share contents
65 * @param share_size size in bytes of each share
66 * @param output_cb the output callback
67 */
68 void decode_shares(const std::map<size_t, const uint8_t*>& shares,
69 size_t share_size,
70 const output_cb_t& output_cb) const;
71
72 private:
73 static void addmul(uint8_t z[], const uint8_t x[], uint8_t y, size_t size);
74
75#if defined(BOTAN_HAS_ZFEC_SSE2)
76 static size_t addmul_sse2(uint8_t z[], const uint8_t x[], uint8_t y, size_t size);
77#endif
78
79#if defined(BOTAN_HAS_ZFEC_VPERM)
80 static size_t addmul_vperm(uint8_t z[], const uint8_t x[], uint8_t y, size_t size);
81#endif
82
83 const size_t m_K, m_N;
84 std::vector<uint8_t> m_enc_matrix;
85};
86
87} // namespace Botan
88
89#endif
std::function< void(size_t, const uint8_t[], size_t)> output_cb_t
Definition zfec.h:32
size_t recovery_threshold() const
Definition zfec.h:41
size_t generated_shares() const
Definition zfec.h:43
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31