An implementation of a secret sharing scheme in Rust.
wrappedsharing contains wrapper functions that wrap around the functionality in basicsharing, which includes using a hash placed at the end to automatically verify if the secret was properly reconstructed.
This implementation uses arithmetic over GF(256), shares using wrapped_sharing use a 64-byte hash placed at the end of the of the secret before sharing that gets shared with it. This way, the reconstruction of the secret can be verified by the hash. This along with a share's corresponding X-value, puts each share at [[1-byte X value]] + [[N-byte Secret]] + [[64-byte hash]]
Notably, given N required shares to reconstruct, and M shares generated, any X number of shares where N <= X <= M can be used, without the need of specifying how many were required (using more shares however will increase reconstruction time). This goes for both wrappedsharing and basicsharing.
rust
use wrapped_sharing::{Secret, share};
let shares_required = 3;
let shares_to_create = 3;
let secret: Vec<u8> = vec![5, 4, 9, 1, 2, 128, 43];
let shares = share(Secret::InMemory(secret), shares_required, shares_to_create).unwrap();
let mut recon = Secret::empty_in_memory();
recon.reconstruct(shares);
assert_eq!(secret, recon.unwrap_vec());
```rust
// While this just uses a single secret sharing function, there are variants for Vec
let shares: Vec<(u8, u8)> = fromsecret(secret, sharesrequired, sharestocreate, Some(rand)).unwrap(); let secretrecon = reconstructsecret(shares);
asserteq!(secret, secretrecon); ```