Botan 2.19.3
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 <string>
15#include <map>
16#include <vector>
17#include <functional>
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 {
32 public:
33 typedef std::function<void (size_t, const uint8_t[], size_t)> output_cb_t;
34
35 /**
36 * FEC constructor
37 * @param K the number of shares needed for recovery
38 * @param N the number of shares generated
39 */
40 ZFEC(size_t K, size_t N);
41
42 size_t recovery_threshold() const { return m_K; }
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(
53 const uint8_t input[], size_t size,
54 output_cb_t output_cb)
55 const;
56
57 /**
58 * @param shares exactly K shares of data to FEC
59 * @param share_size the length in bytes of each share
60 * @param output_cb the output callback
61 */
62 void encode_shares(
63 const std::vector<const uint8_t*>& shares,
64 size_t share_size,
65 output_cb_t output_cb)
66 const;
67
68 /**
69 * @param shares map of share id to share contents
70 * @param share_size size in bytes of each share
71 * @param output_cb the output callback
72 */
73 void decode_shares(
74 const std::map<size_t, const uint8_t*>& shares,
75 size_t share_size,
76 output_cb_t output_cb)
77 const;
78
79 private:
80 static void addmul(uint8_t z[], const uint8_t x[], uint8_t y, size_t size);
81
82#if defined(BOTAN_HAS_ZFEC_SSE2)
83 static size_t addmul_sse2(uint8_t z[], const uint8_t x[], uint8_t y, size_t size);
84#endif
85
86#if defined(BOTAN_HAS_ZFEC_VPERM)
87 static size_t addmul_vperm(uint8_t z[], const uint8_t x[], uint8_t y, size_t size);
88#endif
89
90 const size_t m_K, m_N;
91 std::vector<uint8_t> m_enc_matrix;
92 };
93
94}
95
96#endif
size_t recovery_threshold() const
Definition zfec.h:42
std::function< void(size_t, const uint8_t[], size_t)> output_cb_t
Definition zfec.h:33
size_t generated_shares() const
Definition zfec.h:43
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31