Skip to main content

Polynomial

Struct Polynomial 

Source
pub struct Polynomial {
    pub points: Vec<PointInFiniteField>,
    pub threshold: usize,
}
Expand description

Polynomial over GF(p) represented by its evaluation points.

Used for Lagrange interpolation in Shamir’s Secret Sharing. The polynomial passes through the stored points and can be evaluated at any x value using Lagrange interpolation.

Fields§

§points: Vec<PointInFiniteField>§threshold: usize

Implementations§

Source§

impl Polynomial

Source

pub fn new(points: Vec<PointInFiniteField>, threshold: Option<usize>) -> Self

Create a new polynomial from points with optional threshold.

If threshold is not specified, it defaults to the number of points.

Source

pub fn from_private_key(key_bytes: &[u8], threshold: usize) -> Self

Create a polynomial from a private key for Shamir’s Secret Sharing.

The private key value is the y-intercept (x=0, y=key). Additional (threshold - 1) random points are generated.

Source

pub fn value_at(&self, x: &BigNumber) -> BigNumber

Evaluate the polynomial at x using Lagrange interpolation.

Uses the stored points and Lagrange basis polynomials to compute the polynomial’s value at the given x coordinate. All arithmetic is performed mod p (secp256k1 field prime).

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.