pub struct Poly { /* private fields */ }Expand description
A univariate polynomial in the prime field.
Polynomials are used for secret sharing in threshold cryptography. A polynomial
of degree t can be used to create n shares such that any t + 1 shares
can reconstruct the secret (the polynomial’s value at 0).
§Example
use threshold_pairing::poly::Poly;
// Create a random polynomial of degree 2
let mut rng = rand::thread_rng();
let poly = Poly::random(2, &mut rng);
// Evaluate the polynomial at different points
let y1 = poly.evaluate(1u64);
let y2 = poly.evaluate(2u64);
// Get the corresponding public commitment
let commitment = poly.commitment();
assert_eq!(poly.degree(), commitment.degree());§Security
The polynomial coefficients are zeroized on drop to prevent secret leakage.
Implementations§
Source§impl Poly
impl Poly
Sourcepub fn random<R: RngCore>(degree: usize, rng: &mut R) -> Self
pub fn random<R: RngCore>(degree: usize, rng: &mut R) -> Self
Creates a random polynomial.
§Panics
Panics if the degree is too large for the coefficients to fit into a Vec.
Sourcepub fn try_random<R: RngCore>(degree: usize, rng: &mut R) -> Result<Self>
pub fn try_random<R: RngCore>(degree: usize, rng: &mut R) -> Result<Self>
Creates a random polynomial. This constructor is identical to the Poly::random()
constructor in every way except that this constructor will return an Err where
try_random would return an error.
Sourcepub fn interpolate<T, U, I>(samples_repr: I) -> Self
pub fn interpolate<T, U, I>(samples_repr: I) -> Self
Returns the unique polynomial f of degree samples.len() - 1 with the given values
(x, f(x)).
Sourcepub fn evaluate<T: IntoScalar>(&self, i: T) -> Scalar
pub fn evaluate<T: IntoScalar>(&self, i: T) -> Scalar
Returns the value at the point i.
Sourcepub fn commitment(&self) -> Commitment
pub fn commitment(&self) -> Commitment
Returns the corresponding commitment.
Trait Implementations§
Source§impl<B: Borrow<Poly>> AddAssign<B> for Poly
impl<B: Borrow<Poly>> AddAssign<B> for Poly
Source§fn add_assign(&mut self, rhs: B)
fn add_assign(&mut self, rhs: B)
+= operation. Read moreSource§impl Debug for Poly
A debug statement where the coeff vector of prime field elements has been redacted.
impl Debug for Poly
A debug statement where the coeff vector of prime field elements has been redacted.
Source§impl<'de> Deserialize<'de> for Poly
impl<'de> Deserialize<'de> for Poly
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<Poly> for SecretKeySet
impl From<Poly> for SecretKeySet
Source§fn from(poly: Poly) -> SecretKeySet
fn from(poly: Poly) -> SecretKeySet
Source§impl From<Vec<Scalar>> for Poly
Creates a new Poly instance from a vector of prime field elements representing the
coefficients of the polynomial.
impl From<Vec<Scalar>> for Poly
Creates a new Poly instance from a vector of prime field elements representing the
coefficients of the polynomial.
Source§impl<B: Borrow<Self>> MulAssign<B> for Poly
impl<B: Borrow<Self>> MulAssign<B> for Poly
Source§fn mul_assign(&mut self, rhs: B)
fn mul_assign(&mut self, rhs: B)
*= operation. Read moreSource§impl MulAssign<Scalar> for Poly
impl MulAssign<Scalar> for Poly
Source§fn mul_assign(&mut self, rhs: Scalar)
fn mul_assign(&mut self, rhs: Scalar)
*= operation. Read moreSource§impl<B: Borrow<Poly>> SubAssign<B> for Poly
impl<B: Borrow<Poly>> SubAssign<B> for Poly
Source§fn sub_assign(&mut self, rhs: B)
fn sub_assign(&mut self, rhs: B)
-= operation. Read moreimpl Eq for Poly
impl StructuralPartialEq for Poly
Auto Trait Implementations§
impl Freeze for Poly
impl RefUnwindSafe for Poly
impl Send for Poly
impl Sync for Poly
impl Unpin for Poly
impl UnsafeUnpin for Poly
impl UnwindSafe for Poly
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.