Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | List of all members
Botan::RTSS_Share Class Reference

`#include <tss.h>`

## Public Member Functions
bool | initialized () const
| RTSS_Share ()=default
| RTSS_Share (const std::string &hex_input)
uint8_t | share_id () const
size_t | size () const
std::string | to_string () const

## Static Public Member Functions
static secure_vector< uint8_t > | reconstruct (const std::vector< RTSS_Share > &shares)
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)

## Detailed Description

A split secret, using the format from draft-mcgrew-tss-03

Definition at line 21 of file tss.h.

## Constructor & Destructor Documentation

Botan::RTSS_Share::RTSS_Share | ( |  | ) |
| default

Botan::RTSS_Share::RTSS_Share | ( | const std::string & | hex_input | ) |
| explicit

Parameters

  hex_input | the share encoded in hexadecimal

Definition at line 105 of file tss.cpp.

References Botan::hex_decode_locked().

106 {
107 m_contents = hex_decode_locked(hex_input);
108 }
Botan::hex_decode_locked
secure_vector< uint8_t > hex_decode_locked(const char input[], size_t input_length, bool ignore_ws)
Definition: hex.cpp:162

## Member Function Documentation

bool Botan::RTSS_Share::initialized | ( |  | ) | const
| inline

Returns
  if this TSS share was initialized or not

Definition at line 69 of file tss.h.

Referenced by share_id().

69 { return (m_contents.size() > 0); }

secure_vector< uint8_t > Botan::RTSS_Share::reconstruct | ( | const std::vector< RTSS_Share > & | shares | ) |
| static

Parameters

  shares | the list of shares

Definition at line 180 of file tss.cpp.

References hash, Botan::make_uint16(), Botan::same_mem(), share_id(), and size().

181 {
182 const size_t RTSS_HEADER_SIZE = 20;
183
184 for(size_t i = 0; i != shares.size(); ++i)
185 {
186 if(shares[i].size() != shares[0].size())
187 throw Decoding_Error("Different sized RTSS shares detected");
188 if(shares[i].share_id() == 0)
189 throw Decoding_Error("Invalid (id = 0) RTSS share detected");
190 if(shares[i].size() < RTSS_HEADER_SIZE)
191 throw Decoding_Error("Missing or malformed RTSS header");
192
193 if(!same_mem(&shares[0].m_contents[0],
194 &shares[i].m_contents[0], RTSS_HEADER_SIZE))
195 throw Decoding_Error("Different RTSS headers detected");
196 }
197
198 if(shares.size() < shares[0].m_contents[17])
199 throw Decoding_Error("Insufficient shares to do TSS reconstruction");
200
201 uint16_t secret_len = make_uint16(shares[0].m_contents[18],
202 shares[0].m_contents[19]);
203
204 uint8_t hash_id = shares[0].m_contents[16];
205
206 std::unique_ptr<HashFunction> hash(get_rtss_hash_by_id(hash_id));
207
208 if(shares[0].size() != secret_len + hash->output_length() + RTSS_HEADER_SIZE + 1)
209 throw Decoding_Error("Bad RTSS length field in header");
210
211 std::vector<uint8_t> V(shares.size());
212 secure_vector<uint8_t> secret;
213
214 for(size_t i = RTSS_HEADER_SIZE + 1; i != shares[0].size(); ++i)
215 {
216 for(size_t j = 0; j != V.size(); ++j)
217 V[j] = shares[j].m_contents[i];
218
219 uint8_t r = 0;
220 for(size_t k = 0; k != shares.size(); ++k)
221 {
222 // L_i function:
223 uint8_t r2 = 1;
224 for(size_t l = 0; l != shares.size(); ++l)
225 {
226 if(k == l)
227 continue;
228
229 uint8_t share_k = shares[k].share_id();
230 uint8_t share_l = shares[l].share_id();
231
232 if(share_k == share_l)
233 throw Decoding_Error("Duplicate shares found in RTSS recovery");
234
235 uint8_t div = RTSS_EXP[(255 +
236 RTSS_LOG[share_l] -
237 RTSS_LOG[share_k ^ share_l]) % 255];
238
239 r2 = gfp_mul(r2, div);
240 }
241
242 r ^= gfp_mul(V[k], r2);
243 }
244 secret.push_back(r);
245 }
246
247 if(secret.size() != secret_len + hash->output_length())
248 throw Decoding_Error("Bad length in RTSS output");
249
250 hash->update(secret.data(), secret_len);
251 secure_vector<uint8_t> hash_check = hash->final();
252
253 if(!same_mem(hash_check.data(),
254 &secret[secret_len], hash->output_length()))
255 throw Decoding_Error("RTSS hash check failed");
256
257 return secure_vector<uint8_t>(secret.cbegin(), secret.cbegin() + secret_len);
258 }
Botan::RTSS_Share::size
size_t size() const
Definition: tss.h:64
Botan::same_mem
bool same_mem(const T *p1, const T *p2, size_t n)
Definition: mem_ops.h:98
Botan::make_uint16
uint16_t make_uint16(uint8_t i0, uint8_t i1)
Definition: loadstor.h:60
hash
MechanismType hash
Definition: p11_mechanism.cpp:63
Botan::RTSS_Share::share_id
uint8_t share_id() const
Definition: tss.cpp:110

