mirror of
https://github.com/mii443/RustySecrets.git
synced 2025-08-22 16:25:32 +00:00
Remove DuplicateShareData
error and validation
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.
This commit is contained in:
committed by
Romain Ruetschi
parent
ed867ba938
commit
cdcf012a59
@ -118,11 +118,6 @@ error_chain! {
|
||||
display("This share number ({}) has already been used by a previous share.", share_id)
|
||||
}
|
||||
|
||||
DuplicateShareData(share_id: u8) {
|
||||
description("The data encoded in this share is the same as the one found in a previous share")
|
||||
display("The data encoded in share #{} is the same as the one found in a previous share.", share_id)
|
||||
}
|
||||
|
||||
InconsistentShares {
|
||||
description("The shares are inconsistent")
|
||||
display("The shares are inconsistent")
|
||||
|
@ -55,11 +55,6 @@ pub(crate) fn validate_shares<S: IsShare>(shares: Vec<S>) -> Result<(u8, Vec<S>)
|
||||
bail!(ErrorKind::ShareParsingErrorEmptyShare(id))
|
||||
}
|
||||
|
||||
if result.iter().any(|s| s.get_data() == share.get_data()) && share.get_threshold() != 1 {
|
||||
// When threshold = 1, shares data can be the same
|
||||
bail!(ErrorKind::DuplicateShareData(id));
|
||||
}
|
||||
|
||||
result.push(share);
|
||||
}
|
||||
|
||||
|
@ -66,17 +66,6 @@ fn test_recover_duplicate_shares_number() {
|
||||
recover_secret(&shares, false).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "DuplicateShareData")]
|
||||
fn test_recover_duplicate_shares_data() {
|
||||
let share1 = "2-1-CgnlCxRNtnkzENE".to_string();
|
||||
let share2 = "2-2-CgnlCxRNtnkzENE".to_string();
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(&shares, false).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "MissingShares")]
|
||||
fn test_recover_too_few_shares() {
|
||||
|
@ -135,32 +135,6 @@ fn test_recover_duplicate_shares_number() {
|
||||
recover_secret(&shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "DuplicateShareData")]
|
||||
fn test_recover_duplicate_shares_data() {
|
||||
let hash = get_test_hash();
|
||||
let share1 = Share {
|
||||
id: 1,
|
||||
threshold: TEST_THRESHOLD,
|
||||
shares_count: TEST_SHARES_COUNT,
|
||||
data: "1YAYwmOHqZ69jA".to_string().into_bytes(),
|
||||
hash: hash.clone(),
|
||||
metadata: None,
|
||||
};
|
||||
let share2 = Share {
|
||||
id: 2,
|
||||
threshold: TEST_THRESHOLD,
|
||||
shares_count: TEST_SHARES_COUNT,
|
||||
data: "1YAYwmOHqZ69jA".to_string().into_bytes(),
|
||||
hash: hash.clone(),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(&shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "MissingShares")]
|
||||
fn test_recover_too_few_shares() {
|
||||
|
@ -106,29 +106,6 @@ fn test_recover_duplicate_shares_number() {
|
||||
recover_secret(&shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "DuplicateShareData")]
|
||||
fn test_recover_duplicate_shares_data() {
|
||||
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: "1YAYwmOHqZ69jA".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() {
|
||||
|
Reference in New Issue
Block a user