11#include <openssl/crypto.h>
21 entropy->random((
unsigned char*)buf, n);
43 using Share = std::array<uint8_t, SHARE_LENGTH>;
44 using SplitSecret = std::array<uint8_t, SECRET_TO_SPLIT_LENGTH>;
46 static std::vector<Share>
split(
47 const SplitSecret& secret_to_split,
size_t n,
size_t k)
51 throw std::logic_error(fmt::format(
52 "Share creation failed: n ({}) not in 1-{} range",
59 throw std::logic_error(fmt::format(
60 "Share creation failed: k not in 1-n range (k: {}, n: {})", k, n));
63 std::vector<Share> shares(n);
66 reinterpret_cast<sss_Share*
>(shares.data()),
67 secret_to_split.data(),
76 if (k == 0 || k > shares.size())
78 throw std::logic_error(fmt::format(
79 "Share combination failed: k not in 1-n range (k: {}, n: {})",
88 restored_secret.data(), (sss_Share*)shares.data(), k) != 0)
90 throw std::logic_error(fmt::format(
91 "Share combination failed: {} shares may be corrupted", k));
94 for (
auto& s : shares)
96 OPENSSL_cleanse(s.data(), s.size());
99 return restored_secret;
Definition secret_share.h:37
std::array< uint8_t, SHARE_LENGTH > Share
Definition secret_share.h:43
static std::vector< Share > split(const SplitSecret &secret_to_split, size_t n, size_t k)
Definition secret_share.h:46
static SplitSecret combine(std::vector< Share > &shares, size_t k)
Definition secret_share.h:74
static constexpr size_t MAX_NUMBER_SHARES
Definition secret_share.h:41
static constexpr size_t SECRET_TO_SPLIT_LENGTH
Definition secret_share.h:39
static constexpr size_t SHARE_LENGTH
Definition secret_share.h:40
std::array< uint8_t, SECRET_TO_SPLIT_LENGTH > SplitSecret
Definition secret_share.h:44
EntropyPtr get_entropy()
Definition entropy.cpp:10
std::shared_ptr< Entropy > EntropyPtr
Definition entropy.h:303
Definition app_interface.h:15
int randombytes(void *buf, size_t n)
SSS assumes that there is a function of this prototype.
Definition secret_share.h:18