Skip to content

Commit

Permalink
Fix unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
lthibault committed Sep 17, 2024
1 parent 605447b commit c264d9c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/qos_crypto/src/shamir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,36 +186,36 @@ mod test {
// Reconstruct with all the shares
let shares = all_shares.clone();
let reconstructed = shares_reconstruct(&shares).unwrap();
let old_reconstructed = deprecated_insecure_shares_reconstruct(&shares);
let old_reconstructed = shares_reconstruct(&shares).unwrap();
assert_eq!(secret.to_vec(), reconstructed);
assert_eq!(secret.to_vec(), old_reconstructed);

// Reconstruct with enough shares
let shares = &all_shares[..k];
let reconstructed = shares_reconstruct(shares).unwrap();
let old_reconstructed = deprecated_insecure_shares_reconstruct(shares);
let old_reconstructed = shares_reconstruct(shares).unwrap();
assert_eq!(secret.to_vec(), reconstructed);
assert_eq!(secret.to_vec(), old_reconstructed);

// Reconstruct with not enough shares
let shares = &all_shares[..(k - 1)];
let reconstructed = shares_reconstruct(shares).unwrap();
let old_reconstructed = deprecated_insecure_shares_reconstruct(shares);
let old_reconstructed = shares_reconstruct(shares).unwrap();
assert!(secret.to_vec() != reconstructed);
assert!(secret.to_vec() != old_reconstructed);

// Reconstruct with enough shuffled shares
let mut shares = all_shares.clone()[..k].to_vec();
shares.shuffle(&mut rand::thread_rng());
let reconstructed = shares_reconstruct(&shares).unwrap();
let old_reconstructed = deprecated_insecure_shares_reconstruct(&shares);
let old_reconstructed = shares_reconstruct(&shares).unwrap();
assert_eq!(secret.to_vec(), reconstructed);
assert_eq!(secret.to_vec(), old_reconstructed);

for combo in crate::n_choose_k::combinations(&all_shares, k) {
let reconstructed = shares_reconstruct(&combo).unwrap();
let old_reconstructed =
deprecated_insecure_shares_reconstruct(&shares);
shares_reconstruct(&shares).unwrap();
assert_eq!(secret.to_vec(), reconstructed);
assert_eq!(secret.to_vec(), old_reconstructed);
}
Expand Down

0 comments on commit c264d9c

Please sign in to comment.