Botan 3.13.0
Crypto and TLS for C&
tss.h
Go to the documentation of this file.
1/*
2* RTSS (threshold secret sharing)
3* (C) 2009,2018 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_RTSS_H_
9#define BOTAN_RTSS_H_
10
11#include <botan/secmem.h>
12#include <string>
13#include <vector>
14
15namespace Botan {
16
18
19/**
20* A split secret, using the format from draft-mcgrew-tss-03
21*/
22class BOTAN_PUBLIC_API(2, 0) RTSS_Share final {
23 public:
24 /**
25 * Split a secret into shares
26 * @param M the number of shares needed to reconstruct
27 * @param N the number of shares generated
28 * @param secret the secret to split
29 * @param secret_len the length of the secret
30 * @param identifier the 16 byte share identifier
31 * @param rng the random number generator to use
32 */
33 static std::vector<RTSS_Share> split(uint8_t M,
34 uint8_t N,
35 const uint8_t secret[],
36 uint16_t secret_len,
37 const uint8_t identifier[16],
39
40 /**
41 * Split a secret into shares
42 * @param M the number of shares needed to reconstruct
43 * @param N the number of shares generated
44 * @param secret the secret to split
45 * @param secret_len the length of the secret
46 * @param identifier the share identifier
47 * @param hash_fn the hash function to use for a checksum ("None", "SHA-1", "SHA-256")
48 * @param rng the random number generator to use
49 */
50 static std::vector<RTSS_Share> split(uint8_t M,
51 uint8_t N,
52 const uint8_t secret[],
53 uint16_t secret_len,
54 const std::vector<uint8_t>& identifier,
55 std::string_view hash_fn,
57
58 /**
59 * Reconstruct a secret from a set of shares
60 * @param shares the list of shares
61 */
62 static secure_vector<uint8_t> reconstruct(const std::vector<RTSS_Share>& shares);
63
64 /**
65 * Create an uninitialized share
66 */
67 RTSS_Share() = default;
68
69 /**
70 * Decode a share from its hex representation
71 * @param hex_input the share encoded in hexadecimal
72 */
73 explicit RTSS_Share(std::string_view hex_input);
74
75 /**
76 * Create a share from its binary representation
77 * @param data the shared data
78 * @param len the length of data
79 */
80 RTSS_Share(const uint8_t data[], size_t len);
81
82 /**
83 * Access the binary representation of this share
84 * @return binary representation
85 */
86 const secure_vector<uint8_t>& data() const { return m_contents; }
87
88 /**
89 * Format this share as a hex string
90 * @return hex representation
91 */
92 std::string to_string() const;
93
94 /**
95 * Return the identifier of this share
96 * @return share identifier
97 */
98 uint8_t share_id() const;
99
100 /**
101 * Return the size of this share
102 * @return size of this share in bytes
103 */
104 size_t size() const { return m_contents.size(); }
105
106 /**
107 * Test whether this share was initialized
108 * @return if this TSS share was initialized or not
109 */
110 bool initialized() const { return (!m_contents.empty()); }
111
112 private:
113 secure_vector<uint8_t> m_contents;
114};
115
116} // namespace Botan
117
118#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
const secure_vector< uint8_t > & data() const
Definition tss.h:86
size_t size() const
Definition tss.h:104
static std::vector< RTSS_Share > split(uint8_t M, uint8_t N, const uint8_t secret[], uint16_t secret_len, const uint8_t identifier[16], RandomNumberGenerator &rng)
Definition tss.cpp:109
RTSS_Share()=default
static secure_vector< uint8_t > reconstruct(const std::vector< RTSS_Share > &shares)
Definition tss.cpp:191
bool initialized() const
Definition tss.h:110
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition exceptn.cpp:13