1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//! Implements the `ThSS` threshold secret sharing scheme.
//!
//! This scheme satisfies the following security properties:
//!
//! **Property** | **Satisifed?** | **Description**
//! -------------|----------------|----------------
//! **Basic** | Yes | Basic correctness: If you attempt to recover a secret from an authorized set of shares that were obtained by sharing out a secret **M** using an access structure **A**, you're sure to get back **A** and **M**.<br> <em>Note: in this implementation **A** is not actually returned, but definitely could.</em>
//! **Priv1** | Yes | Standard privacy notation: When the coins are used by the dealer are uniformly random, unauthorized sets of shares have no computationally extractable information about the underlying secret.
//! **Priv2** | No | Privacy for deterministic or hedged schemes: extract whatever entropy one can from the underlying secret. If it’s adequate, no additional randomness is needed in order to achieve a meaningful notion of privacy.
//! **Auth1** | No | A share obtained from an honest dealer commits it to a single underlying secret: that and only that value can be recovered.
//! **Auth2** | No | A share obtained even from a dishonest dealer commits it to a single underlying secret: that and only that value might be recovered. Implies Auth1.
//! **ErrDet** | Yes | An inauthentic set of shares produced by an adversary will be flagged as such when fed to the recovery algorithm.
//! **Repro** | No | Share reproducible: The scheme can produce shares in a deterministic way.
use *;
pub use *;
pub use ThSS;
use AccessStructure;
/// Performs threshold k-out-of-n secret sharing using the `ThSS` scheme.
///
/// # Examples
///
/// ```rust
/// use rusty_secrets::dss::thss;
///
/// let secret = "These programs were never about terrorism: they’re about economic spying, \
/// social control, and diplomatic manipulation. They’re about power.";
///
/// let mut metadata = thss::MetaData::new();
/// metadata.tags.insert("mime_type".to_string(), "text/plain".to_string());
///
/// let result = thss::split_secret(
/// 7,
/// 10,
/// &secret.as_bytes(),
/// &Some(metadata)
/// );
///
/// match result {
/// Ok(shares) => {
/// // Do something with the shares
/// },
/// Err(e) => {
/// // Deal with error
/// }
/// }
///
/// ```
/// Recovers the secret from a k-out-of-n secret sharing scheme (`ThSS`).
///
/// At least `k` distinct shares need to be provided to recover the secret.
///
/// # Examples
///
/// ```rust
/// use rusty_secrets::dss::thss;
///
/// let secret = "These programs were never about terrorism: they’re about economic spying, \
/// social control, and diplomatic manipulation. They’re about power.";
///
/// let mut metadata = thss::MetaData::new();
/// metadata.tags.insert("mime_type".to_string(), "text/plain".to_string());
///
/// let shares = thss::split_secret(
/// 7,
/// 10,
/// &secret.as_bytes(),
/// &Some(metadata)
/// ).unwrap();
///
/// match thss::recover_secret(&shares) {
/// Ok((secret, access_structure, metadata)) => {
/// // Do something with the secret and the metadata
/// },
/// Err(e) => {
/// // Deal with the error
/// }
/// }
/// ```