shamir_secret_sharing

Crates.ioshamir_secret_sharing
lib.rsshamir_secret_sharing
version0.1.1
sourcesrc
created_at2020-04-02 12:53:13.767508
updated_at2020-04-02 12:59:45.124798
descriptionA rust implementation of Shamir Secret Sharing over Finite Field.
homepage
repositoryhttps://github.com/bitrocks/shamir-secret-sharing
max_upload_size
id225504
size10,041
Peng Hu (bitrocks)

documentation

https://docs.rs/shamir_secret_sharing

README

Shamir Secret Sharing(Rust)

Intro

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

Example

use shamir_secret_sharing::ShamirSecretSharing as SSS;
use num_bigint::{BigInt, BigUint};
use num_bigint::Sign::*;
fn main() {
let sss = SSS {
    threshold: 3,
    share_amount: 5,
    prime: BigInt::parse_bytes(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]));
}

Commit count: 11

cargo fmt