An implementation of a secret sharing scheme in Rust.
wrappedsharing contains wrapper functions that wrap around the functionality in basicsharing, which can include using a hash placed at the end to automatically verify if the secret was properly reconstructed, ease of 'compressing' the shares by not requiring an X-value for every Y-value, and sharing/reconstructing to and from memory and files interchangeably.
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 (optional)]]
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 verify = true;
let secret: Vec<u8> = vec![5, 4, 9, 1, 2, 128, 43];
let shares = share(Secret::InMemory(secret), shares_required, shares_to_create, verify).unwrap();
let mut recon = Secret::empty_in_memory();
recon.reconstruct(shares);
assert_eq!(secret, recon.unwrap_vec());
```rust
use basicsharing::{fromsecret, reconstructsecret};
// 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); ```