uint8_t Botan::RTSS_Share::share_id | ( |  | ) | const

Returns
  share identifier

Definition at line 110 of file tss.cpp.

References initialized().

Referenced by reconstruct().

111 {
112 if(!initialized())
113 throw Invalid_State("RTSS_Share::share_id not initialized");
114
115 return m_contents[20];
116 }
Botan::RTSS_Share::initialized
bool initialized() const
Definition: tss.h:69

size_t Botan::RTSS_Share::size | ( |  | ) | const
| inline

Returns
  size of this share in bytes

Definition at line 64 of file tss.h.

Referenced by reconstruct().

64 { return m_contents.size(); }

std::vector< RTSS_Share > Botan::RTSS_Share::split | ( | uint8_t | M,
|  | uint8_t | N,
|  | const uint8_t | secret[],
|  | uint16_t | secret_len,
|  | const uint8_t | identifier[16],
|  | RandomNumberGenerator & | rng
| ) |  |
| static

Parameters

  M | the number of shares needed to reconstruct
  N | the number of shares generated
  secret | the secret to split
  secret_len | the length of the secret
  identifier | the 16 byte share identifier
  rng | the random number generator to use

Definition at line 124 of file tss.cpp.

References Botan::get_byte(), hash, Botan::SHA_256::name(), Botan::Buffered_Computation::process(), and Botan::RandomNumberGenerator::randomize().

128 {
129 if(M == 0 || N == 0 || M > N)
130 throw Encoding_Error("RTSS_Share::split: M == 0 or N == 0 or M > N");
131
132 SHA_256 hash; // always use SHA-256 when generating shares
133
134 std::vector<RTSS_Share> shares(N);
135
136 // Create RTSS header in each share
137 for(uint8_t i = 0; i != N; ++i)
138 {
139 shares[i].m_contents += std::make_pair(identifier, 16);
140 shares[i].m_contents += rtss_hash_id(hash.name());
141 shares[i].m_contents += M;
142 shares[i].m_contents += get_byte(0, S_len);
143 shares[i].m_contents += get_byte(1, S_len);
144 }
145
146 // Choose sequential values for X starting from 1
147 for(uint8_t i = 0; i != N; ++i)
148 shares[i].m_contents.push_back(i+1);
149
150 // secret = S || H(S)
151 secure_vector<uint8_t> secret(S, S + S_len);
152 secret += hash.process(S, S_len);
153
154 for(size_t i = 0; i != secret.size(); ++i)
155 {
156 std::vector<uint8_t> coefficients(M-1);
157 rng.randomize(coefficients.data(), coefficients.size());
158
159 for(uint8_t j = 0; j != N; ++j)
160 {
161 const uint8_t X = j + 1;
162
163 uint8_t sum = secret[i];
164 uint8_t X_i = X;
165
166 for(size_t k = 0; k != coefficients.size(); ++k)
167 {
168 sum ^= gfp_mul(X_i, coefficients[k]);
169 X_i = gfp_mul(X_i, X);
170 }
171
172 shares[j].m_contents.push_back(sum);
173 }
174 }
175
176 return shares;
177 }
Botan::get_byte
uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:47
hash
MechanismType hash
Definition: p11_mechanism.cpp:63

std::string Botan::RTSS_Share::to_string | ( |  | ) | const

Returns
  hex representation

Definition at line 118 of file tss.cpp.

References Botan::hex_encode().

119 {
120 return hex_encode(m_contents.data(), m_contents.size());
121 }
Botan::hex_encode
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition: hex.cpp:14

The documentation for this class was generated from the following files:

- src/lib/misc/tss/tss.h
- src/lib/misc/tss/tss.cpp