|
@@ -12,7 +12,7 @@ pub struct Share {
|
|
|
value: Scalar,
|
|
|
}
|
|
|
|
|
|
-type Commitment = Vec<RistrettoPoint>;
|
|
|
+pub struct Commitment(Vec<RistrettoPoint>);
|
|
|
|
|
|
/// Create secret shares for a given secret.
|
|
|
pub fn generate_shares(
|
|
@@ -38,7 +38,7 @@ pub fn generate_shares(
|
|
|
|
|
|
let mut shares: Vec<Share> = Vec::with_capacity(numshares as usize);
|
|
|
|
|
|
- let mut commitment: Commitment = Vec::with_capacity(threshold as usize);
|
|
|
+ let mut commitment = Commitment(Vec::with_capacity(threshold as usize));
|
|
|
|
|
|
for _ in 0..numcoeffs {
|
|
|
coefficients.push(Scalar::random(&mut rng));
|
|
@@ -61,9 +61,9 @@ pub fn generate_shares(
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- commitment.push(RISTRETTO_BASEPOINT_POINT * secret);
|
|
|
+ commitment.0.push(RISTRETTO_BASEPOINT_POINT * secret);
|
|
|
for c in coefficients {
|
|
|
- commitment.push(RISTRETTO_BASEPOINT_POINT * c);
|
|
|
+ commitment.0.push(RISTRETTO_BASEPOINT_POINT * c);
|
|
|
}
|
|
|
|
|
|
Ok((commitment, shares))
|
|
@@ -75,7 +75,7 @@ pub fn verify_share(share: &Share, commitment: &Commitment) -> Result<bool, &'st
|
|
|
|
|
|
let x = Scalar::from(share.index);
|
|
|
|
|
|
- let (_, result) = commitment.iter().fold(
|
|
|
+ let (_, result) = commitment.0.iter().fold(
|
|
|
(Scalar::one(), RistrettoPoint::identity()),
|
|
|
|(x_to_the_i, sum_so_far), comm_i| (x_to_the_i * x, sum_so_far + x_to_the_i * comm_i),
|
|
|
);
|
|
@@ -132,10 +132,10 @@ pub fn apply_commitment_update(
|
|
|
old_commitment: &Commitment,
|
|
|
update: &Commitment,
|
|
|
) -> Result<Commitment, &'static str> {
|
|
|
- let mut new_commitments: Commitment = Vec::with_capacity(old_commitment.len());
|
|
|
- for i in 0..old_commitment.len() {
|
|
|
- let new_commitment = old_commitment[i] + update[i];
|
|
|
- new_commitments.push(new_commitment);
|
|
|
+ let mut new_commitments = Commitment(Vec::with_capacity(old_commitment.0.len()));
|
|
|
+ for i in 0..old_commitment.0.len() {
|
|
|
+ let new_commitment = old_commitment.0[i] + update.0[i];
|
|
|
+ new_commitments.0.push(new_commitment);
|
|
|
}
|
|
|
|
|
|
Ok(new_commitments)
|
|
@@ -176,7 +176,7 @@ mod tests {
|
|
|
assert!(res.is_ok());
|
|
|
let (com, shares) = res.unwrap();
|
|
|
assert!(shares.len() == 5);
|
|
|
- assert!(com.len() == 2);
|
|
|
+ assert!(com.0.len() == 2);
|
|
|
|
|
|
let mut recshares: Vec<Share> = Vec::new();
|
|
|
recshares.push(shares[1]);
|