Scheme

Struct Scheme 

Source
pub struct Scheme { /* private fields */ }
Expand description

The main struct implementing Shamir’s Secret Sharing scheme

Implementations§

Source§

impl Scheme

Source

pub fn new( threshold: usize, total_shares: usize, prime_modulus: BigUint, ) -> Result<Self, SssError>

Creates a new Shamir’s Secret Sharing scheme with the specified parameters.

§Arguments
  • threshold - Minimum number of shares needed to reconstruct the secret (k)
  • total_shares - Total number of shares to generate (n)
  • prime_modulus - Prime number defining the finite field. Must be larger than both the secret and total_shares.
§Returns
  • Ok(Scheme) - If parameters are valid
  • Err(SssError::InvalidThreshold) - If threshold is 0 or greater than total_shares
§Example
use num_bigint::BigUint;
use shamir_rs::Scheme;
 
let prime = BigUint::from(257u32);
let scheme = Scheme::new(3, 5, prime).unwrap();
Source

pub fn split_secret(&self, secret: &BigUint) -> Vec<Share>

Splits a secret into n shares where k shares are required to reconstruct.

§Arguments
  • secret - The secret to split. Must be less than prime_modulus.
§Returns

A vector of n shares. Each share is a point on a random polynomial of degree k-1 where the constant term is the secret.

§Example
let secret = BigUint::from(123u32);
let shares = scheme.split_secret(&secret);
assert_eq!(shares.len(), 5);
Source

pub fn reconstruct_secret(&self, shares: &[Share]) -> Result<BigUint, SssError>

Reconstructs a secret from k or more shares using Lagrange interpolation.

§Arguments
  • shares - Slice of shares to use for reconstruction. Must contain at least k shares with unique indices.
§Returns
  • Ok(BigUint) - The reconstructed secret
  • Err(SssError::NotEnoughShares) - If fewer than k shares provided
  • Err(SssError::DuplicateShares) - If shares contain duplicate indices
§Example
let reconstructed = scheme.reconstruct_secret(&shares[0..3]).unwrap();
assert_eq!(reconstructed, secret);

Trait Implementations§

Source§

impl Debug for Scheme

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Scheme

§

impl RefUnwindSafe for Scheme

§

impl Send for Scheme

§

impl Sync for Scheme

§

impl Unpin for Scheme

§

impl UnwindSafe for Scheme

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V