string_to_secret

Function string_to_secret 

Source
pub fn string_to_secret(message: &str) -> BigInt
Examples found in repository?
examples/mpvss_all.rs (line 20)
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
Hide additional examples
examples/mpvss_sub.rs (line 22)
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}