Struct mpvss_rs::Participant
source · 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();
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();
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,
);
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();
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
);
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
);
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);
Trait Implementations§
source§impl Clone for Participant
impl Clone for Participant
source§fn clone(&self) -> Participant
fn clone(&self) -> Participant
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more