pub struct Participant {
pub privatekey: BigInt,
pub publickey: BigInt,
/* private fields */
}
Expand description
A participant represents one party in the secret sharing scheme. The participant can share a secret among a group of other participants and it is then called the “dealer”. The receiving participants that receive a part of the secret can use it to reconstruct the secret Therefore the partticipants need to collaborate and exchange their parts. A participant represents as a Node in the Distributed Public NetWork
Fields§
§privatekey: BigInt
§publickey: BigInt
Implementations§
Source§impl Participant
impl Participant
Sourcepub fn new() -> Self
pub fn new() -> Self
Create A default participant
§Example
use mpvss_rs::Participant;
let mut dealer = Participant::new();
Examples found in repository?
8fn main() {
9 let secret_message = String::from("Hello MPVSS Example.");
10 let mut dealer = Participant::new();
11 dealer.initialize();
12 let mut p1 = Participant::new();
13 let mut p2 = Participant::new();
14 let mut p3 = Participant::new();
15 p1.initialize();
16 p2.initialize();
17 p3.initialize();
18
19 let distribute_shares_box = dealer.distribute_secret(
20 &string_to_secret(&secret_message),
21 &vec![
22 p1.publickey.clone(),
23 p2.publickey.clone(),
24 p3.publickey.clone(),
25 ],
26 3,
27 );
28
29 assert_eq!(p1.verify_distribution_shares(&distribute_shares_box), true);
30
31 assert_eq!(p2.verify_distribution_shares(&distribute_shares_box), true);
32
33 assert_eq!(p3.verify_distribution_shares(&distribute_shares_box), true);
34
35 // p1 extracts the share. [p2 and p3 do this as well.]
36 let s1 = p1
37 .extract_secret_share(&distribute_shares_box, &p1.privatekey)
38 .unwrap();
39
40 // p1, p2 and p3 exchange their descrypted shares.
41 // ...
42 let s2 = p2
43 .extract_secret_share(&distribute_shares_box, &p2.privatekey)
44 .unwrap();
45 let s3 = p3
46 .extract_secret_share(&distribute_shares_box, &p3.privatekey)
47 .unwrap();
48
49 // p1 verifies the share received from p2. [Actually everybody verifies every received share.]
50
51 assert_eq!(
52 p1.verify_share(&s2, &distribute_shares_box, &p2.publickey),
53 true
54 );
55
56 assert_eq!(
57 p2.verify_share(&s3, &distribute_shares_box, &p3.publickey),
58 true
59 );
60
61 assert_eq!(
62 p3.verify_share(&s1, &distribute_shares_box, &s1.publickey),
63 true
64 );
65
66 let share_boxs = [s1, s2, s3];
67 let r1 = p1.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
68 let r2 = p2.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
69 let r3 = p3.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
70
71 let r1_str = string_from_secret(&r1);
72 assert_eq!(secret_message.clone(), r1_str);
73 let r2_str = string_from_secret(&r2);
74 assert_eq!(secret_message.clone(), r2_str);
75 let r3_str = string_from_secret(&r3);
76 assert_eq!(secret_message.clone(), r3_str);
77
78 println!("secret message: {}", secret_message);
79 println!("r1 str: {}", r1_str);
80 println!("r2 str: {}", r2_str);
81 println!("r3 str: {}", r3_str);
82}
More examples
8fn main() {
9 let secret_message = String::from("Hello Sub MPVSS Example.");
10 let mut dealer = Participant::new();
11 dealer.initialize();
12 let mut p1 = Participant::new();
13 let mut p2 = Participant::new();
14 let mut p3 = Participant::new();
15 let mut p4 = Participant::new();
16 p1.initialize();
17 p2.initialize();
18 p3.initialize();
19 p4.initialize();
20
21 let distribute_shares_box = dealer.distribute_secret(
22 &string_to_secret(&secret_message),
23 &vec![
24 p1.publickey.clone(),
25 p2.publickey.clone(),
26 p3.publickey.clone(),
27 p4.publickey.clone(),
28 ],
29 3,
30 );
31
32 assert_eq!(p1.verify_distribution_shares(&distribute_shares_box), true);
33
34 assert_eq!(p2.verify_distribution_shares(&distribute_shares_box), true);
35
36 assert_eq!(p3.verify_distribution_shares(&distribute_shares_box), true);
37
38 assert_eq!(p4.verify_distribution_shares(&distribute_shares_box), true);
39
40 // p1 extracts the share. [p2 and p3 do this as well.]
41 let s1 = p1
42 .extract_secret_share(&distribute_shares_box, &p1.privatekey)
43 .unwrap();
44
45 // p1, p2, p3 p4 exchange their descrypted shares.
46 // ...
47 let s2 = p2
48 .extract_secret_share(&distribute_shares_box, &p2.privatekey)
49 .unwrap();
50 let s3 = p3
51 .extract_secret_share(&distribute_shares_box, &p3.privatekey)
52 .unwrap();
53
54 let s4 = p4
55 .extract_secret_share(&distribute_shares_box, &p4.privatekey)
56 .unwrap();
57
58 // p1 verifies the share received from p2. [Actually everybody verifies every received share.]
59
60 assert_eq!(
61 p1.verify_share(&s2, &distribute_shares_box, &p2.publickey),
62 true
63 );
64
65 assert_eq!(
66 p2.verify_share(&s3, &distribute_shares_box, &p3.publickey),
67 true
68 );
69
70 assert_eq!(
71 p3.verify_share(&s1, &distribute_shares_box, &s1.publickey),
72 true
73 );
74
75 assert_eq!(
76 p4.verify_share(&s2, &distribute_shares_box, &s2.publickey),
77 true
78 );
79
80 let share_boxs = [s1.clone(), s2.clone(), s4.clone()];
81 let r1 = p1.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
82 let r2 = p2.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
83 let r3 = p3.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
84 let r4 = p4.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
85
86 let r1_str = string_from_secret(&r1);
87 assert_eq!(secret_message.clone(), r1_str);
88 let r2_str = string_from_secret(&r2);
89 assert_eq!(secret_message.clone(), r2_str);
90 let r3_str = string_from_secret(&r3);
91 assert_eq!(secret_message.clone(), r3_str);
92 let r4_str = string_from_secret(&r4);
93 assert_eq!(secret_message.clone(), r4_str);
94
95 println!("secret message: {}", secret_message);
96 println!("r1 str: {}", r1_str);
97 println!("r2 str: {}", r2_str);
98 println!("r3 str: {}", r3_str);
99 println!("r3 str: {}", r4_str);
100}
Sourcepub fn initialize(&mut self)
pub fn initialize(&mut self)
Initializes a new participant with the default MPVSS.
§Example
use mpvss_rs::Participant;
let mut dealer = Participant::new();
dealer.initialize();
Examples found in repository?
8fn main() {
9 let secret_message = String::from("Hello MPVSS Example.");
10 let mut dealer = Participant::new();
11 dealer.initialize();
12 let mut p1 = Participant::new();
13 let mut p2 = Participant::new();
14 let mut p3 = Participant::new();
15 p1.initialize();
16 p2.initialize();
17 p3.initialize();
18
19 let distribute_shares_box = dealer.distribute_secret(
20 &string_to_secret(&secret_message),
21 &vec![
22 p1.publickey.clone(),
23 p2.publickey.clone(),
24 p3.publickey.clone(),
25 ],
26 3,
27 );
28
29 assert_eq!(p1.verify_distribution_shares(&distribute_shares_box), true);
30
31 assert_eq!(p2.verify_distribution_shares(&distribute_shares_box), true);
32
33 assert_eq!(p3.verify_distribution_shares(&distribute_shares_box), true);
34
35 // p1 extracts the share. [p2 and p3 do this as well.]
36 let s1 = p1
37 .extract_secret_share(&distribute_shares_box, &p1.privatekey)
38 .unwrap();
39
40 // p1, p2 and p3 exchange their descrypted shares.
41 // ...
42 let s2 = p2
43 .extract_secret_share(&distribute_shares_box, &p2.privatekey)
44 .unwrap();
45 let s3 = p3
46 .extract_secret_share(&distribute_shares_box, &p3.privatekey)
47 .unwrap();
48
49 // p1 verifies the share received from p2. [Actually everybody verifies every received share.]
50
51 assert_eq!(
52 p1.verify_share(&s2, &distribute_shares_box, &p2.publickey),
53 true
54 );
55
56 assert_eq!(
57 p2.verify_share(&s3, &distribute_shares_box, &p3.publickey),
58 true
59 );
60
61 assert_eq!(
62 p3.verify_share(&s1, &distribute_shares_box, &s1.publickey),
63 true
64 );
65
66 let share_boxs = [s1, s2, s3];
67 let r1 = p1.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
68 let r2 = p2.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
69 let r3 = p3.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
70
71 let r1_str = string_from_secret(&r1);
72 assert_eq!(secret_message.clone(), r1_str);
73 let r2_str = string_from_secret(&r2);
74 assert_eq!(secret_message.clone(), r2_str);
75 let r3_str = string_from_secret(&r3);
76 assert_eq!(secret_message.clone(), r3_str);
77
78 println!("secret message: {}", secret_message);
79 println!("r1 str: {}", r1_str);
80 println!("r2 str: {}", r2_str);
81 println!("r3 str: {}", r3_str);
82}
More examples
8fn main() {
9 let secret_message = String::from("Hello Sub MPVSS Example.");
10 let mut dealer = Participant::new();
11 dealer.initialize();
12 let mut p1 = Participant::new();
13 let mut p2 = Participant::new();
14 let mut p3 = Participant::new();
15 let mut p4 = Participant::new();
16 p1.initialize();
17 p2.initialize();
18 p3.initialize();
19 p4.initialize();
20
21 let distribute_shares_box = dealer.distribute_secret(
22 &string_to_secret(&secret_message),
23 &vec![
24 p1.publickey.clone(),
25 p2.publickey.clone(),
26 p3.publickey.clone(),
27 p4.publickey.clone(),
28 ],
29 3,
30 );
31
32 assert_eq!(p1.verify_distribution_shares(&distribute_shares_box), true);
33
34 assert_eq!(p2.verify_distribution_shares(&distribute_shares_box), true);
35
36 assert_eq!(p3.verify_distribution_shares(&distribute_shares_box), true);
37
38 assert_eq!(p4.verify_distribution_shares(&distribute_shares_box), true);
39
40 // p1 extracts the share. [p2 and p3 do this as well.]
41 let s1 = p1
42 .extract_secret_share(&distribute_shares_box, &p1.privatekey)
43 .unwrap();
44
45 // p1, p2, p3 p4 exchange their descrypted shares.
46 // ...
47 let s2 = p2
48 .extract_secret_share(&distribute_shares_box, &p2.privatekey)
49 .unwrap();
50 let s3 = p3
51 .extract_secret_share(&distribute_shares_box, &p3.privatekey)
52 .unwrap();
53
54 let s4 = p4
55 .extract_secret_share(&distribute_shares_box, &p4.privatekey)
56 .unwrap();
57
58 // p1 verifies the share received from p2. [Actually everybody verifies every received share.]
59
60 assert_eq!(
61 p1.verify_share(&s2, &distribute_shares_box, &p2.publickey),
62 true
63 );
64
65 assert_eq!(
66 p2.verify_share(&s3, &distribute_shares_box, &p3.publickey),
67 true
68 );
69
70 assert_eq!(
71 p3.verify_share(&s1, &distribute_shares_box, &s1.publickey),
72 true
73 );
74
75 assert_eq!(
76 p4.verify_share(&s2, &distribute_shares_box, &s2.publickey),
77 true
78 );
79
80 let share_boxs = [s1.clone(), s2.clone(), s4.clone()];
81 let r1 = p1.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
82 let r2 = p2.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
83 let r3 = p3.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
84 let r4 = p4.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
85
86 let r1_str = string_from_secret(&r1);
87 assert_eq!(secret_message.clone(), r1_str);
88 let r2_str = string_from_secret(&r2);
89 assert_eq!(secret_message.clone(), r2_str);
90 let r3_str = string_from_secret(&r3);
91 assert_eq!(secret_message.clone(), r3_str);
92 let r4_str = string_from_secret(&r4);
93 assert_eq!(secret_message.clone(), r4_str);
94
95 println!("secret message: {}", secret_message);
96 println!("r1 str: {}", r1_str);
97 println!("r2 str: {}", r2_str);
98 println!("r3 str: {}", r3_str);
99 println!("r3 str: {}", r4_str);
100}
Sourcepub fn distribute_secret(
&mut self,
secret: &BigInt,
publickeys: &[BigInt],
threshold: u32,
) -> DistributionSharesBox
pub fn distribute_secret( &mut self, secret: &BigInt, publickeys: &[BigInt], threshold: u32, ) -> DistributionSharesBox
Takes a secret as input and returns the distribution shares Box which is going to be submitted to all the participants the secret is going to be shared with. Those participants are specified by their public keys. They use the distribution shares box to verify that the shares are correct (without learning anything about the shares that are not supposed to be decrypted by them) and extract their encrypted shares. In fact, the distribution shares box can be published to everyone allowing even external parties to verify the integrity of the shares.
- Parameters:
- secret: The value that is going to be shared among the other participants.
- publicKeys: Array of public keys of each participant the secret is to be shared with.
- threshold: The number of shares that is needed in order to reconstruct the secret. It must not be greater than the total number of participants.
- Requires:
threshold
<= number of participants - Returns: The distribution shares Box that is published to everyone (especially but not only the participants) can check the shares’ integrity. Furthermore the participants extract their shares from it.
§Example
use mpvss_rs::Participant;
use num_bigint::{BigUint, ToBigInt};
let secret_message = String::from("Hello MPVSS Example.");
let secret = BigUint::from_bytes_be(&secret_message.as_bytes());
let mut dealer = Participant::new();
dealer.initialize();
let mut p1 = Participant::new();
let mut p2 = Participant::new();
let mut p3 = Participant::new();
p1.initialize();
p2.initialize();
p3.initialize();
let distribute_shares_box = dealer.distribute_secret(
&secret.to_bigint().unwrap(),
&vec![
p1.publickey.clone(),
p2.publickey.clone(),
p3.publickey.clone(),
],
3,
);
Examples found in repository?
8fn main() {
9 let secret_message = String::from("Hello MPVSS Example.");
10 let mut dealer = Participant::new();
11 dealer.initialize();
12 let mut p1 = Participant::new();
13 let mut p2 = Participant::new();
14 let mut p3 = Participant::new();
15 p1.initialize();
16 p2.initialize();
17 p3.initialize();
18
19 let distribute_shares_box = dealer.distribute_secret(
20 &string_to_secret(&secret_message),
21 &vec![
22 p1.publickey.clone(),
23 p2.publickey.clone(),
24 p3.publickey.clone(),
25 ],
26 3,
27 );
28
29 assert_eq!(p1.verify_distribution_shares(&distribute_shares_box), true);
30
31 assert_eq!(p2.verify_distribution_shares(&distribute_shares_box), true);
32
33 assert_eq!(p3.verify_distribution_shares(&distribute_shares_box), true);
34
35 // p1 extracts the share. [p2 and p3 do this as well.]
36 let s1 = p1
37 .extract_secret_share(&distribute_shares_box, &p1.privatekey)
38 .unwrap();
39
40 // p1, p2 and p3 exchange their descrypted shares.
41 // ...
42 let s2 = p2
43 .extract_secret_share(&distribute_shares_box, &p2.privatekey)
44 .unwrap();
45 let s3 = p3
46 .extract_secret_share(&distribute_shares_box, &p3.privatekey)
47 .unwrap();
48
49 // p1 verifies the share received from p2. [Actually everybody verifies every received share.]
50
51 assert_eq!(
52 p1.verify_share(&s2, &distribute_shares_box, &p2.publickey),
53 true
54 );
55
56 assert_eq!(
57 p2.verify_share(&s3, &distribute_shares_box, &p3.publickey),
58 true
59 );
60
61 assert_eq!(
62 p3.verify_share(&s1, &distribute_shares_box, &s1.publickey),
63 true
64 );
65
66 let share_boxs = [s1, s2, s3];
67 let r1 = p1.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
68 let r2 = p2.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
69 let r3 = p3.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
70
71 let r1_str = string_from_secret(&r1);
72 assert_eq!(secret_message.clone(), r1_str);
73 let r2_str = string_from_secret(&r2);
74 assert_eq!(secret_message.clone(), r2_str);
75 let r3_str = string_from_secret(&r3);
76 assert_eq!(secret_message.clone(), r3_str);
77
78 println!("secret message: {}", secret_message);
79 println!("r1 str: {}", r1_str);
80 println!("r2 str: {}", r2_str);
81 println!("r3 str: {}", r3_str);
82}
More examples
8fn main() {
9 let secret_message = String::from("Hello Sub MPVSS Example.");
10 let mut dealer = Participant::new();
11 dealer.initialize();
12 let mut p1 = Participant::new();
13 let mut p2 = Participant::new();
14 let mut p3 = Participant::new();
15 let mut p4 = Participant::new();
16 p1.initialize();
17 p2.initialize();
18 p3.initialize();
19 p4.initialize();
20
21 let distribute_shares_box = dealer.distribute_secret(
22 &string_to_secret(&secret_message),
23 &vec![
24 p1.publickey.clone(),
25 p2.publickey.clone(),
26 p3.publickey.clone(),
27 p4.publickey.clone(),
28 ],
29 3,
30 );
31
32 assert_eq!(p1.verify_distribution_shares(&distribute_shares_box), true);
33
34 assert_eq!(p2.verify_distribution_shares(&distribute_shares_box), true);
35
36 assert_eq!(p3.verify_distribution_shares(&distribute_shares_box), true);
37
38 assert_eq!(p4.verify_distribution_shares(&distribute_shares_box), true);
39
40 // p1 extracts the share. [p2 and p3 do this as well.]
41 let s1 = p1
42 .extract_secret_share(&distribute_shares_box, &p1.privatekey)
43 .unwrap();
44
45 // p1, p2, p3 p4 exchange their descrypted shares.
46 // ...
47 let s2 = p2
48 .extract_secret_share(&distribute_shares_box, &p2.privatekey)
49 .unwrap();
50 let s3 = p3
51 .extract_secret_share(&distribute_shares_box, &p3.privatekey)
52 .unwrap();
53
54 let s4 = p4
55 .extract_secret_share(&distribute_shares_box, &p4.privatekey)
56 .unwrap();
57
58 // p1 verifies the share received from p2. [Actually everybody verifies every received share.]
59
60 assert_eq!(
61 p1.verify_share(&s2, &distribute_shares_box, &p2.publickey),
62 true
63 );
64
65 assert_eq!(
66 p2.verify_share(&s3, &distribute_shares_box, &p3.publickey),
67 true
68 );
69
70 assert_eq!(
71 p3.verify_share(&s1, &distribute_shares_box, &s1.publickey),
72 true
73 );
74
75 assert_eq!(
76 p4.verify_share(&s2, &distribute_shares_box, &s2.publickey),
77 true
78 );
79
80 let share_boxs = [s1.clone(), s2.clone(), s4.clone()];
81 let r1 = p1.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
82 let r2 = p2.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
83 let r3 = p3.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
84 let r4 = p4.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
85
86 let r1_str = string_from_secret(&r1);
87 assert_eq!(secret_message.clone(), r1_str);
88 let r2_str = string_from_secret(&r2);
89 assert_eq!(secret_message.clone(), r2_str);
90 let r3_str = string_from_secret(&r3);
91 assert_eq!(secret_message.clone(), r3_str);
92 let r4_str = string_from_secret(&r4);
93 assert_eq!(secret_message.clone(), r4_str);
94
95 println!("secret message: {}", secret_message);
96 println!("r1 str: {}", r1_str);
97 println!("r2 str: {}", r2_str);
98 println!("r3 str: {}", r3_str);
99 println!("r3 str: {}", r4_str);
100}
Extracts the share from a given distribution shares box that is addressed to the calling participant. The extracted share is boxed with a proof which allows the other participants to verify the share’s correctness.
- Parameters:
- shares_box: The distribution shares box that consists the share to be extracted.
- private_key: The participant’s private key used to decrypt the share.
- Returns: The share box that is to be submitted to all the other participants in order to reconstruct the secret.
It consists of the share itself and the proof that allows the receiving participant to verify its correctness.
Return
None
if the distribution shares box does not contain a share for the participant.
§Example
use mpvss_rs::Participant;
use num_bigint::{BigUint, ToBigInt};
let secret_message = String::from("Hello MPVSS Example.");
let secret = BigUint::from_bytes_be(&secret_message.as_bytes());
let mut dealer = Participant::new();
dealer.initialize();
let mut p1 = Participant::new();
let mut p2 = Participant::new();
let mut p3 = Participant::new();
p1.initialize();
p2.initialize();
p3.initialize();
let distribute_shares_box = dealer.distribute_secret(
&secret.to_bigint().unwrap(),
&vec![
p1.publickey.clone(),
p2.publickey.clone(),
p3.publickey.clone(),
],
3,
);
let s1 = p1
.extract_secret_share(&distribute_shares_box, &p1.privatekey)
.unwrap();
let s2 = p2
.extract_secret_share(&distribute_shares_box, &p2.privatekey)
.unwrap();
let s3 = p3
.extract_secret_share(&distribute_shares_box, &p3.privatekey)
.unwrap();
Examples found in repository?
8fn main() {
9 let secret_message = String::from("Hello MPVSS Example.");
10 let mut dealer = Participant::new();
11 dealer.initialize();
12 let mut p1 = Participant::new();
13 let mut p2 = Participant::new();
14 let mut p3 = Participant::new();
15 p1.initialize();
16 p2.initialize();
17 p3.initialize();
18
19 let distribute_shares_box = dealer.distribute_secret(
20 &string_to_secret(&secret_message),
21 &vec![
22 p1.publickey.clone(),
23 p2.publickey.clone(),
24 p3.publickey.clone(),
25 ],
26 3,
27 );
28
29 assert_eq!(p1.verify_distribution_shares(&distribute_shares_box), true);
30
31 assert_eq!(p2.verify_distribution_shares(&distribute_shares_box), true);
32
33 assert_eq!(p3.verify_distribution_shares(&distribute_shares_box), true);
34
35 // p1 extracts the share. [p2 and p3 do this as well.]
36 let s1 = p1
37 .extract_secret_share(&distribute_shares_box, &p1.privatekey)
38 .unwrap();
39
40 // p1, p2 and p3 exchange their descrypted shares.
41 // ...
42 let s2 = p2
43 .extract_secret_share(&distribute_shares_box, &p2.privatekey)
44 .unwrap();
45 let s3 = p3
46 .extract_secret_share(&distribute_shares_box, &p3.privatekey)
47 .unwrap();
48
49 // p1 verifies the share received from p2. [Actually everybody verifies every received share.]
50
51 assert_eq!(
52 p1.verify_share(&s2, &distribute_shares_box, &p2.publickey),
53 true
54 );
55
56 assert_eq!(
57 p2.verify_share(&s3, &distribute_shares_box, &p3.publickey),
58 true
59 );
60
61 assert_eq!(
62 p3.verify_share(&s1, &distribute_shares_box, &s1.publickey),
63 true
64 );
65
66 let share_boxs = [s1, s2, s3];
67 let r1 = p1.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
68 let r2 = p2.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
69 let r3 = p3.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
70
71 let r1_str = string_from_secret(&r1);
72 assert_eq!(secret_message.clone(), r1_str);
73 let r2_str = string_from_secret(&r2);
74 assert_eq!(secret_message.clone(), r2_str);
75 let r3_str = string_from_secret(&r3);
76 assert_eq!(secret_message.clone(), r3_str);
77
78 println!("secret message: {}", secret_message);
79 println!("r1 str: {}", r1_str);
80 println!("r2 str: {}", r2_str);
81 println!("r3 str: {}", r3_str);
82}
More examples
8fn main() {
9 let secret_message = String::from("Hello Sub MPVSS Example.");
10 let mut dealer = Participant::new();
11 dealer.initialize();
12 let mut p1 = Participant::new();
13 let mut p2 = Participant::new();
14 let mut p3 = Participant::new();
15 let mut p4 = Participant::new();
16 p1.initialize();
17 p2.initialize();
18 p3.initialize();
19 p4.initialize();
20
21 let distribute_shares_box = dealer.distribute_secret(
22 &string_to_secret(&secret_message),
23 &vec![
24 p1.publickey.clone(),
25 p2.publickey.clone(),
26 p3.publickey.clone(),
27 p4.publickey.clone(),
28 ],
29 3,
30 );
31
32 assert_eq!(p1.verify_distribution_shares(&distribute_shares_box), true);
33
34 assert_eq!(p2.verify_distribution_shares(&distribute_shares_box), true);
35
36 assert_eq!(p3.verify_distribution_shares(&distribute_shares_box), true);
37
38 assert_eq!(p4.verify_distribution_shares(&distribute_shares_box), true);
39
40 // p1 extracts the share. [p2 and p3 do this as well.]
41 let s1 = p1
42 .extract_secret_share(&distribute_shares_box, &p1.privatekey)
43 .unwrap();
44
45 // p1, p2, p3 p4 exchange their descrypted shares.
46 // ...
47 let s2 = p2
48 .extract_secret_share(&distribute_shares_box, &p2.privatekey)
49 .unwrap();
50 let s3 = p3
51 .extract_secret_share(&distribute_shares_box, &p3.privatekey)
52 .unwrap();
53
54 let s4 = p4
55 .extract_secret_share(&distribute_shares_box, &p4.privatekey)
56 .unwrap();
57
58 // p1 verifies the share received from p2. [Actually everybody verifies every received share.]
59
60 assert_eq!(
61 p1.verify_share(&s2, &distribute_shares_box, &p2.publickey),
62 true
63 );
64
65 assert_eq!(
66 p2.verify_share(&s3, &distribute_shares_box, &p3.publickey),
67 true
68 );
69
70 assert_eq!(
71 p3.verify_share(&s1, &distribute_shares_box, &s1.publickey),
72 true
73 );
74
75 assert_eq!(
76 p4.verify_share(&s2, &distribute_shares_box, &s2.publickey),
77 true
78 );
79
80 let share_boxs = [s1.clone(), s2.clone(), s4.clone()];
81 let r1 = p1.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
82 let r2 = p2.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
83 let r3 = p3.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
84 let r4 = p4.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
85
86 let r1_str = string_from_secret(&r1);
87 assert_eq!(secret_message.clone(), r1_str);
88 let r2_str = string_from_secret(&r2);
89 assert_eq!(secret_message.clone(), r2_str);
90 let r3_str = string_from_secret(&r3);
91 assert_eq!(secret_message.clone(), r3_str);
92 let r4_str = string_from_secret(&r4);
93 assert_eq!(secret_message.clone(), r4_str);
94
95 println!("secret message: {}", secret_message);
96 println!("r1 str: {}", r1_str);
97 println!("r2 str: {}", r2_str);
98 println!("r3 str: {}", r3_str);
99 println!("r3 str: {}", r4_str);
100}
Verifies that the shares the distribution shares box consists are consistent so that they can be used to reconstruct the secret later.
- Parameter distribute_sharesbox: The distribution shares box whose consistency is to be verified.
- Returns: Returns
true
if the shares are correct andfalse
otherwise.
§Example
use mpvss_rs::Participant;
use num_bigint::{BigUint, ToBigInt};
let secret_message = String::from("Hello MPVSS Example.");
let secret = BigUint::from_bytes_be(&secret_message.as_bytes());
let mut dealer = Participant::new();
dealer.initialize();
let mut p1 = Participant::new();
let mut p2 = Participant::new();
let mut p3 = Participant::new();
p1.initialize();
p2.initialize();
p3.initialize();
let distribute_shares_box = dealer.distribute_secret(
&secret.to_bigint().unwrap(),
&vec![
p1.publickey.clone(),
p2.publickey.clone(),
p3.publickey.clone(),
],
3,
);
assert_eq!(
p1.verify_distribution_shares(&distribute_shares_box),
true
);
assert_eq!(
p2.verify_distribution_shares(&distribute_shares_box),
true
);
assert_eq!(
p3.verify_distribution_shares(&distribute_shares_box),
true
);
Examples found in repository?
8fn main() {
9 let secret_message = String::from("Hello MPVSS Example.");
10 let mut dealer = Participant::new();
11 dealer.initialize();
12 let mut p1 = Participant::new();
13 let mut p2 = Participant::new();
14 let mut p3 = Participant::new();
15 p1.initialize();
16 p2.initialize();
17 p3.initialize();
18
19 let distribute_shares_box = dealer.distribute_secret(
20 &string_to_secret(&secret_message),
21 &vec![
22 p1.publickey.clone(),
23 p2.publickey.clone(),
24 p3.publickey.clone(),
25 ],
26 3,
27 );
28
29 assert_eq!(p1.verify_distribution_shares(&distribute_shares_box), true);
30
31 assert_eq!(p2.verify_distribution_shares(&distribute_shares_box), true);
32
33 assert_eq!(p3.verify_distribution_shares(&distribute_shares_box), true);
34
35 // p1 extracts the share. [p2 and p3 do this as well.]
36 let s1 = p1
37 .extract_secret_share(&distribute_shares_box, &p1.privatekey)
38 .unwrap();
39
40 // p1, p2 and p3 exchange their descrypted shares.
41 // ...
42 let s2 = p2
43 .extract_secret_share(&distribute_shares_box, &p2.privatekey)
44 .unwrap();
45 let s3 = p3
46 .extract_secret_share(&distribute_shares_box, &p3.privatekey)
47 .unwrap();
48
49 // p1 verifies the share received from p2. [Actually everybody verifies every received share.]
50
51 assert_eq!(
52 p1.verify_share(&s2, &distribute_shares_box, &p2.publickey),
53 true
54 );
55
56 assert_eq!(
57 p2.verify_share(&s3, &distribute_shares_box, &p3.publickey),
58 true
59 );
60
61 assert_eq!(
62 p3.verify_share(&s1, &distribute_shares_box, &s1.publickey),
63 true
64 );
65
66 let share_boxs = [s1, s2, s3];
67 let r1 = p1.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
68 let r2 = p2.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
69 let r3 = p3.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
70
71 let r1_str = string_from_secret(&r1);
72 assert_eq!(secret_message.clone(), r1_str);
73 let r2_str = string_from_secret(&r2);
74 assert_eq!(secret_message.clone(), r2_str);
75 let r3_str = string_from_secret(&r3);
76 assert_eq!(secret_message.clone(), r3_str);
77
78 println!("secret message: {}", secret_message);
79 println!("r1 str: {}", r1_str);
80 println!("r2 str: {}", r2_str);
81 println!("r3 str: {}", r3_str);
82}
More examples
8fn main() {
9 let secret_message = String::from("Hello Sub MPVSS Example.");
10 let mut dealer = Participant::new();
11 dealer.initialize();
12 let mut p1 = Participant::new();
13 let mut p2 = Participant::new();
14 let mut p3 = Participant::new();
15 let mut p4 = Participant::new();
16 p1.initialize();
17 p2.initialize();
18 p3.initialize();
19 p4.initialize();
20
21 let distribute_shares_box = dealer.distribute_secret(
22 &string_to_secret(&secret_message),
23 &vec![
24 p1.publickey.clone(),
25 p2.publickey.clone(),
26 p3.publickey.clone(),
27 p4.publickey.clone(),
28 ],
29 3,
30 );
31
32 assert_eq!(p1.verify_distribution_shares(&distribute_shares_box), true);
33
34 assert_eq!(p2.verify_distribution_shares(&distribute_shares_box), true);
35
36 assert_eq!(p3.verify_distribution_shares(&distribute_shares_box), true);
37
38 assert_eq!(p4.verify_distribution_shares(&distribute_shares_box), true);
39
40 // p1 extracts the share. [p2 and p3 do this as well.]
41 let s1 = p1
42 .extract_secret_share(&distribute_shares_box, &p1.privatekey)
43 .unwrap();
44
45 // p1, p2, p3 p4 exchange their descrypted shares.
46 // ...
47 let s2 = p2
48 .extract_secret_share(&distribute_shares_box, &p2.privatekey)
49 .unwrap();
50 let s3 = p3
51 .extract_secret_share(&distribute_shares_box, &p3.privatekey)
52 .unwrap();
53
54 let s4 = p4
55 .extract_secret_share(&distribute_shares_box, &p4.privatekey)
56 .unwrap();
57
58 // p1 verifies the share received from p2. [Actually everybody verifies every received share.]
59
60 assert_eq!(
61 p1.verify_share(&s2, &distribute_shares_box, &p2.publickey),
62 true
63 );
64
65 assert_eq!(
66 p2.verify_share(&s3, &distribute_shares_box, &p3.publickey),
67 true
68 );
69
70 assert_eq!(
71 p3.verify_share(&s1, &distribute_shares_box, &s1.publickey),
72 true
73 );
74
75 assert_eq!(
76 p4.verify_share(&s2, &distribute_shares_box, &s2.publickey),
77 true
78 );
79
80 let share_boxs = [s1.clone(), s2.clone(), s4.clone()];
81 let r1 = p1.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
82 let r2 = p2.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
83 let r3 = p3.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
84 let r4 = p4.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
85
86 let r1_str = string_from_secret(&r1);
87 assert_eq!(secret_message.clone(), r1_str);
88 let r2_str = string_from_secret(&r2);
89 assert_eq!(secret_message.clone(), r2_str);
90 let r3_str = string_from_secret(&r3);
91 assert_eq!(secret_message.clone(), r3_str);
92 let r4_str = string_from_secret(&r4);
93 assert_eq!(secret_message.clone(), r4_str);
94
95 println!("secret message: {}", secret_message);
96 println!("r1 str: {}", r1_str);
97 println!("r2 str: {}", r2_str);
98 println!("r3 str: {}", r3_str);
99 println!("r3 str: {}", r4_str);
100}
Verifies if the share in the distribution share box was decrypted correctly by the respective participant.
- Parameters:
- shareBox: The share box containing the share to be verified.
- distributionShareBox: The distribution share box that contains the share.
- publicKey: The public key of the sender of the share bundle.
- Returns: Returns
true
if the share in the distribution share box matches the decryption of the encrypted share andfalse
otherwise.
§Example
use mpvss_rs::Participant;
use num_bigint::{BigUint, ToBigInt};
let secret_message = String::from("Hello MPVSS Example.");
let secret = BigUint::from_bytes_be(&secret_message.as_bytes());
let mut dealer = Participant::new();
dealer.initialize();
let mut p1 = Participant::new();
let mut p2 = Participant::new();
let mut p3 = Participant::new();
p1.initialize();
p2.initialize();
p3.initialize();
let distribute_shares_box = dealer.distribute_secret(
&secret.to_bigint().unwrap(),
&vec![
p1.publickey.clone(),
p2.publickey.clone(),
p3.publickey.clone(),
],
3,
);
let s1 = p1
.extract_secret_share(&distribute_shares_box, &p1.privatekey)
.unwrap();
let s2 = p2
.extract_secret_share(&distribute_shares_box, &p2.privatekey)
.unwrap();
let s3 = p3
.extract_secret_share(&distribute_shares_box, &p3.privatekey)
.unwrap();
assert_eq!(
p1.verify_share(&s2, &distribute_shares_box, &p2.publickey),
true
);
assert_eq!(
p2.verify_share(&s3, &distribute_shares_box, &p3.publickey),
true
);
assert_eq!(
p3.verify_share(&s1, &distribute_shares_box, &s1.publickey),
true
);
Examples found in repository?
8fn main() {
9 let secret_message = String::from("Hello MPVSS Example.");
10 let mut dealer = Participant::new();
11 dealer.initialize();
12 let mut p1 = Participant::new();
13 let mut p2 = Participant::new();
14 let mut p3 = Participant::new();
15 p1.initialize();
16 p2.initialize();
17 p3.initialize();
18
19 let distribute_shares_box = dealer.distribute_secret(
20 &string_to_secret(&secret_message),
21 &vec![
22 p1.publickey.clone(),
23 p2.publickey.clone(),
24 p3.publickey.clone(),
25 ],
26 3,
27 );
28
29 assert_eq!(p1.verify_distribution_shares(&distribute_shares_box), true);
30
31 assert_eq!(p2.verify_distribution_shares(&distribute_shares_box), true);
32
33 assert_eq!(p3.verify_distribution_shares(&distribute_shares_box), true);
34
35 // p1 extracts the share. [p2 and p3 do this as well.]
36 let s1 = p1
37 .extract_secret_share(&distribute_shares_box, &p1.privatekey)
38 .unwrap();
39
40 // p1, p2 and p3 exchange their descrypted shares.
41 // ...
42 let s2 = p2
43 .extract_secret_share(&distribute_shares_box, &p2.privatekey)
44 .unwrap();
45 let s3 = p3
46 .extract_secret_share(&distribute_shares_box, &p3.privatekey)
47 .unwrap();
48
49 // p1 verifies the share received from p2. [Actually everybody verifies every received share.]
50
51 assert_eq!(
52 p1.verify_share(&s2, &distribute_shares_box, &p2.publickey),
53 true
54 );
55
56 assert_eq!(
57 p2.verify_share(&s3, &distribute_shares_box, &p3.publickey),
58 true
59 );
60
61 assert_eq!(
62 p3.verify_share(&s1, &distribute_shares_box, &s1.publickey),
63 true
64 );
65
66 let share_boxs = [s1, s2, s3];
67 let r1 = p1.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
68 let r2 = p2.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
69 let r3 = p3.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
70
71 let r1_str = string_from_secret(&r1);
72 assert_eq!(secret_message.clone(), r1_str);
73 let r2_str = string_from_secret(&r2);
74 assert_eq!(secret_message.clone(), r2_str);
75 let r3_str = string_from_secret(&r3);
76 assert_eq!(secret_message.clone(), r3_str);
77
78 println!("secret message: {}", secret_message);
79 println!("r1 str: {}", r1_str);
80 println!("r2 str: {}", r2_str);
81 println!("r3 str: {}", r3_str);
82}
More examples
8fn main() {
9 let secret_message = String::from("Hello Sub MPVSS Example.");
10 let mut dealer = Participant::new();
11 dealer.initialize();
12 let mut p1 = Participant::new();
13 let mut p2 = Participant::new();
14 let mut p3 = Participant::new();
15 let mut p4 = Participant::new();
16 p1.initialize();
17 p2.initialize();
18 p3.initialize();
19 p4.initialize();
20
21 let distribute_shares_box = dealer.distribute_secret(
22 &string_to_secret(&secret_message),
23 &vec![
24 p1.publickey.clone(),
25 p2.publickey.clone(),
26 p3.publickey.clone(),
27 p4.publickey.clone(),
28 ],
29 3,
30 );
31
32 assert_eq!(p1.verify_distribution_shares(&distribute_shares_box), true);
33
34 assert_eq!(p2.verify_distribution_shares(&distribute_shares_box), true);
35
36 assert_eq!(p3.verify_distribution_shares(&distribute_shares_box), true);
37
38 assert_eq!(p4.verify_distribution_shares(&distribute_shares_box), true);
39
40 // p1 extracts the share. [p2 and p3 do this as well.]
41 let s1 = p1
42 .extract_secret_share(&distribute_shares_box, &p1.privatekey)
43 .unwrap();
44
45 // p1, p2, p3 p4 exchange their descrypted shares.
46 // ...
47 let s2 = p2
48 .extract_secret_share(&distribute_shares_box, &p2.privatekey)
49 .unwrap();
50 let s3 = p3
51 .extract_secret_share(&distribute_shares_box, &p3.privatekey)
52 .unwrap();
53
54 let s4 = p4
55 .extract_secret_share(&distribute_shares_box, &p4.privatekey)
56 .unwrap();
57
58 // p1 verifies the share received from p2. [Actually everybody verifies every received share.]
59
60 assert_eq!(
61 p1.verify_share(&s2, &distribute_shares_box, &p2.publickey),
62 true
63 );
64
65 assert_eq!(
66 p2.verify_share(&s3, &distribute_shares_box, &p3.publickey),
67 true
68 );
69
70 assert_eq!(
71 p3.verify_share(&s1, &distribute_shares_box, &s1.publickey),
72 true
73 );
74
75 assert_eq!(
76 p4.verify_share(&s2, &distribute_shares_box, &s2.publickey),
77 true
78 );
79
80 let share_boxs = [s1.clone(), s2.clone(), s4.clone()];
81 let r1 = p1.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
82 let r2 = p2.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
83 let r3 = p3.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
84 let r4 = p4.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
85
86 let r1_str = string_from_secret(&r1);
87 assert_eq!(secret_message.clone(), r1_str);
88 let r2_str = string_from_secret(&r2);
89 assert_eq!(secret_message.clone(), r2_str);
90 let r3_str = string_from_secret(&r3);
91 assert_eq!(secret_message.clone(), r3_str);
92 let r4_str = string_from_secret(&r4);
93 assert_eq!(secret_message.clone(), r4_str);
94
95 println!("secret message: {}", secret_message);
96 println!("r1 str: {}", r1_str);
97 println!("r2 str: {}", r2_str);
98 println!("r3 str: {}", r3_str);
99 println!("r3 str: {}", r4_str);
100}
Sourcepub fn reconstruct(
&self,
share_boxs: &[ShareBox],
distribute_share_box: &DistributionSharesBox,
) -> Option<BigInt>
pub fn reconstruct( &self, share_boxs: &[ShareBox], distribute_share_box: &DistributionSharesBox, ) -> Option<BigInt>
Reconstruct secret from share boxs
§Example
use mpvss_rs::Participant;
use num_bigint::{BigUint, ToBigInt};
let secret_message = String::from("Hello MPVSS Example.");
let secret = BigUint::from_bytes_be(&secret_message.as_bytes());
let mut dealer = Participant::new();
dealer.initialize();
let mut p1 = Participant::new();
let mut p2 = Participant::new();
let mut p3 = Participant::new();
p1.initialize();
p2.initialize();
p3.initialize();
let distribute_shares_box = dealer.distribute_secret(
&secret.to_bigint().unwrap(),
&vec![
p1.publickey.clone(),
p2.publickey.clone(),
p3.publickey.clone(),
],
3,
);
assert_eq!(
p1.verify_distribution_shares(&distribute_shares_box),
true
);
assert_eq!(
p2.verify_distribution_shares(&distribute_shares_box),
true
);
assert_eq!(
p3.verify_distribution_shares(&distribute_shares_box),
true
);
let s1 = p1
.extract_secret_share(&distribute_shares_box, &p1.privatekey)
.unwrap();
let s2 = p2
.extract_secret_share(&distribute_shares_box, &p2.privatekey)
.unwrap();
let s3 = p3
.extract_secret_share(&distribute_shares_box, &p3.privatekey)
.unwrap();
assert_eq!(
p1.verify_share(&s2, &distribute_shares_box, &p2.publickey),
true
);
assert_eq!(
p2.verify_share(&s3, &distribute_shares_box, &p3.publickey),
true
);
assert_eq!(
p3.verify_share(&s1, &distribute_shares_box, &s1.publickey),
true
);
let share_boxs = [s1, s2, s3];
let r1 = p1
.reconstruct(&share_boxs, &distribute_shares_box)
.unwrap();
let r2 = p2
.reconstruct(&share_boxs, &distribute_shares_box)
.unwrap();
let r3 = p3
.reconstruct(&share_boxs, &distribute_shares_box)
.unwrap();
let r1_str =
String::from_utf8(r1.to_biguint().unwrap().to_bytes_be()).unwrap();
assert_eq!(secret_message.clone(), r1_str);
let r2_str =
String::from_utf8(r2.to_biguint().unwrap().to_bytes_be()).unwrap();
assert_eq!(secret_message.clone(), r2_str);
let r3_str =
String::from_utf8(r3.to_biguint().unwrap().to_bytes_be()).unwrap();
assert_eq!(secret_message.clone(), r3_str);
Examples found in repository?
8fn main() {
9 let secret_message = String::from("Hello MPVSS Example.");
10 let mut dealer = Participant::new();
11 dealer.initialize();
12 let mut p1 = Participant::new();
13 let mut p2 = Participant::new();
14 let mut p3 = Participant::new();
15 p1.initialize();
16 p2.initialize();
17 p3.initialize();
18
19 let distribute_shares_box = dealer.distribute_secret(
20 &string_to_secret(&secret_message),
21 &vec![
22 p1.publickey.clone(),
23 p2.publickey.clone(),
24 p3.publickey.clone(),
25 ],
26 3,
27 );
28
29 assert_eq!(p1.verify_distribution_shares(&distribute_shares_box), true);
30
31 assert_eq!(p2.verify_distribution_shares(&distribute_shares_box), true);
32
33 assert_eq!(p3.verify_distribution_shares(&distribute_shares_box), true);
34
35 // p1 extracts the share. [p2 and p3 do this as well.]
36 let s1 = p1
37 .extract_secret_share(&distribute_shares_box, &p1.privatekey)
38 .unwrap();
39
40 // p1, p2 and p3 exchange their descrypted shares.
41 // ...
42 let s2 = p2
43 .extract_secret_share(&distribute_shares_box, &p2.privatekey)
44 .unwrap();
45 let s3 = p3
46 .extract_secret_share(&distribute_shares_box, &p3.privatekey)
47 .unwrap();
48
49 // p1 verifies the share received from p2. [Actually everybody verifies every received share.]
50
51 assert_eq!(
52 p1.verify_share(&s2, &distribute_shares_box, &p2.publickey),
53 true
54 );
55
56 assert_eq!(
57 p2.verify_share(&s3, &distribute_shares_box, &p3.publickey),
58 true
59 );
60
61 assert_eq!(
62 p3.verify_share(&s1, &distribute_shares_box, &s1.publickey),
63 true
64 );
65
66 let share_boxs = [s1, s2, s3];
67 let r1 = p1.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
68 let r2 = p2.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
69 let r3 = p3.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
70
71 let r1_str = string_from_secret(&r1);
72 assert_eq!(secret_message.clone(), r1_str);
73 let r2_str = string_from_secret(&r2);
74 assert_eq!(secret_message.clone(), r2_str);
75 let r3_str = string_from_secret(&r3);
76 assert_eq!(secret_message.clone(), r3_str);
77
78 println!("secret message: {}", secret_message);
79 println!("r1 str: {}", r1_str);
80 println!("r2 str: {}", r2_str);
81 println!("r3 str: {}", r3_str);
82}
More examples
8fn main() {
9 let secret_message = String::from("Hello Sub MPVSS Example.");
10 let mut dealer = Participant::new();
11 dealer.initialize();
12 let mut p1 = Participant::new();
13 let mut p2 = Participant::new();
14 let mut p3 = Participant::new();
15 let mut p4 = Participant::new();
16 p1.initialize();
17 p2.initialize();
18 p3.initialize();
19 p4.initialize();
20
21 let distribute_shares_box = dealer.distribute_secret(
22 &string_to_secret(&secret_message),
23 &vec![
24 p1.publickey.clone(),
25 p2.publickey.clone(),
26 p3.publickey.clone(),
27 p4.publickey.clone(),
28 ],
29 3,
30 );
31
32 assert_eq!(p1.verify_distribution_shares(&distribute_shares_box), true);
33
34 assert_eq!(p2.verify_distribution_shares(&distribute_shares_box), true);
35
36 assert_eq!(p3.verify_distribution_shares(&distribute_shares_box), true);
37
38 assert_eq!(p4.verify_distribution_shares(&distribute_shares_box), true);
39
40 // p1 extracts the share. [p2 and p3 do this as well.]
41 let s1 = p1
42 .extract_secret_share(&distribute_shares_box, &p1.privatekey)
43 .unwrap();
44
45 // p1, p2, p3 p4 exchange their descrypted shares.
46 // ...
47 let s2 = p2
48 .extract_secret_share(&distribute_shares_box, &p2.privatekey)
49 .unwrap();
50 let s3 = p3
51 .extract_secret_share(&distribute_shares_box, &p3.privatekey)
52 .unwrap();
53
54 let s4 = p4
55 .extract_secret_share(&distribute_shares_box, &p4.privatekey)
56 .unwrap();
57
58 // p1 verifies the share received from p2. [Actually everybody verifies every received share.]
59
60 assert_eq!(
61 p1.verify_share(&s2, &distribute_shares_box, &p2.publickey),
62 true
63 );
64
65 assert_eq!(
66 p2.verify_share(&s3, &distribute_shares_box, &p3.publickey),
67 true
68 );
69
70 assert_eq!(
71 p3.verify_share(&s1, &distribute_shares_box, &s1.publickey),
72 true
73 );
74
75 assert_eq!(
76 p4.verify_share(&s2, &distribute_shares_box, &s2.publickey),
77 true
78 );
79
80 let share_boxs = [s1.clone(), s2.clone(), s4.clone()];
81 let r1 = p1.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
82 let r2 = p2.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
83 let r3 = p3.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
84 let r4 = p4.reconstruct(&share_boxs, &distribute_shares_box).unwrap();
85
86 let r1_str = string_from_secret(&r1);
87 assert_eq!(secret_message.clone(), r1_str);
88 let r2_str = string_from_secret(&r2);
89 assert_eq!(secret_message.clone(), r2_str);
90 let r3_str = string_from_secret(&r3);
91 assert_eq!(secret_message.clone(), r3_str);
92 let r4_str = string_from_secret(&r4);
93 assert_eq!(secret_message.clone(), r4_str);
94
95 println!("secret message: {}", secret_message);
96 println!("r1 str: {}", r1_str);
97 println!("r2 str: {}", r2_str);
98 println!("r3 str: {}", r3_str);
99 println!("r3 str: {}", r4_str);
100}
Trait Implementations§
Source§impl Clone for Participant
impl Clone for Participant
Source§fn clone(&self) -> Participant
fn clone(&self) -> Participant
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read more