#secret-sharing #finite-fields #shamir #field #verifiable #prime

shamir_secret_sharing

A rust implementation of Shamir Secret Sharing over Finite Field

2 releases

0.1.1 Apr 2, 2020
0.1.0 Apr 2, 2020

#13 in #shamir

Download history 143/week @ 2024-11-24 280/week @ 2024-12-01 112/week @ 2024-12-08 66/week @ 2024-12-15 94/week @ 2024-12-22 73/week @ 2024-12-29 178/week @ 2025-01-05 37/week @ 2025-01-12 249/week @ 2025-01-19 112/week @ 2025-01-26 52/week @ 2025-02-02 115/week @ 2025-02-09 106/week @ 2025-02-16 32/week @ 2025-02-23 134/week @ 2025-03-02 85/week @ 2025-03-09

379 downloads per month
Used in spark-rust

MIT license

11KB
155 lines

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]));
}

Dependencies

~0.8–1.1MB
~20K SLoC