Struct mpvss_rs::Participant[][src]

pub struct Participant {
    pub privatekey: BigInt,
    pub publickey: BigInt,
    // some fields omitted
}

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: BigIntpublickey: BigInt

Implementations

impl Participant[src]

pub fn new() -> Self[src]

Create A default participant

Example

use mpvss_rs::Participant;
let mut dealer = Participant::new();

pub fn initialize(&mut self)[src]

Initializes a new participant with the default MPVSS.

Example

use mpvss_rs::Participant;
let mut dealer = Participant::new();
dealer.initialize();

pub fn distribute_secret(
    &mut self,
    secret: BigInt,
    publickeys: Vec<BigInt>,
    threshold: u32
) -> DistributionSharesBox
[src]

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,
);

pub fn extract_secret_share(
    &self,
    shares_box: &DistributionSharesBox,
    private_key: &BigInt
) -> Option<ShareBox>
[src]

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();

pub fn verify_distribution_shares(
    &self,
    distribute_sharesbox: &DistributionSharesBox
) -> bool
[src]

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 and false 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
);

pub fn verify_share(
    &self,
    sharebox: &ShareBox,
    distribution_sharebox: &DistributionSharesBox,
    publickey: &BigInt
) -> bool
[src]

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 and false 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
  );

pub fn reconstruct(
    &self,
    share_boxs: &[ShareBox],
    distribute_share_box: &DistributionSharesBox
) -> Option<BigInt>
[src]

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);

pub fn reconstruct_parallelized(
    &self,
    share_boxs: &[ShareBox],
    distribute_share_box: &DistributionSharesBox
) -> Option<BigInt>
[src]

Reconstruct secret from share boxs using multi-threads

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_parallelized(&share_boxs, &distribute_shares_box)
    .unwrap();
let r2 = p2
    .reconstruct_parallelized(&share_boxs, &distribute_shares_box)
    .unwrap();
let r3 = p3
    .reconstruct_parallelized(&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

impl Clone for Participant[src]

impl Debug for Participant[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.