mirror of
https://github.com/mii443/RustySecrets.git
synced 2025-08-22 16:25:32 +00:00
It's possible that two different points have the same data. To give a concrete example consider the secret polynomial `x^2 + x + s`, where `s` is the secret byte. Plugging in 214 and 215 (both elements of the cyclic subgroup of order 2) for `x` will give the same result, `1 + s`. More broadly, for any polynomial `b*x^t + b*x^(t-1) + ... + x + s`, where `t` is the order of at least one subgroup of GF(256), for all subgroups of order `t`, all elements of that subgroup, when chosen for `x`, will produce the same result. There are certainly other types of polynomials that have "share collisions." This type was just easy to find because it exploits the nature of finite fields.
131 lines
3.0 KiB
Rust
131 lines
3.0 KiB
Rust
#![cfg(feature = "dss")]
|
|
|
|
extern crate rusty_secrets;
|
|
|
|
use rusty_secrets::dss::thss::{recover_secret, Share};
|
|
|
|
#[test]
|
|
#[should_panic(expected = "EmptyShares")]
|
|
fn test_recover_no_shares() {
|
|
let shares = vec![];
|
|
recover_secret(&shares).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
#[should_panic(expected = "ShareParsingErrorEmptyShare")]
|
|
fn test_recover_2_parts_share() {
|
|
let share1 = Share {
|
|
id: 1,
|
|
threshold: 2,
|
|
shares_count: 2,
|
|
data: "CgmKQZHMO+5n5pU".to_string().into_bytes(),
|
|
metadata: None,
|
|
};
|
|
let share2 = Share {
|
|
id: 2,
|
|
threshold: 2,
|
|
shares_count: 2,
|
|
data: "".to_string().into_bytes(),
|
|
metadata: None,
|
|
};
|
|
|
|
let shares = vec![share1, share2];
|
|
|
|
recover_secret(&shares).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
#[should_panic(expected = "ShareParsingInvalidShareId")]
|
|
fn test_recover_0_share_num() {
|
|
let share1 = Share {
|
|
id: 0,
|
|
threshold: 2,
|
|
shares_count: 2,
|
|
data: "1YAYwmOHqZ69jA".to_string().into_bytes(),
|
|
metadata: None,
|
|
};
|
|
let share2 = Share {
|
|
id: 1,
|
|
threshold: 2,
|
|
shares_count: 2,
|
|
data: "YJZQDGm22Y77Gw".to_string().into_bytes(),
|
|
metadata: None,
|
|
};
|
|
|
|
let shares = vec![share1, share2];
|
|
|
|
recover_secret(&shares).unwrap();
|
|
}
|
|
|
|
// ---
|
|
// TODO: will be implemented when serialization is done for thss shares
|
|
// ---
|
|
// #[test]
|
|
// #[should_panic(expected = "ShareParsingError")]
|
|
// fn test_recover_invalid_b64() {
|
|
// let share1 = Share {
|
|
// id: 1,
|
|
// threshold: 2,
|
|
// shares_count: 2,
|
|
// data: "1YAYwmOHqZ69jA".to_string().into_bytes(),
|
|
// metadata: None
|
|
// };
|
|
// let share2 = Share {
|
|
// id: 2,
|
|
// threshold: 2,
|
|
// shares_count: 2,
|
|
// data: "YJZQDG((((m22Y)))77Gw".to_string().into_bytes(),
|
|
// metadata: None
|
|
// };
|
|
//
|
|
// let shares = vec![share1, share2];
|
|
//
|
|
// recover_secret(&shares).unwrap();
|
|
// }
|
|
|
|
#[test]
|
|
#[should_panic(expected = "DuplicateShareId")]
|
|
fn test_recover_duplicate_shares_number() {
|
|
let share1 = Share {
|
|
id: 1,
|
|
threshold: 2,
|
|
shares_count: 2,
|
|
data: "1YAYwmOHqZ69jA".to_string().into_bytes(),
|
|
metadata: None,
|
|
};
|
|
let share2 = Share {
|
|
id: 1,
|
|
threshold: 2,
|
|
shares_count: 2,
|
|
data: "YJZQDGm22Y77Gw".to_string().into_bytes(),
|
|
metadata: None,
|
|
};
|
|
|
|
let shares = vec![share1, share2];
|
|
|
|
recover_secret(&shares).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
#[should_panic(expected = "MissingShares")]
|
|
fn test_recover_too_few_shares() {
|
|
let share1 = Share {
|
|
id: 1,
|
|
threshold: 3,
|
|
shares_count: 3,
|
|
data: "1YAYwmOHqZ69jA".to_string().into_bytes(),
|
|
metadata: None,
|
|
};
|
|
let share2 = Share {
|
|
id: 2,
|
|
threshold: 3,
|
|
shares_count: 3,
|
|
data: "YJZQDGm22Y77Gw".to_string().into_bytes(),
|
|
metadata: None,
|
|
};
|
|
|
|
let shares = vec![share1, share2];
|
|
|
|
recover_secret(&shares).unwrap();
|
|
}
|