Skip to main content

ShamirSecretShare

Struct ShamirSecretShare 

Source
pub struct ShamirSecretShare {
    pub p: u64,
    pub k: usize,
    pub n: usize,
}
Expand description

Shamir’s Secret Sharing over a finite field Z_p.

Splits a secret s into n shares such that any k shares can reconstruct s via Lagrange interpolation, but any k-1 shares reveal nothing about s.

§WARNING

Educational implementation. The polynomial coefficients are NOT generated with cryptographically secure randomness. Do NOT use for real secrets.

Fields§

§p: u64

Prime modulus p (field F_p)

§k: usize

Threshold k: minimum shares needed for reconstruction

§n: usize

Total shares n

Implementations§

Source§

impl ShamirSecretShare

Source

pub fn new(p: u64, k: usize, n: usize) -> Self

Create a new Shamir secret sharing instance.

Source

pub fn share(&self, secret: u64, seed: u64) -> Vec<(u64, u64)>

Split a secret s into n shares using a deterministic polynomial with coefficients derived from seed (for reproducibility in tests).

Returns a vector of (x, y) pairs where x = 1..=n and y = f(x).

§WARNING

The seed-based coefficient generation is NOT secure. Real Shamir’s scheme requires cryptographically random coefficients.

Source

pub fn reconstruct(&self, shares: &[(u64, u64)]) -> Option<u64>

Reconstruct the secret from any k shares using Lagrange interpolation over F_p.

Each share is an (x, y) pair. Computes f(0) = Σ y_i * L_i(0) mod p.

Auto Trait Implementations§

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.