A rust implementation of Shamir Secret Sharing over Finite Field.
The lib support large field charactirics prime
by taking advantage of num_bigint
.
It's not optimized for production purpose, which can be improved in several aspects:
replace the extended_euclid_algo
with machine-friendly stein_algo
when calculate the modulo inverse
add commitment scheme to make it verifiable
``` rust use shamirsecretsharing::ShamirSecretSharing as SSS; use numbigint::{BigInt, BigUint}; use numbigint::Sign::*; fn main() { let sss = SSS { threshold: 3, shareamount: 5, prime: BigInt::parsebytes(b"fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",16).unwrap() };
let secret = BigInt::parse_bytes(b"ffffffffffffffffffffffffffffffffffffff", 16).unwrap();
let shares = sss.split(secret.clone());
println!("shares: {:?}", shares); assert_eq!(secret, sss.recover(&shares[0..sss.threshold as usize])); }
```