Expand description
Fast, small and secure Shamir’s Secret Sharing library crate
§Usage
§(std)
use ssskit::{ SecretSharing, Share };
// Set a minimum threshold of 10 shares for an irreducible polynomial POLY
let sss = SecretSharing::<POLY>(10);
// Obtain an iterator over the shares for secret [1, 2, 3, 4]
let dealer = sss.dealer(&[1, 2, 3, 4]);
// Get 10 shares
let shares = dealer.take(10).collect::<Vec<Share<POLY>>>();
// Recover the original secret!
let secret = sss.recover(shares.as_slice()).unwrap();
assert_eq!(secret, vec![1, 2, 3, 4]);§(no std)
use ssskit::{ SecretSharing, Share };
use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng};
// Set a minimum threshold of 10 shares
let sss = SecretSharing::<POLY>(10);
// Obtain an iterator over the shares for secret [1, 2, 3, 4]
let mut rng = rand_chacha::ChaCha8Rng::from_seed([0x90; 32]);
let dealer = sss.dealer_rng::<ChaCha8Rng>(&[1, 2, 3, 4], &mut rng);
// Get 10 shares
let shares = dealer.take(10).collect::<Vec<Share<POLY>>>();
// Recover the original secret!
let secret = sss.recover(shares.as_slice()).unwrap();
assert_eq!(secret, vec![1, 2, 3, 4]);§Irreducible Polynomials
This crate supports all 30 degree-8 irreducible polynomials over GF(2).
See the exported list PRIMITIVE_POLYS (defined in field.rs).
Commonly used polynomials:
- 0x11B — used in AES (Rijndael)
- 0x11D — commonly used in Reed–Solomon (e.g., QR codes)
Structs§
- Secret
Sharing - Tuple struct which implements methods to generate shares and recover secrets over a 256 bits Galois Field. Its only parameter is the minimum shares threshold.
- Share
- A share used to reconstruct the secret. Can be serialized to and from a byte array.
Constants§
- PRIMITIVE_
POLYS - Known primitive degree-8 polynomials over GF(2).
Any
POLYmust be one of these to give a field with multiplicative group of order 255.